mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Kotlinify LayoutUpdateAnimation (#43890)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43890 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Reviewed By: cortinico Differential Revision: D55766128 fbshipit-source-id: a7f5fc653bd44ec7fc9f4995e82193d8b0d28660
This commit is contained in:
committed by
Facebook GitHub Bot
parent
092ed2fc21
commit
7cffdf2d73
-49
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.uimanager.layoutanimation;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.TranslateAnimation;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
|
||||
/**
|
||||
* Class responsible for handling layout update animation, applied to view whenever a valid config
|
||||
* was supplied for the layout animation of UPDATE type.
|
||||
*/
|
||||
/* package */ @Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
class LayoutUpdateAnimation extends AbstractLayoutAnimation {
|
||||
|
||||
// We are currently not enabling translation GPU-accelerated animated, as it creates odd
|
||||
// artifacts with native react scrollview. This needs to be investigated.
|
||||
private static final boolean USE_TRANSLATE_ANIMATION = false;
|
||||
|
||||
@Override
|
||||
boolean isValid() {
|
||||
return mDurationMs > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
Animation createAnimationImpl(View view, int x, int y, int width, int height) {
|
||||
boolean animateLocation = view.getX() != x || view.getY() != y;
|
||||
boolean animateSize = view.getWidth() != width || view.getHeight() != height;
|
||||
if (!animateLocation && !animateSize) {
|
||||
return null;
|
||||
} else if (animateLocation && !animateSize && USE_TRANSLATE_ANIMATION) {
|
||||
// Use GPU-accelerated animation, however we loose the ability to resume interrupted
|
||||
// animation where it was left off. We may be able to listen to animation interruption
|
||||
// and set the layout manually in this case, so that next animation kicks off smoothly.
|
||||
return new TranslateAnimation(view.getX() - x, 0, view.getY() - y, 0);
|
||||
} else {
|
||||
// Animation is sub-optimal for perf, but scale transformation can't be use in this case.
|
||||
return new PositionAndSizeAnimation(view, x, y, width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.uimanager.layoutanimation
|
||||
|
||||
import android.view.View
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.TranslateAnimation
|
||||
|
||||
/**
|
||||
* Class responsible for handling layout update animation, applied to view whenever a valid config
|
||||
* was supplied for the layout animation of UPDATE type.
|
||||
*/
|
||||
internal class LayoutUpdateAnimation : AbstractLayoutAnimation() {
|
||||
|
||||
override internal fun isValid(): Boolean = mDurationMs > 0
|
||||
|
||||
override internal fun createAnimationImpl(
|
||||
view: View,
|
||||
x: Int,
|
||||
y: Int,
|
||||
width: Int,
|
||||
height: Int
|
||||
): Animation? {
|
||||
val animateLocation = view.x.toInt() != x || view.y.toInt() != y
|
||||
val animateSize = view.width != width || view.height != height
|
||||
if (!animateLocation && !animateSize) {
|
||||
return null
|
||||
} else if (animateLocation && !animateSize && USE_TRANSLATE_ANIMATION) {
|
||||
// Use GPU-accelerated animation, however we loose the ability to resume interrupted
|
||||
// animation where it was left off. We may be able to listen to animation interruption
|
||||
// and set the layout manually in this case, so that next animation kicks off smoothly.
|
||||
return TranslateAnimation(view.x - x, 0f, view.y - y, 0f)
|
||||
} else {
|
||||
// Animation is sub-optimal for perf, but scale transformation can't be use in this case.
|
||||
return PositionAndSizeAnimation(view, x, y, width, height)
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
// We are currently not enabling translation GPU-accelerated animated, as it creates odd
|
||||
// artifacts with native react scrollview. This needs to be investigated.
|
||||
private const val USE_TRANSLATE_ANIMATION = false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user