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

fix: change default value of context of ScreenGestureDetector, add warning for goBackGesture #2013

Merged
merged 7 commits into from
Jan 18, 2024
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
12 changes: 4 additions & 8 deletions src/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import React, {
Fragment,
PropsWithChildren,
ReactNode,
useEffect,
useRef,
} from 'react';
import React, { PropsWithChildren, ReactNode, useEffect, useRef } from 'react';
import {
Animated,
Image,
Expand Down Expand Up @@ -510,7 +504,7 @@
console.warn(
'Importing SearchBar is only valid on iOS and Android devices.'
);
return View as any as ReactNode;

Check warning on line 507 in src/index.native.tsx

View workflow job for this annotation

GitHub Actions / install-and-lint

Unexpected any. Specify a different type
}

return (
Expand Down Expand Up @@ -581,7 +575,9 @@
const ScreenContext = React.createContext(InnerScreen);

// context to be used when the user wants full screen swipe (see `gesture-handler` folder in repo)
const GHContext = React.createContext(Fragment);
const GHContext = React.createContext(
(props: { children: React.ReactNode }) => <>{props.children}</>
);

class Screen extends React.Component<ScreenProps> {
static contextType = ScreenContext;
Expand Down
20 changes: 16 additions & 4 deletions src/native-stack/views/NativeStackView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
screensRefs.current[route.key] = screenRef;
return () => {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete screensRefs.current[route.key];

Check warning on line 276 in src/native-stack/views/NativeStackView.tsx

View workflow job for this annotation

GitHub Actions / install-and-lint

The ref value 'screensRefs.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy 'screensRefs.current' to a variable inside the effect, and use that variable in the cleanup function
};
});

Expand Down Expand Up @@ -419,7 +419,8 @@
const { key, routes } = state;

const currentRouteKey = routes[state.index].key;
const topScreenOptions = descriptors[currentRouteKey].options;
const { goBackGesture, transitionAnimation, screenEdgeGesture } =
descriptors[currentRouteKey].options;
const gestureDetectorBridge = React.useRef<GestureDetectorBridge>({
stackUseEffectCallback: _stackRef => {
// this method will be override in GestureDetector
Expand All @@ -432,12 +433,23 @@
const screensRefs = React.useRef<RefHolder>({});
const ScreenGestureDetector = React.useContext(GHContext);

React.useEffect(() => {
if (
ScreenGestureDetector.name !== 'GHWrapper' &&
goBackGesture !== undefined
) {
console.warn(
'Cannot detect GestureDetectorProvider in a screen that uses `goBackGesture`. Make sure your navigator is wrapped in GestureDetectorProvider.'
);
}
}, [ScreenGestureDetector.name, goBackGesture]);

return (
<ScreenGestureDetector
gestureDetectorBridge={gestureDetectorBridge}
goBackGesture={topScreenOptions?.goBackGesture}
transitionAnimation={topScreenOptions?.transitionAnimation}
screenEdgeGesture={topScreenOptions?.screenEdgeGesture ?? false}
goBackGesture={goBackGesture}
transitionAnimation={transitionAnimation}
screenEdgeGesture={screenEdgeGesture ?? false}
screensRefs={screensRefs}
currentRouteKey={currentRouteKey}>
<ScreenStack
Expand Down
Loading