StfalconImageViewer icon indicating copy to clipboard operation
StfalconImageViewer copied to clipboard

Allow apps to provide customized ViewHolders

Open svank opened this issue 7 years ago • 1 comments

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 a PhotoView, along with the ImagesPagerAdapter and MultiTouchViewPager. My changes add a ViewHolderLoader interface and an optional additional argument to the Builder, allowing apps to pass in a ViewHolderLoader. This loader, or a default loader if none is passed, provides ViewHolders to ImagesPagerAdapter. Apps that choose to implement a ViewHolderLoader can then have their implementation return a subclass of the default ViewHolder 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 usual PhotoView in a FrameLayout along with a VideoView, and then in bind() 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.

svank avatar Mar 25 '19 01:03 svank

nice work bro

mrkazansky avatar May 13 '19 03:05 mrkazansky