-
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.
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.
- Loading branch information
Showing
12 changed files
with
169 additions
and
28 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
13 changes: 13 additions & 0 deletions
13
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,13 @@ | ||
package com.reactnativenavigation.utils | ||
|
||
import android.animation.Animator | ||
|
||
fun Animator.withStartDelay(delay: Long): Animator { | ||
startDelay = delay | ||
return this | ||
} | ||
|
||
fun Animator.withDuration(duration: Long): Animator { | ||
this.duration = duration | ||
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
29 changes: 29 additions & 0 deletions
29
...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,29 @@ | ||
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.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()) | ||
} | ||
|
||
} |
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
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