Skip to content

Commit

Permalink
RN][Android] Add a ReactNativeFeatureFlag to enable/disable LayoutAni…
Browse files Browse the repository at this point in the history
…mations in Android

Summary:
Add a ReactNativeFeatureFlag to enable/disable LayoutAnimations in Android, default false

Changelog: [internal] internal

Differential Revision: D64073913
  • Loading branch information
arushikesarwani94 authored and facebook-github-bot committed Oct 8, 2024
1 parent 05cc409 commit 9a178de
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<7d80322a6a37083c5e52e6914de49ce2>>
* @generated SignedSource<<405d53cd6aba78616b8690c26a0accad>>
*/

/**
Expand Down Expand Up @@ -124,6 +124,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun enableIOSViewClipToPaddingBox(): Boolean = accessor.enableIOSViewClipToPaddingBox()

/**
* When enabled, LayoutAnimations API will animate state changes on Android.
*/
@JvmStatic
public fun enableLayoutAnimationsOnAndroid(): Boolean = accessor.enableLayoutAnimationsOnAndroid()

/**
* When enabled, LayoutAnimations API will animate state changes on iOS.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<761d3e7b100a4f5ee6f8bda71f84918b>>
* @generated SignedSource<<84ee754f916b48a7c55ea94e166510c7>>
*/

/**
Expand Down Expand Up @@ -36,6 +36,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
private var enableFabricRendererExclusivelyCache: Boolean? = null
private var enableGranularShadowTreeStateReconciliationCache: Boolean? = null
private var enableIOSViewClipToPaddingBoxCache: Boolean? = null
private var enableLayoutAnimationsOnAndroidCache: Boolean? = null
private var enableLayoutAnimationsOnIOSCache: Boolean? = null
private var enableLongTaskAPICache: Boolean? = null
private var enableMicrotasksCache: Boolean? = null
Expand Down Expand Up @@ -213,6 +214,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
return cached
}

override fun enableLayoutAnimationsOnAndroid(): Boolean {
var cached = enableLayoutAnimationsOnAndroidCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.enableLayoutAnimationsOnAndroid()
enableLayoutAnimationsOnAndroidCache = cached
}
return cached
}

override fun enableLayoutAnimationsOnIOS(): Boolean {
var cached = enableLayoutAnimationsOnIOSCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<1ed46e0bf712406c1bf6159e1bca3c15>>
* @generated SignedSource<<eebeaa749dafac5d49d9d6b356f88817>>
*/

/**
Expand Down Expand Up @@ -60,6 +60,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun enableIOSViewClipToPaddingBox(): Boolean

@DoNotStrip @JvmStatic public external fun enableLayoutAnimationsOnAndroid(): Boolean

@DoNotStrip @JvmStatic public external fun enableLayoutAnimationsOnIOS(): Boolean

@DoNotStrip @JvmStatic public external fun enableLongTaskAPI(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<19cf402242ebd8b3a08dfb7c755b801b>>
* @generated SignedSource<<d44c7d51caea5eaa3074217361959b3a>>
*/

/**
Expand Down Expand Up @@ -55,6 +55,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun enableIOSViewClipToPaddingBox(): Boolean = false

override fun enableLayoutAnimationsOnAndroid(): Boolean = false

override fun enableLayoutAnimationsOnIOS(): Boolean = true

override fun enableLongTaskAPI(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a307a1f9b5064547ce32f9519bbf27c4>>
* @generated SignedSource<<4dc2364f5bcd765d7b61dbcab0d9533d>>
*/

/**
Expand Down Expand Up @@ -40,6 +40,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
private var enableFabricRendererExclusivelyCache: Boolean? = null
private var enableGranularShadowTreeStateReconciliationCache: Boolean? = null
private var enableIOSViewClipToPaddingBoxCache: Boolean? = null
private var enableLayoutAnimationsOnAndroidCache: Boolean? = null
private var enableLayoutAnimationsOnIOSCache: Boolean? = null
private var enableLongTaskAPICache: Boolean? = null
private var enableMicrotasksCache: Boolean? = null
Expand Down Expand Up @@ -233,6 +234,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun enableLayoutAnimationsOnAndroid(): Boolean {
var cached = enableLayoutAnimationsOnAndroidCache
if (cached == null) {
cached = currentProvider.enableLayoutAnimationsOnAndroid()
accessedFeatureFlags.add("enableLayoutAnimationsOnAndroid")
enableLayoutAnimationsOnAndroidCache = cached
}
return cached
}

override fun enableLayoutAnimationsOnIOS(): Boolean {
var cached = enableLayoutAnimationsOnIOSCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<bda9e94a5fe61a16e7d001ea3acfed0c>>
* @generated SignedSource<<193bb7803261004003d9009b44810c2c>>
*/

