mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-01-16 22:44:03 +08:00
Compare commits
3 Commits
@react-nav
...
@react-nav
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29cdd886a0 | ||
|
|
1d40279db1 | ||
|
|
cde44a5785 |
@@ -3,6 +3,17 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [6.0.0-next.14](https://github.com/react-navigation/react-navigation/compare/@react-navigation/bottom-tabs@6.0.0-next.13...@react-navigation/bottom-tabs@6.0.0-next.14) (2021-05-26)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add screenListeners prop on navigators similar to screenOptions ([cde44a5](https://github.com/react-navigation/react-navigation/commit/cde44a5785444a121aa08f94af9f8fe4fc89910a))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [6.0.0-next.13](https://github.com/react-navigation/react-navigation/compare/@react-navigation/bottom-tabs@6.0.0-next.12...@react-navigation/bottom-tabs@6.0.0-next.13) (2021-05-25)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/bottom-tabs",
|
||||
"description": "Bottom tab navigator following iOS design guidelines",
|
||||
"version": "6.0.0-next.13",
|
||||
"version": "6.0.0-next.14",
|
||||
"keywords": [
|
||||
"react-native-component",
|
||||
"react-component",
|
||||
@@ -36,12 +36,12 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/elements": "^1.0.0-next.12",
|
||||
"@react-navigation/elements": "^1.0.0-next.13",
|
||||
"color": "^3.1.3",
|
||||
"warn-once": "^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-navigation/native": "^6.0.0-next.9",
|
||||
"@react-navigation/native": "^6.0.0-next.10",
|
||||
"@testing-library/react-native": "^7.2.0",
|
||||
"@types/color": "^3.0.1",
|
||||
"@types/react": "^16.9.53",
|
||||
|
||||
@@ -17,7 +17,12 @@ import type {
|
||||
BottomTabNavigationEventMap,
|
||||
} from '../types';
|
||||
|
||||
type Props = DefaultNavigatorOptions<BottomTabNavigationOptions> &
|
||||
type Props = DefaultNavigatorOptions<
|
||||
ParamListBase,
|
||||
TabNavigationState<ParamListBase>,
|
||||
BottomTabNavigationOptions,
|
||||
BottomTabNavigationEventMap
|
||||
> &
|
||||
TabRouterOptions &
|
||||
BottomTabNavigationConfig;
|
||||
|
||||
@@ -25,6 +30,7 @@ function BottomTabNavigator({
|
||||
initialRouteName,
|
||||
backBehavior,
|
||||
children,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
sceneContainerStyle,
|
||||
// @ts-expect-error: lazy is deprecated
|
||||
@@ -85,6 +91,7 @@ function BottomTabNavigator({
|
||||
initialRouteName,
|
||||
backBehavior,
|
||||
children,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
defaultScreenOptions,
|
||||
});
|
||||
|
||||
@@ -3,6 +3,18 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [6.0.0-next.10](https://github.com/react-navigation/react-navigation/compare/@react-navigation/core@6.0.0-next.9...@react-navigation/core@6.0.0-next.10) (2021-05-26)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add screenListeners prop on navigators similar to screenOptions ([cde44a5](https://github.com/react-navigation/react-navigation/commit/cde44a5785444a121aa08f94af9f8fe4fc89910a))
|
||||
* expose container ref in useNavigation ([1d40279](https://github.com/react-navigation/react-navigation/commit/1d40279db18ab2aed12517ed3ca6af6d509477d2))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [6.0.0-next.9](https://github.com/react-navigation/react-navigation/compare/@react-navigation/core@6.0.0-next.8...@react-navigation/core@6.0.0-next.9) (2021-05-23)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/core
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/core",
|
||||
"description": "Core utilities for building navigators",
|
||||
"version": "6.0.0-next.9",
|
||||
"version": "6.0.0-next.10",
|
||||
"keywords": [
|
||||
"react",
|
||||
"react-native",
|
||||
|
||||
@@ -29,6 +29,7 @@ import type {
|
||||
NavigationContainerRef,
|
||||
NavigationContainerProps,
|
||||
} from './types';
|
||||
import NavigationContainerRefContext from './NavigationContainerRefContext';
|
||||
|
||||
type State = NavigationState | PartialState<NavigationState> | undefined;
|
||||
|
||||
@@ -136,17 +137,22 @@ const BaseNavigationContainer = React.forwardRef(
|
||||
|
||||
const { keyedListeners, addKeyedListener } = useKeyedChildListeners();
|
||||
|
||||
const dispatch = (
|
||||
action: NavigationAction | ((state: NavigationState) => NavigationAction)
|
||||
) => {
|
||||
if (listeners.focus[0] == null) {
|
||||
console.error(NOT_INITIALIZED_ERROR);
|
||||
} else {
|
||||
listeners.focus[0]((navigation) => navigation.dispatch(action));
|
||||
}
|
||||
};
|
||||
const dispatch = React.useCallback(
|
||||
(
|
||||
action:
|
||||
| NavigationAction
|
||||
| ((state: NavigationState) => NavigationAction)
|
||||
) => {
|
||||
if (listeners.focus[0] == null) {
|
||||
console.error(NOT_INITIALIZED_ERROR);
|
||||
} else {
|
||||
listeners.focus[0]((navigation) => navigation.dispatch(action));
|
||||
}
|
||||
},
|
||||
[listeners.focus]
|
||||
);
|
||||
|
||||
const canGoBack = () => {
|
||||
const canGoBack = React.useCallback(() => {
|
||||
if (listeners.focus[0] == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -160,7 +166,7 @@ const BaseNavigationContainer = React.forwardRef(
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}, [listeners.focus]);
|
||||
|
||||
const resetRoot = React.useCallback(
|
||||
(state?: PartialState<NavigationState> | NavigationState) => {
|
||||
@@ -200,24 +206,38 @@ const BaseNavigationContainer = React.forwardRef(
|
||||
|
||||
const { addOptionsGetter, getCurrentOptions } = useOptionsGetters({});
|
||||
|
||||
React.useImperativeHandle(ref, () => ({
|
||||
...Object.keys(CommonActions).reduce<any>((acc, name) => {
|
||||
acc[name] = (...args: any[]) =>
|
||||
// @ts-expect-error: this is ok
|
||||
dispatch(CommonActions[name](...args));
|
||||
return acc;
|
||||
}, {}),
|
||||
...emitter.create('root'),
|
||||
resetRoot,
|
||||
dispatch,
|
||||
canGoBack,
|
||||
getRootState,
|
||||
getState: () => state,
|
||||
getParent: () => undefined,
|
||||
getCurrentRoute,
|
||||
getCurrentOptions,
|
||||
isReady: () => listeners.focus[0] != null,
|
||||
}));
|
||||
const navigation: NavigationContainerRef<ParamListBase> = React.useMemo(
|
||||
() => ({
|
||||
...Object.keys(CommonActions).reduce<any>((acc, name) => {
|
||||
acc[name] = (...args: any[]) =>
|
||||
// @ts-expect-error: this is ok
|
||||
dispatch(CommonActions[name](...args));
|
||||
return acc;
|
||||
}, {}),
|
||||
...emitter.create('root'),
|
||||
resetRoot,
|
||||
dispatch,
|
||||
canGoBack,
|
||||
getRootState,
|
||||
getState: () => stateRef.current,
|
||||
getParent: () => undefined,
|
||||
getCurrentRoute,
|
||||
getCurrentOptions,
|
||||
isReady: () => listeners.focus[0] != null,
|
||||
}),
|
||||
[
|
||||
canGoBack,
|
||||
dispatch,
|
||||
emitter,
|
||||
getCurrentOptions,
|
||||
getCurrentRoute,
|
||||
getRootState,
|
||||
listeners.focus,
|
||||
resetRoot,
|
||||
]
|
||||
);
|
||||
|
||||
React.useImperativeHandle(ref, () => navigation, [navigation]);
|
||||
|
||||
const onDispatchAction = React.useCallback(
|
||||
(action: NavigationAction, noop: boolean) => {
|
||||
@@ -285,10 +305,12 @@ const BaseNavigationContainer = React.forwardRef(
|
||||
);
|
||||
|
||||
const onStateChangeRef = React.useRef(onStateChange);
|
||||
const stateRef = React.useRef(state);
|
||||
|
||||
React.useEffect(() => {
|
||||
isInitialRef.current = false;
|
||||
onStateChangeRef.current = onStateChange;
|
||||
stateRef.current = state;
|
||||
});
|
||||
|
||||
React.useEffect(() => {
|
||||
@@ -415,17 +437,19 @@ const BaseNavigationContainer = React.forwardRef(
|
||||
);
|
||||
|
||||
let element = (
|
||||
<ScheduleUpdateContext.Provider value={scheduleContext}>
|
||||
<NavigationBuilderContext.Provider value={builderContext}>
|
||||
<NavigationStateContext.Provider value={context}>
|
||||
<UnhandledActionContext.Provider
|
||||
value={onUnhandledAction ?? defaultOnUnhandledAction}
|
||||
>
|
||||
<EnsureSingleNavigator>{children}</EnsureSingleNavigator>
|
||||
</UnhandledActionContext.Provider>
|
||||
</NavigationStateContext.Provider>
|
||||
</NavigationBuilderContext.Provider>
|
||||
</ScheduleUpdateContext.Provider>
|
||||
<NavigationContainerRefContext.Provider value={navigation}>
|
||||
<ScheduleUpdateContext.Provider value={scheduleContext}>
|
||||
<NavigationBuilderContext.Provider value={builderContext}>
|
||||
<NavigationStateContext.Provider value={context}>
|
||||
<UnhandledActionContext.Provider
|
||||
value={onUnhandledAction ?? defaultOnUnhandledAction}
|
||||
>
|
||||
<EnsureSingleNavigator>{children}</EnsureSingleNavigator>
|
||||
</UnhandledActionContext.Provider>
|
||||
</NavigationStateContext.Provider>
|
||||
</NavigationBuilderContext.Provider>
|
||||
</ScheduleUpdateContext.Provider>
|
||||
</NavigationContainerRefContext.Provider>
|
||||
);
|
||||
|
||||
if (independent) {
|
||||
|
||||
12
packages/core/src/NavigationContainerRefContext.tsx
Normal file
12
packages/core/src/NavigationContainerRefContext.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
import * as React from 'react';
|
||||
import type { ParamListBase } from '@react-navigation/routers';
|
||||
import type { NavigationContainerRef } from './types';
|
||||
|
||||
/**
|
||||
* Context which holds the route prop for a screen.
|
||||
*/
|
||||
const NavigationContainerRefContext = React.createContext<
|
||||
NavigationContainerRef<ParamListBase> | undefined
|
||||
>(undefined);
|
||||
|
||||
export default NavigationContainerRefContext;
|
||||
@@ -4,8 +4,8 @@ import type { Route } from '@react-navigation/routers';
|
||||
/**
|
||||
* Context which holds the route prop for a screen.
|
||||
*/
|
||||
const NavigationContext = React.createContext<Route<string> | undefined>(
|
||||
const NavigationRouteContext = React.createContext<Route<string> | undefined>(
|
||||
undefined
|
||||
);
|
||||
|
||||
export default NavigationContext;
|
||||
export default NavigationRouteContext;
|
||||
|
||||
@@ -106,13 +106,40 @@ it("gets navigation's parent's parent from context", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('gets navigation from container from context', () => {
|
||||
expect.assertions(1);
|
||||
|
||||
const TestNavigator = (props: any): any => {
|
||||
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
||||
|
||||
return state.routes.map((route) => descriptors[route.key].render());
|
||||
};
|
||||
|
||||
const Test = () => {
|
||||
const navigation = useNavigation();
|
||||
|
||||
expect(navigation.navigate).toBeDefined();
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
render(
|
||||
<BaseNavigationContainer>
|
||||
<Test />
|
||||
<TestNavigator>
|
||||
<Screen name="foo">{() => null}</Screen>
|
||||
</TestNavigator>
|
||||
</BaseNavigationContainer>
|
||||
);
|
||||
});
|
||||
|
||||
it('throws if called outside a navigation context', () => {
|
||||
expect.assertions(1);
|
||||
|
||||
const Test = () => {
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
expect(() => useNavigation()).toThrow(
|
||||
"Couldn't find a navigation object. Is your component inside a screen in a navigator?"
|
||||
"Couldn't find a navigation object. Is your component inside NavigationContainer?"
|
||||
);
|
||||
|
||||
return null;
|
||||
|
||||
@@ -6,6 +6,7 @@ export { default as createNavigatorFactory } from './createNavigatorFactory';
|
||||
export { default as createNavigationContainerRef } from './createNavigationContainerRef';
|
||||
export { default as useNavigationContainerRef } from './useNavigationContainerRef';
|
||||
|
||||
export { default as NavigationContainerRefContext } from './NavigationContainerRefContext';
|
||||
export { default as NavigationHelpersContext } from './NavigationHelpersContext';
|
||||
export { default as NavigationContext } from './NavigationContext';
|
||||
export { default as NavigationRouteContext } from './NavigationRouteContext';
|
||||
|
||||
@@ -20,14 +20,25 @@ declare global {
|
||||
type Keyof<T extends {}> = Extract<keyof T, string>;
|
||||
|
||||
export type DefaultNavigatorOptions<
|
||||
ParamList extends ParamListBase,
|
||||
State extends NavigationState,
|
||||
ScreenOptions extends {},
|
||||
ParamList extends ParamListBase = ParamListBase
|
||||
EventMap extends EventMapBase
|
||||
> = DefaultRouterOptions<Keyof<ParamList>> & {
|
||||
/**
|
||||
* Children React Elements to extract the route configuration from.
|
||||
* Only `Screen`, `Group` and `React.Fragment` are supported as children.
|
||||
*/
|
||||
children: React.ReactNode;
|
||||
/**
|
||||
* Event listeners for all the screens in the navigator.
|
||||
*/
|
||||
screenListeners?:
|
||||
| ScreenListeners<State, EventMap>
|
||||
| ((props: {
|
||||
route: RouteProp<ParamList>;
|
||||
navigation: any;
|
||||
}) => ScreenListeners<State, EventMap>);
|
||||
/**
|
||||
* Default options for all screens under this navigator.
|
||||
*/
|
||||
@@ -564,9 +575,9 @@ export type TypedNavigator<
|
||||
Navigator: React.ComponentType<
|
||||
Omit<
|
||||
React.ComponentProps<Navigator>,
|
||||
keyof DefaultNavigatorOptions<any, any>
|
||||
keyof DefaultNavigatorOptions<any, any, any, any>
|
||||
> &
|
||||
DefaultNavigatorOptions<ScreenOptions, ParamList>
|
||||
DefaultNavigatorOptions<ParamList, State, ScreenOptions, EventMap>
|
||||
>;
|
||||
/**
|
||||
* Component used for grouping multiple route configuration.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import NavigationContainerRefContext from './NavigationContainerRefContext';
|
||||
import NavigationContext from './NavigationContext';
|
||||
import type { NavigationProp } from './types';
|
||||
|
||||
@@ -10,14 +11,15 @@ import type { NavigationProp } from './types';
|
||||
export default function useNavigation<
|
||||
T = NavigationProp<ReactNavigation.RootParamList>
|
||||
>(): T {
|
||||
const root = React.useContext(NavigationContainerRefContext);
|
||||
const navigation = React.useContext(NavigationContext);
|
||||
|
||||
if (navigation === undefined) {
|
||||
if (navigation === undefined && root === undefined) {
|
||||
throw new Error(
|
||||
"Couldn't find a navigation object. Is your component inside a screen in a navigator?"
|
||||
"Couldn't find a navigation object. Is your component inside NavigationContainer?"
|
||||
);
|
||||
}
|
||||
|
||||
// FIXME: Figure out a better way to do this
|
||||
return (navigation as unknown) as T;
|
||||
return ((navigation ?? root) as unknown) as T;
|
||||
}
|
||||
|
||||
@@ -202,7 +202,13 @@ export default function useNavigationBuilder<
|
||||
EventMap extends Record<string, any>
|
||||
>(
|
||||
createRouter: RouterFactory<State, any, RouterOptions>,
|
||||
options: DefaultNavigatorOptions<ScreenOptions> & RouterOptions
|
||||
options: DefaultNavigatorOptions<
|
||||
ParamListBase,
|
||||
State,
|
||||
ScreenOptions,
|
||||
EventMap
|
||||
> &
|
||||
RouterOptions
|
||||
) {
|
||||
const navigatorKey = useRegisterNavigator();
|
||||
|
||||
@@ -210,7 +216,7 @@ export default function useNavigationBuilder<
|
||||
| NavigatorRoute<State>
|
||||
| undefined;
|
||||
|
||||
const { children, ...rest } = options;
|
||||
const { children, screenListeners, ...rest } = options;
|
||||
const { current: router } = React.useRef<Router<State, any>>(
|
||||
createRouter({
|
||||
...((rest as unknown) as RouterOptions),
|
||||
@@ -487,8 +493,14 @@ export default function useNavigationBuilder<
|
||||
|
||||
const listeners = ([] as (((e: any) => void) | undefined)[])
|
||||
.concat(
|
||||
...routeNames.map((name) => {
|
||||
const { listeners } = screens[name][1];
|
||||
// Get an array of listeners for all screens + common listeners on navigator
|
||||
...[
|
||||
screenListeners,
|
||||
...routeNames.map((name) => {
|
||||
const { listeners } = screens[name][1];
|
||||
return listeners;
|
||||
}),
|
||||
].map((listeners) => {
|
||||
const map =
|
||||
typeof listeners === 'function'
|
||||
? listeners({ route: route as any, navigation })
|
||||
@@ -501,6 +513,8 @@ export default function useNavigationBuilder<
|
||||
: undefined;
|
||||
})
|
||||
)
|
||||
// We don't want same listener to be called multiple times for same event
|
||||
// So we remove any duplicate functions from the array
|
||||
.filter((cb, i, self) => cb && self.lastIndexOf(cb) === i);
|
||||
|
||||
listeners.forEach((listener) => listener?.(e));
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [6.0.0-next.11](https://github.com/react-navigation/react-navigation/compare/@react-navigation/devtools@6.0.0-next.10...@react-navigation/devtools@6.0.0-next.11) (2021-05-26)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/devtools
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [6.0.0-next.10](https://github.com/react-navigation/react-navigation/compare/@react-navigation/devtools@6.0.0-next.9...@react-navigation/devtools@6.0.0-next.10) (2021-05-25)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/devtools",
|
||||
"description": "Developer tools for React Navigation",
|
||||
"version": "6.0.0-next.10",
|
||||
"version": "6.0.0-next.11",
|
||||
"keywords": [
|
||||
"react",
|
||||
"react-native",
|
||||
@@ -40,7 +40,7 @@
|
||||
"nanoid": "^3.1.22"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-navigation/core": "^6.0.0-next.9",
|
||||
"@react-navigation/core": "^6.0.0-next.10",
|
||||
"@testing-library/react-native": "^7.2.0",
|
||||
"@types/deep-equal": "^1.0.1",
|
||||
"@types/react": "^16.9.53",
|
||||
|
||||
@@ -3,6 +3,17 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [6.0.0-next.13](https://github.com/react-navigation/react-navigation/compare/@react-navigation/drawer@6.0.0-next.12...@react-navigation/drawer@6.0.0-next.13) (2021-05-26)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add screenListeners prop on navigators similar to screenOptions ([cde44a5](https://github.com/react-navigation/react-navigation/commit/cde44a5785444a121aa08f94af9f8fe4fc89910a))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [6.0.0-next.12](https://github.com/react-navigation/react-navigation/compare/@react-navigation/drawer@6.0.0-next.11...@react-navigation/drawer@6.0.0-next.12) (2021-05-25)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/drawer
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/drawer",
|
||||
"description": "Drawer navigator component with animated transitions and gesturess",
|
||||
"version": "6.0.0-next.12",
|
||||
"version": "6.0.0-next.13",
|
||||
"keywords": [
|
||||
"react-native-component",
|
||||
"react-component",
|
||||
@@ -41,12 +41,12 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/elements": "^1.0.0-next.12",
|
||||
"@react-navigation/elements": "^1.0.0-next.13",
|
||||
"color": "^3.1.3",
|
||||
"warn-once": "^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-navigation/native": "^6.0.0-next.9",
|
||||
"@react-navigation/native": "^6.0.0-next.10",
|
||||
"@testing-library/react-native": "^7.2.0",
|
||||
"@types/react": "^16.9.53",
|
||||
"@types/react-native": "~0.64.4",
|
||||
|
||||
@@ -17,7 +17,12 @@ import type {
|
||||
DrawerNavigationEventMap,
|
||||
} from '../types';
|
||||
|
||||
type Props = DefaultNavigatorOptions<DrawerNavigationOptions> &
|
||||
type Props = DefaultNavigatorOptions<
|
||||
ParamListBase,
|
||||
DrawerNavigationState<ParamListBase>,
|
||||
DrawerNavigationOptions,
|
||||
DrawerNavigationEventMap
|
||||
> &
|
||||
DrawerRouterOptions &
|
||||
DrawerNavigationConfig;
|
||||
|
||||
@@ -26,6 +31,7 @@ function DrawerNavigator({
|
||||
defaultStatus,
|
||||
backBehavior,
|
||||
children,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
// @ts-expect-error: lazy is deprecated
|
||||
lazy,
|
||||
@@ -83,6 +89,7 @@ function DrawerNavigator({
|
||||
defaultStatus,
|
||||
backBehavior,
|
||||
children,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
defaultScreenOptions,
|
||||
});
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [1.0.0-next.13](https://github.com/react-navigation/react-navigation/compare/@react-navigation/elements@1.0.0-next.12...@react-navigation/elements@1.0.0-next.13) (2021-05-26)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/elements
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [1.0.0-next.12](https://github.com/react-navigation/react-navigation/compare/@react-navigation/elements@1.0.0-next.11...@react-navigation/elements@1.0.0-next.12) (2021-05-25)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/elements
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/elements",
|
||||
"description": "UI Components for React Navigation",
|
||||
"version": "1.0.0-next.12",
|
||||
"version": "1.0.0-next.13",
|
||||
"keywords": [
|
||||
"react-native",
|
||||
"react-navigation",
|
||||
@@ -38,7 +38,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-native-masked-view/masked-view": "^0.2.3",
|
||||
"@react-navigation/native": "^6.0.0-next.9",
|
||||
"@react-navigation/native": "^6.0.0-next.10",
|
||||
"@testing-library/react-native": "^7.2.0",
|
||||
"@types/react": "^16.9.53",
|
||||
"@types/react-native": "~0.64.4",
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.1](https://github.com/react-navigation/react-navigation/compare/flipper-plugin-react-navigation@1.1.0...flipper-plugin-react-navigation@1.1.1) (2021-05-26)
|
||||
|
||||
**Note:** Version bump only for package flipper-plugin-react-navigation
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 1.1.0 (2021-05-23)
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://fbflipper.com/schemas/plugin-package/v2.json",
|
||||
"name": "flipper-plugin-react-navigation",
|
||||
"id": "react-navigation",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"pluginType": "client",
|
||||
"main": "dist/bundle.js",
|
||||
"flipperBundlerEntry": "src/index.tsx",
|
||||
@@ -28,7 +28,7 @@
|
||||
"@ant-design/icons": "^4.6.2",
|
||||
"@babel/preset-react": "^7.12.13",
|
||||
"@babel/preset-typescript": "^7.13.0",
|
||||
"@react-navigation/core": "^6.0.0-next.9",
|
||||
"@react-navigation/core": "^6.0.0-next.10",
|
||||
"@types/react": "^17.0.3",
|
||||
"@types/react-dom": "^17.0.2",
|
||||
"antd": "^4.14.0",
|
||||
|
||||
@@ -3,6 +3,17 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [6.0.0-next.10](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-bottom-tabs@6.0.0-next.9...@react-navigation/material-bottom-tabs@6.0.0-next.10) (2021-05-26)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add screenListeners prop on navigators similar to screenOptions ([cde44a5](https://github.com/react-navigation/react-navigation/commit/cde44a5785444a121aa08f94af9f8fe4fc89910a))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [6.0.0-next.9](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-bottom-tabs@6.0.0-next.8...@react-navigation/material-bottom-tabs@6.0.0-next.9) (2021-05-23)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/material-bottom-tabs",
|
||||
"description": "Integration for bottom navigation component from react-native-paper",
|
||||
"version": "6.0.0-next.9",
|
||||
"version": "6.0.0-next.10",
|
||||
"keywords": [
|
||||
"react-native-component",
|
||||
"react-component",
|
||||
@@ -41,7 +41,7 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-navigation/native": "^6.0.0-next.9",
|
||||
"@react-navigation/native": "^6.0.0-next.10",
|
||||
"@testing-library/react-native": "^7.2.0",
|
||||
"@types/react": "^16.9.53",
|
||||
"@types/react-native": "~0.64.4",
|
||||
|
||||
@@ -17,7 +17,12 @@ import type {
|
||||
MaterialBottomTabNavigationEventMap,
|
||||
} from '../types';
|
||||
|
||||
type Props = DefaultNavigatorOptions<MaterialBottomTabNavigationOptions> &
|
||||
type Props = DefaultNavigatorOptions<
|
||||
ParamListBase,
|
||||
TabNavigationState<ParamListBase>,
|
||||
MaterialBottomTabNavigationOptions,
|
||||
MaterialBottomTabNavigationEventMap
|
||||
> &
|
||||
TabRouterOptions &
|
||||
MaterialBottomTabNavigationConfig;
|
||||
|
||||
@@ -25,6 +30,7 @@ function MaterialBottomTabNavigator({
|
||||
initialRouteName,
|
||||
backBehavior,
|
||||
children,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
...rest
|
||||
}: Props) {
|
||||
@@ -43,6 +49,7 @@ function MaterialBottomTabNavigator({
|
||||
initialRouteName,
|
||||
backBehavior,
|
||||
children,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,17 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [6.0.0-next.11](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-top-tabs@6.0.0-next.10...@react-navigation/material-top-tabs@6.0.0-next.11) (2021-05-26)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add screenListeners prop on navigators similar to screenOptions ([cde44a5](https://github.com/react-navigation/react-navigation/commit/cde44a5785444a121aa08f94af9f8fe4fc89910a))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [6.0.0-next.10](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-top-tabs@6.0.0-next.9...@react-navigation/material-top-tabs@6.0.0-next.10) (2021-05-23)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/material-top-tabs",
|
||||
"description": "Integration for the animated tab view component from react-native-tab-view",
|
||||
"version": "6.0.0-next.10",
|
||||
"version": "6.0.0-next.11",
|
||||
"keywords": [
|
||||
"react-native-component",
|
||||
"react-component",
|
||||
@@ -45,7 +45,7 @@
|
||||
"warn-once": "^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-navigation/native": "^6.0.0-next.9",
|
||||
"@react-navigation/native": "^6.0.0-next.10",
|
||||
"@testing-library/react-native": "^7.2.0",
|
||||
"@types/react": "^16.9.53",
|
||||
"@types/react-native": "~0.64.4",
|
||||
|
||||
@@ -17,7 +17,12 @@ import type {
|
||||
MaterialTopTabNavigationEventMap,
|
||||
} from '../types';
|
||||
|
||||
type Props = DefaultNavigatorOptions<MaterialTopTabNavigationOptions> &
|
||||
type Props = DefaultNavigatorOptions<
|
||||
ParamListBase,
|
||||
TabNavigationState<ParamListBase>,
|
||||
MaterialTopTabNavigationOptions,
|
||||
MaterialTopTabNavigationEventMap
|
||||
> &
|
||||
TabRouterOptions &
|
||||
MaterialTopTabNavigationConfig;
|
||||
|
||||
@@ -25,6 +30,7 @@ function MaterialTopTabNavigator({
|
||||
initialRouteName,
|
||||
backBehavior,
|
||||
children,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
lazy,
|
||||
tabBarOptions,
|
||||
@@ -86,6 +92,7 @@ function MaterialTopTabNavigator({
|
||||
initialRouteName,
|
||||
backBehavior,
|
||||
children,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,17 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
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-stack@6.0.0-next.2...@react-navigation/native-stack@6.0.0-next.3) (2021-05-26)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add screenListeners prop on navigators similar to screenOptions ([cde44a5](https://github.com/react-navigation/react-navigation/commit/cde44a5785444a121aa08f94af9f8fe4fc89910a))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [6.0.0-next.2](https://github.com/react-navigation/react-navigation/compare/@react-navigation/native-stack@6.0.0-next.1...@react-navigation/native-stack@6.0.0-next.2) (2021-05-25)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/native-stack
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/native-stack",
|
||||
"description": "Native stack navigator using react-native-screens",
|
||||
"version": "6.0.0-next.2",
|
||||
"version": "6.0.0-next.3",
|
||||
"keywords": [
|
||||
"react-native-component",
|
||||
"react-component",
|
||||
@@ -41,11 +41,11 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/elements": "^1.0.0-next.12",
|
||||
"@react-navigation/elements": "^1.0.0-next.13",
|
||||
"warn-once": "^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-navigation/native": "^6.0.0-next.9",
|
||||
"@react-navigation/native": "^6.0.0-next.10",
|
||||
"@testing-library/react-native": "^7.2.0",
|
||||
"@types/react": "^16.9.53",
|
||||
"@types/react-native": "~0.64.4",
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
createNavigatorFactory,
|
||||
DefaultNavigatorOptions,
|
||||
EventArg,
|
||||
StackActions,
|
||||
StackActionHelpers,
|
||||
@@ -16,16 +15,13 @@ import NativeStackView from '../views/NativeStackView';
|
||||
import type {
|
||||
NativeStackNavigationOptions,
|
||||
NativeStackNavigationEventMap,
|
||||
NativeStackNavigationConfig,
|
||||
NativeStackNavigatorProps,
|
||||
} from '../types';
|
||||
|
||||
export type NativeStackNavigatorProps = DefaultNavigatorOptions<NativeStackNavigationOptions> &
|
||||
StackRouterOptions &
|
||||
NativeStackNavigationConfig;
|
||||
|
||||
function NativeStackNavigator({
|
||||
initialRouteName,
|
||||
children,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
...rest
|
||||
}: NativeStackNavigatorProps) {
|
||||
@@ -38,6 +34,7 @@ function NativeStackNavigator({
|
||||
>(StackRouter, {
|
||||
initialRouteName,
|
||||
children,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
});
|
||||
|
||||
|
||||
@@ -322,7 +322,12 @@ export type NativeStackNavigationOptions = {
|
||||
orientation?: ScreenStackHeaderConfigProps['screenOrientation'];
|
||||
};
|
||||
|
||||
export type NativeStackNavigatorProps = DefaultNavigatorOptions<NativeStackNavigationOptions> &
|
||||
export type NativeStackNavigatorProps = DefaultNavigatorOptions<
|
||||
ParamListBase,
|
||||
StackNavigationState<ParamListBase>,
|
||||
NativeStackNavigationOptions,
|
||||
NativeStackNavigationEventMap
|
||||
> &
|
||||
StackRouterOptions &
|
||||
NativeStackNavigationConfig;
|
||||
|
||||
|
||||
@@ -3,6 +3,17 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [6.0.0-next.10](https://github.com/react-navigation/react-navigation/compare/@react-navigation/native@6.0.0-next.9...@react-navigation/native@6.0.0-next.10) (2021-05-26)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* expose container ref in useNavigation ([1d40279](https://github.com/react-navigation/react-navigation/commit/1d40279db18ab2aed12517ed3ca6af6d509477d2))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [6.0.0-next.9](https://github.com/react-navigation/react-navigation/compare/@react-navigation/native@6.0.0-next.8...@react-navigation/native@6.0.0-next.9) (2021-05-23)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/native",
|
||||
"description": "React Native integration for React Navigation",
|
||||
"version": "6.0.0-next.9",
|
||||
"version": "6.0.0-next.10",
|
||||
"keywords": [
|
||||
"react-native",
|
||||
"react-navigation",
|
||||
@@ -37,7 +37,7 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/core": "^6.0.0-next.9",
|
||||
"@react-navigation/core": "^6.0.0-next.10",
|
||||
"escape-string-regexp": "^4.0.0",
|
||||
"nanoid": "^3.1.22"
|
||||
},
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as React from 'react';
|
||||
import { Platform, GestureResponderEvent } from 'react-native';
|
||||
import {
|
||||
NavigationAction,
|
||||
NavigationContainerRefContext,
|
||||
NavigationHelpersContext,
|
||||
} from '@react-navigation/core';
|
||||
import useLinkTo, { To } from './useLinkTo';
|
||||
@@ -20,6 +21,7 @@ type Props<ParamList extends ReactNavigation.RootParamList> = {
|
||||
export default function useLinkProps<
|
||||
ParamList extends ReactNavigation.RootParamList
|
||||
>({ to, action }: Props<ParamList>) {
|
||||
const root = React.useContext(NavigationContainerRefContext);
|
||||
const navigation = React.useContext(NavigationHelpersContext);
|
||||
const linkTo = useLinkTo<ParamList>();
|
||||
|
||||
@@ -47,8 +49,12 @@ export default function useLinkProps<
|
||||
if (action) {
|
||||
if (navigation) {
|
||||
navigation.dispatch(action);
|
||||
} else if (root) {
|
||||
root.dispatch(action);
|
||||
} else {
|
||||
throw new Error("Couldn't find a navigation object.");
|
||||
throw new Error(
|
||||
"Couldn't find a navigation object. Is your component inside NavigationContainer?"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
linkTo(to);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as React from 'react';
|
||||
import {
|
||||
NavigationContainerRefContext,
|
||||
getStateFromPath,
|
||||
getActionFromState,
|
||||
NavigationContext,
|
||||
} from '@react-navigation/core';
|
||||
import LinkingContext from './LinkingContext';
|
||||
|
||||
@@ -24,25 +24,17 @@ export type To<
|
||||
export default function useLinkTo<
|
||||
ParamList extends ReactNavigation.RootParamList
|
||||
>() {
|
||||
const navigation = React.useContext(NavigationContext);
|
||||
const navigation = React.useContext(NavigationContainerRefContext);
|
||||
const linking = React.useContext(LinkingContext);
|
||||
|
||||
const linkTo = React.useCallback(
|
||||
(to: To<ParamList>) => {
|
||||
if (navigation === undefined) {
|
||||
throw new Error(
|
||||
"Couldn't find a navigation object. Is your component inside a screen in a navigator?"
|
||||
"Couldn't find a navigation object. Is your component inside NavigationContainer?"
|
||||
);
|
||||
}
|
||||
|
||||
let root = navigation;
|
||||
let current;
|
||||
|
||||
// Traverse up to get the root navigation
|
||||
while ((current = root.getParent())) {
|
||||
root = current;
|
||||
}
|
||||
|
||||
if (typeof to !== 'string') {
|
||||
// @ts-expect-error: This is fine
|
||||
root.navigate(to.screen, to.params);
|
||||
@@ -63,9 +55,9 @@ export default function useLinkTo<
|
||||
const action = getActionFromState(state, options?.config);
|
||||
|
||||
if (action !== undefined) {
|
||||
root.dispatch(action);
|
||||
navigation.dispatch(action);
|
||||
} else {
|
||||
root.reset(state);
|
||||
navigation.reset(state);
|
||||
}
|
||||
} else {
|
||||
throw new Error('Failed to parse the path to a navigation state.');
|
||||
|
||||
@@ -3,6 +3,17 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [6.0.0-next.21](https://github.com/react-navigation/react-navigation/compare/@react-navigation/stack@6.0.0-next.20...@react-navigation/stack@6.0.0-next.21) (2021-05-26)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add screenListeners prop on navigators similar to screenOptions ([cde44a5](https://github.com/react-navigation/react-navigation/commit/cde44a5785444a121aa08f94af9f8fe4fc89910a))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [6.0.0-next.20](https://github.com/react-navigation/react-navigation/compare/@react-navigation/stack@6.0.0-next.19...@react-navigation/stack@6.0.0-next.20) (2021-05-25)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/stack
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/stack",
|
||||
"description": "Stack navigator component for iOS and Android with animated transitions and gestures",
|
||||
"version": "6.0.0-next.20",
|
||||
"version": "6.0.0-next.21",
|
||||
"keywords": [
|
||||
"react-native-component",
|
||||
"react-component",
|
||||
@@ -40,13 +40,13 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/elements": "^1.0.0-next.12",
|
||||
"@react-navigation/elements": "^1.0.0-next.13",
|
||||
"color": "^3.1.3",
|
||||
"react-native-iphone-x-helper": "^1.3.0",
|
||||
"warn-once": "^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-navigation/native": "^6.0.0-next.9",
|
||||
"@react-navigation/native": "^6.0.0-next.10",
|
||||
"@testing-library/react-native": "^7.2.0",
|
||||
"@types/color": "^3.0.1",
|
||||
"@types/react": "^16.9.53",
|
||||
|
||||
@@ -20,13 +20,19 @@ import type {
|
||||
StackHeaderMode,
|
||||
} from '../types';
|
||||
|
||||
type Props = DefaultNavigatorOptions<StackNavigationOptions> &
|
||||
type Props = DefaultNavigatorOptions<
|
||||
ParamListBase,
|
||||
StackNavigationState<ParamListBase>,
|
||||
StackNavigationOptions,
|
||||
StackNavigationEventMap
|
||||
> &
|
||||
StackRouterOptions &
|
||||
StackNavigationConfig;
|
||||
|
||||
function StackNavigator({
|
||||
initialRouteName,
|
||||
children,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
...rest
|
||||
}: Props) {
|
||||
@@ -65,6 +71,7 @@ function StackNavigator({
|
||||
>(StackRouter, {
|
||||
initialRouteName,
|
||||
children,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
defaultScreenOptions: () => ({
|
||||
presentation: mode,
|
||||
|
||||
Reference in New Issue
Block a user