Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added integration for InteractionManager with native-stack #11887

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 32 additions & 2 deletions packages/native-stack/src/views/NativeStackView.native.tsx
Expand Up @@ -19,6 +19,7 @@ import {
import * as React from 'react';
import {
Animated,
InteractionManager,
Platform,
StyleSheet,
useAnimatedValue,
Expand Down Expand Up @@ -136,7 +137,7 @@ type SceneViewProps = {
isPresentationModal?: boolean;
onWillDisappear: () => void;
onWillAppear: () => void;
onAppear: () => void;
onAppear: ScreenProps['onAppear'];
onDisappear: () => void;
onDismissed: ScreenProps['onDismissed'];
onHeaderBackButtonClicked: ScreenProps['onHeaderBackButtonClicked'];
Expand Down Expand Up @@ -254,6 +255,35 @@ const SceneView = ({

const defaultHeaderHeight = getDefaultHeaderHeight(frame, isModal, topInset);

const interactionHandleRef = React.useRef<number>();

// this memo acts as a synchronous `useEffect`
React.useMemo(() => {
if (focused && interactionHandleRef.current === undefined) {
interactionHandleRef.current =
InteractionManager.createInteractionHandle();
}
}, [focused]);
const finishInteraction = React.useCallback(() => {
if (interactionHandleRef.current !== undefined) {
InteractionManager.clearInteractionHandle(interactionHandleRef.current);
interactionHandleRef.current = undefined;
}
}, []);
// in case if screen is unmounted faster than transition finishes, then `onAppear` will not be fired
// so we clean up an interaction here
React.useEffect(() => finishInteraction, [finishInteraction]);
const onAppearCallback = React.useCallback<
NonNullable<ScreenProps['onAppear']>
>(
(e) => {
onAppear?.(e);

finishInteraction();
},
[onAppear, finishInteraction]
);

const [customHeaderHeight, setCustomHeaderHeight] =
React.useState(defaultHeaderHeight);

Expand Down Expand Up @@ -315,7 +345,7 @@ const SceneView = ({
transitionDuration={animationDuration}
onWillAppear={onWillAppear}
onWillDisappear={onWillDisappear}
onAppear={onAppear}
onAppear={onAppearCallback}
onDisappear={onDisappear}
onDismissed={onDismissed}
onGestureCancel={onGestureCancel}
Expand Down