Allow apps to provide customized ViewHolders #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi! This is a great library you've made---and it's the only one I could find with this type of functionality, which surprised me.
I'm using StfalconImageViewer with the camera function in my app to let users view the images they've taken. I'm expanding to include video recording, so I'd like users to be able to view both photos and videos in the same pop-up viewer. After a few attempts, I made what I think are useful, generally-applicable changes to StfalconImageViewer to enable my use case and many others. These changes do not affect existing users of the library or significantly increase the library's scope, which I think makes them a candidate for merging.
In short, the image viewer currently uses a
ViewHolder
, holding aPhotoView
, along with theImagesPagerAdapter
andMultiTouchViewPager
. My changes add aViewHolderLoader
interface and an optional additional argument to theBuilder
, allowing apps to pass in aViewHolderLoader
. This loader, or a default loader if none is passed, providesViewHolders
toImagesPagerAdapter
. Apps that choose to implement aViewHolderLoader
can then have their implementation return a subclass of the defaultViewHolder
which customizes the paging views as desired. A few additional details are described in the commit message.In my video use case, my custom
ViewHolder
puts the usualPhotoView
in aFrameLayout
along with aVideoView
, and then inbind()
it displays one view or the other as appropriate.Other use cases might want to customize each Pager page with additional views (e.g. a caption or a "new image!" icon) which scroll with the images---as opposed to placing that extra content in an overlay view, where the content would be statically positioned.
I created a repo demonstrating the use of these changes. It replicates my mixed photos/videos use case and shows how additional views (in the demo, a TextView) can add content alongside the image on each page.
This was my first time working with Kotlin, so I'm very open to suggested revisions.