/**
Expand Down Expand Up @@ -55,6 +55,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun enableIOSViewClipToPaddingBox(): Boolean

@DoNotStrip public fun enableLayoutAnimationsOnAndroid(): Boolean

@DoNotStrip public fun enableLayoutAnimationsOnIOS(): Boolean

@DoNotStrip public fun enableLongTaskAPI(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ void FabricUIManagerBinding::startSurfaceWithSurfaceHandler(

surfaceHandler.start();

surfaceHandler.getMountingCoordinator()->setMountingOverrideDelegate(
animationDriver_);
if (ReactNativeFeatureFlags::enableLayoutAnimationsOnAndroid()) {
surfaceHandler.getMountingCoordinator()->setMountingOverrideDelegate(
animationDriver_);
}

{
std::unique_lock lock(surfaceHandlerRegistryMutex_);
Expand Down Expand Up @@ -214,8 +216,10 @@ void FabricUIManagerBinding::startSurface(

surfaceHandler.start();

surfaceHandler.getMountingCoordinator()->setMountingOverrideDelegate(
animationDriver_);
if (ReactNativeFeatureFlags::enableLayoutAnimationsOnAndroid()) {
surfaceHandler.getMountingCoordinator()->setMountingOverrideDelegate(
animationDriver_);
}

{
SystraceSection s2("FabricUIManagerBinding::startSurface::surfaceId::lock");
Expand Down Expand Up @@ -284,8 +288,10 @@ void FabricUIManagerBinding::startSurfaceWithConstraints(

surfaceHandler.start();

surfaceHandler.getMountingCoordinator()->setMountingOverrideDelegate(
animationDriver_);
if (ReactNativeFeatureFlags::enableLayoutAnimationsOnAndroid()) {
surfaceHandler.getMountingCoordinator()->setMountingOverrideDelegate(
animationDriver_);
}

{
SystraceSection s2(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<0ec332b341bc55ba1a0ab75f2ede82f6>>
* @generated SignedSource<<0bb021affcef5162b578ad3f1e45508f>>
*/

/**
Expand Down Expand Up @@ -135,6 +135,12 @@ class ReactNativeFeatureFlagsProviderHolder
return method(javaProvider_);
}

bool enableLayoutAnimationsOnAndroid() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableLayoutAnimationsOnAndroid");
return method(javaProvider_);
}

bool enableLayoutAnimationsOnIOS() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableLayoutAnimationsOnIOS");
Expand Down Expand Up @@ -411,6 +417,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableIOSViewClipToPaddingBox(
return ReactNativeFeatureFlags::enableIOSViewClipToPaddingBox();
}

bool JReactNativeFeatureFlagsCxxInterop::enableLayoutAnimationsOnAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableLayoutAnimationsOnAndroid();
}

bool JReactNativeFeatureFlagsCxxInterop::enableLayoutAnimationsOnIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableLayoutAnimationsOnIOS();
Expand Down Expand Up @@ -636,6 +647,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"enableIOSViewClipToPaddingBox",
JReactNativeFeatureFlagsCxxInterop::enableIOSViewClipToPaddingBox),
makeNativeMethod(
"enableLayoutAnimationsOnAndroid",
JReactNativeFeatureFlagsCxxInterop::enableLayoutAnimationsOnAndroid),
makeNativeMethod(
"enableLayoutAnimationsOnIOS",
JReactNativeFeatureFlagsCxxInterop::enableLayoutAnimationsOnIOS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a0c02cb18082c572be8d584737cea8fa>>
* @generated SignedSource<<fe97369e30d5359ffcd9c8e304dbc121>>
*/

/**
Expand Down Expand Up @@ -78,6 +78,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool enableIOSViewClipToPaddingBox(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enableLayoutAnimationsOnAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enableLayoutAnimationsOnIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<2cf7555474bd4808f9f451485da01d1a>>
* @generated SignedSource<<013c1fa01cf029635c04b50f83cc80ef>>
*/

/**
Expand Down Expand Up @@ -85,6 +85,10 @@ bool ReactNativeFeatureFlags::enableIOSViewClipToPaddingBox() {
return getAccessor().enableIOSViewClipToPaddingBox();
}

bool ReactNativeFeatureFlags::enableLayoutAnimationsOnAndroid() {
return getAccessor().enableLayoutAnimationsOnAndroid();
}

bool ReactNativeFeatureFlags::enableLayoutAnimationsOnIOS() {
return getAccessor().enableLayoutAnimationsOnIOS();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<c7dceca0eab479fd67c8e8e25656b1bf>>
* @generated SignedSource<<3bbe3eb333030be7f32c0965c9db4a5c>>
*/

/**
Expand Down Expand Up @@ -117,6 +117,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool enableIOSViewClipToPaddingBox();

/**
* When enabled, LayoutAnimations API will animate state changes on Android.
*/
RN_EXPORT static bool enableLayoutAnimationsOnAndroid();

/**
* When enabled, LayoutAnimations API will animate state changes on iOS.
*/
Expand Down
Loading

0 comments on commit 9a178de

Please sign in to comment.