Skip to content
Open
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
16 changes: 15 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import Animated, {
useSharedValue,
withDecay,
} from 'react-native-reanimated';
import {useFocusEffect} from '@react-navigation/native';


type MarqueeDirection = 'horizontal' | 'vertical';
export type MarqueeProps = React.PropsWithChildren<{
Expand Down Expand Up @@ -105,7 +107,7 @@ export const Marquee = React.memo(
});
const [cloneTimes, setCloneTimes] = React.useState(0);
const anim = useSharedValue(0);

const frameRateMs = frameRate ? 1000 / frameRate : null;

const frameCallback = useFrameCallback((frameInfo) => {
Expand Down Expand Up @@ -197,6 +199,18 @@ export const Marquee = React.memo(
);
});

// detect focus
useFocusEffect(
React.useCallback(() => {
frameCallback.setActive(true);

return () => {
frameCallback.setActive(false);
anim.value = 0;
};
}, []),
);

return (
<Animated.View
key={direction}
Expand Down