Skip to content

Instantly share code, notes, and snippets.

@guyca
guyca / gist:b7ab4713f9be9a9309a361029fffd64d
Last active May 1, 2021 13:33
An animated vector drawable that animates a dismiss button to a back button (both with rounded corners, reversed animation in comments).
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
android:name="vector"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
@guyca
guyca / back_to_dismiss.xml
Last active May 1, 2021 13:33
An animated vector drawable that animates a back button to a dismiss button (both with rounded corners, reversed animation in comments).
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
android:name="vector"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
@guyca
guyca / findViews.kt
Created June 14, 2020 10:42
Find the from and to views which are involved in the transition
val fromView: View = ReactFindViewUtil.findView(from, fromViewNativeID)!!
ReactFindViewUtil.findView(toScreen, object : OnViewFoundListener {
override fun getNativeId(): String {
return enteringViewNativeID
}
override fun onViewFound(to: View) {
// We found the corresponding entering view - move on to the next step!
}
})
@guyca
guyca / xAnimator.kt
Created June 14, 2020 07:45
An animator responsible for animating a views X coordinate
class XAnimatorCreator(from: View, to: View) : PropertyAnimatorCreator(from, to) {
private val dx: Int
init {
val fromXy = ViewUtils.getLocationOnScreen(from)
val toXy = ViewUtils.getLocationOnScreen(to)
dx = fromXy.x - toXy.x
}
override fun shouldAnimateProperty() = dx != 0
@guyca
guyca / animateSharedElement.kt
Created June 14, 2020 07:44
Create the animators and animate the appearing view
private fun animateSharedElement(from: View, to: View): AnimatorSet {
AnimatorSet().apply {
playTogether(
listOf(
MatrixAnimatorCreator(from, to),
XAnimatorCreator(from, to),
YAnimatorCreator(from, to),
RotationAnimatorCreator(from, to),
ScaleXAnimatorCreator(from, to),
ScaleYAnimatorCreator(from, to),
@guyca
guyca / onViewFound.kt
Created June 14, 2020 07:42
Animate the transition once the entering view is laid out
override fun onViewFound(to: View) {
to.doOnLayout {
// Create transition animators after entering view is laid out
animateSharedElement(from, to)
}
}
@guyca
guyca / push.jsx
Created June 14, 2020 07:14
Push a screen with Shared Element Transition
Navigation.push(this.props.componentId, {
component: {
Name: `MY_SCREEN`,
options: {
animations: {
push: {
sharedElementTransitions: [
{
fromId: `sourceImage`,
toId: `destinationImage`
<Image
source={this.props.image}
nativeID={`destinationImage`} />
<Image
source={this.props.image}
nativeID={`sourceImage`} />
import android.support.annotation.Nullable;
import java.lang.reflect.Field;
class ReflectionUtils {
@Nullable
static Object getDeclaredField(Object obj, String fieldName) {
try {
Field f = getField(obj.getClass(), fieldName);