Compare commits

..

9 Commits

Author SHA1 Message Date
Satyajit Sahoo
cf6a9e614d chore: publish
- @react-navigation/bottom-tabs@6.0.0-next.6
 - @react-navigation/core@6.0.0-next.3
 - @react-navigation/devtools@6.0.0-next.3
 - @react-navigation/drawer@6.0.0-next.5
 - @react-navigation/elements@1.0.0-next.5
 - @react-navigation/material-bottom-tabs@6.0.0-next.3
 - @react-navigation/material-top-tabs@6.0.0-next.4
 - @react-navigation/native@6.0.0-next.3
 - @react-navigation/stack@6.0.0-next.10
2021-05-01 23:53:18 +02:00
Satyajit Sahoo
0ecd112ec9 feat: add helper and hook for container ref 2021-05-01 23:51:10 +02:00
Satyajit Sahoo
def7c03d7d feat: add a CompositeScreenProps type 2021-05-01 21:58:33 +02:00
Satyajit Sahoo
83242a7bef refactor: tweak the types 2021-05-01 21:32:10 +02:00
Satyajit Sahoo
f48303f036 chore: add an action to label sponsors 2021-04-24 17:37:03 +02:00
Satyajit Sahoo
dc779b8d82 chore: fix string interpolation in first pr action 2021-04-19 15:21:54 +02:00
Satyajit Sahoo
d7401b0200 chore: use pull_request_target for first pr action 2021-04-19 00:42:43 +02:00
Satyajit Sahoo
372d5921b8 chore: fix typo 2021-04-17 15:07:14 +02:00
Satyajit Sahoo
f940153d02 chore: add stale bit to close issues without repro 2021-04-16 22:16:06 +02:00
51 changed files with 380 additions and 163 deletions

View File

@@ -1,5 +1,5 @@
name: First pull request name: First pull request
on: pull_request on: pull_request_target
jobs: jobs:
welcome: welcome:
@@ -12,13 +12,13 @@ jobs:
// Get a list of all issues created by the PR opener // Get a list of all issues created by the PR opener
// See: https://octokit.github.io/rest.js/#pagination // See: https://octokit.github.io/rest.js/#pagination
const creator = context.payload.sender.login; const creator = context.payload.sender.login;
const opts = github.issues.listForRepo.endpoint.merge({ const options = github.issues.listForRepo.endpoint.merge({
...context.issue, ...context.issue,
creator, creator,
state: 'all' state: 'all'
}); });
const issues = await github.paginate(opts); const issues = await github.paginate(options);
for (const issue of issues) { for (const issue of issues) {
if (issue.number === context.issue.number) { if (issue.number === context.issue.number) {
@@ -26,7 +26,7 @@ jobs:
} }
if (issue.pull_request) { if (issue.pull_request) {
return ;// Creator is already a contributor. return; // Creator is already a contributor.
} }
} }
@@ -41,5 +41,5 @@ jobs:
issue_number: context.issue.number, issue_number: context.issue.number,
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
body: "Hey ${creator}! Thanks for opening the pull request. If you haven't already, make sure to read our [contribution guidelines](https://github.com/react-navigation/react-navigation/blob/main/CONTRIBUTING.md)." body: `Hey ${creator}! Thanks for opening your first pull request in this repo. If you haven't already, make sure to read our [contribution guidelines](https://github.com/react-navigation/react-navigation/blob/main/CONTRIBUTING.md).`
}); });

15
.github/workflows/sponsor.yml vendored Normal file
View File

@@ -0,0 +1,15 @@
name: Label sponsors
on:
pull_request:
types: [opened]
issues:
types: [opened]
jobs:
build:
name: is-sponsor-label
runs-on: ubuntu-latest
steps:
- uses: JasonEtco/is-sponsor-label-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

21
.github/workflows/stale.yml vendored Normal file
View File

@@ -0,0 +1,21 @@
name: Close stale issues and PRs
on:
schedule:
- cron: '30 1 * * *'
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 30
days-before-close: 7
any-of-labels: 'needs more info,needs repro,needs response'
exempt-issue-labels: 'repro provided,keep open'
exempt-pr-labels: 'keep open'
stale-issue-label: 'stale'
stale-pr-label: 'stale'
stale-issue-message: 'Hello 👋, this issue has been open for more than a month without a repro or any activity. If the issue is still present in the latest version, please provide a repro or leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution or workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix it.'
stale-pr-message: 'Hello 👋, this pull request has been open for more than a month with no activity on it. If you think this is still necessary with the latest version, please comment and ping a maintainer to get this reviewed, otherwise it will be closed automatically in 7 days.'

2
.gitignore vendored
View File

@@ -33,3 +33,5 @@ npm-debug.*
*.key *.key
*.mobileprovision *.mobileprovision
*.orig.* *.orig.*
*.iml

View File

