Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/components/Modal/ReanimatedModal/Container/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useMemo} from 'react';
import React, {useEffect, useMemo} from 'react';
import {View} from 'react-native';
import Animated, {Keyframe, runOnJS} from 'react-native-reanimated';
import type ReanimatedModalProps from '@components/Modal/ReanimatedModal/types';
Expand Down Expand Up @@ -27,12 +27,8 @@ function Container({
const Entering = useMemo(() => {
const AnimationIn = new Keyframe(getModalInAnimation(animationIn));

return AnimationIn.duration(animationInTiming).withCallback(() => {
'worklet';

runOnJS(onOpenCallBack)();
});
}, [animationIn, animationInTiming, onOpenCallBack]);
return AnimationIn.duration(animationInTiming);
}, [animationIn, animationInTiming]);

const Exiting = useMemo(() => {
const AnimationOut = new Keyframe(getModalOutAnimation(animationOut));
Expand All @@ -44,6 +40,19 @@ function Container({
});
}, [animationOutTiming, onCloseCallBack, animationOut]);

// Temporary solution to run animation callbacks even with reduced motion setting turned on
// since .reduceMotion method doesn't work in the current version of Reanimated (https://github.com/software-mansion/react-native-reanimated/issues/8046)
// We will remove this once fixed upstream https://github.com/Expensify/App/issues/69190
useEffect(() => {
setTimeout(onOpenCallBack, animationInTiming);

return () => {
setTimeout(onCloseCallBack, animationOutTiming);
};
// calling callbacks only when the layout animations are run - on mount and unmount
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []);

return (
<View
style={style}
Expand Down
14 changes: 13 additions & 1 deletion src/components/Modal/ReanimatedModal/Container/index.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ function Container({
return;
}
isInitiated.set(true);
initProgress.set(withTiming(1, {duration: animationInTiming, easing, reduceMotion: ReduceMotion.Never}, onOpenCallBack));
initProgress.set(
withTiming(
1,
{
duration: animationInTiming,
easing,
// ensuring the callback is called even with reduced motion setting turned on
reduceMotion: ReduceMotion.Never,
},
onOpenCallBack,
),
);
}, [animationInTiming, onOpenCallBack, initProgress, isInitiated]);

// instead of an entering transition since keyframe animations break keyboard on mWeb Chrome (#62799)
Expand All @@ -43,6 +54,7 @@ function Container({
.duration(animationOutTiming)
// eslint-disable-next-line react-compiler/react-compiler
.withCallback(() => onCloseCallbackRef.current())
// ensuring the callback is called even with reduced motion setting turned on
.reduceMotion(ReduceMotion.Never),
[animationOutTiming, animationOut],
);
Expand Down
7 changes: 4 additions & 3 deletions src/components/Modal/ReanimatedModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ function ReanimatedModal({
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [isVisible, isContainerOpen, isTransitioning]);

const backdropStyle: ViewStyle = useMemo(() => {
return {width: windowWidth, height: windowHeight, backgroundColor: backdropColor};
}, [windowWidth, windowHeight, backdropColor]);
const backdropStyle: ViewStyle = useMemo(
() => ({width: windowWidth, height: windowHeight, backgroundColor: backdropColor, opacity: backdropOpacity}),
[windowWidth, windowHeight, backdropColor, backdropOpacity],
);

const onOpenCallBack = useCallback(() => {
setIsTransitioning(false);
Expand Down
Loading