mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
LayoutAnimation: ensure onCompleteCallback is called in Fabric and non-Fabric
Summary: Previously this branch of code only ran on Fabric+iOS. It is also needed for non-Fabric+Android in case `setLayoutAnimationEnabledExperimental` is not called on Android and an animation is queued up. Changelog: [Internal] Reviewed By: ShikaSD Differential Revision: D26466482 fbshipit-source-id: 11c50bf94daa287a619f2b623785b60675eb6cf0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1641d46529
commit
84778d7cfd
@@ -43,10 +43,29 @@ function configureNext(
|
||||
return;
|
||||
}
|
||||
|
||||
// Since LayoutAnimations may possibly be disabled for now on iOS (Fabric),
|
||||
// or Android (non-Fabric) we race a setTimeout with animation completion,
|
||||
// in case onComplete is never called
|
||||
// from native. Once LayoutAnimations+Fabric unconditionally ship everywhere, we can
|
||||
// delete this mechanism at least in the Fabric branch.
|
||||
let animationCompletionHasRun = false;
|
||||
const onAnimationComplete = () => {
|
||||
if (animationCompletionHasRun) {
|
||||
return;
|
||||
}
|
||||
animationCompletionHasRun = true;
|
||||
clearTimeout(raceWithAnimationId);
|
||||
onAnimationDidEnd?.();
|
||||
};
|
||||
const raceWithAnimationId = setTimeout(
|
||||
onAnimationComplete,
|
||||
(config.duration ?? 0) + 17 /* one frame + 1ms */,
|
||||
);
|
||||
|
||||
if (UIManager?.configureNextLayoutAnimation) {
|
||||
UIManager.configureNextLayoutAnimation(
|
||||
config,
|
||||
onAnimationDidEnd ?? function() {},
|
||||
onAnimationComplete ?? function() {},
|
||||
onAnimationDidFail ??
|
||||
function() {} /* this should never be called in Non-Fabric */,
|
||||
);
|
||||
@@ -56,30 +75,6 @@ function configureNext(
|
||||
// conditionally enabled on iOS (pending fully shipping; this is a temporary state).
|
||||
const FabricUIManager: FabricUIManagerSpec = global?.nativeFabricUIManager;
|
||||
if (FabricUIManager?.configureNextLayoutAnimation) {
|
||||
// Since LayoutAnimations may possibly be disabled for now on iOS, we race
|
||||
// a setTimeout with animation completion, in case onComplete is never called
|
||||
// from native. Once LayoutAnimations unconditionally ship everywhere, we can
|
||||
// delete this mechanism.
|
||||
// TODO: (T65643440) remove timeout once LayoutAnimation ships on iOS.
|
||||
let animationCompletionHasRun = false;
|
||||
const onAnimationComplete = () => {
|
||||
if (Platform.OS === 'ios') {
|
||||
if (animationCompletionHasRun) {
|
||||
return;
|
||||
}
|
||||
animationCompletionHasRun = true;
|
||||
clearTimeout(raceWithAnimationId);
|
||||
}
|
||||
onAnimationDidEnd?.();
|
||||
};
|
||||
const raceWithAnimationId =
|
||||
Platform.OS === 'ios'
|
||||
? setTimeout(
|
||||
onAnimationComplete,
|
||||
(config.duration ?? 0) + 17 /* one frame + 1ms */,
|
||||
)
|
||||
: null;
|
||||
|
||||
global?.nativeFabricUIManager?.configureNextLayoutAnimation(
|
||||
config,
|
||||
onAnimationComplete,
|
||||
|
||||
Reference in New Issue
Block a user