Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overload setCurrentPosition() to allow disabling the scroll animation #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ internal class ImageViewerDialog<T>(
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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ internal class ImageViewerView<T> @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

Expand Down