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

Make smooth animation of different image scale type #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import android.view.ViewGroup
import android.view.animation.DecelerateInterpolator
import android.widget.FrameLayout
import android.widget.ImageView
import androidx.transition.AutoTransition
import androidx.transition.Transition
import androidx.transition.TransitionManager
import androidx.transition.*
import com.stfalcon.imageviewer.common.extensions.*

internal class TransitionImageAnimator(
Expand Down Expand Up @@ -91,6 +89,7 @@ internal class TransitionImageAnimator(

internalImageContainer.makeViewMatchParent()
internalImage.makeViewMatchParent()
internalImage.scaleType = ImageView.ScaleType.FIT_CENTER

internalRoot.applyMargin(
containerPadding[0],
Expand Down Expand Up @@ -126,6 +125,8 @@ internal class TransitionImageAnimator(
}
}

internalImage.scaleType = it.scaleType

resetRootTranslation()
}
}
Expand All @@ -144,9 +145,18 @@ internal class TransitionImageAnimator(
.start()
}

private fun createTransition(onTransitionEnd: (() -> Unit)? = null): Transition =
AutoTransition()
.setDuration(transitionDuration)
.setInterpolator(DecelerateInterpolator())
.addListener(onTransitionEnd = { onTransitionEnd?.invoke() })
private fun createTransition(onTransitionEnd: (() -> Unit)? = null): Transition {
var transition =
TransitionSet ()
.setOrdering(TransitionSet.ORDERING_TOGETHER)
.addTransition(ChangeBounds())
.addTransition(ChangeTransform())
.addTransition(ChangeClipBounds())
.addTransition(ChangeImageTransform())

return transition
.setDuration(transitionDuration)
.setInterpolator(DecelerateInterpolator())
.addListener(onTransitionEnd = { onTransitionEnd?.invoke() })
}
}