diff --git a/README.md b/README.md index 83236edd..7a63ea3a 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ If you need more advanced behavior like updating transition target while changin There are a lot of common cases (such as pagination, deleting, editing etc.) where you need to update the existing images list while the viewer is running. To do this you can simply update the existing list (or even replace it with a new one) and then call `updateImages(images)`. #### Change current image -Images are not always leafed through by the user. Maybe you want to implement some kind of preview list at the bottom of the viewer - `setCurrentPosition` is here for help. Change images programmatically wherever you want! +Images are not always leafed through by the user. Maybe you want to implement some kind of preview list at the bottom of the viewer - `setCurrentPosition` is here for help. Change images programmatically wherever you want! Set the optional second argument to false to disable the scroll animation while the image changes. #### Custom overlay view If you need to show some content over the image (e.g. sharing or download button, description, numeration etc.) you can set your own custom view using the `setOverlayView(customView)` and bind it with the viewer through the `ImageViewer.OnImageChangeListener`. diff --git a/imageviewer/src/main/java/com/stfalcon/imageviewer/StfalconImageViewer.java b/imageviewer/src/main/java/com/stfalcon/imageviewer/StfalconImageViewer.java index 61d8179a..46931a25 100644 --- a/imageviewer/src/main/java/com/stfalcon/imageviewer/StfalconImageViewer.java +++ b/imageviewer/src/main/java/com/stfalcon/imageviewer/StfalconImageViewer.java @@ -103,8 +103,12 @@ public int currentPosition() { return dialog.getCurrentPosition(); } - public int setCurrentPosition(int position){ - return dialog.setCurrentPosition(position); + public int setCurrentPosition(int position, boolean smoothScroll) { + return dialog.setCurrentPosition(position, smoothScroll); + } + + public int setCurrentPosition(int position) { + return setCurrentPosition(position, true); } /** diff --git a/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/dialog/ImageViewerDialog.kt b/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/dialog/ImageViewerDialog.kt index bfb14f57..fb627778 100644 --- a/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/dialog/ImageViewerDialog.kt +++ b/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/dialog/ImageViewerDialog.kt @@ -72,8 +72,8 @@ internal class ImageViewerDialog( fun getCurrentPosition(): Int = viewerView.currentPosition - fun setCurrentPosition(position: Int): Int { - viewerView.currentPosition = position + fun setCurrentPosition(position: Int, smoothScroll: Boolean): Int { + viewerView.setCurrentPosition(position, smoothScroll) return viewerView.currentPosition } diff --git a/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/view/ImageViewerView.kt b/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/view/ImageViewerView.kt index 796d1d0b..c1ed6a4e 100644 --- a/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/view/ImageViewerView.kt +++ b/imageviewer/src/main/java/com/stfalcon/imageviewer/viewer/view/ImageViewerView.kt @@ -64,6 +64,10 @@ internal class ImageViewerView @JvmOverloads constructor( imagesPager.currentItem = value } + fun setCurrentPosition(position: Int, smoothScroll: Boolean) { + imagesPager.setCurrentItem(position, smoothScroll) + } + internal var onDismiss: (() -> Unit)? = null internal var onPageChange: ((position: Int) -> Unit)? = null