Skip to content

Commit

Permalink
refactor: add UNSTABLE to useUnhandledLinking
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jan 7, 2024
1 parent 573d0b8 commit 2e014e9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions example/src/Screens/LinkingScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button } from '@react-navigation/elements';
import { useUnhandledLinking } from '@react-navigation/native';
import { UNSTABLE_useUnhandledLinking } from '@react-navigation/native';
import {
createStackNavigator,
type StackScreenProps,
Expand Down Expand Up @@ -77,7 +77,7 @@ const Stack = createStackNavigator<StackParamList>();

export function LinkingScreen() {
const [isSignedIn, setSignedIn] = React.useState(false);
const { getStateForRouteNamesChange } = useUnhandledLinking();
const { getStateForRouteNamesChange } = UNSTABLE_useUnhandledLinking();
return (
<SigningContext.Provider
value={{
Expand Down
16 changes: 9 additions & 7 deletions packages/native/src/__tests__/useUnhandledLinking.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as React from 'react';
import { Button, Text } from 'react-native';

import { NavigationContainer } from '../NavigationContainer';
import { useUnhandledLinking } from '../useUnhandledLinking';
import { UNSTABLE_useUnhandledLinking } from '../useUnhandledLinking';

const createTestNavigator = createNavigatorFactory((props: any) => {
const { state, descriptors, NavigationContent } = useNavigationBuilder(
Expand Down Expand Up @@ -58,7 +58,7 @@ it('schedules a state to be handled on conditional linking', async () => {

const StackNavigator = () => {
const [isSignedIn, setSignedIn] = React.useState(false);
const { getStateForRouteNamesChange } = useUnhandledLinking();
const { getStateForRouteNamesChange } = UNSTABLE_useUnhandledLinking();

return (
<Stack.Navigator
Expand Down Expand Up @@ -159,7 +159,7 @@ it('schedules a state to be handled on conditional linking under nested navigato
};

const InnerStackNavigator = () => {
const { getStateForRouteNamesChange } = useUnhandledLinking();
const { getStateForRouteNamesChange } = UNSTABLE_useUnhandledLinking();
const [isSignedIn, setSignedIn] = React.useState(false);
return (
<Stack.Navigator
Expand Down Expand Up @@ -257,7 +257,7 @@ it('schedules a state to be handled on conditional linking in nested stack', asy

const StackNavigation = () => {
const [isSignedIn, setSignedIn] = React.useState(false);
const { getStateForRouteNamesChange } = useUnhandledLinking();
const { getStateForRouteNamesChange } = UNSTABLE_useUnhandledLinking();

return (
<Stack.Navigator
Expand Down Expand Up @@ -347,15 +347,15 @@ it('clears lastUnhandledLink upon successful linking handling', () => {
};

const ProfileScreen = (): any => {
const { lastUnhandledLink } = useUnhandledLinking();
const { lastUnhandledLink } = UNSTABLE_useUnhandledLinking();
return lastUnhandledLink;
};

const InnerStack = createTestNavigator();
const Stack = createTestNavigator();

const InnerStackNavigator = () => {
const { getStateForRouteNamesChange } = useUnhandledLinking();
const { getStateForRouteNamesChange } = UNSTABLE_useUnhandledLinking();
return (
<InnerStack.Navigator
getStateForRouteNamesChange={getStateForRouteNamesChange}
Expand Down Expand Up @@ -385,7 +385,9 @@ it('clears lastUnhandledLink upon calling clearUnhandledLink', async () => {
const Stack = createTestNavigator();

const LinkDisplayScreen = (): any => {
const { lastUnhandledLink, clearUnhandledLink } = useUnhandledLinking();
const { lastUnhandledLink, clearUnhandledLink } =
UNSTABLE_useUnhandledLinking();

return (
<>
<Text>{lastUnhandledLink}</Text>
Expand Down
2 changes: 1 addition & 1 deletion packages/native/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export { useLinkBuilder } from './useLinkBuilder';
export { useLinkProps } from './useLinkProps';
export { useLocale } from './useLocale';
export { useScrollToTop } from './useScrollToTop';
export { useUnhandledLinking } from './useUnhandledLinking';
export { UNSTABLE_useUnhandledLinking } from './useUnhandledLinking';
export * from '@react-navigation/core';
3 changes: 2 additions & 1 deletion packages/native/src/useUnhandledLinking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import useLatestCallback from 'use-latest-callback';
import { LinkingContext } from './LinkingContext';
import { UnhandledLinkingContext } from './UnhandledLinkingContext';

// FIXME: don't rely on depth only to get the navigator state
function extractNavigatorSpecificState(
_: NavigationState,
pathState: PartialState<NavigationState>,
Expand All @@ -29,7 +30,7 @@ function extractNavigatorSpecificState(
return partialPathState;
}

export function useUnhandledLinking() {
export function UNSTABLE_useUnhandledLinking() {
const navigation = React.useContext(NavigationContext);
const linking = React.useContext(LinkingContext);
const { setLastUnhandledLink, lastUnhandledLink } = React.useContext(
Expand Down

0 comments on commit 2e014e9

Please sign in to comment.