@@ -28,13 +28,13 @@ import {
DefaultTheme, DefaultTheme,
DarkTheme, DarkTheme,
PathConfigMap, PathConfigMap,
NavigationContainerRef, useNavigationContainerRef,
} from '@react-navigation/native'; } from '@react-navigation/native';
import { createDrawerNavigator } from '@react-navigation/drawer'; import { createDrawerNavigator } from '@react-navigation/drawer';
import { import {
createStackNavigator, createStackNavigator,
StackScreenProps,
HeaderStyleInterpolators, HeaderStyleInterpolators,
StackNavigationProp,
} from '@react-navigation/stack'; } from '@react-navigation/stack';
import { useReduxDevToolsExtension } from '@react-navigation/devtools'; import { useReduxDevToolsExtension } from '@react-navigation/devtools';
@@ -193,7 +193,7 @@ export default function App() {
return () => Dimensions.removeEventListener('change', onDimensionsChange); return () => Dimensions.removeEventListener('change', onDimensionsChange);
}, []); }, []);
const navigationRef = React.useRef<NavigationContainerRef>(null); const navigationRef = useNavigationContainerRef<RootStackParamList>();
useReduxDevToolsExtension(navigationRef); useReduxDevToolsExtension(navigationRef);
@@ -304,7 +304,11 @@ export default function App() {
), ),
}} }}
> >
{({ navigation }: StackScreenProps<RootStackParamList>) => ( {({
navigation,
}: {
navigation: StackNavigationProp<RootStackParamList>;
}) => (
<ScrollView <ScrollView
style={{ backgroundColor: theme.colors.background }} style={{ backgroundColor: theme.colors.background }}
> >

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.6](https://github.com/react-navigation/react-navigation/compare/@react-navigation/bottom-tabs@6.0.0-next.5...@react-navigation/bottom-tabs@6.0.0-next.6) (2021-05-01)
**Note:** Version bump only for package @react-navigation/bottom-tabs
# [6.0.0-next.5](https://github.com/react-navigation/react-navigation/compare/@react-navigation/bottom-tabs@6.0.0-next.4...@react-navigation/bottom-tabs@6.0.0-next.5) (2021-04-16) # [6.0.0-next.5](https://github.com/react-navigation/react-navigation/compare/@react-navigation/bottom-tabs@6.0.0-next.4...@react-navigation/bottom-tabs@6.0.0-next.5) (2021-04-16)

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/bottom-tabs", "name": "@react-navigation/bottom-tabs",
"description": "Bottom tab navigator following iOS design guidelines", "description": "Bottom tab navigator following iOS design guidelines",
"version": "6.0.0-next.5", "version": "6.0.0-next.6",
"keywords": [ "keywords": [
"react-native-component", "react-native-component",
"react-component", "react-component",
@@ -36,12 +36,12 @@
"clean": "del lib" "clean": "del lib"
}, },
"dependencies": { "dependencies": {
"@react-navigation/elements": "^1.0.0-next.4", "@react-navigation/elements": "^1.0.0-next.5",
"color": "^3.1.3", "color": "^3.1.3",
"warn-once": "^0.0.1" "warn-once": "^0.0.1"
}, },
"devDependencies": { "devDependencies": {
"@react-navigation/native": "^6.0.0-next.2", "@react-navigation/native": "^6.0.0-next.3",
"@testing-library/react-native": "^7.2.0", "@testing-library/react-native": "^7.2.0",
"@types/color": "^3.0.1", "@types/color": "^3.0.1",
"@types/react": "^16.9.53", "@types/react": "^16.9.53",

View File

@@ -42,7 +42,7 @@ export type BottomTabNavigationHelpers = NavigationHelpers<
export type BottomTabNavigationProp< export type BottomTabNavigationProp<
ParamList extends ParamListBase, ParamList extends ParamListBase,
RouteName extends keyof ParamList = string RouteName extends keyof ParamList = keyof ParamList
> = NavigationProp< > = NavigationProp<
ParamList, ParamList,
RouteName, RouteName,
@@ -54,7 +54,7 @@ export type BottomTabNavigationProp<
export type BottomTabScreenProps< export type BottomTabScreenProps<
ParamList extends ParamListBase, ParamList extends ParamListBase,
RouteName extends keyof ParamList = string RouteName extends keyof ParamList = keyof ParamList
> = { > = {
navigation: BottomTabNavigationProp<ParamList, RouteName>; navigation: BottomTabNavigationProp<ParamList, RouteName>;
route: RouteProp<ParamList, RouteName>; route: RouteProp<ParamList, RouteName>;
@@ -239,7 +239,7 @@ export type BottomTabNavigationOptions = HeaderOptions & {
export type BottomTabDescriptor = Descriptor< export type BottomTabDescriptor = Descriptor<
BottomTabNavigationOptions, BottomTabNavigationOptions,
BottomTabNavigationProp<ParamListBase>, BottomTabNavigationProp<ParamListBase>,
RouteProp<ParamListBase, string> RouteProp<ParamListBase>
>; >;
export type BottomTabDescriptorMap = Record<string, BottomTabDescriptor>; export type BottomTabDescriptorMap = Record<string, BottomTabDescriptor>;
@@ -283,7 +283,7 @@ export type BottomTabHeaderProps = {
/** /**
* Route object for the current screen. * Route object for the current screen.
*/ */
route: RouteProp<ParamListBase, string>; route: RouteProp<ParamListBase>;
/** /**
* Navigation prop for the header. * Navigation prop for the header.
*/ */

View File

@@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.3](https://github.com/react-navigation/react-navigation/compare/@react-navigation/core@6.0.0-next.2...@react-navigation/core@6.0.0-next.3) (2021-05-01)
### Features
* add a CompositeScreenProps type ([def7c03](https://github.com/react-navigation/react-navigation/commit/def7c03d7d7b42cf322f4e277f8f76858717654e))
* add helper and hook for container ref ([0ecd112](https://github.com/react-navigation/react-navigation/commit/0ecd112ec9786a26261ada3d33ef44dc1ec84da0))
# [6.0.0-next.2](https://github.com/react-navigation/react-navigation/compare/@react-navigation/core@6.0.0-next.1...@react-navigation/core@6.0.0-next.2) (2021-04-08) # [6.0.0-next.2](https://github.com/react-navigation/react-navigation/compare/@react-navigation/core@6.0.0-next.1...@react-navigation/core@6.0.0-next.2) (2021-04-08)

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/core", "name": "@react-navigation/core",
"description": "Core utilities for building navigators", "description": "Core utilities for building navigators",
"version": "6.0.0-next.2", "version": "6.0.0-next.3",
"keywords": [ "keywords": [
"react", "react",
"react-native", "react-native",

View File

@@ -6,6 +6,7 @@ import {
InitialState, InitialState,
PartialState, PartialState,
NavigationAction, NavigationAction,
ParamListBase,
} from '@react-navigation/routers'; } from '@react-navigation/routers';
import EnsureSingleNavigator from './EnsureSingleNavigator'; import EnsureSingleNavigator from './EnsureSingleNavigator';
import UnhandledActionContext from './UnhandledActionContext'; import UnhandledActionContext from './UnhandledActionContext';
@@ -22,6 +23,7 @@ import useSyncState from './useSyncState';
import checkSerializable from './checkSerializable'; import checkSerializable from './checkSerializable';
import checkDuplicateRouteNames from './checkDuplicateRouteNames'; import checkDuplicateRouteNames from './checkDuplicateRouteNames';
import findFocusedRoute from './findFocusedRoute'; import findFocusedRoute from './findFocusedRoute';
import { NOT_INITIALIZED_ERROR } from './createNavigationContainerRef';
import type { import type {
NavigationContainerEventMap, NavigationContainerEventMap,
NavigationContainerRef, NavigationContainerRef,
@@ -30,9 +32,6 @@ import type {
type State = NavigationState | PartialState<NavigationState> | undefined; type State = NavigationState | PartialState<NavigationState> | undefined;
const NOT_INITIALIZED_ERROR =
"The 'navigation' object hasn't been initialized yet. This might happen if you don't have a navigator mounted, or if the navigator hasn't finished mounting. See https://reactnavigation.org/docs/navigating-without-navigation-prop#handling-initialization for more details.";
const serializableWarnings: string[] = []; const serializableWarnings: string[] = [];
const duplicateNameWarnings: string[] = []; const duplicateNameWarnings: string[] = [];
@@ -103,7 +102,7 @@ const BaseNavigationContainer = React.forwardRef(
independent, independent,
children, children,
}: NavigationContainerProps, }: NavigationContainerProps,
ref?: React.Ref<NavigationContainerRef> ref?: React.Ref<NavigationContainerRef<ParamListBase>>
) { ) {
const parent = React.useContext(NavigationStateContext); const parent = React.useContext(NavigationStateContext);
@@ -202,16 +201,10 @@ const BaseNavigationContainer = React.forwardRef(
const { addOptionsGetter, getCurrentOptions } = useOptionsGetters({}); const { addOptionsGetter, getCurrentOptions } = useOptionsGetters({});
React.useImperativeHandle(ref, () => ({ React.useImperativeHandle(ref, () => ({
...(Object.keys( ...Object.keys(CommonActions).reduce<any>((acc, name) => {
CommonActions
) as (keyof typeof CommonActions)[]).reduce<any>((acc, name) => {
acc[name] = (...args: any[]) => acc[name] = (...args: any[]) =>
dispatch( // @ts-expect-error: this is ok
CommonActions[name]( dispatch(CommonActions[name](...args));
// @ts-expect-error: we can't know the type statically
...args
)
);
return acc; return acc;
}, {}), }, {}),
...emitter.create('root'), ...emitter.create('root'),
@@ -223,6 +216,7 @@ const BaseNavigationContainer = React.forwardRef(
getParent: () => undefined, getParent: () => undefined,
getCurrentRoute, getCurrentRoute,
getCurrentOptions, getCurrentOptions,
isReady: () => listeners.focus[0] != null,
})); }));
const onDispatchAction = React.useCallback( const onDispatchAction = React.useCallback(

View File

@@ -6,7 +6,7 @@ import type { NavigationProp } from './types';
* Context which holds the navigation prop for a screen. * Context which holds the navigation prop for a screen.
*/ */
const NavigationContext = React.createContext< const NavigationContext = React.createContext<
NavigationProp<ParamListBase, string, any, any> | undefined NavigationProp<ParamListBase> | undefined
>(undefined); >(undefined);
export default NavigationContext; export default NavigationContext;

View File

@@ -3,16 +3,17 @@ import { act, render } from '@testing-library/react-native';
import { import {
DefaultRouterOptions, DefaultRouterOptions,
NavigationState, NavigationState,
ParamListBase,
Router, Router,
StackRouter, StackRouter,
TabRouter, TabRouter,
} from '@react-navigation/routers'; } from '@react-navigation/routers';
import BaseNavigationContainer from '../BaseNavigationContainer'; import BaseNavigationContainer from '../BaseNavigationContainer';
import NavigationStateContext from '../NavigationStateContext'; import NavigationStateContext from '../NavigationStateContext';
import createNavigationContainerRef from '../createNavigationContainerRef';
import MockRouter, { MockActions } from './__fixtures__/MockRouter'; import MockRouter, { MockActions } from './__fixtures__/MockRouter';
import useNavigationBuilder from '../useNavigationBuilder'; import useNavigationBuilder from '../useNavigationBuilder';
import Screen from '../Screen'; import Screen from '../Screen';
import type { NavigationContainerRef } from '../types';
it('throws when getState is accessed without a container', () => { it('throws when getState is accessed without a container', () => {
expect.assertions(1); expect.assertions(1);
@@ -128,7 +129,7 @@ it('handle dispatching with ref', () => {
); );
}; };
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const onStateChange = jest.fn(); const onStateChange = jest.fn();
@@ -226,7 +227,7 @@ it('handle resetting state with ref', () => {
); );
}; };
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const onStateChange = jest.fn(); const onStateChange = jest.fn();
@@ -316,7 +317,7 @@ it('handles getRootState', () => {
return descriptors[state.routes[state.index].key].render(); return descriptors[state.routes[state.index].key].render();
}; };
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const element = ( const element = (
<BaseNavigationContainer ref={ref}> <BaseNavigationContainer ref={ref}>
@@ -378,7 +379,7 @@ it('emits state events when the state changes', () => {
); );
}; };
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const element = ( const element = (
<BaseNavigationContainer ref={ref}> <BaseNavigationContainer ref={ref}>
@@ -448,7 +449,7 @@ it('emits state events when new navigator mounts', () => {
); );
}; };
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const NestedNavigator = () => { const NestedNavigator = () => {
const [isRendered, setIsRendered] = React.useState(false); const [isRendered, setIsRendered] = React.useState(false);
@@ -537,7 +538,7 @@ it('emits option events when options change with tab router', () => {
); );
}; };
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const element = ( const element = (
<BaseNavigationContainer ref={ref}> <BaseNavigationContainer ref={ref}>
@@ -611,7 +612,7 @@ it('emits option events when options change with stack router', () => {
); );
}; };
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const element = ( const element = (
<BaseNavigationContainer ref={ref}> <BaseNavigationContainer ref={ref}>
@@ -677,7 +678,7 @@ it('emits option events when options change with stack router', () => {
it('throws if there is no navigator rendered', () => { it('throws if there is no navigator rendered', () => {
expect.assertions(1); expect.assertions(1);
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const element = <BaseNavigationContainer ref={ref} children={null} />; const element = <BaseNavigationContainer ref={ref} children={null} />;
@@ -697,7 +698,7 @@ it('throws if there is no navigator rendered', () => {
it("throws if the ref hasn't finished initializing", () => { it("throws if the ref hasn't finished initializing", () => {
expect.assertions(1); expect.assertions(1);
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const TestNavigator = (props: any) => { const TestNavigator = (props: any) => {
const { state, descriptors } = useNavigationBuilder(MockRouter, props); const { state, descriptors } = useNavigationBuilder(MockRouter, props);
@@ -733,7 +734,7 @@ it("throws if the ref hasn't finished initializing", () => {
}); });
it('invokes the unhandled action listener with the unhandled action', () => { it('invokes the unhandled action listener with the unhandled action', () => {
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const fn = jest.fn(); const fn = jest.fn();
const TestNavigator = (props: any) => { const TestNavigator = (props: any) => {
@@ -779,7 +780,7 @@ it('works with state change events in independent nested container', () => {
); );
}; };
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const onStateChange = jest.fn(); const onStateChange = jest.fn();

View File

@@ -1,12 +1,12 @@
import * as React from 'react'; import * as React from 'react';
import { render, act } from '@testing-library/react-native'; import { render, act } from '@testing-library/react-native';
import type { NavigationState } from '@react-navigation/routers'; import type { NavigationState, ParamListBase } from '@react-navigation/routers';
import Screen from '../Screen'; import Screen from '../Screen';
import BaseNavigationContainer from '../BaseNavigationContainer'; import BaseNavigationContainer from '../BaseNavigationContainer';
import useNavigationBuilder from '../useNavigationBuilder'; import useNavigationBuilder from '../useNavigationBuilder';
import createNavigationContainerRef from '../createNavigationContainerRef';
import useNavigation from '../useNavigation'; import useNavigation from '../useNavigation';
import MockRouter, { MockRouterKey } from './__fixtures__/MockRouter'; import MockRouter, { MockRouterKey } from './__fixtures__/MockRouter';
import type { NavigationContainerRef } from '../types';
beforeEach(() => (MockRouterKey.current = 0)); beforeEach(() => (MockRouterKey.current = 0));
@@ -679,7 +679,7 @@ it('navigates to nested child in a navigator', () => {
const onStateChange = jest.fn(); const onStateChange = jest.fn();
const navigation = React.createRef<NavigationContainerRef>(); const navigation = createNavigationContainerRef<ParamListBase>();
const element = render( const element = render(
<BaseNavigationContainer ref={navigation} onStateChange={onStateChange}> <BaseNavigationContainer ref={navigation} onStateChange={onStateChange}>
@@ -715,7 +715,7 @@ it('navigates to nested child in a navigator', () => {
expect(element).toMatchInlineSnapshot(`"[foo-a, undefined]"`); expect(element).toMatchInlineSnapshot(`"[foo-a, undefined]"`);
act(() => act(() =>
navigation.current?.navigate('bar', { navigation.navigate('bar', {
screen: 'bar-b', screen: 'bar-b',
params: { test: 42 }, params: { test: 42 },
}) })
@@ -726,7 +726,7 @@ it('navigates to nested child in a navigator', () => {
); );
act(() => act(() =>
navigation.current?.navigate('bar', { navigation.navigate('bar', {
screen: 'bar-a', screen: 'bar-a',
params: { whoa: 'test' }, params: { whoa: 'test' },
}) })
@@ -736,15 +736,15 @@ it('navigates to nested child in a navigator', () => {
`"[bar-a, {\\"lol\\":\\"why\\",\\"whoa\\":\\"test\\"}]"` `"[bar-a, {\\"lol\\":\\"why\\",\\"whoa\\":\\"test\\"}]"`
); );
act(() => navigation.current?.navigate('bar', { screen: 'bar-b' })); act(() => navigation.navigate('bar', { screen: 'bar-b' }));
act(() => navigation.current?.goBack()); act(() => navigation.goBack());
expect(element).toMatchInlineSnapshot( expect(element).toMatchInlineSnapshot(
`"[bar-a, {\\"lol\\":\\"why\\",\\"whoa\\":\\"test\\"}]"` `"[bar-a, {\\"lol\\":\\"why\\",\\"whoa\\":\\"test\\"}]"`
); );
act(() => navigation.current?.navigate('bar', { screen: 'bar-b' })); act(() => navigation.navigate('bar', { screen: 'bar-b' }));
expect(element).toMatchInlineSnapshot( expect(element).toMatchInlineSnapshot(
`"[bar-b, {\\"some\\":\\"stuff\\",\\"test\\":42,\\"whoa\\":\\"test\\"}]"` `"[bar-b, {\\"some\\":\\"stuff\\",\\"test\\":42,\\"whoa\\":\\"test\\"}]"`
@@ -799,7 +799,7 @@ it('navigates to nested child in a navigator with initial: false', () => {
const onStateChange = jest.fn(); const onStateChange = jest.fn();
const navigation = React.createRef<NavigationContainerRef>(); const navigation = createNavigationContainerRef<ParamListBase>();
const first = render( const first = render(
<BaseNavigationContainer ref={navigation} onStateChange={onStateChange}> <BaseNavigationContainer ref={navigation} onStateChange={onStateChange}>
@@ -833,7 +833,7 @@ it('navigates to nested child in a navigator with initial: false', () => {
); );
expect(first).toMatchInlineSnapshot(`"[foo-a, undefined]"`); expect(first).toMatchInlineSnapshot(`"[foo-a, undefined]"`);
expect(navigation.current?.getRootState()).toEqual({ expect(navigation.getRootState()).toEqual({
index: 0, index: 0,
key: '0', key: '0',
routeNames: ['foo', 'bar'], routeNames: ['foo', 'bar'],
@@ -866,7 +866,7 @@ it('navigates to nested child in a navigator with initial: false', () => {
}); });
act(() => act(() =>
navigation.current?.navigate('bar', { navigation.navigate('bar', {
screen: 'bar-b', screen: 'bar-b',
params: { test: 42 }, params: { test: 42 },
}) })
@@ -876,7 +876,7 @@ it('navigates to nested child in a navigator with initial: false', () => {
`"[bar-b, {\\"some\\":\\"stuff\\",\\"test\\":42}]"` `"[bar-b, {\\"some\\":\\"stuff\\",\\"test\\":42}]"`
); );
expect(navigation.current?.getRootState()).toEqual({ expect(navigation.getRootState()).toEqual({
index: 2, index: 2,
key: '0', key: '0',
routeNames: ['foo', 'bar'], routeNames: ['foo', 'bar'],
@@ -944,7 +944,7 @@ it('navigates to nested child in a navigator with initial: false', () => {
); );
expect(second).toMatchInlineSnapshot(`"[foo-a, undefined]"`); expect(second).toMatchInlineSnapshot(`"[foo-a, undefined]"`);
expect(navigation.current?.getRootState()).toEqual({ expect(navigation.getRootState()).toEqual({
index: 0, index: 0,
key: '4', key: '4',
routeNames: ['foo', 'bar'], routeNames: ['foo', 'bar'],
@@ -971,7 +971,7 @@ it('navigates to nested child in a navigator with initial: false', () => {
}); });
act(() => act(() =>
navigation.current?.navigate('bar', { navigation.navigate('bar', {
screen: 'bar-b', screen: 'bar-b',
params: { test: 42 }, params: { test: 42 },
initial: false, initial: false,
@@ -980,7 +980,7 @@ it('navigates to nested child in a navigator with initial: false', () => {
expect(second).toMatchInlineSnapshot(`"[bar-b, {\\"test\\":42}]"`); expect(second).toMatchInlineSnapshot(`"[bar-b, {\\"test\\":42}]"`);
expect(navigation.current?.getRootState()).toEqual({ expect(navigation.getRootState()).toEqual({
index: 2, index: 2,
key: '4', key: '4',
routeNames: ['foo', 'bar'], routeNames: ['foo', 'bar'],
@@ -1071,7 +1071,7 @@ it('navigates to nested child in a navigator with initial: false', () => {
expect(third).toMatchInlineSnapshot(`"[bar-b, {\\"some\\":\\"stuff\\"}]"`); expect(third).toMatchInlineSnapshot(`"[bar-b, {\\"some\\":\\"stuff\\"}]"`);
expect(navigation.current?.getRootState()).toEqual({ expect(navigation.getRootState()).toEqual({
index: 1, index: 1,
key: '11', key: '11',
routeNames: ['foo', 'bar'], routeNames: ['foo', 'bar'],
@@ -1119,7 +1119,7 @@ it('resets state of a nested child in a navigator', () => {
const onStateChange = jest.fn(); const onStateChange = jest.fn();
const navigation = React.createRef<NavigationContainerRef>(); const navigation = createNavigationContainerRef<ParamListBase>();
const first = render( const first = render(
<BaseNavigationContainer ref={navigation} onStateChange={onStateChange}> <BaseNavigationContainer ref={navigation} onStateChange={onStateChange}>
@@ -1150,7 +1150,7 @@ it('resets state of a nested child in a navigator', () => {
expect(first).toMatchInlineSnapshot(`"[foo-a, undefined]"`); expect(first).toMatchInlineSnapshot(`"[foo-a, undefined]"`);
expect(navigation.current?.getRootState()).toEqual({ expect(navigation.getRootState()).toEqual({
index: 0, index: 0,
key: '0', key: '0',
routeNames: ['foo', 'bar'], routeNames: ['foo', 'bar'],
@@ -1183,7 +1183,7 @@ it('resets state of a nested child in a navigator', () => {
}); });
act(() => act(() =>
navigation.current?.navigate('bar', { navigation.navigate('bar', {
state: { state: {
routes: [{ name: 'bar-a' }, { name: 'bar-b' }], routes: [{ name: 'bar-a' }, { name: 'bar-b' }],
}, },
@@ -1192,7 +1192,7 @@ it('resets state of a nested child in a navigator', () => {
expect(first).toMatchInlineSnapshot(`"[bar-a, undefined]"`); expect(first).toMatchInlineSnapshot(`"[bar-a, undefined]"`);
expect(navigation.current?.getRootState()).toEqual({ expect(navigation.getRootState()).toEqual({
index: 1, index: 1,
key: '0', key: '0',
routeNames: ['foo', 'bar'], routeNames: ['foo', 'bar'],
@@ -1231,7 +1231,7 @@ it('resets state of a nested child in a navigator', () => {
}); });
act(() => act(() =>
navigation.current?.navigate('bar', { navigation.navigate('bar', {
state: { state: {
index: 2, index: 2,
routes: [ routes: [
@@ -1245,7 +1245,7 @@ it('resets state of a nested child in a navigator', () => {
expect(first).toMatchInlineSnapshot(`"[bar-a, {\\"test\\":18}]"`); expect(first).toMatchInlineSnapshot(`"[bar-a, {\\"test\\":18}]"`);
expect(navigation.current?.getRootState()).toEqual({ expect(navigation.getRootState()).toEqual({
index: 1, index: 1,
key: '0', key: '0',
routeNames: ['foo', 'bar'], routeNames: ['foo', 'bar'],
@@ -1336,7 +1336,7 @@ it('preserves order of screens in state with non-numeric names', () => {
return null; return null;
}; };
const navigation = React.createRef<NavigationContainerRef>(); const navigation = createNavigationContainerRef<ParamListBase>();
const root = ( const root = (
<BaseNavigationContainer ref={navigation}> <BaseNavigationContainer ref={navigation}>
@@ -1350,11 +1350,7 @@ it('preserves order of screens in state with non-numeric names', () => {
render(root); render(root);
expect(navigation.current?.getRootState().routeNames).toEqual([ expect(navigation.getRootState().routeNames).toEqual(['foo', 'bar', 'baz']);
'foo',
'bar',
'baz',
]);
}); });
it('preserves order of screens in state with numeric names', () => { it('preserves order of screens in state with numeric names', () => {
@@ -1363,7 +1359,7 @@ it('preserves order of screens in state with numeric names', () => {
return null; return null;
}; };
const navigation = React.createRef<NavigationContainerRef>(); const navigation = createNavigationContainerRef<ParamListBase>();
const root = ( const root = (
<BaseNavigationContainer ref={navigation}> <BaseNavigationContainer ref={navigation}>
@@ -1377,11 +1373,7 @@ it('preserves order of screens in state with numeric names', () => {
render(root); render(root);
expect(navigation.current?.getRootState().routeNames).toEqual([ expect(navigation.getRootState().routeNames).toEqual(['4', '7', '1']);
'4',
'7',
'1',
]);
}); });
it("throws if navigator doesn't have any screens", () => { it("throws if navigator doesn't have any screens", () => {
@@ -1801,7 +1793,7 @@ it('returns currently focused route with getCurrentRoute', () => {
const TestScreen = () => null; const TestScreen = () => null;
const navigation = React.createRef<NavigationContainerRef>(); const navigation = createNavigationContainerRef<ParamListBase>();
const container = ( const container = (
<BaseNavigationContainer ref={navigation}> <BaseNavigationContainer ref={navigation}>
@@ -1824,7 +1816,7 @@ it('returns currently focused route with getCurrentRoute', () => {
render(container).update(container); render(container).update(container);
expect(navigation.current?.getCurrentRoute()).toEqual({ expect(navigation.getCurrentRoute()).toEqual({
key: 'bar-a', key: 'bar-a',
name: 'bar-a', name: 'bar-a',
}); });
@@ -1839,7 +1831,7 @@ it("returns focused screen's options with getCurrentOptions when focused screen
const TestScreen = () => null; const TestScreen = () => null;
const navigation = React.createRef<NavigationContainerRef>(); const navigation = createNavigationContainerRef<ParamListBase>();
const container = ( const container = (
<BaseNavigationContainer ref={navigation}> <BaseNavigationContainer ref={navigation}>
@@ -1870,14 +1862,14 @@ it("returns focused screen's options with getCurrentOptions when focused screen
render(container).update(container); render(container).update(container);
expect(navigation.current?.getCurrentOptions()).toEqual({ expect(navigation.getCurrentOptions()).toEqual({
sample: 'data', sample: 'data',
sample2: 'data', sample2: 'data',
}); });
act(() => navigation.current?.navigate('bar-b')); act(() => navigation.navigate('bar-b'));
expect(navigation.current?.getCurrentOptions()).toEqual({ expect(navigation.getCurrentOptions()).toEqual({
sample2: 'data', sample2: 'data',
sample3: 'data', sample3: 'data',
}); });
@@ -1892,7 +1884,7 @@ it("returns focused screen's options with getCurrentOptions when all screens are
const TestScreen = () => null; const TestScreen = () => null;
const navigation = React.createRef<NavigationContainerRef>(); const navigation = createNavigationContainerRef<ParamListBase>();
const container = ( const container = (
<BaseNavigationContainer ref={navigation}> <BaseNavigationContainer ref={navigation}>
@@ -1923,14 +1915,14 @@ it("returns focused screen's options with getCurrentOptions when all screens are
render(container).update(container); render(container).update(container);
expect(navigation.current?.getCurrentOptions()).toEqual({ expect(navigation.getCurrentOptions()).toEqual({
sample: 'data', sample: 'data',
sample2: 'data', sample2: 'data',
}); });
act(() => navigation.current?.navigate('bar-b')); act(() => navigation.navigate('bar-b'));
expect(navigation.current?.getCurrentOptions()).toEqual({ expect(navigation.getCurrentOptions()).toEqual({
sample2: 'data', sample2: 'data',
sample3: 'data', sample3: 'data',
}); });
@@ -1945,7 +1937,7 @@ it('does not throw if while getting current options with no options defined', ()
const TestScreen = () => null; const TestScreen = () => null;
const navigation = React.createRef<NavigationContainerRef>(); const navigation = createNavigationContainerRef<ParamListBase>();
const container = ( const container = (
<BaseNavigationContainer ref={navigation}> <BaseNavigationContainer ref={navigation}>
@@ -1968,11 +1960,11 @@ it('does not throw if while getting current options with no options defined', ()
render(container).update(container); render(container).update(container);
expect(navigation.current?.getCurrentOptions()).toEqual({}); expect(navigation.getCurrentOptions()).toEqual({});
}); });
it('does not throw if while getting current options with empty container', () => { it('does not throw if while getting current options with empty container', () => {
const navigation = React.createRef<NavigationContainerRef>(); const navigation = createNavigationContainerRef<ParamListBase>();
const container = ( const container = (
<BaseNavigationContainer ref={navigation} children={null} /> <BaseNavigationContainer ref={navigation} children={null} />
@@ -1980,5 +1972,5 @@ it('does not throw if while getting current options with empty container', () =>
render(container).update(container); render(container).update(container);
expect(navigation.current?.getCurrentOptions()).toEqual(undefined); expect(navigation.getCurrentOptions()).toEqual(undefined);
}); });

View File

@@ -5,15 +5,16 @@ import {
DefaultRouterOptions, DefaultRouterOptions,
NavigationState, NavigationState,
StackRouter, StackRouter,
ParamListBase,
} from '@react-navigation/routers'; } from '@react-navigation/routers';
import useNavigationBuilder from '../useNavigationBuilder'; import useNavigationBuilder from '../useNavigationBuilder';
import BaseNavigationContainer from '../BaseNavigationContainer'; import BaseNavigationContainer from '../BaseNavigationContainer';
import Screen from '../Screen'; import Screen from '../Screen';
import createNavigationContainerRef from '../createNavigationContainerRef';
import MockRouter, { import MockRouter, {
MockActions, MockActions,
MockRouterKey, MockRouterKey,
} from './__fixtures__/MockRouter'; } from './__fixtures__/MockRouter';
import type { NavigationContainerRef } from '../types';
jest.mock('nanoid/non-secure', () => { jest.mock('nanoid/non-secure', () => {
const m = { nanoid: () => String(++m.__key), __key: 0 }; const m = { nanoid: () => String(++m.__key), __key: 0 };
@@ -571,7 +572,7 @@ it("prevents removing a screen with 'beforeRemove' event", () => {
const onStateChange = jest.fn(); const onStateChange = jest.fn();
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const element = ( const element = (
<BaseNavigationContainer ref={ref} onStateChange={onStateChange}> <BaseNavigationContainer ref={ref} onStateChange={onStateChange}>
@@ -706,7 +707,7 @@ it("prevents removing a child screen with 'beforeRemove' event", () => {
const onStateChange = jest.fn(); const onStateChange = jest.fn();
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const element = ( const element = (
<BaseNavigationContainer ref={ref} onStateChange={onStateChange}> <BaseNavigationContainer ref={ref} onStateChange={onStateChange}>
@@ -867,7 +868,7 @@ it("prevents removing a grand child screen with 'beforeRemove' event", () => {
const onStateChange = jest.fn(); const onStateChange = jest.fn();
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const element = ( const element = (
<BaseNavigationContainer ref={ref} onStateChange={onStateChange}> <BaseNavigationContainer ref={ref} onStateChange={onStateChange}>
@@ -1065,7 +1066,7 @@ it("prevents removing by multiple screens with 'beforeRemove' event", () => {
const onStateChange = jest.fn(); const onStateChange = jest.fn();
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const element = ( const element = (
<BaseNavigationContainer ref={ref} onStateChange={onStateChange}> <BaseNavigationContainer ref={ref} onStateChange={onStateChange}>
@@ -1217,7 +1218,7 @@ it("prevents removing a child screen with 'beforeRemove' event with 'resetRoot'"
const onStateChange = jest.fn(); const onStateChange = jest.fn();
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const element = ( const element = (
<BaseNavigationContainer ref={ref} onStateChange={onStateChange}> <BaseNavigationContainer ref={ref} onStateChange={onStateChange}>

View File

@@ -0,0 +1,47 @@
import { CommonActions, ParamListBase } from '@react-navigation/routers';
import type { NavigationContainerRefWithCurrent } from './types';
export const NOT_INITIALIZED_ERROR =
"The 'navigation' object hasn't been initialized yet. This might happen if you don't have a navigator mounted, or if the navigator hasn't finished mounting. See https://reactnavigation.org/docs/navigating-without-navigation-prop#handling-initialization for more details.";
export default function createNavigationContainerRef<
ParamList extends ParamListBase
>(): NavigationContainerRefWithCurrent<ParamList> {
const methods = [
...Object.keys(CommonActions),
'addListener',
'removeListener',
'resetRoot',
'dispatch',
'canGoBack',
'getRootState',
'getState',
'getParent',
'getCurrentRoute',
'getCurrentOptions',
] as const;
const ref: NavigationContainerRefWithCurrent<ParamList> = {
...methods.reduce<any>((acc, name) => {
acc[name] = (...args: any[]) => {
if (ref.current == null) {
console.error(NOT_INITIALIZED_ERROR);
} else {
// @ts-expect-error: this is ok
return ref.current[name](...args);
}
};
return acc;
}, {}),
isReady: () => {
if (ref.current == null) {
return false;
}
return ref.current.isReady();
},
current: null,
};
return ref;
}

View File

@@ -3,6 +3,9 @@ export * from '@react-navigation/routers';
export { default as BaseNavigationContainer } from './BaseNavigationContainer'; export { default as BaseNavigationContainer } from './BaseNavigationContainer';
export { default as createNavigatorFactory } from './createNavigatorFactory'; export { default as createNavigatorFactory } from './createNavigatorFactory';
export { default as createNavigationContainerRef } from './createNavigationContainerRef';
export { default as useNavigationContainerRef } from './useNavigationContainerRef';
export { default as NavigationHelpersContext } from './NavigationHelpersContext'; export { default as NavigationHelpersContext } from './NavigationHelpersContext';
export { default as NavigationContext } from './NavigationContext'; export { default as NavigationContext } from './NavigationContext';
export { default as NavigationRouteContext } from './NavigationRouteContext'; export { default as NavigationRouteContext } from './NavigationRouteContext';

View File

@@ -9,10 +9,12 @@ import type {
ParamListBase, ParamListBase,
} from '@react-navigation/routers'; } from '@react-navigation/routers';
type Keyof<T extends {}> = Extract<keyof T, string>;
export type DefaultNavigatorOptions< export type DefaultNavigatorOptions<
ScreenOptions extends {}, ScreenOptions extends {},
ParamList extends ParamListBase = ParamListBase ParamList extends ParamListBase = ParamListBase
> = DefaultRouterOptions<Extract<keyof ParamList, string>> & { > = DefaultRouterOptions<Keyof<ParamList>> & {
/** /**
* Children React Elements to extract the route configuration from. * Children React Elements to extract the route configuration from.
* Only `Screen` components are supported as children. * Only `Screen` components are supported as children.
@@ -24,7 +26,7 @@ export type DefaultNavigatorOptions<
screenOptions?: screenOptions?:
| ScreenOptions | ScreenOptions
| ((props: { | ((props: {
route: RouteProp<ParamList, keyof ParamList>; route: RouteProp<ParamList>;
navigation: any; navigation: any;
}) => ScreenOptions); }) => ScreenOptions);
/** /**
@@ -34,7 +36,7 @@ export type DefaultNavigatorOptions<
defaultScreenOptions?: defaultScreenOptions?:
| ScreenOptions | ScreenOptions
| ((props: { | ((props: {
route: RouteProp<ParamList, keyof ParamList>; route: RouteProp<ParamList>;
navigation: any; navigation: any;
options: ScreenOptions; options: ScreenOptions;
}) => ScreenOptions); }) => ScreenOptions);
@@ -96,11 +98,11 @@ export type EventConsumer<EventMap extends EventMapBase> = {
* @param type Type of the event (e.g. `focus`, `blur`) * @param type Type of the event (e.g. `focus`, `blur`)
* @param callback Callback listener which is executed upon receiving the event. * @param callback Callback listener which is executed upon receiving the event.
*/ */
addListener<EventName extends Extract<keyof EventMap, string>>( addListener<EventName extends Keyof<EventMap>>(
type: EventName, type: EventName,
callback: EventListenerCallback<EventMap, EventName> callback: EventListenerCallback<EventMap, EventName>
): () => void; ): () => void;
removeListener<EventName extends Extract<keyof EventMap, string>>( removeListener<EventName extends Keyof<EventMap>>(
type: EventName, type: EventName,
callback: EventListenerCallback<EventMap, EventName> callback: EventListenerCallback<EventMap, EventName>
): void; ): void;
@@ -115,7 +117,7 @@ export type EventEmitter<EventMap extends EventMapBase> = {
* @param [options.target] Key of the target route which should receive the event. * @param [options.target] Key of the target route which should receive the event.
* If not specified, all routes receive the event. * If not specified, all routes receive the event.
*/ */
emit<EventName extends Extract<keyof EventMap, string>>( emit<EventName extends Keyof<EventMap>>(
options: { options: {
type: EventName; type: EventName;
target?: string; target?: string;
@@ -264,7 +266,7 @@ export type NavigationContainerProps = {
export type NavigationProp< export type NavigationProp<
ParamList extends ParamListBase, ParamList extends ParamListBase,
RouteName extends keyof ParamList = string, RouteName extends keyof ParamList = Keyof<ParamList>,
State extends NavigationState = NavigationState<ParamList>, State extends NavigationState = NavigationState<ParamList>,
ScreenOptions extends {} = {}, ScreenOptions extends {} = {},
EventMap extends EventMapBase = {} EventMap extends EventMapBase = {}
@@ -289,7 +291,7 @@ export type NavigationProp<
export type RouteProp< export type RouteProp<
ParamList extends ParamListBase, ParamList extends ParamListBase,
RouteName extends keyof ParamList RouteName extends keyof ParamList = Keyof<ParamList>
> = Route<Extract<RouteName, string>, ParamList[RouteName]>; > = Route<Extract<RouteName, string>, ParamList[RouteName]>;
export type CompositeNavigationProp< export type CompositeNavigationProp<
@@ -325,6 +327,19 @@ export type CompositeNavigationProp<
A extends NavigationProp<any, any, any, any, infer E> ? E : {} A extends NavigationProp<any, any, any, any, infer E> ? E : {}
>; >;
export type CompositeScreenProps<
A extends {
navigation: NavigationProp<ParamListBase, string, any, any>;
route: RouteProp<ParamListBase>;
},
B extends {
navigation: NavigationHelpersCommon<ParamListBase, any>;
}
> = {
navigation: CompositeNavigationProp<A['navigation'], B['navigation']>;
route: A['route'];
};
export type Descriptor< export type Descriptor<
ScreenOptions extends {}, ScreenOptions extends {},
Navigation extends NavigationProp<any, any, any, any, any>, Navigation extends NavigationProp<any, any, any, any, any>,
@@ -470,7 +485,9 @@ export type NavigationContainerEventMap = {
}; };
}; };
export type NavigationContainerRef = NavigationHelpers<ParamListBase> & export type NavigationContainerRef<
ParamList extends ParamListBase
> = NavigationHelpers<ParamList> &
EventConsumer<NavigationContainerEventMap> & { EventConsumer<NavigationContainerEventMap> & {
/** /**
* Reset the navigation state of the root navigator to the provided state. * Reset the navigation state of the root navigator to the provided state.
@@ -490,8 +507,18 @@ export type NavigationContainerRef = NavigationHelpers<ParamListBase> &
* Get the currently focused route's options. * Get the currently focused route's options.
*/ */
getCurrentOptions(): object | undefined; getCurrentOptions(): object | undefined;
/**
* Whether the navigation container is ready to handle actions.
*/
isReady(): boolean;
}; };
export type NavigationContainerRefWithCurrent<
ParamList extends ParamListBase
> = NavigationContainerRef<ParamList> & {
current: NavigationContainerRef<ParamList> | null;
};
export type TypedNavigator< export type TypedNavigator<
ParamList extends ParamListBase, ParamList extends ParamListBase,
State extends NavigationState, State extends NavigationState,

View File

@@ -13,11 +13,7 @@ type Options = {
navigation: NavigationHelpers<ParamListBase>; navigation: NavigationHelpers<ParamListBase>;
descriptors: Record< descriptors: Record<
string, string,
Descriptor< Descriptor<object, NavigationProp<ParamListBase>, RouteProp<ParamListBase>>
object,
NavigationProp<ParamListBase>,
RouteProp<ParamListBase, string>
>
>; >;
}; };

View File

@@ -38,13 +38,13 @@ type Options<
screenOptions?: screenOptions?:
| ScreenOptions | ScreenOptions
| ((props: { | ((props: {
route: RouteProp<ParamListBase, string>; route: RouteProp<ParamListBase>;
navigation: any; navigation: any;
}) => ScreenOptions); }) => ScreenOptions);
defaultScreenOptions?: defaultScreenOptions?:
| ScreenOptions | ScreenOptions
| ((props: { | ((props: {
route: RouteProp<ParamListBase, string>; route: RouteProp<ParamListBase>;
navigation: any; navigation: any;
options: ScreenOptions; options: ScreenOptions;
}) => ScreenOptions); }) => ScreenOptions);
@@ -133,7 +133,7 @@ export default function useDescriptors<
ScreenOptions, ScreenOptions,
NavigationProp<ParamListBase, string, State, ScreenOptions, EventMap> & NavigationProp<ParamListBase, string, State, ScreenOptions, EventMap> &
ActionHelpers, ActionHelpers,
RouteProp<ParamListBase, string> RouteProp<ParamListBase>
> >
> >
>((acc, route, i) => { >((acc, route, i) => {

View File

@@ -0,0 +1,18 @@
import * as React from 'react';
import type { ParamListBase } from '@react-navigation/routers';
import createNavigationContainerRef from './createNavigationContainerRef';
import type { NavigationContainerRefWithCurrent } from './types';
export default function useNavigationContainerRef<
ParamList extends ParamListBase
>(): NavigationContainerRefWithCurrent<ParamList> {
const navigation = React.useRef<NavigationContainerRefWithCurrent<ParamList> | null>(
null
);
if (navigation.current == null) {
navigation.current = createNavigationContainerRef<ParamList>();
}
return navigation.current;
}

View File

@@ -1,12 +1,12 @@
import * as React from 'react'; import * as React from 'react';
import type { ParamListBase, NavigationState } from '@react-navigation/routers'; import type { ParamListBase } from '@react-navigation/routers';
import NavigationStateContext from './NavigationStateContext'; import NavigationStateContext from './NavigationStateContext';
import NavigationBuilderContext from './NavigationBuilderContext'; import NavigationBuilderContext from './NavigationBuilderContext';
import type { NavigationProp } from './types'; import type { NavigationProp } from './types';
type Options = { type Options = {
key?: string; key?: string;
navigation?: NavigationProp<ParamListBase, string, NavigationState, object>; navigation?: NavigationProp<ParamListBase>;
options?: object | undefined; options?: object | undefined;
}; };

View File

@@ -8,9 +8,7 @@ import type { RouteProp } from './types';
* *
* @returns Route prop of the parent screen. * @returns Route prop of the parent screen.
*/ */
export default function useRoute< export default function useRoute<T extends RouteProp<ParamListBase>>(): T {
T extends RouteProp<ParamListBase, string>
>(): T {
const route = React.useContext(NavigationRouteContext); const route = React.useContext(NavigationRouteContext);
if (route === undefined) { if (route === undefined) {

View File

@@ -6,7 +6,7 @@ import type {
} from '@react-navigation/routers'; } from '@react-navigation/routers';
import type { RouteProp } from './types'; import type { RouteProp } from './types';
type RouteCache = Map<Route<string>, RouteProp<ParamListBase, string>>; type RouteCache = Map<Route<string>, RouteProp<ParamListBase>>;
/** /**
* Utilites such as `getFocusedRouteNameFromRoute` need to access state. * Utilites such as `getFocusedRouteNameFromRoute` need to access state.

View File

@@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.3](https://github.com/react-navigation/react-navigation/compare/@react-navigation/devtools@6.0.0-next.2...@react-navigation/devtools@6.0.0-next.3) (2021-05-01)
### Features
* add helper and hook for container ref ([0ecd112](https://github.com/react-navigation/react-navigation/commit/0ecd112ec9786a26261ada3d33ef44dc1ec84da0))
# [6.0.0-next.2](https://github.com/react-navigation/react-navigation/compare/@react-navigation/devtools@6.0.0-next.1...@react-navigation/devtools@6.0.0-next.2) (2021-04-08) # [6.0.0-next.2](https://github.com/react-navigation/react-navigation/compare/@react-navigation/devtools@6.0.0-next.1...@react-navigation/devtools@6.0.0-next.2) (2021-04-08)
**Note:** Version bump only for package @react-navigation/devtools **Note:** Version bump only for package @react-navigation/devtools

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/devtools", "name": "@react-navigation/devtools",
"description": "Developer tools for React Navigation", "description": "Developer tools for React Navigation",
"version": "6.0.0-next.2", "version": "6.0.0-next.3",
"keywords": [ "keywords": [
"react", "react",
"react-native", "react-native",
@@ -36,7 +36,7 @@
"clean": "del lib" "clean": "del lib"
}, },
"dependencies": { "dependencies": {
"@react-navigation/core": "^6.0.0-next.2", "@react-navigation/core": "^6.0.0-next.3",
"deep-equal": "^2.0.5" "deep-equal": "^2.0.5"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -3,6 +3,7 @@ import type {
NavigationContainerRef, NavigationContainerRef,
NavigationState, NavigationState,
NavigationAction, NavigationAction,
ParamListBase,
} from '@react-navigation/core'; } from '@react-navigation/core';
import deepEqual from 'deep-equal'; import deepEqual from 'deep-equal';
@@ -22,7 +23,7 @@ type DevToolsExtension = {
declare const __REDUX_DEVTOOLS_EXTENSION__: DevToolsExtension | undefined; declare const __REDUX_DEVTOOLS_EXTENSION__: DevToolsExtension | undefined;
export default function useReduxDevToolsExtension( export default function useReduxDevToolsExtension(
ref: React.RefObject<NavigationContainerRef> ref: React.RefObject<NavigationContainerRef<ParamListBase>>
) { ) {
const devToolsRef = React.useRef<DevToolsConnection>(); const devToolsRef = React.useRef<DevToolsConnection>();

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.5](https://github.com/react-navigation/react-navigation/compare/@react-navigation/drawer@6.0.0-next.4...@react-navigation/drawer@6.0.0-next.5) (2021-05-01)
**Note:** Version bump only for package @react-navigation/drawer
# [6.0.0-next.4](https://github.com/react-navigation/react-navigation/compare/@react-navigation/drawer@6.0.0-next.3...@react-navigation/drawer@6.0.0-next.4) (2021-04-08) # [6.0.0-next.4](https://github.com/react-navigation/react-navigation/compare/@react-navigation/drawer@6.0.0-next.3...@react-navigation/drawer@6.0.0-next.4) (2021-04-08)

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/drawer", "name": "@react-navigation/drawer",
"description": "Drawer navigator component with animated transitions and gesturess", "description": "Drawer navigator component with animated transitions and gesturess",
"version": "6.0.0-next.4", "version": "6.0.0-next.5",
"keywords": [ "keywords": [
"react-native-component", "react-native-component",
"react-component", "react-component",
@@ -41,12 +41,12 @@
"clean": "del lib" "clean": "del lib"
}, },
"dependencies": { "dependencies": {
"@react-navigation/elements": "^1.0.0-next.4", "@react-navigation/elements": "^1.0.0-next.5",
"color": "^3.1.3", "color": "^3.1.3",
"warn-once": "^0.0.1" "warn-once": "^0.0.1"
}, },
"devDependencies": { "devDependencies": {
"@react-navigation/native": "^6.0.0-next.2", "@react-navigation/native": "^6.0.0-next.3",
"@testing-library/react-native": "^7.2.0", "@testing-library/react-native": "^7.2.0",
"@types/react": "^16.9.53", "@types/react": "^16.9.53",
"@types/react-native": "~0.63.51", "@types/react-native": "~0.63.51",

View File

@@ -235,7 +235,7 @@ export type DrawerHeaderProps = {
/** /**
* Route object for the current screen. * Route object for the current screen.
*/ */
route: RouteProp<ParamListBase, string>; route: RouteProp<ParamListBase>;
/** /**
* Navigation prop for the header. * Navigation prop for the header.
*/ */
@@ -252,7 +252,7 @@ export type DrawerNavigationHelpers = NavigationHelpers<
export type DrawerNavigationProp< export type DrawerNavigationProp<
ParamList extends ParamListBase, ParamList extends ParamListBase,
RouteName extends keyof ParamList = string RouteName extends keyof ParamList = keyof ParamList
> = NavigationProp< > = NavigationProp<
ParamList, ParamList,
RouteName, RouteName,
@@ -264,7 +264,7 @@ export type DrawerNavigationProp<
export type DrawerScreenProps< export type DrawerScreenProps<
ParamList extends ParamListBase, ParamList extends ParamListBase,
RouteName extends keyof ParamList = string RouteName extends keyof ParamList = keyof ParamList
> = { > = {
navigation: DrawerNavigationProp<ParamList, RouteName>; navigation: DrawerNavigationProp<ParamList, RouteName>;
route: RouteProp<ParamList, RouteName>; route: RouteProp<ParamList, RouteName>;
@@ -273,7 +273,7 @@ export type DrawerScreenProps<
export type DrawerDescriptor = Descriptor< export type DrawerDescriptor = Descriptor<
DrawerNavigationOptions, DrawerNavigationOptions,
DrawerNavigationProp<ParamListBase>, DrawerNavigationProp<ParamListBase>,
RouteProp<ParamListBase, string> RouteProp<ParamListBase>
>; >;
export type DrawerDescriptorMap = Record<string, DrawerDescriptor>; export type DrawerDescriptorMap = Record<string, DrawerDescriptor>;

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [1.0.0-next.5](https://github.com/react-navigation/react-navigation/compare/@react-navigation/elements@1.0.0-next.4...@react-navigation/elements@1.0.0-next.5) (2021-05-01)
**Note:** Version bump only for package @react-navigation/elements
# [1.0.0-next.4](https://github.com/react-navigation/react-navigation/compare/@react-navigation/elements@1.0.0-next.3...@react-navigation/elements@1.0.0-next.4) (2021-04-08) # [1.0.0-next.4](https://github.com/react-navigation/react-navigation/compare/@react-navigation/elements@1.0.0-next.3...@react-navigation/elements@1.0.0-next.4) (2021-04-08)
**Note:** Version bump only for package @react-navigation/elements **Note:** Version bump only for package @react-navigation/elements

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/elements", "name": "@react-navigation/elements",
"description": "UI Components for React Navigation", "description": "UI Components for React Navigation",
"version": "1.0.0-next.4", "version": "1.0.0-next.5",
"keywords": [ "keywords": [
"react-native", "react-native",
"react-navigation", "react-navigation",
@@ -38,7 +38,7 @@
}, },
"devDependencies": { "devDependencies": {
"@react-native-masked-view/masked-view": "^0.2.3", "@react-native-masked-view/masked-view": "^0.2.3",
"@react-navigation/native": "^6.0.0-next.2", "@react-navigation/native": "^6.0.0-next.3",
"@testing-library/react-native": "^7.2.0", "@testing-library/react-native": "^7.2.0",
"@types/react": "^16.9.53", "@types/react": "^16.9.53",
"@types/react-native": "~0.63.51", "@types/react-native": "~0.63.51",

View File

@@ -20,7 +20,7 @@ import getDefaultHeaderHeight from './Header/getDefaultHeaderHeight';
type Props = { type Props = {
focused: boolean; focused: boolean;
navigation: NavigationProp<ParamListBase>; navigation: NavigationProp<ParamListBase>;
route: RouteProp<ParamListBase, string>; route: RouteProp<ParamListBase>;
header: React.ReactNode; header: React.ReactNode;
headerShown?: boolean; headerShown?: boolean;
headerStatusBarHeight?: number; headerStatusBarHeight?: number;

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.3](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-bottom-tabs@6.0.0-next.2...@react-navigation/material-bottom-tabs@6.0.0-next.3) (2021-05-01)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
# [6.0.0-next.2](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-bottom-tabs@6.0.0-next.1...@react-navigation/material-bottom-tabs@6.0.0-next.2) (2021-04-08) # [6.0.0-next.2](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-bottom-tabs@6.0.0-next.1...@react-navigation/material-bottom-tabs@6.0.0-next.2) (2021-04-08)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs **Note:** Version bump only for package @react-navigation/material-bottom-tabs

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/material-bottom-tabs", "name": "@react-navigation/material-bottom-tabs",
"description": "Integration for bottom navigation component from react-native-paper", "description": "Integration for bottom navigation component from react-native-paper",
"version": "6.0.0-next.2", "version": "6.0.0-next.3",
"keywords": [ "keywords": [
"react-native-component", "react-native-component",
"react-component", "react-component",
@@ -41,7 +41,7 @@
"clean": "del lib" "clean": "del lib"
}, },
"devDependencies": { "devDependencies": {
"@react-navigation/native": "^6.0.0-next.2", "@react-navigation/native": "^6.0.0-next.3",
"@testing-library/react-native": "^7.2.0", "@testing-library/react-native": "^7.2.0",
"@types/react": "^16.9.53", "@types/react": "^16.9.53",
"@types/react-native": "~0.63.51", "@types/react-native": "~0.63.51",

View File

@@ -24,7 +24,7 @@ export type MaterialBottomTabNavigationHelpers = NavigationHelpers<
export type MaterialBottomTabNavigationProp< export type MaterialBottomTabNavigationProp<
ParamList extends ParamListBase, ParamList extends ParamListBase,
RouteName extends keyof ParamList = string RouteName extends keyof ParamList = keyof ParamList
> = NavigationProp< > = NavigationProp<
ParamList, ParamList,
RouteName, RouteName,
@@ -36,7 +36,7 @@ export type MaterialBottomTabNavigationProp<
export type MaterialBottomTabScreenProps< export type MaterialBottomTabScreenProps<
ParamList extends ParamListBase, ParamList extends ParamListBase,
RouteName extends keyof ParamList = string RouteName extends keyof ParamList = keyof ParamList
> = { > = {
navigation: MaterialBottomTabNavigationProp<ParamList, RouteName>; navigation: MaterialBottomTabNavigationProp<ParamList, RouteName>;
route: RouteProp<ParamList, RouteName>; route: RouteProp<ParamList, RouteName>;
@@ -85,7 +85,7 @@ export type MaterialBottomTabNavigationOptions = {
export type MaterialBottomTabDescriptor = Descriptor< export type MaterialBottomTabDescriptor = Descriptor<
MaterialBottomTabNavigationOptions, MaterialBottomTabNavigationOptions,
MaterialBottomTabNavigationProp<ParamListBase>, MaterialBottomTabNavigationProp<ParamListBase>,
RouteProp<ParamListBase, string> RouteProp<ParamListBase>
>; >;
export type MaterialBottomTabDescriptorMap = Record< export type MaterialBottomTabDescriptorMap = Record<

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.4](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-top-tabs@6.0.0-next.3...@react-navigation/material-top-tabs@6.0.0-next.4) (2021-05-01)
**Note:** Version bump only for package @react-navigation/material-top-tabs
# [6.0.0-next.3](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-top-tabs@6.0.0-next.2...@react-navigation/material-top-tabs@6.0.0-next.3) (2021-04-08) # [6.0.0-next.3](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-top-tabs@6.0.0-next.2...@react-navigation/material-top-tabs@6.0.0-next.3) (2021-04-08)
**Note:** Version bump only for package @react-navigation/material-top-tabs **Note:** Version bump only for package @react-navigation/material-top-tabs

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/material-top-tabs", "name": "@react-navigation/material-top-tabs",
"description": "Integration for the animated tab view component from react-native-tab-view", "description": "Integration for the animated tab view component from react-native-tab-view",
"version": "6.0.0-next.3", "version": "6.0.0-next.4",
"keywords": [ "keywords": [
"react-native-component", "react-native-component",
"react-component", "react-component",
@@ -45,7 +45,7 @@
"warn-once": "^0.0.1" "warn-once": "^0.0.1"
}, },
"devDependencies": { "devDependencies": {
"@react-navigation/native": "^6.0.0-next.2", "@react-navigation/native": "^6.0.0-next.3",
"@testing-library/react-native": "^7.2.0", "@testing-library/react-native": "^7.2.0",
"@types/react": "^16.9.53", "@types/react": "^16.9.53",
"@types/react-native": "~0.63.51", "@types/react-native": "~0.63.51",

View File

@@ -38,7 +38,7 @@ export type MaterialTopTabNavigationHelpers = NavigationHelpers<
export type MaterialTopTabNavigationProp< export type MaterialTopTabNavigationProp<
ParamList extends ParamListBase, ParamList extends ParamListBase,
RouteName extends keyof ParamList = string RouteName extends keyof ParamList = keyof ParamList
> = NavigationProp< > = NavigationProp<
ParamList, ParamList,
RouteName, RouteName,
@@ -50,7 +50,7 @@ export type MaterialTopTabNavigationProp<
export type MaterialTopTabScreenProps< export type MaterialTopTabScreenProps<
ParamList extends ParamListBase, ParamList extends ParamListBase,
RouteName extends keyof ParamList = string RouteName extends keyof ParamList = keyof ParamList
> = { > = {
navigation: MaterialTopTabNavigationProp<ParamList, RouteName>; navigation: MaterialTopTabNavigationProp<ParamList, RouteName>;
route: RouteProp<ParamList, RouteName>; route: RouteProp<ParamList, RouteName>;
@@ -189,7 +189,7 @@ export type MaterialTopTabNavigationOptions = {
export type MaterialTopTabDescriptor = Descriptor< export type MaterialTopTabDescriptor = Descriptor<
MaterialTopTabNavigationOptions, MaterialTopTabNavigationOptions,
MaterialTopTabNavigationProp<ParamListBase>, MaterialTopTabNavigationProp<ParamListBase>,
RouteProp<ParamListBase, string> RouteProp<ParamListBase>
>; >;
export type MaterialTopTabDescriptorMap = Record< export type MaterialTopTabDescriptorMap = Record<

View File

@@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.3](https://github.com/react-navigation/react-navigation/compare/@react-navigation/native@6.0.0-next.2...@react-navigation/native@6.0.0-next.3) (2021-05-01)
### Features
* add helper and hook for container ref ([0ecd112](https://github.com/react-navigation/react-navigation/commit/0ecd112ec9786a26261ada3d33ef44dc1ec84da0))
# [6.0.0-next.2](https://github.com/react-navigation/react-navigation/compare/@react-navigation/native@6.0.0-next.1...@react-navigation/native@6.0.0-next.2) (2021-04-08) # [6.0.0-next.2](https://github.com/react-navigation/react-navigation/compare/@react-navigation/native@6.0.0-next.1...@react-navigation/native@6.0.0-next.2) (2021-04-08)
**Note:** Version bump only for package @react-navigation/native **Note:** Version bump only for package @react-navigation/native

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/native", "name": "@react-navigation/native",
"description": "React Native integration for React Navigation", "description": "React Native integration for React Navigation",
"version": "6.0.0-next.2", "version": "6.0.0-next.3",
"keywords": [ "keywords": [
"react-native", "react-native",
"react-navigation", "react-navigation",
@@ -37,7 +37,7 @@
"clean": "del lib" "clean": "del lib"
}, },
"dependencies": { "dependencies": {
"@react-navigation/core": "^6.0.0-next.2", "@react-navigation/core": "^6.0.0-next.3",
"escape-string-regexp": "^4.0.0", "escape-string-regexp": "^4.0.0",
"nanoid": "^3.1.22" "nanoid": "^3.1.22"
}, },

View File

@@ -3,6 +3,7 @@ import {
BaseNavigationContainer, BaseNavigationContainer,
NavigationContainerProps, NavigationContainerProps,
NavigationContainerRef, NavigationContainerRef,
ParamListBase,
} from '@react-navigation/core'; } from '@react-navigation/core';
import ThemeProvider from './theming/ThemeProvider'; import ThemeProvider from './theming/ThemeProvider';
import DefaultTheme from './theming/DefaultTheme'; import DefaultTheme from './theming/DefaultTheme';
@@ -44,11 +45,13 @@ const NavigationContainer = React.forwardRef(function NavigationContainer(
onReady, onReady,
...rest ...rest
}: Props, }: Props,
ref?: React.Ref<NavigationContainerRef | null> ref?: React.Ref<NavigationContainerRef<ParamListBase> | null>
) { ) {
const isLinkingEnabled = linking ? linking.enabled !== false : false; const isLinkingEnabled = linking ? linking.enabled !== false : false;
const refContainer = React.useRef<NavigationContainerRef>(null); const refContainer = React.useRef<NavigationContainerRef<ParamListBase>>(
null
);
useBackButton(refContainer); useBackButton(refContainer);
useDocumentTitle(refContainer, documentTitle); useDocumentTitle(refContainer, documentTitle);

View File

@@ -5,7 +5,8 @@ import {
StackRouter, StackRouter,
TabRouter, TabRouter,
NavigationHelpersContext, NavigationHelpersContext,
NavigationContainerRef, createNavigationContainerRef,
ParamListBase,
} from '@react-navigation/core'; } from '@react-navigation/core';
import { act, render } from '@testing-library/react-native'; import { act, render } from '@testing-library/react-native';
import NavigationContainer from '../NavigationContainer'; import NavigationContainer from '../NavigationContainer';
@@ -79,7 +80,7 @@ it('integrates with the history API', () => {
}, },
}; };
const navigation = React.createRef<NavigationContainerRef>(); const navigation = createNavigationContainerRef<ParamListBase>();
render( render(
<NavigationContainer ref={navigation} linking={linking}> <NavigationContainer ref={navigation} linking={linking}>

View File

@@ -1,10 +1,13 @@
import * as React from 'react'; import * as React from 'react';
import { render, RenderAPI } from '@testing-library/react-native'; import { render, RenderAPI } from '@testing-library/react-native';
import type { NavigationContainerRef } from '@react-navigation/core'; import {
createNavigationContainerRef,
ParamListBase,
} from '@react-navigation/core';
import useLinking from '../useLinking'; import useLinking from '../useLinking';
it('throws if multiple instances of useLinking are used', () => { it('throws if multiple instances of useLinking are used', () => {
const ref = React.createRef<NavigationContainerRef>(); const ref = createNavigationContainerRef<ParamListBase>();
const options = { prefixes: [] }; const options = { prefixes: [] };

View File

@@ -1,9 +1,12 @@
import * as React from 'react'; import * as React from 'react';
import { BackHandler } from 'react-native'; import { BackHandler } from 'react-native';
import type { NavigationContainerRef } from '@react-navigation/core'; import type {
NavigationContainerRef,
ParamListBase,
} from '@react-navigation/core';
export default function useBackButton( export default function useBackButton(
ref: React.RefObject<NavigationContainerRef> ref: React.RefObject<NavigationContainerRef<ParamListBase>>
) { ) {
React.useEffect(() => { React.useEffect(() => {
const subscription = BackHandler.addEventListener( const subscription = BackHandler.addEventListener(

View File

@@ -1,12 +1,15 @@
import * as React from 'react'; import * as React from 'react';
import type { NavigationContainerRef } from '@react-navigation/core'; import type {
NavigationContainerRef,
ParamListBase,
} from '@react-navigation/core';
import type { DocumentTitleOptions } from './types'; import type { DocumentTitleOptions } from './types';
/** /**
* Set the document title for the active screen * Set the document title for the active screen
*/ */
export default function useDocumentTitle( export default function useDocumentTitle(
ref: React.RefObject<NavigationContainerRef>, ref: React.RefObject<NavigationContainerRef<ParamListBase>>,
{ {
enabled = true, enabled = true,
formatter = (options, route) => options?.title ?? route?.name, formatter = (options, route) => options?.title ?? route?.name,

View File

@@ -4,6 +4,7 @@ import {
getActionFromState, getActionFromState,
getStateFromPath as getStateFromPathDefault, getStateFromPath as getStateFromPathDefault,
NavigationContainerRef, NavigationContainerRef,
ParamListBase,
} from '@react-navigation/core'; } from '@react-navigation/core';
import extractPathFromURL from './extractPathFromURL'; import extractPathFromURL from './extractPathFromURL';
import type { LinkingOptions } from './types'; import type { LinkingOptions } from './types';
@@ -13,7 +14,7 @@ type ResultState = ReturnType<typeof getStateFromPathDefault>;
let isUsingLinking = false; let isUsingLinking = false;
export default function useLinking( export default function useLinking(
ref: React.RefObject<NavigationContainerRef>, ref: React.RefObject<NavigationContainerRef<ParamListBase>>,
{ {
enabled = true, enabled = true,
prefixes, prefixes,

View File

@@ -6,6 +6,7 @@ import {
NavigationState, NavigationState,
getActionFromState, getActionFromState,
findFocusedRoute, findFocusedRoute,
ParamListBase,
} from '@react-navigation/core'; } from '@react-navigation/core';
import { nanoid } from 'nanoid/non-secure'; import { nanoid } from 'nanoid/non-secure';
import ServerContext from './ServerContext'; import ServerContext from './ServerContext';
@@ -288,7 +289,7 @@ const series = (cb: () => Promise<void>) => {
let isUsingLinking = false; let isUsingLinking = false;
export default function useLinking( export default function useLinking(
ref: React.RefObject<NavigationContainerRef>, ref: React.RefObject<NavigationContainerRef<ParamListBase>>,
{ {
enabled = true, enabled = true,
config, config,

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.10](https://github.com/react-navigation/react-navigation/compare/@react-navigation/stack@6.0.0-next.9...@react-navigation/stack@6.0.0-next.10) (2021-05-01)
**Note:** Version bump only for package @react-navigation/stack
# [6.0.0-next.9](https://github.com/react-navigation/react-navigation/compare/@react-navigation/stack@6.0.0-next.8...@react-navigation/stack@6.0.0-next.9) (2021-04-08) # [6.0.0-next.9](https://github.com/react-navigation/react-navigation/compare/@react-navigation/stack@6.0.0-next.8...@react-navigation/stack@6.0.0-next.9) (2021-04-08)
**Note:** Version bump only for package @react-navigation/stack **Note:** Version bump only for package @react-navigation/stack

View File

@@ -1,7 +1,7 @@
{ {
"name": "@react-navigation/stack", "name": "@react-navigation/stack",
"description": "Stack navigator component for iOS and Android with animated transitions and gestures", "description": "Stack navigator component for iOS and Android with animated transitions and gestures",
"version": "6.0.0-next.9", "version": "6.0.0-next.10",
"keywords": [ "keywords": [
"react-native-component", "react-native-component",
"react-component", "react-component",
@@ -40,13 +40,13 @@
"clean": "del lib" "clean": "del lib"
}, },
"dependencies": { "dependencies": {
"@react-navigation/elements": "^1.0.0-next.4", "@react-navigation/elements": "^1.0.0-next.5",
"color": "^3.1.3", "color": "^3.1.3",
"react-native-iphone-x-helper": "^1.3.0", "react-native-iphone-x-helper": "^1.3.0",
"warn-once": "^0.0.1" "warn-once": "^0.0.1"
}, },
"devDependencies": { "devDependencies": {
"@react-navigation/native": "^6.0.0-next.2", "@react-navigation/native": "^6.0.0-next.3",
"@testing-library/react-native": "^7.2.0", "@testing-library/react-native": "^7.2.0",
"@types/color": "^3.0.1", "@types/color": "^3.0.1",
"@types/react": "^16.9.53", "@types/react": "^16.9.53",

View File

@@ -46,7 +46,7 @@ export type StackNavigationHelpers = NavigationHelpers<
export type StackNavigationProp< export type StackNavigationProp<
ParamList extends ParamListBase, ParamList extends ParamListBase,
RouteName extends keyof ParamList = string RouteName extends keyof ParamList = keyof ParamList
> = NavigationProp< > = NavigationProp<
ParamList, ParamList,
RouteName, RouteName,
@@ -58,7 +58,7 @@ export type StackNavigationProp<
export type StackScreenProps< export type StackScreenProps<
ParamList extends ParamListBase, ParamList extends ParamListBase,
RouteName extends keyof ParamList = string RouteName extends keyof ParamList = keyof ParamList
> = { > = {
navigation: StackNavigationProp<ParamList, RouteName>; navigation: StackNavigationProp<ParamList, RouteName>;
route: RouteProp<ParamList, RouteName>; route: RouteProp<ParamList, RouteName>;
@@ -182,7 +182,7 @@ export type StackHeaderProps = {
export type StackDescriptor = Descriptor< export type StackDescriptor = Descriptor<
StackNavigationOptions, StackNavigationOptions,
StackNavigationProp<ParamListBase>, StackNavigationProp<ParamListBase>,
RouteProp<ParamListBase, string> RouteProp<ParamListBase>
>; >;
export type StackDescriptorMap = Record<string, StackDescriptor>; export type StackDescriptorMap = Record<string, StackDescriptor>;