Skip to content

Commit

Permalink
fix(Fabric): not working animations on second-top screen (software-ma…
Browse files Browse the repository at this point in the history
…nsion#2270)

PR fixing animations on Fabric.

The problem started in RN 0.74, from which suspending the component triggers its useLayoutEffect. It has the consequences in Animated since detaching the native node happens then: facebook/react-native@a5b84b9/packages/react-native/Libraries/Animated/useAnimatedProps.js#L221-L238.
  • Loading branch information
WoLewicki authored and ja1ns committed Oct 9, 2024
1 parent 8163afa commit d148c8a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/components/ScreenStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import ScreenStackNativeComponent from '../fabric/ScreenStackNativeComponent';
const NativeScreenStack: React.ComponentType<ScreenStackProps> =
ScreenStackNativeComponent as any;

function isFabric() {
return 'nativeFabricUIManager' in global;
}

function ScreenStack(props: ScreenStackProps) {
const { children, gestureDetectorBridge, ...rest } = props;
const ref = React.useRef(null);
Expand All @@ -19,8 +23,14 @@ function ScreenStack(props: ScreenStackProps) {
const isFreezeEnabled =
descriptor?.options?.freezeOnBlur ?? freezeEnabled();

// On Fabric, when screen is frozen, animated and reanimated values are not updated
// due to component being unmounted. To avoid this, we don't freeze the previous screen there
const freezePreviousScreen = isFabric()
? size - index > 2
: size - index > 1;

return (
<DelayedFreeze freeze={isFreezeEnabled && size - index > 1}>
<DelayedFreeze freeze={isFreezeEnabled && freezePreviousScreen}>
{child}
</DelayedFreeze>
);
Expand Down

0 comments on commit d148c8a

Please sign in to comment.