-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: disable child navigators handling actions by default (#10905)
Due to backward compatibility reasons, React Navigation 5 and 6 support navigating to a screen in a child navigator with `navigation.navigate(ScreenName)` syntax. But this is problematic with the new architecture - it only works if the navigator is already mounted, doesn't work with TypeScript, etc. That's why there's a special API to navigate to a nested screen (`navigation.navigate(ParentScreenName, { screen: ScreenName })`). This drops this behavior and adds a prop to explicitly enable it to make it easier to migrate. This prop will be removed in the next major.
- Loading branch information
Showing
23 changed files
with
195 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as React from 'react'; | ||
|
||
/** | ||
* Context which enables deprecated bubbling to child navigators. | ||
*/ | ||
const DeprecatedNavigationInChildContext = React.createContext(false); | ||
|
||
export default DeprecatedNavigationInChildContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from 'react'; | ||
|
||
import NavigationContext from './NavigationContext'; | ||
import NavigationIndependentTreeContext from './NavigationIndependentTreeContext'; | ||
import NavigationRouteContext from './NavigationRouteContext'; | ||
|
||
/** | ||
* Component to make the child navigation container independent of parent containers. | ||
*/ | ||
export default function NavigationIndependentTree({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
// We need to clear any existing contexts for nested independent container to work correctly | ||
<NavigationRouteContext.Provider value={undefined}> | ||
<NavigationContext.Provider value={undefined}> | ||
<NavigationIndependentTreeContext.Provider value> | ||
{children} | ||
</NavigationIndependentTreeContext.Provider> | ||
</NavigationContext.Provider> | ||
</NavigationRouteContext.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as React from 'react'; | ||
|
||
/** | ||
* Context which marks the navigation tree as independent. | ||
*/ | ||
const NavigationIndependentTreeContext = React.createContext(false); | ||
|
||
export default NavigationIndependentTreeContext; |
Oops, something went wrong.