-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support declaring interpolation per shared element transition (#6139)
* Implement startDelay + fix image scale transition This commit adds support to the startDelay option in shared element transitions on Android. It also fixes image scale transition which only animated the image's scale type, but not its bounds. * Support declaring interpolator per element transition
- Loading branch information
Showing
14 changed files
with
200 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
lib/android/app/src/main/java/com/reactnativenavigation/utils/Animator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.reactnativenavigation.utils | ||
|
||
import android.animation.Animator | ||
import android.animation.TimeInterpolator | ||
import android.view.animation.Interpolator | ||
|
||
fun Animator.withStartDelay(delay: Long): Animator { | ||
startDelay = delay | ||
return this | ||
} | ||
|
||
fun Animator.withDuration(duration: Long): Animator { | ||
this.duration = duration | ||
return this | ||
} | ||
|
||
fun Animator.withInterpolator(interpolator: TimeInterpolator): Animator { | ||
this.interpolator = interpolator | ||
return this | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...app/src/main/java/com/reactnativenavigation/views/element/animators/ClipBoundsAnimator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.reactnativenavigation.views.element.animators | ||
|
||
import android.animation.Animator | ||
import android.animation.ObjectAnimator | ||
import android.graphics.Rect | ||
import android.view.View | ||
import com.facebook.react.views.image.ReactImageView | ||
import com.reactnativenavigation.parse.SharedElementTransitionOptions | ||
import com.reactnativenavigation.utils.ViewUtils | ||
import com.reactnativenavigation.utils.withDuration | ||
import com.reactnativenavigation.utils.withInterpolator | ||
import com.reactnativenavigation.utils.withStartDelay | ||
|
||
class ClipBoundsAnimator(from: View, to: View) : PropertyAnimatorCreator<ReactImageView>(from, to) { | ||
override fun shouldAnimateProperty(fromChild: ReactImageView, toChild: ReactImageView): Boolean { | ||
return !ViewUtils.areDimensionsEqual(from, to) | ||
} | ||
|
||
override fun create(options: SharedElementTransitionOptions): Animator { | ||
val startDrawingRect = Rect(); from.getDrawingRect(startDrawingRect) | ||
val endDrawingRect = Rect(); to.getDrawingRect(endDrawingRect) | ||
return ObjectAnimator.ofObject( | ||
ClipBoundsEvaluator(), | ||
startDrawingRect, | ||
endDrawingRect | ||
) | ||
.setDuration(options.getDuration()) | ||
.withStartDelay(options.getStartDelay()) | ||
.withInterpolator(options.interpolation.interpolator) | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...pp/src/main/java/com/reactnativenavigation/views/element/animators/ClipBoundsEvaluator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.reactnativenavigation.views.element.animators | ||
|
||
import android.animation.TypeEvaluator | ||
import android.graphics.Rect | ||
|
||
class ClipBoundsEvaluator : TypeEvaluator<Rect> { | ||
private var fromWidth = 0 | ||
private var fromHeight = 0 | ||
private var toWidth = 0 | ||
private var toHeight = 0 | ||
private val result = Rect() | ||
|
||
override fun evaluate(ratio: Float, from: Rect, to: Rect): Rect { | ||
sync(from, to) | ||
if (toHeight == fromHeight) { | ||
result.bottom = toHeight | ||
} else { | ||
if (toHeight > fromHeight) { | ||
result.bottom = (toHeight - (toHeight - fromHeight) * (1 - ratio)).toInt() | ||
} else { | ||
result.bottom = (toHeight + (fromHeight - toHeight) * (1 - ratio)).toInt() | ||
} | ||
} | ||
if (toWidth == fromWidth) { | ||
result.right = toWidth | ||
} else { | ||
if (toWidth > fromWidth) { | ||
result.right = (toWidth - (toWidth - fromWidth) * (1 - ratio)).toInt() | ||
} else { | ||
result.right = (toWidth + (fromWidth - toWidth) * (1 - ratio)).toInt() | ||
} | ||
} | ||
return result | ||
} | ||
|
||
private fun sync(from: Rect, to: Rect) { | ||
fromWidth = from.right | ||
fromHeight = from.bottom | ||
toWidth = to.right | ||
toHeight = to.bottom | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.