Skip to content

Commit

Permalink
Improvements after Tymek's review
Browse files Browse the repository at this point in the history
  • Loading branch information
piaskowyk committed Dec 5, 2023
1 parent 843ad14 commit 00b81f8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 23 deletions.
8 changes: 4 additions & 4 deletions Example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,9 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/yoga"

SPEC CHECKSUMS:
boost: 57d2868c099736d80fcd648bf211b4431e51a558
boost: a7c83b31436843459a1961bfd74b96033dc77234
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662
FBLazyVector: 5d4a3b7f411219a45a6d952f77d2c0a6c9989da5
FBReactNativeSpec: 3fc2d478e1c4b08276f9dd9128f80ec6d5d85c1f
Flipper: 6edb735e6c3e332975d1b17956bcc584eccf5818
Expand All @@ -726,7 +726,7 @@ SPEC CHECKSUMS:
Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9
FlipperKit: 2efad7007d6745a3f95e4034d547be637f89d3f6
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
glog: 5337263514dd6f09803962437687240c5dc39aa4
hermes-engine: 81191603c4eaa01f5e4ae5737a9efcf64756c7b2
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
Expand Down Expand Up @@ -774,4 +774,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 86e380a4262db238c7a45428750af2d88465585c

COCOAPODS: 1.14.3
COCOAPODS: 1.14.2
2 changes: 1 addition & 1 deletion Example/src/screens/SwipeBackAnimation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const ScreenC = ({ navigation }: ScreenCProps): JSX.Element => (
</View>
);

const Stack = createNativeStackNavigator<StackParamList>() as any;
const Stack = createNativeStackNavigator<StackParamList>();

const App = (): JSX.Element => (
<Stack.Navigator
Expand Down
12 changes: 3 additions & 9 deletions src/fabric/NativeScreensModule.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ import type { Double, Int32 } from 'react-native/Libraries/Types/CodegenTypes';

export default {
startTransition(_tag: Int32 | null) {
console.log(
'[ReactNativeScreens] startTransition is not supported on web]'
);
console.log('[RNScreens] startTransition is not supported on web.');
return false;
},
updateTransition(_tag: Int32 | null, _progress: Double) {
console.log(
'[ReactNativeScreens] updateTransition is not supported on web]'
);
console.log('[RNScreens] startTransition is not supported on web.');
return false;
},
finishTransition(_tag: Int32 | null, _canceled: boolean) {
console.log(
'[ReactNativeScreens] finishTransition is not supported on web]'
);
console.log('[RNScreens] startTransition is not supported on web.');
return false;
},
};
15 changes: 8 additions & 7 deletions src/gesture-handler/GestureDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ const TransitionHandler = ({
screenEdgeGesture,
transitionAnimation: userTransitionAnimation,
}: GestureProviderProps) => {
if (stackRef === undefined) {
throw new Error('[RNScreens] You have to specify `stackRef`');
if (stackRef === undefined || stackRef.current === undefined) {
throw new Error(
'[RNScreens] A required parameter `stackRef` was not specified.'
);
}
stackRef.current = useAnimatedRef();
const sharedEvent = useSharedValue(DefaultEvent);
Expand All @@ -99,14 +101,16 @@ const TransitionHandler = ({
transitionAnimation = userTransitionAnimation;
if (!goBackGesture) {
throw new Error(
'[RNScreens] You have to specify `goBackGesture` when using `transitionAnimation`'
'[RNScreens] You have to specify `goBackGesture` when using `transitionAnimation`.'
);
}
} else {
if (!!goBackGesture && SupportedGestures.includes(goBackGesture)) {
transitionAnimation = AnimationForGesture[goBackGesture];
} else if (goBackGesture !== undefined) {
throw new Error(`[RNScreens] Unknown goBackGesture: ${goBackGesture}`);
throw new Error(
`[RNScreens] Unknown goBackGesture parameter has been specified: ${goBackGesture}.`
);
}
}
const screenTransitionConfig = makeMutable(
Expand All @@ -127,9 +131,6 @@ const TransitionHandler = ({
true
);
const refCurrent = stackRef.current;
if (refCurrent === null) {
throw new Error('[RNScreens] You have to specify `stackRefWrapper`');
}

function onStart(event: GestureUpdateEvent<PanGestureHandlerEventPayload>) {
'worklet';
Expand Down
1 change: 0 additions & 1 deletion src/native-stack/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ export type AnimatedScreenTransition = {
};

export type GestureProviderProps = PropsWithChildren<{
children: React.ReactNode;
stackRef: React.MutableRefObject<unknown>;
goBackGesture: GoBackGesture | undefined;
transitionAnimation: AnimatedScreenTransition | undefined;
Expand Down
3 changes: 2 additions & 1 deletion src/native-stack/views/NativeStackView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ function NativeStackViewInner({
}: Props): JSX.Element {
const { key, routes } = state;

const topScreenOptions = descriptors[state.routes[state.index].key].options;
const currentRouteKey = routes[state.index].key;
const topScreenOptions = descriptors[currentRouteKey].options;
const stackRef = React.useRef(null);
const GestureDetector = React.useContext(GHContext);

Expand Down
1 change: 1 addition & 0 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ export interface ScreenStackProps extends ViewProps {
* A callback that gets called when the current screen finishes its transition.
*/
onFinishTransitioning?: (e: NativeSyntheticEvent<TargetedEvent>) => void;
// stackRef is a container for Reanimated Ref, passed from NativeStack to GestureDetector
stackRef?: React.MutableRefObject<React.Ref<View>>;
ref?: React.MutableRefObject<React.Ref<View>>;
}
Expand Down

0 comments on commit 00b81f8

Please sign in to comment.