Compare commits
69 Commits
@react-nav
...
@react-nav
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71b2bcd14f | ||
|
|
56c2779184 | ||
|
|
c77532174a | ||
|
|
d4072e7d88 | ||
|
|
941249dba9 | ||
|
|
d1ca7f9a09 | ||
|
|
f494f992fa | ||
|
|
66551f29d4 | ||
|
|
270fbdcfaf | ||
|
|
e871fdb074 | ||
|
|
b5d9ad900d | ||
|
|
6aebeec90c | ||
|
|
75ed888b33 | ||
|
|
ee82ab1d1b | ||
|
|
301c35ec32 | ||
|
|
22cb675608 | ||
|
|
c41c824aae | ||
|
|
a93a81e5d3 | ||
|
|
57b411cea8 | ||
|
|
3a4c38bb72 | ||
|
|
e6a06ac56e | ||
|
|
2ef5ad4cc2 | ||
|
|
74ee216ed4 | ||
|
|
77f29d374f | ||
|
|
5a34764404 | ||
|
|
738f226535 | ||
|
|
5cd69401ec | ||
|
|
c55d4511ff | ||
|
|
c07d61dc41 | ||
|
|
67fd69adf6 | ||
|
|
3de9edbe72 | ||
|
|
12d597fcc0 | ||
|
|
50dea65377 | ||
|
|
3d9db6ff25 | ||
|
|
fb749ac064 | ||
|
|
58f7115298 | ||
|
|
3a77107968 | ||
|
|
aa40130266 | ||
|
|
7635373366 | ||
|
|
941f4e2dec | ||
|
|
876c3183e1 | ||
|
|
1cc31bf900 | ||
|
|
8f16085808 | ||
|
|
58fbfdf5c3 | ||
|
|
07bfc86327 | ||
|
|
e54d87c41c | ||
|
|
225e760a54 | ||
|
|
f9cfbd01d8 | ||
|
|
3bf46e1ad2 | ||
|
|
de2b6d8715 | ||
|
|
f22abb726c | ||
|
|
031c4d2378 | ||
|
|
2b5955efbe | ||
|
|
70f7e7a7c0 | ||
|
|
6cf1a041b2 | ||
|
|
0d8cdc8a27 | ||
|
|
2680b461a2 | ||
|
|
fb726eede3 | ||
|
|
3aaf6eb648 | ||
|
|
477c08858d | ||
|
|
300791ab49 | ||
|
|
3e92e22941 | ||
|
|
a543f1bfc3 | ||
|
|
cd5f355bd0 | ||
|
|
cab616069f | ||
|
|
f90e00cc93 | ||
|
|
731cf7d5b1 | ||
|
|
c6d0c19b49 | ||
|
|
442b95d9e4 |
@@ -14,11 +14,11 @@ jobs:
|
|||||||
at: ~/project
|
at: ~/project
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- v1-dependencies-{{ checksum "package.json" }}
|
- v1-dependencies-{{ checksum "yarn.lock" }}
|
||||||
- v1-dependencies-
|
- v1-dependencies-
|
||||||
- run: yarn install
|
- run: yarn install --frozen-lockfile
|
||||||
- save_cache:
|
- save_cache:
|
||||||
key: v1-dependencies-{{ checksum "package.json" }}
|
key: v1-dependencies-{{ checksum "yarn.lock" }}
|
||||||
paths: node_modules
|
paths: node_modules
|
||||||
- persist_to_workspace:
|
- persist_to_workspace:
|
||||||
root: .
|
root: .
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ Navigators bundle a router and a view which takes the navigation state and decid
|
|||||||
A simple navigator could look like this:
|
A simple navigator could look like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { createNavigator } from '@react-navigation/core';
|
import { createNavigatorFactory } from '@react-navigation/core';
|
||||||
|
|
||||||
function StackNavigator({ initialRouteName, children, ...rest }) {
|
function StackNavigator({ initialRouteName, children, ...rest }) {
|
||||||
// The `navigation` object contains the navigation state and some helpers (e.g. push, pop)
|
// The `navigation` object contains the navigation state and some helpers (e.g. push, pop)
|
||||||
@@ -56,7 +56,7 @@ function StackNavigator({ initialRouteName, children, ...rest }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createNavigator(StackNavigator);
|
export default createNavigatorFactory(StackNavigator);
|
||||||
```
|
```
|
||||||
|
|
||||||
The navigator can render a screen by calling `descriptors[route.key].render()`. Internally, the descriptor adds appropriate wrappers to handle nested state.
|
The navigator can render a screen by calling `descriptors[route.key].render()`. Internally, the descriptor adds appropriate wrappers to handle nested state.
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
"jest": "^24.8.0",
|
"jest": "^24.8.0",
|
||||||
"lerna": "^3.16.4",
|
"lerna": "^3.16.4",
|
||||||
"prettier": "^1.18.2",
|
"prettier": "^1.18.2",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.7.2"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"react": "~16.8.3",
|
"react": "~16.8.3",
|
||||||
|
|||||||
@@ -3,6 +3,76 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.21](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.20...@react-navigation/bottom-tabs@5.0.0-alpha.21) (2019-11-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* make bottom tab bar consistent across platforms ([d1ca7f9](https://github.com/react-navigation/navigation-ex/commit/d1ca7f9))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.20](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.19...@react-navigation/bottom-tabs@5.0.0-alpha.20) (2019-11-08)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.19](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.18...@react-navigation/bottom-tabs@5.0.0-alpha.19) (2019-11-04)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* fix default BottomTabBar button ([#161](https://github.com/react-navigation/navigation-ex/issues/161)) ([22cb675](https://github.com/react-navigation/navigation-ex/commit/22cb675))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.18](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.17...@react-navigation/bottom-tabs@5.0.0-alpha.18) (2019-11-04)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.17](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.16...@react-navigation/bottom-tabs@5.0.0-alpha.17) (2019-10-30)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* hide inactive pages from screen reader in tabs ([#148](https://github.com/react-navigation/navigation-ex/issues/148)) ([58f7115](https://github.com/react-navigation/navigation-ex/commit/58f7115))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add an 'unmountInactiveScreens' option ([12d597f](https://github.com/react-navigation/navigation-ex/commit/12d597f))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.16](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.15...@react-navigation/bottom-tabs@5.0.0-alpha.16) (2019-10-29)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.14...@react-navigation/bottom-tabs@5.0.0-alpha.15) (2019-10-22)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.13...@react-navigation/bottom-tabs@5.0.0-alpha.14) (2019-10-15)
|
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.13...@react-navigation/bottom-tabs@5.0.0-alpha.14) (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"android",
|
"android",
|
||||||
"tab"
|
"tab"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.14",
|
"version": "5.0.0-alpha.21",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
"@react-navigation/routers": "^5.0.0-alpha.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
"react": "~16.8.3",
|
"react": "~16.8.3",
|
||||||
"react-native": "~0.59.10",
|
"react-native": "~0.59.10",
|
||||||
"react-native-safe-area-context": "^0.3.6",
|
"react-native-safe-area-context": "^0.3.6",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.7.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {
|
import {
|
||||||
useNavigationBuilder,
|
useNavigationBuilder,
|
||||||
createNavigator,
|
createNavigatorFactory,
|
||||||
DefaultNavigatorOptions,
|
DefaultNavigatorOptions,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/core';
|
||||||
import {
|
import {
|
||||||
@@ -49,7 +49,7 @@ function BottomTabNavigator({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createNavigator<
|
export default createNavigatorFactory<
|
||||||
BottomTabNavigationOptions,
|
BottomTabNavigationOptions,
|
||||||
typeof BottomTabNavigator
|
typeof BottomTabNavigator
|
||||||
>(BottomTabNavigator);
|
>(BottomTabNavigator);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {
|
import {
|
||||||
|
TouchableWithoutFeedbackProps,
|
||||||
AccessibilityRole,
|
AccessibilityRole,
|
||||||
AccessibilityStates,
|
AccessibilityStates,
|
||||||
StyleProp,
|
StyleProp,
|
||||||
@@ -26,8 +27,6 @@ export type BottomTabNavigationEventMap = {
|
|||||||
tabLongPress: undefined;
|
tabLongPress: undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Orientation = 'horizontal' | 'vertical';
|
|
||||||
|
|
||||||
export type LabelPosition = 'beside-icon' | 'below-icon';
|
export type LabelPosition = 'beside-icon' | 'below-icon';
|
||||||
|
|
||||||
export type BottomTabNavigationHelpers = NavigationHelpers<
|
export type BottomTabNavigationHelpers = NavigationHelpers<
|
||||||
@@ -71,11 +70,7 @@ export type BottomTabNavigationOptions = {
|
|||||||
*/
|
*/
|
||||||
tabBarLabel?:
|
tabBarLabel?:
|
||||||
| React.ReactNode
|
| React.ReactNode
|
||||||
| ((props: {
|
| ((props: { focused: boolean; color: string }) => React.ReactNode);
|
||||||
focused: boolean;
|
|
||||||
color: string;
|
|
||||||
size: number;
|
|
||||||
}) => React.ReactNode);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* React Element or a function that given { focused: boolean, color: string } returns a React.Node, to display in the tab bar.
|
* React Element or a function that given { focused: boolean, color: string } returns a React.Node, to display in the tab bar.
|
||||||
@@ -105,9 +100,10 @@ export type BottomTabNavigationOptions = {
|
|||||||
tabBarVisible?: boolean;
|
tabBarVisible?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buttton component to render for the tab items instead of the default `TouchableWithoutFeedback`
|
* Function which returns a React element to render as the tab bar button.
|
||||||
|
* Renders `TouchableWithoutFeedback` by default.
|
||||||
*/
|
*/
|
||||||
tabBarButtonComponent?: React.ComponentType<any>;
|
tabBarButton?: (props: BottomTabBarButtonProps) => React.ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type BottomTabDescriptor = Descriptor<
|
export type BottomTabDescriptor = Descriptor<
|
||||||
@@ -128,9 +124,14 @@ export type BottomTabNavigationConfig = {
|
|||||||
*/
|
*/
|
||||||
lazy?: boolean;
|
lazy?: boolean;
|
||||||
/**
|
/**
|
||||||
* Custom tab bar component.
|
* Whether a screen should be unmounted when navigating away from it.
|
||||||
|
* Defaults to `false`.
|
||||||
*/
|
*/
|
||||||
tabBarComponent?: React.ComponentType<BottomTabBarProps>;
|
unmountInactiveScreens?: boolean;
|
||||||
|
/**
|
||||||
|
* Function that returns a React element to display as the tab bar.
|
||||||
|
*/
|
||||||
|
tabBar?: (props: BottomTabBarProps) => React.ReactNode;
|
||||||
/**
|
/**
|
||||||
* Options for the tab bar which will be passed as props to the tab bar component.
|
* Options for the tab bar which will be passed as props to the tab bar component.
|
||||||
*/
|
*/
|
||||||
@@ -180,12 +181,14 @@ export type BottomTabBarOptions = {
|
|||||||
tabStyle?: StyleProp<ViewStyle>;
|
tabStyle?: StyleProp<ViewStyle>;
|
||||||
/**
|
/**
|
||||||
* Whether the label is renderd below the icon or beside the icon.
|
* Whether the label is renderd below the icon or beside the icon.
|
||||||
* When a function is passed, it receives the device orientation to render the label differently.
|
* When a function is passed, it receives the device dimensions to render the label differently.
|
||||||
* By default, in `vertical` orinetation, label is rendered below and in `horizontal` orientation, it's renderd beside.
|
* By default, in `vertical` orinetation, label is rendered below and in `horizontal` orientation, it's renderd beside.
|
||||||
*/
|
*/
|
||||||
labelPosition?:
|
labelPosition?:
|
||||||
| LabelPosition
|
| LabelPosition
|
||||||
| ((options: { deviceOrientation: Orientation }) => LabelPosition);
|
| ((options: {
|
||||||
|
dimensions: { height: number; width: number };
|
||||||
|
}) => LabelPosition);
|
||||||
/**
|
/**
|
||||||
* Whether the label position should adapt to the orientation.
|
* Whether the label position should adapt to the orientation.
|
||||||
*/
|
*/
|
||||||
@@ -212,25 +215,26 @@ export type BottomTabBarProps = BottomTabBarOptions & {
|
|||||||
route: Route<string>;
|
route: Route<string>;
|
||||||
focused: boolean;
|
focused: boolean;
|
||||||
}) => AccessibilityStates[];
|
}) => AccessibilityStates[];
|
||||||
getButtonComponent: (props: {
|
|
||||||
route: Route<string>;
|
|
||||||
}) => React.ComponentType<any> | undefined;
|
|
||||||
getLabelText: (props: {
|
getLabelText: (props: {
|
||||||
route: Route<string>;
|
route: Route<string>;
|
||||||
}) =>
|
}) =>
|
||||||
| ((scene: {
|
| ((scene: {
|
||||||
focused: boolean;
|
focused: boolean;
|
||||||
color: string;
|
color: string;
|
||||||
orientation: 'horizontal' | 'vertical';
|
|
||||||
}) => React.ReactNode | undefined)
|
}) => React.ReactNode | undefined)
|
||||||
| React.ReactNode;
|
| React.ReactNode;
|
||||||
getTestID: (props: { route: Route<string> }) => string | undefined;
|
getTestID: (props: { route: Route<string> }) => string | undefined;
|
||||||
|
renderButton: (
|
||||||
|
props: { route: Route<string> } & BottomTabBarButtonProps
|
||||||
|
) => React.ReactNode;
|
||||||
renderIcon: (props: {
|
renderIcon: (props: {
|
||||||
route: Route<string>;
|
route: Route<string>;
|
||||||
focused: boolean;
|
focused: boolean;
|
||||||
color: string;
|
color: string;
|
||||||
size: number;
|
size: number;
|
||||||
}) => React.ReactNode;
|
}) => React.ReactNode;
|
||||||
activeTintColor: string;
|
};
|
||||||
inactiveTintColor: string;
|
|
||||||
|
export type BottomTabBarButtonProps = TouchableWithoutFeedbackProps & {
|
||||||
|
children: React.ReactNode;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import { Route, NavigationContext } from '@react-navigation/core';
|
|||||||
import { SafeAreaConsumer } from 'react-native-safe-area-context';
|
import { SafeAreaConsumer } from 'react-native-safe-area-context';
|
||||||
|
|
||||||
import TabBarIcon from './TabBarIcon';
|
import TabBarIcon from './TabBarIcon';
|
||||||
import TouchableWithoutFeedbackWrapper from './TouchableWithoutFeedbackWrapper';
|
|
||||||
import { BottomTabBarProps } from '../types';
|
import { BottomTabBarProps } from '../types';
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
@@ -23,12 +22,12 @@ type State = {
|
|||||||
visible: Animated.Value;
|
visible: Animated.Value;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Props = BottomTabBarProps;
|
type Props = BottomTabBarProps & {
|
||||||
|
activeTintColor: string;
|
||||||
const majorVersion = parseInt(Platform.Version as string, 10);
|
inactiveTintColor: string;
|
||||||
const isIos = Platform.OS === 'ios';
|
};
|
||||||
const isIOS11 = majorVersion >= 11 && isIos;
|
|
||||||
|
|
||||||
|
const DEFAULT_TABBAR_HEIGHT = 50;
|
||||||
const DEFAULT_MAX_TAB_ITEM_WIDTH = 125;
|
const DEFAULT_MAX_TAB_ITEM_WIDTH = 125;
|
||||||
|
|
||||||
export default class TabBarBottom extends React.Component<Props, State> {
|
export default class TabBarBottom extends React.Component<Props, State> {
|
||||||
@@ -41,7 +40,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
showLabel: true,
|
showLabel: true,
|
||||||
showIcon: true,
|
showIcon: true,
|
||||||
allowFontScaling: true,
|
allowFontScaling: true,
|
||||||
adaptive: isIOS11,
|
adaptive: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
@@ -157,11 +156,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof label === 'function') {
|
if (typeof label === 'function') {
|
||||||
return label({
|
return label({ focused, color });
|
||||||
focused,
|
|
||||||
color,
|
|
||||||
orientation: horizontal ? 'horizontal' : 'vertical',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return label;
|
return label;
|
||||||
@@ -179,7 +174,6 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
inactiveTintColor,
|
inactiveTintColor,
|
||||||
renderIcon,
|
renderIcon,
|
||||||
showIcon,
|
showIcon,
|
||||||
showLabel,
|
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
if (showIcon === false) {
|
if (showIcon === false) {
|
||||||
@@ -200,11 +194,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
activeTintColor={activeTintColor}
|
activeTintColor={activeTintColor}
|
||||||
inactiveTintColor={inactiveTintColor}
|
inactiveTintColor={inactiveTintColor}
|
||||||
renderIcon={renderIcon}
|
renderIcon={renderIcon}
|
||||||
style={[
|
style={horizontal ? styles.iconHorizontal : styles.iconVertical}
|
||||||
styles.iconWithExplicitHeight,
|
|
||||||
showLabel === false && !horizontal && styles.iconWithoutLabel,
|
|
||||||
showLabel !== false && !horizontal && styles.iconWithLabel,
|
|
||||||
]}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -217,12 +207,11 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
|
|
||||||
if (labelPosition) {
|
if (labelPosition) {
|
||||||
let position;
|
let position;
|
||||||
|
|
||||||
if (typeof labelPosition === 'string') {
|
if (typeof labelPosition === 'string') {
|
||||||
position = labelPosition;
|
position = labelPosition;
|
||||||
} else {
|
} else {
|
||||||
position = labelPosition({
|
position = labelPosition({ dimensions });
|
||||||
deviceOrientation: isLandscape ? 'horizontal' : 'vertical',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position) {
|
if (position) {
|
||||||
@@ -234,8 +223,8 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
if (dimensions.width >= 768) {
|
||||||
if (Platform.isPad) {
|
// Screen size matches a tablet
|
||||||
let maxTabItemWidth = DEFAULT_MAX_TAB_ITEM_WIDTH;
|
let maxTabItemWidth = DEFAULT_MAX_TAB_ITEM_WIDTH;
|
||||||
|
|
||||||
const flattenedStyle = StyleSheet.flatten(tabStyle);
|
const flattenedStyle = StyleSheet.flatten(tabStyle);
|
||||||
@@ -266,7 +255,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
getAccessibilityLabel,
|
getAccessibilityLabel,
|
||||||
getAccessibilityRole,
|
getAccessibilityRole,
|
||||||
getAccessibilityStates,
|
getAccessibilityStates,
|
||||||
getButtonComponent,
|
renderButton,
|
||||||
getTestID,
|
getTestID,
|
||||||
style,
|
style,
|
||||||
tabStyle,
|
tabStyle,
|
||||||
@@ -296,11 +285,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
{
|
{
|
||||||
height:
|
height: DEFAULT_TABBAR_HEIGHT + (insets ? insets.bottom : 0),
|
||||||
// @ts-ignore
|
|
||||||
(this.shouldUseHorizontalLabels() && !Platform.isPad
|
|
||||||
? COMPACT_HEIGHT
|
|
||||||
: DEFAULT_HEIGHT) + (insets ? insets.bottom : 0),
|
|
||||||
paddingBottom: insets ? insets.bottom : 0,
|
paddingBottom: insets ? insets.bottom : 0,
|
||||||
},
|
},
|
||||||
style,
|
style,
|
||||||
@@ -329,34 +314,34 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
? activeBackgroundColor
|
? activeBackgroundColor
|
||||||
: inactiveBackgroundColor;
|
: inactiveBackgroundColor;
|
||||||
|
|
||||||
const ButtonComponent =
|
|
||||||
getButtonComponent({ route }) ||
|
|
||||||
TouchableWithoutFeedbackWrapper;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NavigationContext.Provider
|
<NavigationContext.Provider
|
||||||
key={route.key}
|
key={route.key}
|
||||||
value={descriptors[route.key].navigation}
|
value={descriptors[route.key].navigation}
|
||||||
>
|
>
|
||||||
<ButtonComponent
|
{renderButton({
|
||||||
onPress={() => onTabPress({ route })}
|
route,
|
||||||
onLongPress={() => onTabLongPress({ route })}
|
onPress: () => onTabPress({ route }),
|
||||||
testID={testID}
|
onLongPress: () => onTabLongPress({ route }),
|
||||||
accessibilityLabel={accessibilityLabel}
|
testID,
|
||||||
accessibilityRole={accessibilityRole}
|
accessibilityLabel,
|
||||||
accessibilityStates={accessibilityStates}
|
accessibilityRole,
|
||||||
style={[
|
accessibilityStates,
|
||||||
|
style: [
|
||||||
styles.tab,
|
styles.tab,
|
||||||
{ backgroundColor },
|
{ backgroundColor },
|
||||||
this.shouldUseHorizontalLabels()
|
this.shouldUseHorizontalLabels()
|
||||||
? styles.tabLandscape
|
? styles.tabLandscape
|
||||||
: styles.tabPortrait,
|
: styles.tabPortrait,
|
||||||
tabStyle,
|
tabStyle,
|
||||||
]}
|
],
|
||||||
>
|
children: (
|
||||||
{this.renderIcon(scene)}
|
<React.Fragment>
|
||||||
{this.renderLabel(scene)}
|
{this.renderIcon(scene)}
|
||||||
</ButtonComponent>
|
{this.renderLabel(scene)}
|
||||||
|
</React.Fragment>
|
||||||
|
),
|
||||||
|
})}
|
||||||
</NavigationContext.Provider>
|
</NavigationContext.Provider>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -368,9 +353,6 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_HEIGHT = 49;
|
|
||||||
const COMPACT_HEIGHT = 29;
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
tabBar: {
|
tabBar: {
|
||||||
left: 0,
|
left: 0,
|
||||||
@@ -387,7 +369,7 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
tab: {
|
tab: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
alignItems: isIos ? 'center' : 'stretch',
|
alignItems: 'center',
|
||||||
},
|
},
|
||||||
tabPortrait: {
|
tabPortrait: {
|
||||||
justifyContent: 'flex-end',
|
justifyContent: 'flex-end',
|
||||||
@@ -397,15 +379,11 @@ const styles = StyleSheet.create({
|
|||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
},
|
},
|
||||||
iconWithoutLabel: {
|
iconVertical: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
},
|
},
|
||||||
iconWithLabel: {
|
iconHorizontal: {
|
||||||
flex: 1,
|
height: '100%',
|
||||||
},
|
|
||||||
iconWithExplicitHeight: {
|
|
||||||
// @ts-ignore
|
|
||||||
height: Platform.isPad ? DEFAULT_HEIGHT : COMPACT_HEIGHT,
|
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
|
|||||||
@@ -1,23 +1,27 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {
|
import {
|
||||||
View,
|
View,
|
||||||
|
TouchableWithoutFeedback,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
AccessibilityRole,
|
AccessibilityRole,
|
||||||
AccessibilityStates,
|
AccessibilityStates,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
|
|
||||||
import { Route, CommonActions } from '@react-navigation/core';
|
import { Route, CommonActions } from '@react-navigation/core';
|
||||||
import { TabNavigationState } from '@react-navigation/routers';
|
import { TabNavigationState } from '@react-navigation/routers';
|
||||||
// eslint-disable-next-line import/no-unresolved
|
// eslint-disable-next-line import/no-unresolved
|
||||||
import { ScreenContainer } from 'react-native-screens';
|
import { ScreenContainer } from 'react-native-screens';
|
||||||
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
||||||
|
|
||||||
|
import ResourceSavingScene from './ResourceSavingScene';
|
||||||
import BottomTabBar from './BottomTabBar';
|
import BottomTabBar from './BottomTabBar';
|
||||||
import {
|
import {
|
||||||
BottomTabNavigationConfig,
|
BottomTabNavigationConfig,
|
||||||
BottomTabDescriptorMap,
|
BottomTabDescriptorMap,
|
||||||
BottomTabNavigationHelpers,
|
BottomTabNavigationHelpers,
|
||||||
|
BottomTabBarProps,
|
||||||
|
BottomTabBarButtonProps,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import ResourceSavingScene from './ResourceSavingScene';
|
|
||||||
|
|
||||||
type Props = BottomTabNavigationConfig & {
|
type Props = BottomTabNavigationConfig & {
|
||||||
state: TabNavigationState;
|
state: TabNavigationState;
|
||||||
@@ -49,16 +53,25 @@ export default class BottomTabView extends React.Component<Props, State> {
|
|||||||
loaded: [this.props.state.index],
|
loaded: [this.props.state.index],
|
||||||
};
|
};
|
||||||
|
|
||||||
private getButtonComponent = ({ route }: { route: Route<string> }) => {
|
private renderButton = ({
|
||||||
|
route,
|
||||||
|
children,
|
||||||
|
style,
|
||||||
|
...rest
|
||||||
|
}: { route: Route<string> } & BottomTabBarButtonProps) => {
|
||||||
const { descriptors } = this.props;
|
const { descriptors } = this.props;
|
||||||
const descriptor = descriptors[route.key];
|
const descriptor = descriptors[route.key];
|
||||||
const options = descriptor.options;
|
const options = descriptor.options;
|
||||||
|
|
||||||
if (options.tabBarButtonComponent) {
|
if (options.tabBarButton) {
|
||||||
return options.tabBarButtonComponent;
|
return options.tabBarButton({ children, style, ...rest });
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return (
|
||||||
|
<TouchableWithoutFeedback {...rest}>
|
||||||
|
<View style={style}>{children}</View>
|
||||||
|
</TouchableWithoutFeedback>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
private renderIcon = ({
|
private renderIcon = ({
|
||||||
@@ -159,7 +172,7 @@ export default class BottomTabView extends React.Component<Props, State> {
|
|||||||
|
|
||||||
private renderTabBar = () => {
|
private renderTabBar = () => {
|
||||||
const {
|
const {
|
||||||
tabBarComponent: TabBarComponent = BottomTabBar,
|
tabBar = (props: BottomTabBarProps) => <BottomTabBar {...props} />,
|
||||||
tabBarOptions,
|
tabBarOptions,
|
||||||
state,
|
state,
|
||||||
navigation,
|
navigation,
|
||||||
@@ -174,27 +187,25 @@ export default class BottomTabView extends React.Component<Props, State> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return tabBar({
|
||||||
<TabBarComponent
|
...tabBarOptions,
|
||||||
{...tabBarOptions}
|
state: state,
|
||||||
state={state}
|
descriptors: descriptors,
|
||||||
descriptors={descriptors}
|
navigation: navigation,
|
||||||
navigation={navigation}
|
onTabPress: this.handleTabPress,
|
||||||
onTabPress={this.handleTabPress}
|
onTabLongPress: this.handleTabLongPress,
|
||||||
onTabLongPress={this.handleTabLongPress}
|
getLabelText: this.getLabelText,
|
||||||
getLabelText={this.getLabelText}
|
getAccessibilityLabel: this.getAccessibilityLabel,
|
||||||
getButtonComponent={this.getButtonComponent}
|
getAccessibilityRole: this.getAccessibilityRole,
|
||||||
getAccessibilityLabel={this.getAccessibilityLabel}
|
getAccessibilityStates: this.getAccessibilityStates,
|
||||||
getAccessibilityRole={this.getAccessibilityRole}
|
getTestID: this.getTestID,
|
||||||
getAccessibilityStates={this.getAccessibilityStates}
|
renderButton: this.renderButton,
|
||||||
getTestID={this.getTestID}
|
renderIcon: this.renderIcon,
|
||||||
renderIcon={this.renderIcon}
|
});
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { state, descriptors, lazy } = this.props;
|
const { state, descriptors, lazy, unmountInactiveScreens } = this.props;
|
||||||
const { routes } = state;
|
const { routes } = state;
|
||||||
const { loaded } = this.state;
|
const { loaded } = this.state;
|
||||||
|
|
||||||
@@ -203,6 +214,10 @@ export default class BottomTabView extends React.Component<Props, State> {
|
|||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<ScreenContainer style={styles.pages}>
|
<ScreenContainer style={styles.pages}>
|
||||||
{routes.map((route, index) => {
|
{routes.map((route, index) => {
|
||||||
|
if (unmountInactiveScreens && index !== state.index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (lazy && !loaded.includes(index)) {
|
if (lazy && !loaded.includes(index)) {
|
||||||
// Don't render a screen if we've never navigated to it
|
// Don't render a screen if we've never navigated to it
|
||||||
return null;
|
return null;
|
||||||
@@ -216,7 +231,15 @@ export default class BottomTabView extends React.Component<Props, State> {
|
|||||||
style={StyleSheet.absoluteFill}
|
style={StyleSheet.absoluteFill}
|
||||||
isVisible={isFocused}
|
isVisible={isFocused}
|
||||||
>
|
>
|
||||||
{descriptors[route.key].render()}
|
<View
|
||||||
|
accessibilityElementsHidden={!isFocused}
|
||||||
|
importantForAccessibility={
|
||||||
|
isFocused ? 'auto' : 'no-hide-descendants'
|
||||||
|
}
|
||||||
|
style={styles.content}
|
||||||
|
>
|
||||||
|
{descriptors[route.key].render()}
|
||||||
|
</View>
|
||||||
</ResourceSavingScene>
|
</ResourceSavingScene>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -236,4 +259,7 @@ const styles = StyleSheet.create({
|
|||||||
pages: {
|
pages: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
},
|
},
|
||||||
|
content: {
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { TouchableWithoutFeedback, View } from 'react-native';
|
|
||||||
|
|
||||||
export default function TouchableWithoutFeedbackWrapper({
|
|
||||||
onPress,
|
|
||||||
onLongPress,
|
|
||||||
testID,
|
|
||||||
accessibilityLabel,
|
|
||||||
accessibilityRole,
|
|
||||||
accessibilityStates,
|
|
||||||
...rest
|
|
||||||
}: React.ComponentProps<typeof TouchableWithoutFeedback> & {
|
|
||||||
children: React.ReactNode;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<TouchableWithoutFeedback
|
|
||||||
onPress={onPress}
|
|
||||||
onLongPress={onLongPress}
|
|
||||||
testID={testID}
|
|
||||||
hitSlop={{ left: 15, right: 15, top: 0, bottom: 5 }}
|
|
||||||
accessibilityLabel={accessibilityLabel}
|
|
||||||
accessibilityRole={accessibilityRole}
|
|
||||||
accessibilityStates={accessibilityStates}
|
|
||||||
>
|
|
||||||
<View {...rest} />
|
|
||||||
</TouchableWithoutFeedback>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,57 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.13...@react-navigation/compat@5.0.0-alpha.14) (2019-11-10)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/compat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.12...@react-navigation/compat@5.0.0-alpha.13) (2019-11-08)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/compat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.11...@react-navigation/compat@5.0.0-alpha.12) (2019-11-04)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/compat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.11](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.10...@react-navigation/compat@5.0.0-alpha.11) (2019-10-30)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* drop isFirstRouteInParent method ([#145](https://github.com/react-navigation/navigation-ex/issues/145)) ([3a77107](https://github.com/react-navigation/navigation-ex/commit/3a77107))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.10](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.9...@react-navigation/compat@5.0.0-alpha.10) (2019-10-29)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/compat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.9](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.8...@react-navigation/compat@5.0.0-alpha.9) (2019-10-22)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/compat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.8](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.7...@react-navigation/compat@5.0.0-alpha.8) (2019-10-15)
|
# [5.0.0-alpha.8](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.7...@react-navigation/compat@5.0.0-alpha.8) (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@react-navigation/compat",
|
"name": "@react-navigation/compat",
|
||||||
"description": "Compatibility layer to write navigator definitions in static configuration format",
|
"description": "Compatibility layer to write navigator definitions in static configuration format",
|
||||||
"version": "5.0.0-alpha.8",
|
"version": "5.0.0-alpha.14",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -24,12 +24,12 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
"@react-navigation/routers": "^5.0.0-alpha.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/react": "^16.9.4",
|
"@types/react": "^16.9.4",
|
||||||
"react": "~16.8.3",
|
"react": "~16.8.3",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.7.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||||
|
|||||||
@@ -173,6 +173,12 @@ export default function createCompatNavigationProp<
|
|||||||
|
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
},
|
},
|
||||||
|
isFirstRouteInParent(): boolean {
|
||||||
|
const { routes } = navigation.dangerouslyGetState();
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
return routes[0].key === state.key;
|
||||||
|
},
|
||||||
dangerouslyGetParent() {
|
dangerouslyGetParent() {
|
||||||
const parent = navigation.dangerouslyGetParent();
|
const parent = navigation.dangerouslyGetParent();
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export default function createCompatNavigatorFactory<
|
|||||||
navigationConfig: Partial<Omit<NavigationConfig, 'screenOptions'>> & {
|
navigationConfig: Partial<Omit<NavigationConfig, 'screenOptions'>> & {
|
||||||
order?: Array<Extract<keyof ParamList, string>>;
|
order?: Array<Extract<keyof ParamList, string>>;
|
||||||
defaultNavigationOptions?: ScreenOptions;
|
defaultNavigationOptions?: ScreenOptions;
|
||||||
navigationOptions?: { [key: string]: any };
|
navigationOptions?: Record<string, any>;
|
||||||
} = {}
|
} = {}
|
||||||
) => {
|
) => {
|
||||||
const Pair = createNavigator();
|
const Pair = createNavigator();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
useNavigationBuilder,
|
useNavigationBuilder,
|
||||||
createNavigator,
|
createNavigatorFactory,
|
||||||
DefaultNavigatorOptions,
|
DefaultNavigatorOptions,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/core';
|
||||||
import {
|
import {
|
||||||
@@ -24,5 +24,5 @@ function SwitchNavigator(props: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default createCompatNavigatorFactory(
|
export default createCompatNavigatorFactory(
|
||||||
createNavigator<{}, typeof SwitchNavigator>(SwitchNavigator)
|
createNavigatorFactory<{}, typeof SwitchNavigator>(SwitchNavigator)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export type CompatNavigationProp<
|
|||||||
paramName: T,
|
paramName: T,
|
||||||
defaultValue?: ParamList[RouteName][T]
|
defaultValue?: ParamList[RouteName][T]
|
||||||
): ParamList[RouteName][T];
|
): ParamList[RouteName][T];
|
||||||
|
isFirstRouteInParent(): boolean;
|
||||||
dangerouslyGetParent<
|
dangerouslyGetParent<
|
||||||
T = NavigationProp<ParamListBase> | undefined
|
T = NavigationProp<ParamListBase> | undefined
|
||||||
>(): T extends NavigationProp<ParamListBase>
|
>(): T extends NavigationProp<ParamListBase>
|
||||||
|
|||||||
@@ -3,6 +3,86 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.22](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.21...@react-navigation/core@5.0.0-alpha.22) (2019-11-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* throw when containers are nested within another ([d4072e7](https://github.com/react-navigation/navigation-ex/commit/d4072e7))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.21](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.20...@react-navigation/core@5.0.0-alpha.21) (2019-11-08)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* don't crash if initialState is null ([270fbdc](https://github.com/react-navigation/navigation-ex/commit/270fbdc))
|
||||||
|
* fix types for resetRoot to accept undefined ([e871fdb](https://github.com/react-navigation/navigation-ex/commit/e871fdb))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.20](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.19...@react-navigation/core@5.0.0-alpha.20) (2019-11-02)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* pass rehydrated state in onStateChange and devtools ([5a34764](https://github.com/react-navigation/navigation-ex/commit/5a34764))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.19](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.18...@react-navigation/core@5.0.0-alpha.19) (2019-10-30)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* drop isFirstRouteInParent method ([#145](https://github.com/react-navigation/navigation-ex/issues/145)) ([3a77107](https://github.com/react-navigation/navigation-ex/commit/3a77107))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.18](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.17...@react-navigation/core@5.0.0-alpha.18) (2019-10-29)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* improve type annotation for screens ([8f16085](https://github.com/react-navigation/navigation-ex/commit/8f16085))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.17](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.16...@react-navigation/core@5.0.0-alpha.17) (2019-10-22)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/core
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.16](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.15...@react-navigation/core@5.0.0-alpha.16) (2019-10-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* rehydrate state before using it ([3e92e22](https://github.com/react-navigation/navigation-ex/commit/3e92e22))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* make it easier to navigate to a specific route in navigator ([#114](https://github.com/react-navigation/navigation-ex/issues/114)) ([a543f1b](https://github.com/react-navigation/navigation-ex/commit/a543f1b)), closes [#90](https://github.com/react-navigation/navigation-ex/issues/90)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.14...@react-navigation/core@5.0.0-alpha.15) (2019-10-15)
|
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.14...@react-navigation/core@5.0.0-alpha.15) (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ yarn add @react-navigation/core
|
|||||||
A basic custom navigator bundling a router and a view looks like this:
|
A basic custom navigator bundling a router and a view looks like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { useNavigationBuilder } from '@react-navigation/core';
|
import { createNavigatorFactory, useNavigationBuilder } from '@react-navigation/core';
|
||||||
import { StackRouter } from '@react-navigation/routers';
|
import { StackRouter } from '@react-navigation/routers';
|
||||||
|
|
||||||
function StackNavigator({ initialRouteName, children, ...rest }) {
|
function StackNavigator({ initialRouteName, children, ...rest }) {
|
||||||
@@ -34,5 +34,5 @@ function StackNavigator({ initialRouteName, children, ...rest }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createNavigator(StackNavigator);
|
export default createNavigatorFactory(StackNavigator);
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"react-native",
|
"react-native",
|
||||||
"react-navigation"
|
"react-navigation"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.15",
|
"version": "5.0.0-alpha.22",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
"react": "~16.8.3",
|
"react": "~16.8.3",
|
||||||
"react-native-testing-library": "^1.9.1",
|
"react-native-testing-library": "^1.9.1",
|
||||||
"react-test-renderer": "~16.8.3",
|
"react-test-renderer": "~16.8.3",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.7.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"react": "~16.8.3"
|
"react": "~16.8.3"
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ const MISSING_CONTEXT_ERROR =
|
|||||||
"We couldn't find a navigation context. Have you wrapped your app with 'NavigationContainer'?";
|
"We couldn't find a navigation context. Have you wrapped your app with 'NavigationContainer'?";
|
||||||
|
|
||||||
export const NavigationStateContext = React.createContext<{
|
export const NavigationStateContext = React.createContext<{
|
||||||
|
isDefault?: true;
|
||||||
state?: NavigationState | PartialState<NavigationState>;
|
state?: NavigationState | PartialState<NavigationState>;
|
||||||
getState: () => NavigationState | PartialState<NavigationState> | undefined;
|
getState: () => NavigationState | PartialState<NavigationState> | undefined;
|
||||||
setState: (
|
setState: (
|
||||||
@@ -31,6 +32,8 @@ export const NavigationStateContext = React.createContext<{
|
|||||||
key?: string;
|
key?: string;
|
||||||
performTransaction: (action: () => void) => void;
|
performTransaction: (action: () => void) => void;
|
||||||
}>({
|
}>({
|
||||||
|
isDefault: true,
|
||||||
|
|
||||||
get getState(): any {
|
get getState(): any {
|
||||||
throw new Error(MISSING_CONTEXT_ERROR);
|
throw new Error(MISSING_CONTEXT_ERROR);
|
||||||
},
|
},
|
||||||
@@ -83,11 +86,24 @@ const getPartialState = (
|
|||||||
* @param props.ref Ref object which refers to the navigation object containing helper methods.
|
* @param props.ref Ref object which refers to the navigation object containing helper methods.
|
||||||
*/
|
*/
|
||||||
const Container = React.forwardRef(function NavigationContainer(
|
const Container = React.forwardRef(function NavigationContainer(
|
||||||
{ initialState, onStateChange, children }: NavigationContainerProps,
|
{
|
||||||
|
initialState,
|
||||||
|
onStateChange,
|
||||||
|
independent,
|
||||||
|
children,
|
||||||
|
}: NavigationContainerProps,
|
||||||
ref: React.Ref<NavigationContainerRef>
|
ref: React.Ref<NavigationContainerRef>
|
||||||
) {
|
) {
|
||||||
|
const parent = React.useContext(NavigationStateContext);
|
||||||
|
|
||||||
|
if (!parent.isDefault && !independent) {
|
||||||
|
throw new Error(
|
||||||
|
"Looks like you have nested a 'NavigationContainer' inside another. Normally you need only one container at the root of the app, so this was probably an error. If this was intentional, pass 'independent={true}' explicitely."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const [state, setNavigationState] = React.useState<State>(() =>
|
const [state, setNavigationState] = React.useState<State>(() =>
|
||||||
getPartialState(initialState)
|
getPartialState(initialState == null ? undefined : initialState)
|
||||||
);
|
);
|
||||||
|
|
||||||
const navigationStateRef = React.useRef<State>();
|
const navigationStateRef = React.useRef<State>();
|
||||||
@@ -130,16 +146,16 @@ const Container = React.forwardRef(function NavigationContainer(
|
|||||||
};
|
};
|
||||||
|
|
||||||
const resetRoot = React.useCallback(
|
const resetRoot = React.useCallback(
|
||||||
(state: PartialState<NavigationState> | NavigationState) => {
|
(state?: PartialState<NavigationState> | NavigationState) => {
|
||||||
trackAction('@@RESET_ROOT');
|
trackAction('@@RESET_ROOT');
|
||||||
setNavigationState(state);
|
setNavigationState(state);
|
||||||
},
|
},
|
||||||
[trackAction]
|
[trackAction]
|
||||||
);
|
);
|
||||||
|
|
||||||
const getRootState = () => {
|
const getRootState = React.useCallback(() => {
|
||||||
return getStateForRoute('root');
|
return getStateForRoute('root');
|
||||||
};
|
}, [getStateForRoute]);
|
||||||
|
|
||||||
React.useImperativeHandle(ref, () => ({
|
React.useImperativeHandle(ref, () => ({
|
||||||
...(Object.keys(CommonActions) as Array<keyof typeof CommonActions>).reduce<
|
...(Object.keys(CommonActions) as Array<keyof typeof CommonActions>).reduce<
|
||||||
@@ -220,18 +236,18 @@ const Container = React.forwardRef(function NavigationContainer(
|
|||||||
if (skipTrackingRef.current) {
|
if (skipTrackingRef.current) {
|
||||||
skipTrackingRef.current = false;
|
skipTrackingRef.current = false;
|
||||||
} else {
|
} else {
|
||||||
trackState(state);
|
trackState(getRootState);
|
||||||
}
|
}
|
||||||
|
|
||||||
navigationStateRef.current = state;
|
navigationStateRef.current = state;
|
||||||
transactionStateRef.current = null;
|
transactionStateRef.current = null;
|
||||||
|
|
||||||
if (!isFirstMountRef.current && onStateChange) {
|
if (!isFirstMountRef.current && onStateChange) {
|
||||||
onStateChange(state);
|
onStateChange(getRootState());
|
||||||
}
|
}
|
||||||
|
|
||||||
isFirstMountRef.current = false;
|
isFirstMountRef.current = false;
|
||||||
}, [state, onStateChange, trackState]);
|
}, [state, onStateChange, trackState, getRootState]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NavigationBuilderContext.Provider value={builderContext}>
|
<NavigationBuilderContext.Provider value={builderContext}>
|
||||||
|
|||||||
@@ -90,8 +90,10 @@ export default function SceneView<
|
|||||||
route={route}
|
route={route}
|
||||||
>
|
>
|
||||||
{'component' in screen && screen.component !== undefined ? (
|
{'component' in screen && screen.component !== undefined ? (
|
||||||
|
// @ts-ignore
|
||||||
<screen.component navigation={navigation} route={route} />
|
<screen.component navigation={navigation} route={route} />
|
||||||
) : 'children' in screen && screen.children !== undefined ? (
|
) : 'children' in screen && screen.children !== undefined ? (
|
||||||
|
// @ts-ignore
|
||||||
screen.children({ navigation, route })
|
screen.children({ navigation, route })
|
||||||
) : null}
|
) : null}
|
||||||
</StaticContainer>
|
</StaticContainer>
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import * as CommonActions from '../CommonActions';
|
|||||||
jest.mock('shortid', () => () => 'test');
|
jest.mock('shortid', () => () => 'test');
|
||||||
|
|
||||||
const STATE = {
|
const STATE = {
|
||||||
stale: false as false,
|
stale: false as const,
|
||||||
|
type: 'test',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routes: [
|
routes: [
|
||||||
@@ -23,6 +24,7 @@ it('replaces focused screen with REPLACE', () => {
|
|||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routes: [
|
routes: [
|
||||||
@@ -42,6 +44,7 @@ it('replaces source screen with REPLACE', () => {
|
|||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routes: [
|
routes: [
|
||||||
@@ -70,6 +73,7 @@ it('sets params for the focused screen with SET_PARAMS', () => {
|
|||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routes: [
|
routes: [
|
||||||
@@ -89,6 +93,7 @@ it('sets params for the source screen with SET_PARAMS', () => {
|
|||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routes: [
|
routes: [
|
||||||
|
|||||||
@@ -122,6 +122,32 @@ it('throws when nesting performTransaction', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws when nesting containers', () => {
|
||||||
|
expect(() =>
|
||||||
|
render(
|
||||||
|
<NavigationContainer>
|
||||||
|
<NavigationContainer>
|
||||||
|
<React.Fragment />
|
||||||
|
</NavigationContainer>
|
||||||
|
</NavigationContainer>
|
||||||
|
)
|
||||||
|
).toThrowError(
|
||||||
|
"Looks like you have nested a 'NavigationContainer' inside another."
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
render(
|
||||||
|
<NavigationContainer>
|
||||||
|
<NavigationContainer independent>
|
||||||
|
<React.Fragment />
|
||||||
|
</NavigationContainer>
|
||||||
|
</NavigationContainer>
|
||||||
|
)
|
||||||
|
).not.toThrowError(
|
||||||
|
"Looks like you have nested a 'NavigationContainer' inside another."
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('handle dispatching with ref', () => {
|
it('handle dispatching with ref', () => {
|
||||||
const CurrentParentRouter = MockRouter;
|
const CurrentParentRouter = MockRouter;
|
||||||
|
|
||||||
@@ -233,6 +259,7 @@ it('handle dispatching with ref', () => {
|
|||||||
expect(onStateChange).toBeCalledTimes(1);
|
expect(onStateChange).toBeCalledTimes(1);
|
||||||
expect(onStateChange).lastCalledWith({
|
expect(onStateChange).lastCalledWith({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 0,
|
index: 0,
|
||||||
key: '0',
|
key: '0',
|
||||||
routeNames: ['foo', 'foo2', 'bar', 'baz'],
|
routeNames: ['foo', 'foo2', 'bar', 'baz'],
|
||||||
@@ -242,6 +269,7 @@ it('handle dispatching with ref', () => {
|
|||||||
name: 'baz',
|
name: 'baz',
|
||||||
state: {
|
state: {
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 0,
|
index: 0,
|
||||||
key: '1',
|
key: '1',
|
||||||
routeNames: ['qux', 'lex'],
|
routeNames: ['qux', 'lex'],
|
||||||
@@ -319,7 +347,28 @@ it('handle resetting state with ref', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(onStateChange).toBeCalledTimes(1);
|
expect(onStateChange).toBeCalledTimes(1);
|
||||||
expect(onStateChange).lastCalledWith(state);
|
expect(onStateChange).lastCalledWith({
|
||||||
|
index: 1,
|
||||||
|
key: '5',
|
||||||
|
routeNames: ['foo', 'foo2', 'bar', 'baz'],
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
key: 'baz',
|
||||||
|
name: 'baz',
|
||||||
|
state: {
|
||||||
|
index: 0,
|
||||||
|
key: '6',
|
||||||
|
routeNames: ['qux', 'lex'],
|
||||||
|
routes: [{ key: 'qux', name: 'qux' }, { key: 'lex', name: 'lex' }],
|
||||||
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ key: 'bar', name: 'bar' },
|
||||||
|
],
|
||||||
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handle getRootState', () => {
|
it('handle getRootState', () => {
|
||||||
@@ -367,10 +416,12 @@ it('handle getRootState', () => {
|
|||||||
routeNames: ['qux', 'lex'],
|
routeNames: ['qux', 'lex'],
|
||||||
routes: [{ key: 'qux', name: 'qux' }, { key: 'lex', name: 'lex' }],
|
routes: [{ key: 'qux', name: 'qux' }, { key: 'lex', name: 'lex' }],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ key: 'bar', name: 'bar' },
|
{ key: 'bar', name: 'bar' },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ export const MockRouterKey = { current: 0 };
|
|||||||
|
|
||||||
export default function MockRouter(options: DefaultRouterOptions) {
|
export default function MockRouter(options: DefaultRouterOptions) {
|
||||||
const router: Router<NavigationState, MockActions> = {
|
const router: Router<NavigationState, MockActions> = {
|
||||||
|
type: 'test',
|
||||||
|
|
||||||
getInitialState({ routeNames, routeParamList }) {
|
getInitialState({ routeNames, routeParamList }) {
|
||||||
const index =
|
const index =
|
||||||
options.initialRouteName === undefined
|
options.initialRouteName === undefined
|
||||||
@@ -21,6 +23,7 @@ export default function MockRouter(options: DefaultRouterOptions) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
key: String(MockRouterKey.current++),
|
key: String(MockRouterKey.current++),
|
||||||
index,
|
index,
|
||||||
routeNames,
|
routeNames,
|
||||||
@@ -58,6 +61,7 @@ export default function MockRouter(options: DefaultRouterOptions) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
key: String(MockRouterKey.current++),
|
key: String(MockRouterKey.current++),
|
||||||
index:
|
index:
|
||||||
typeof state.index === 'number' && state.index < routes.length
|
typeof state.index === 'number' && state.index < routes.length
|
||||||
@@ -108,7 +112,24 @@ export default function MockRouter(options: DefaultRouterOptions) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...state, index };
|
return {
|
||||||
|
...state,
|
||||||
|
index,
|
||||||
|
routes:
|
||||||
|
action.payload.params !== undefined
|
||||||
|
? state.routes.map((route, i) =>
|
||||||
|
i === index
|
||||||
|
? {
|
||||||
|
...route,
|
||||||
|
params: {
|
||||||
|
...route.params,
|
||||||
|
...action.payload.params,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: route
|
||||||
|
)
|
||||||
|
: state.routes,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import NavigationContainer from '../NavigationContainer';
|
|||||||
import useNavigationBuilder from '../useNavigationBuilder';
|
import useNavigationBuilder from '../useNavigationBuilder';
|
||||||
import useNavigation from '../useNavigation';
|
import useNavigation from '../useNavigation';
|
||||||
import MockRouter, { MockRouterKey } from './__fixtures__/MockRouter';
|
import MockRouter, { MockRouterKey } from './__fixtures__/MockRouter';
|
||||||
import { NavigationState } from '../types';
|
import { NavigationState, NavigationContainerRef } from '../types';
|
||||||
|
|
||||||
beforeEach(() => (MockRouterKey.current = 0));
|
beforeEach(() => (MockRouterKey.current = 0));
|
||||||
|
|
||||||
@@ -52,6 +52,7 @@ it('initializes state for a navigator on navigation', () => {
|
|||||||
expect(onStateChange).toBeCalledTimes(1);
|
expect(onStateChange).toBeCalledTimes(1);
|
||||||
expect(onStateChange).toBeCalledWith({
|
expect(onStateChange).toBeCalledWith({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 0,
|
index: 0,
|
||||||
key: '0',
|
key: '0',
|
||||||
routeNames: ['foo', 'bar', 'baz'],
|
routeNames: ['foo', 'bar', 'baz'],
|
||||||
@@ -63,6 +64,27 @@ it('initializes state for a navigator on navigation', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("doesn't crash when initialState is null", () => {
|
||||||
|
const TestNavigator = (props: any) => {
|
||||||
|
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
||||||
|
|
||||||
|
return descriptors[state.routes[state.index].key].render();
|
||||||
|
};
|
||||||
|
|
||||||
|
const TestScreen = () => null;
|
||||||
|
|
||||||
|
const element = (
|
||||||
|
// @ts-ignore
|
||||||
|
<NavigationContainer initialState={null}>
|
||||||
|
<TestNavigator>
|
||||||
|
<Screen name="foo" component={TestScreen} />
|
||||||
|
</TestNavigator>
|
||||||
|
</NavigationContainer>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(() => render(element)).not.toThrowError();
|
||||||
|
});
|
||||||
|
|
||||||
it('rehydrates state for a navigator on navigation', () => {
|
it('rehydrates state for a navigator on navigation', () => {
|
||||||
const TestNavigator = (props: any) => {
|
const TestNavigator = (props: any) => {
|
||||||
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
||||||
@@ -106,6 +128,66 @@ it('rehydrates state for a navigator on navigation', () => {
|
|||||||
routeNames: ['foo', 'bar'],
|
routeNames: ['foo', 'bar'],
|
||||||
routes: [{ key: 'foo', name: 'foo' }, { key: 'bar', name: 'bar' }],
|
routes: [{ key: 'foo', name: 'foo' }, { key: 'bar', name: 'bar' }],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("doesn't rehydrate state if the type of state didn't match router", () => {
|
||||||
|
const TestNavigator = (props: any) => {
|
||||||
|
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
||||||
|
|
||||||
|
return descriptors[state.routes[state.index].key].render();
|
||||||
|
};
|
||||||
|
|
||||||
|
const FooScreen = (props: any) => {
|
||||||
|
React.useEffect(() => {
|
||||||
|
props.navigation.dispatch({ type: 'UPDATE' });
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
|
index: 1,
|
||||||
|
type: 'something-else',
|
||||||
|
routes: [{ key: 'foo', name: 'foo' }, { key: 'bar', name: 'bar' }],
|
||||||
|
};
|
||||||
|
|
||||||
|
const onStateChange = jest.fn();
|
||||||
|
|
||||||
|
const element = (
|
||||||
|
<NavigationContainer
|
||||||
|
initialState={initialState}
|
||||||
|
onStateChange={onStateChange}
|
||||||
|
>
|
||||||
|
<TestNavigator initialRouteName="foo">
|
||||||
|
<Screen
|
||||||
|
name="foo"
|
||||||
|
component={FooScreen}
|
||||||
|
initialParams={{ answer: 42 }}
|
||||||
|
/>
|
||||||
|
<Screen name="bar" component={jest.fn()} />
|
||||||
|
</TestNavigator>
|
||||||
|
</NavigationContainer>
|
||||||
|
);
|
||||||
|
|
||||||
|
render(element).update(element);
|
||||||
|
|
||||||
|
expect(onStateChange).lastCalledWith({
|
||||||
|
index: 0,
|
||||||
|
key: '0',
|
||||||
|
routeNames: ['foo', 'bar'],
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
key: 'foo',
|
||||||
|
name: 'foo',
|
||||||
|
params: { answer: 42 },
|
||||||
|
},
|
||||||
|
{ key: 'bar', name: 'bar' },
|
||||||
|
],
|
||||||
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -144,6 +226,7 @@ it('initializes state for nested screens in React.Fragment', () => {
|
|||||||
expect(onStateChange).toBeCalledTimes(1);
|
expect(onStateChange).toBeCalledTimes(1);
|
||||||
expect(onStateChange).toBeCalledWith({
|
expect(onStateChange).toBeCalledWith({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 0,
|
index: 0,
|
||||||
key: '0',
|
key: '0',
|
||||||
routeNames: ['foo', 'bar', 'baz'],
|
routeNames: ['foo', 'bar', 'baz'],
|
||||||
@@ -194,6 +277,7 @@ it('initializes state for nested navigator on navigation', () => {
|
|||||||
expect(onStateChange).toBeCalledTimes(1);
|
expect(onStateChange).toBeCalledTimes(1);
|
||||||
expect(onStateChange).toBeCalledWith({
|
expect(onStateChange).toBeCalledWith({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 2,
|
index: 2,
|
||||||
key: '0',
|
key: '0',
|
||||||
routeNames: ['foo', 'bar', 'baz'],
|
routeNames: ['foo', 'bar', 'baz'],
|
||||||
@@ -205,6 +289,7 @@ it('initializes state for nested navigator on navigation', () => {
|
|||||||
name: 'baz',
|
name: 'baz',
|
||||||
state: {
|
state: {
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 0,
|
index: 0,
|
||||||
key: '1',
|
key: '1',
|
||||||
routeNames: ['qux'],
|
routeNames: ['qux'],
|
||||||
@@ -309,6 +394,7 @@ it('cleans up state when the navigator unmounts', () => {
|
|||||||
expect(onStateChange).toBeCalledTimes(1);
|
expect(onStateChange).toBeCalledTimes(1);
|
||||||
expect(onStateChange).lastCalledWith({
|
expect(onStateChange).lastCalledWith({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 0,
|
index: 0,
|
||||||
key: '0',
|
key: '0',
|
||||||
routeNames: ['foo', 'bar'],
|
routeNames: ['foo', 'bar'],
|
||||||
@@ -361,6 +447,7 @@ it('allows state updates by dispatching a function returning an action', () => {
|
|||||||
expect(onStateChange).toBeCalledTimes(1);
|
expect(onStateChange).toBeCalledTimes(1);
|
||||||
expect(onStateChange).toBeCalledWith({
|
expect(onStateChange).toBeCalledWith({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 1,
|
index: 1,
|
||||||
key: '0',
|
key: '0',
|
||||||
routeNames: ['foo', 'bar'],
|
routeNames: ['foo', 'bar'],
|
||||||
@@ -399,6 +486,7 @@ it('updates route params with setParams', () => {
|
|||||||
expect(onStateChange).toBeCalledTimes(1);
|
expect(onStateChange).toBeCalledTimes(1);
|
||||||
expect(onStateChange).lastCalledWith({
|
expect(onStateChange).lastCalledWith({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 0,
|
index: 0,
|
||||||
key: '0',
|
key: '0',
|
||||||
routeNames: ['foo', 'bar'],
|
routeNames: ['foo', 'bar'],
|
||||||
@@ -413,6 +501,7 @@ it('updates route params with setParams', () => {
|
|||||||
expect(onStateChange).toBeCalledTimes(2);
|
expect(onStateChange).toBeCalledTimes(2);
|
||||||
expect(onStateChange).lastCalledWith({
|
expect(onStateChange).lastCalledWith({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 0,
|
index: 0,
|
||||||
key: '0',
|
key: '0',
|
||||||
routeNames: ['foo', 'bar'],
|
routeNames: ['foo', 'bar'],
|
||||||
@@ -466,10 +555,23 @@ it('updates route params with setParams applied to parent', () => {
|
|||||||
key: '0',
|
key: '0',
|
||||||
routeNames: ['foo', 'bar'],
|
routeNames: ['foo', 'bar'],
|
||||||
routes: [
|
routes: [
|
||||||
{ key: 'foo', name: 'foo', params: { username: 'alice' } },
|
{
|
||||||
|
key: 'foo',
|
||||||
|
name: 'foo',
|
||||||
|
params: { username: 'alice' },
|
||||||
|
state: {
|
||||||
|
index: 0,
|
||||||
|
key: '1',
|
||||||
|
routeNames: ['baz'],
|
||||||
|
routes: [{ key: 'baz', name: 'baz' }],
|
||||||
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
|
},
|
||||||
|
},
|
||||||
{ key: 'bar', name: 'bar' },
|
{ key: 'bar', name: 'bar' },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
});
|
});
|
||||||
|
|
||||||
act(() => setParams({ age: 25 }));
|
act(() => setParams({ age: 25 }));
|
||||||
@@ -480,10 +582,23 @@ it('updates route params with setParams applied to parent', () => {
|
|||||||
key: '0',
|
key: '0',
|
||||||
routeNames: ['foo', 'bar'],
|
routeNames: ['foo', 'bar'],
|
||||||
routes: [
|
routes: [
|
||||||
{ key: 'foo', name: 'foo', params: { username: 'alice', age: 25 } },
|
{
|
||||||
|
key: 'foo',
|
||||||
|
name: 'foo',
|
||||||
|
params: { username: 'alice', age: 25 },
|
||||||
|
state: {
|
||||||
|
index: 0,
|
||||||
|
key: '1',
|
||||||
|
routeNames: ['baz'],
|
||||||
|
routes: [{ key: 'baz', name: 'baz' }],
|
||||||
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
|
},
|
||||||
|
},
|
||||||
{ key: 'bar', name: 'bar' },
|
{ key: 'bar', name: 'bar' },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -516,6 +631,7 @@ it('handles change in route names', () => {
|
|||||||
|
|
||||||
expect(onStateChange).toBeCalledWith({
|
expect(onStateChange).toBeCalledWith({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 0,
|
index: 0,
|
||||||
key: '0',
|
key: '0',
|
||||||
routeNames: ['foo', 'baz', 'qux'],
|
routeNames: ['foo', 'baz', 'qux'],
|
||||||
@@ -523,6 +639,80 @@ it('handles change in route names', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('navigates to nested child in a navigator', () => {
|
||||||
|
const TestNavigator = (props: any): any => {
|
||||||
|
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
||||||
|
|
||||||
|
return descriptors[state.routes[state.index].key].render();
|
||||||
|
};
|
||||||
|
|
||||||
|
const TestComponent = ({ route }: any): any =>
|
||||||
|
`[${route.name}, ${JSON.stringify(route.params)}]`;
|
||||||
|
|
||||||
|
const onStateChange = jest.fn();
|
||||||
|
|
||||||
|
const navigation = React.createRef<NavigationContainerRef>();
|
||||||
|
|
||||||
|
const element = render(
|
||||||
|
<NavigationContainer ref={navigation} onStateChange={onStateChange}>
|
||||||
|
<TestNavigator>
|
||||||
|
<Screen name="foo">
|
||||||
|
{() => (
|
||||||
|
<TestNavigator>
|
||||||
|
<Screen name="foo-a" component={TestComponent} />
|
||||||
|
<Screen name="foo-b" component={TestComponent} />
|
||||||
|
</TestNavigator>
|
||||||
|
)}
|
||||||
|
</Screen>
|
||||||
|
<Screen name="bar">
|
||||||
|
{() => (
|
||||||
|
<TestNavigator initialRouteName="bar-a">
|
||||||
|
<Screen
|
||||||
|
name="bar-a"
|
||||||
|
component={TestComponent}
|
||||||
|
initialParams={{ lol: 'why' }}
|
||||||
|
/>
|
||||||
|
<Screen
|
||||||
|
name="bar-b"
|
||||||
|
component={TestComponent}
|
||||||
|
initialParams={{ some: 'stuff' }}
|
||||||
|
/>
|
||||||
|
</TestNavigator>
|
||||||
|
)}
|
||||||
|
</Screen>
|
||||||
|
</TestNavigator>
|
||||||
|
</NavigationContainer>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(element).toMatchInlineSnapshot(`"[foo-a, undefined]"`);
|
||||||
|
|
||||||
|
act(
|
||||||
|
() =>
|
||||||
|
navigation.current &&
|
||||||
|
navigation.current.navigate('bar', {
|
||||||
|
screen: 'bar-b',
|
||||||
|
params: { test: 42 },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(element).toMatchInlineSnapshot(
|
||||||
|
`"[bar-b, {\\"some\\":\\"stuff\\",\\"test\\":42}]"`
|
||||||
|
);
|
||||||
|
|
||||||
|
act(
|
||||||
|
() =>
|
||||||
|
navigation.current &&
|
||||||
|
navigation.current.navigate('bar', {
|
||||||
|
screen: 'bar-a',
|
||||||
|
params: { whoa: 'test' },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(element).toMatchInlineSnapshot(
|
||||||
|
`"[bar-a, {\\"lol\\":\\"why\\",\\"whoa\\":\\"test\\"}]"`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('gives access to internal state', () => {
|
it('gives access to internal state', () => {
|
||||||
const TestNavigator = (props: any): any => {
|
const TestNavigator = (props: any): any => {
|
||||||
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
||||||
@@ -554,6 +744,7 @@ it('gives access to internal state', () => {
|
|||||||
routeNames: ['bar'],
|
routeNames: ['bar'],
|
||||||
routes: [{ key: 'bar', name: 'bar' }],
|
routes: [{ key: 'bar', name: 'bar' }],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -216,6 +216,7 @@ it('fires blur event when a route is removed with a delay', async () => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
key: 'stack',
|
key: 'stack',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames,
|
routeNames,
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ it("lets parent handle the action if child didn't", () => {
|
|||||||
expect(onStateChange).toBeCalledTimes(1);
|
expect(onStateChange).toBeCalledTimes(1);
|
||||||
expect(onStateChange).lastCalledWith({
|
expect(onStateChange).lastCalledWith({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 2,
|
index: 2,
|
||||||
key: '0',
|
key: '0',
|
||||||
routeNames: ['foo', 'bar', 'baz'],
|
routeNames: ['foo', 'bar', 'baz'],
|
||||||
@@ -191,6 +192,7 @@ it("lets children handle the action if parent didn't", () => {
|
|||||||
expect(onStateChange).toBeCalledTimes(1);
|
expect(onStateChange).toBeCalledTimes(1);
|
||||||
expect(onStateChange).lastCalledWith({
|
expect(onStateChange).lastCalledWith({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 0,
|
index: 0,
|
||||||
key: '0',
|
key: '0',
|
||||||
routeNames: ['foo', 'bar', 'baz'],
|
routeNames: ['foo', 'bar', 'baz'],
|
||||||
@@ -200,6 +202,7 @@ it("lets children handle the action if parent didn't", () => {
|
|||||||
name: 'baz',
|
name: 'baz',
|
||||||
state: {
|
state: {
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
index: 0,
|
index: 0,
|
||||||
key: '1',
|
key: '1',
|
||||||
routeNames: ['qux', 'lex'],
|
routeNames: ['qux', 'lex'],
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { ParamListBase, TypedNavigator } from './types';
|
|||||||
* @param Navigator The navigtor component to wrap.
|
* @param Navigator The navigtor component to wrap.
|
||||||
* @returns Factory method to create a `Navigator` and `Screen` pair.
|
* @returns Factory method to create a `Navigator` and `Screen` pair.
|
||||||
*/
|
*/
|
||||||
export default function createNavigator<
|
export default function createNavigatorFactory<
|
||||||
ScreenOptions extends object,
|
ScreenOptions extends object,
|
||||||
NavigatorComponent extends React.ComponentType<any>
|
NavigatorComponent extends React.ComponentType<any>
|
||||||
>(Navigator: NavigatorComponent) {
|
>(Navigator: NavigatorComponent) {
|
||||||
@@ -3,7 +3,7 @@ import { NavigationState, PartialState, Route } from './types';
|
|||||||
|
|
||||||
type State = NavigationState | Omit<PartialState<NavigationState>, 'stale'>;
|
type State = NavigationState | Omit<PartialState<NavigationState>, 'stale'>;
|
||||||
|
|
||||||
type StringifyConfig = { [key: string]: (value: any) => string };
|
type StringifyConfig = Record<string, (value: any) => string>;
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
[routeName: string]: string | { path: string; stringify?: StringifyConfig };
|
[routeName: string]: string | { path: string; stringify?: StringifyConfig };
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import escape from 'escape-string-regexp';
|
|||||||
import queryString from 'query-string';
|
import queryString from 'query-string';
|
||||||
import { NavigationState, PartialState } from './types';
|
import { NavigationState, PartialState } from './types';
|
||||||
|
|
||||||
type ParseConfig = { [key: string]: (value: string) => any };
|
type ParseConfig = Record<string, (value: string) => any>;
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
[routeName: string]: string | { path: string; parse?: ParseConfig };
|
[routeName: string]: string | { path: string; parse?: ParseConfig };
|
||||||
@@ -78,7 +78,7 @@ export default function getStateFromPath(
|
|||||||
.filter(p => p.startsWith(':'));
|
.filter(p => p.startsWith(':'));
|
||||||
|
|
||||||
if (paramPatterns.length) {
|
if (paramPatterns.length) {
|
||||||
params = paramPatterns.reduce<{ [key: string]: any }>((acc, p, i) => {
|
params = paramPatterns.reduce<Record<string, any>>((acc, p, i) => {
|
||||||
const key = p.replace(/^:/, '');
|
const key = p.replace(/^:/, '');
|
||||||
const value = match[i + 1]; // The param segments start from index 1 in the regex match result
|
const value = match[i + 1]; // The param segments start from index 1 in the regex match result
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export { CommonActions };
|
|||||||
|
|
||||||
export { default as BaseRouter } from './BaseRouter';
|
export { default as BaseRouter } from './BaseRouter';
|
||||||
export { default as NavigationContainer } from './NavigationContainer';
|
export { default as NavigationContainer } from './NavigationContainer';
|
||||||
export { default as createNavigator } from './createNavigator';
|
export { default as createNavigatorFactory } from './createNavigatorFactory';
|
||||||
|
|
||||||
export { default as NavigationContext } from './NavigationContext';
|
export { default as NavigationContext } from './NavigationContext';
|
||||||
export { default as NavigationRouteContext } from './NavigationRouteContext';
|
export { default as NavigationRouteContext } from './NavigationRouteContext';
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ export type NavigationState = {
|
|||||||
routes: Array<
|
routes: Array<
|
||||||
Route<string> & { state?: NavigationState | PartialState<NavigationState> }
|
Route<string> & { state?: NavigationState | PartialState<NavigationState> }
|
||||||
>;
|
>;
|
||||||
|
/**
|
||||||
|
* Custom type for the state, whether it's for tab, stack, drawer etc.
|
||||||
|
* During rehydration, the state will be discarded if type doesn't match with router type.
|
||||||
|
* It can also be used to detect the type of the navigator we're dealing with.
|
||||||
|
*/
|
||||||
|
type: string;
|
||||||
/**
|
/**
|
||||||
* Whether the navigation state has been rehydrated.
|
* Whether the navigation state has been rehydrated.
|
||||||
*/
|
*/
|
||||||
@@ -36,9 +42,10 @@ export type InitialState = Partial<
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type PartialState<State extends NavigationState> = Partial<
|
export type PartialState<State extends NavigationState> = Partial<
|
||||||
Omit<State, 'stale' | 'key' | 'routes' | 'routeNames'>
|
Omit<State, 'stale' | 'type' | 'key' | 'routes' | 'routeNames'>
|
||||||
> & {
|
> & {
|
||||||
stale?: true;
|
stale?: true;
|
||||||
|
type?: string;
|
||||||
routes: Array<
|
routes: Array<
|
||||||
Omit<Route<string>, 'key'> & { key?: string; state?: InitialState }
|
Omit<Route<string>, 'key'> & { key?: string; state?: InitialState }
|
||||||
>;
|
>;
|
||||||
@@ -115,6 +122,12 @@ export type Router<
|
|||||||
State extends NavigationState,
|
State extends NavigationState,
|
||||||
Action extends NavigationAction
|
Action extends NavigationAction
|
||||||
> = {
|
> = {
|
||||||
|
/**
|
||||||
|
* Type of the router. Should match the `type` property in state.
|
||||||
|
* If the type doesn't match, the state will be discarded during rehydration.
|
||||||
|
*/
|
||||||
|
type: State['type'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the navigation state.
|
* Initialize the navigation state.
|
||||||
*
|
*
|
||||||
@@ -189,7 +202,7 @@ export type Router<
|
|||||||
actionCreators?: ActionCreators<Action>;
|
actionCreators?: ActionCreators<Action>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ParamListBase = { [key: string]: object | undefined };
|
export type ParamListBase = Record<string, object | undefined>;
|
||||||
|
|
||||||
export type EventMapBase = {
|
export type EventMapBase = {
|
||||||
focus: undefined;
|
focus: undefined;
|
||||||
@@ -215,7 +228,7 @@ export type EventListenerCallback<EventName extends string, Data> = (
|
|||||||
e: EventArg<EventName, Data>
|
e: EventArg<EventName, Data>
|
||||||
) => void;
|
) => void;
|
||||||
|
|
||||||
export type EventConsumer<EventMap extends { [key: string]: any }> = {
|
export type EventConsumer<EventMap extends Record<string, any>> = {
|
||||||
/**
|
/**
|
||||||
* Subscribe to events from the parent navigator.
|
* Subscribe to events from the parent navigator.
|
||||||
*
|
*
|
||||||
@@ -232,7 +245,7 @@ export type EventConsumer<EventMap extends { [key: string]: any }> = {
|
|||||||
): void;
|
): void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type EventEmitter<EventMap extends { [key: string]: any }> = {
|
export type EventEmitter<EventMap extends Record<string, any>> = {
|
||||||
/**
|
/**
|
||||||
* Emit an event to child screens.
|
* Emit an event to child screens.
|
||||||
*
|
*
|
||||||
@@ -325,7 +338,7 @@ type NavigationHelpersCommon<
|
|||||||
*
|
*
|
||||||
* @param state Navigation state object.
|
* @param state Navigation state object.
|
||||||
*/
|
*/
|
||||||
resetRoot(state: PartialState<NavigationState> | NavigationState): void;
|
resetRoot(state?: PartialState<NavigationState> | NavigationState): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Go back to the previous route in history.
|
* Go back to the previous route in history.
|
||||||
@@ -349,7 +362,7 @@ type NavigationHelpersCommon<
|
|||||||
|
|
||||||
export type NavigationHelpers<
|
export type NavigationHelpers<
|
||||||
ParamList extends ParamListBase,
|
ParamList extends ParamListBase,
|
||||||
EventMap extends { [key: string]: any } = {}
|
EventMap extends Record<string, any> = {}
|
||||||
> = NavigationHelpersCommon<ParamList> &
|
> = NavigationHelpersCommon<ParamList> &
|
||||||
EventEmitter<EventMap> & {
|
EventEmitter<EventMap> & {
|
||||||
/**
|
/**
|
||||||
@@ -364,10 +377,23 @@ export type NavigationHelpers<
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type NavigationContainerProps = {
|
export type NavigationContainerProps = {
|
||||||
|
/**
|
||||||
|
* Initial navigation state for the child navigators.
|
||||||
|
*/
|
||||||
initialState?: InitialState;
|
initialState?: InitialState;
|
||||||
onStateChange?: (
|
/**
|
||||||
state: NavigationState | PartialState<NavigationState> | undefined
|
* Callback which is called with the latest navigation state when it changes.
|
||||||
) => void;
|
*/
|
||||||
|
onStateChange?: (state: NavigationState | undefined) => void;
|
||||||
|
/**
|
||||||
|
* Whether this navigation container should be independent of parent containers.
|
||||||
|
* If this is not set to `true`, this container cannot be nested inside another container.
|
||||||
|
* Setting it to `true` disconnects any children navigators from parent container.
|
||||||
|
*/
|
||||||
|
independent?: boolean;
|
||||||
|
/**
|
||||||
|
* Children elements to render.
|
||||||
|
*/
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -376,7 +402,7 @@ export type NavigationProp<
|
|||||||
RouteName extends keyof ParamList = string,
|
RouteName extends keyof ParamList = string,
|
||||||
State extends NavigationState = NavigationState,
|
State extends NavigationState = NavigationState,
|
||||||
ScreenOptions extends object = {},
|
ScreenOptions extends object = {},
|
||||||
EventMap extends { [key: string]: any } = {}
|
EventMap extends Record<string, any> = {}
|
||||||
> = NavigationHelpersCommon<ParamList, State> & {
|
> = NavigationHelpersCommon<ParamList, State> & {
|
||||||
/**
|
/**
|
||||||
* Update the param object for the route.
|
* Update the param object for the route.
|
||||||
@@ -394,13 +420,6 @@ export type NavigationProp<
|
|||||||
*/
|
*/
|
||||||
setOptions(options: Partial<ScreenOptions>): void;
|
setOptions(options: Partial<ScreenOptions>): void;
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the screen is the first route in the navigator.
|
|
||||||
* This method returns `true` if the index of the route is `0`, `false` otherwise.
|
|
||||||
* It can be useful to decide whether to display a back button in a stack.
|
|
||||||
*/
|
|
||||||
isFirstRouteInParent(): boolean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the parent navigator, if any. Reason why the function is called
|
* Returns the parent navigator, if any. Reason why the function is called
|
||||||
* dangerouslyGetParent is to warn developers against overusing it to eg. get parent
|
* dangerouslyGetParent is to warn developers against overusing it to eg. get parent
|
||||||
@@ -468,7 +487,7 @@ export type Descriptor<
|
|||||||
RouteName extends keyof ParamList = string,
|
RouteName extends keyof ParamList = string,
|
||||||
State extends NavigationState = NavigationState,
|
State extends NavigationState = NavigationState,
|
||||||
ScreenOptions extends object = {},
|
ScreenOptions extends object = {},
|
||||||
EventMap extends { [key: string]: any } = {}
|
EventMap extends Record<string, any> = {}
|
||||||
> = {
|
> = {
|
||||||
/**
|
/**
|
||||||
* Render the component associated with this route.
|
* Render the component associated with this route.
|
||||||
@@ -521,13 +540,19 @@ export type RouteConfig<
|
|||||||
/**
|
/**
|
||||||
* React component to render for this screen.
|
* React component to render for this screen.
|
||||||
*/
|
*/
|
||||||
component: React.ComponentType<any>;
|
component: React.ComponentType<{
|
||||||
|
route: RouteProp<ParamList, RouteName>;
|
||||||
|
navigation: any;
|
||||||
|
}>;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
/**
|
/**
|
||||||
* Render callback to render content of this screen.
|
* Render callback to render content of this screen.
|
||||||
*/
|
*/
|
||||||
children: (props: any) => React.ReactNode;
|
children: (props: {
|
||||||
|
route: RouteProp<ParamList, RouteName>;
|
||||||
|
navigation: any;
|
||||||
|
}) => React.ReactNode;
|
||||||
});
|
});
|
||||||
|
|
||||||
export type NavigationContainerRef =
|
export type NavigationContainerRef =
|
||||||
@@ -537,7 +562,7 @@ export type NavigationContainerRef =
|
|||||||
*
|
*
|
||||||
* @param state Navigation state object.
|
* @param state Navigation state object.
|
||||||
*/
|
*/
|
||||||
resetRoot(state: PartialState<NavigationState> | NavigationState): void;
|
resetRoot(state?: PartialState<NavigationState> | NavigationState): void;
|
||||||
getRootState(): NavigationState;
|
getRootState(): NavigationState;
|
||||||
}
|
}
|
||||||
| undefined
|
| undefined
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import {
|
|||||||
|
|
||||||
type Options<State extends NavigationState, ScreenOptions extends object> = {
|
type Options<State extends NavigationState, ScreenOptions extends object> = {
|
||||||
state: State;
|
state: State;
|
||||||
screens: { [key: string]: RouteConfig<ParamListBase, string, ScreenOptions> };
|
screens: Record<string, RouteConfig<ParamListBase, string, ScreenOptions>>;
|
||||||
navigation: NavigationHelpers<ParamListBase>;
|
navigation: NavigationHelpers<ParamListBase>;
|
||||||
screenOptions?:
|
screenOptions?:
|
||||||
| ScreenOptions
|
| ScreenOptions
|
||||||
@@ -68,7 +68,7 @@ export default function useDescriptors<
|
|||||||
router,
|
router,
|
||||||
emitter,
|
emitter,
|
||||||
}: Options<State, ScreenOptions>) {
|
}: Options<State, ScreenOptions>) {
|
||||||
const [options, setOptions] = React.useState<{ [key: string]: object }>({});
|
const [options, setOptions] = React.useState<Record<string, object>>({});
|
||||||
const { trackAction } = React.useContext(NavigationBuilderContext);
|
const { trackAction } = React.useContext(NavigationBuilderContext);
|
||||||
|
|
||||||
const context = React.useMemo(
|
const context = React.useMemo(
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export default function useDevTools({ name, reset, state }: Options) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const trackState = React.useCallback(
|
const trackState = React.useCallback(
|
||||||
(state: State) => {
|
(getState: () => State) => {
|
||||||
if (!devTools) {
|
if (!devTools) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -71,9 +71,11 @@ export default function useDevTools({ name, reset, state }: Options) {
|
|||||||
devTools.send(actions.current.shift(), lastStateRef.current);
|
devTools.send(actions.current.shift(), lastStateRef.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const state = getState();
|
||||||
|
|
||||||
if (actions.current.length) {
|
if (actions.current.length) {
|
||||||
devTools.send(actions.current.pop(), state);
|
devTools.send(actions.current.pop(), state);
|
||||||
} else if (lastStateRef.current !== state) {
|
} else {
|
||||||
devTools.send('@@UNKNOWN', state);
|
devTools.send('@@UNKNOWN', state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { EventEmitter, EventConsumer, EventArg } from './types';
|
import { EventEmitter, EventConsumer, EventArg } from './types';
|
||||||
|
|
||||||
export type NavigationEventEmitter = EventEmitter<{ [key: string]: any }> & {
|
export type NavigationEventEmitter = EventEmitter<Record<string, any>> & {
|
||||||
create: (target: string) => EventConsumer<{ [key: string]: any }>;
|
create: (target: string) => EventConsumer<Record<string, any>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Listeners = Array<(data: any) => void>;
|
type Listeners = Array<(data: any) => void>;
|
||||||
@@ -11,9 +11,7 @@ type Listeners = Array<(data: any) => void>;
|
|||||||
* Hook to manage the event system used by the navigator to notify screens of various events.
|
* Hook to manage the event system used by the navigator to notify screens of various events.
|
||||||
*/
|
*/
|
||||||
export default function useEventEmitter(): NavigationEventEmitter {
|
export default function useEventEmitter(): NavigationEventEmitter {
|
||||||
const listeners = React.useRef<{
|
const listeners = React.useRef<Record<string, Record<string, Listeners>>>({});
|
||||||
[key: string]: { [key: string]: Listeners };
|
|
||||||
}>({});
|
|
||||||
|
|
||||||
const create = React.useCallback((target: string) => {
|
const create = React.useCallback((target: string) => {
|
||||||
const removeListener = (type: string, callback: (data: any) => void) => {
|
const removeListener = (type: string, callback: (data: any) => void) => {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { NavigationStateContext } from './NavigationContainer';
|
import { NavigationStateContext } from './NavigationContainer';
|
||||||
|
import NavigationRouteContext from './NavigationRouteContext';
|
||||||
import Screen from './Screen';
|
import Screen from './Screen';
|
||||||
|
import { navigate } from './CommonActions';
|
||||||
import useEventEmitter from './useEventEmitter';
|
import useEventEmitter from './useEventEmitter';
|
||||||
import useRegisterNavigator from './useRegisterNavigator';
|
import useRegisterNavigator from './useRegisterNavigator';
|
||||||
import useDescriptors from './useDescriptors';
|
import useDescriptors from './useDescriptors';
|
||||||
@@ -30,6 +32,13 @@ import useOnGetState from './useOnGetState';
|
|||||||
// eslint-disable-next-line babel/no-unused-expressions
|
// eslint-disable-next-line babel/no-unused-expressions
|
||||||
PrivateValueStore;
|
PrivateValueStore;
|
||||||
|
|
||||||
|
type NavigatorRoute = {
|
||||||
|
params?: {
|
||||||
|
screen?: string;
|
||||||
|
params?: object;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare two arrays with primitive values as the content.
|
* Compare two arrays with primitive values as the content.
|
||||||
* We need to make sure that both values and order match.
|
* We need to make sure that both values and order match.
|
||||||
@@ -89,39 +98,66 @@ export default function useNavigationBuilder<
|
|||||||
State extends NavigationState,
|
State extends NavigationState,
|
||||||
RouterOptions extends DefaultRouterOptions,
|
RouterOptions extends DefaultRouterOptions,
|
||||||
ScreenOptions extends object,
|
ScreenOptions extends object,
|
||||||
EventMap extends { [key: string]: any }
|
EventMap extends Record<string, any>
|
||||||
>(
|
>(
|
||||||
createRouter: RouterFactory<State, any, RouterOptions>,
|
createRouter: RouterFactory<State, any, RouterOptions>,
|
||||||
options: DefaultNavigatorOptions<ScreenOptions> & RouterOptions
|
options: DefaultNavigatorOptions<ScreenOptions> & RouterOptions
|
||||||
) {
|
) {
|
||||||
useRegisterNavigator();
|
useRegisterNavigator();
|
||||||
|
|
||||||
|
const route = React.useContext(NavigationRouteContext) as (
|
||||||
|
| NavigatorRoute
|
||||||
|
| undefined);
|
||||||
|
|
||||||
|
const previousRouteRef = React.useRef(route);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
previousRouteRef.current = route;
|
||||||
|
}, [route]);
|
||||||
|
|
||||||
const { children, ...rest } = options;
|
const { children, ...rest } = options;
|
||||||
const { current: router } = React.useRef<Router<State, any>>(
|
const { current: router } = React.useRef<Router<State, any>>(
|
||||||
createRouter((rest as unknown) as RouterOptions)
|
createRouter({
|
||||||
|
...((rest as unknown) as RouterOptions),
|
||||||
|
...(route && route.params && typeof route.params.screen === 'string'
|
||||||
|
? { initialRouteName: route.params.screen }
|
||||||
|
: null),
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const screens = getRouteConfigsFromChildren<ScreenOptions>(children).reduce(
|
const screens = getRouteConfigsFromChildren<ScreenOptions>(children).reduce<
|
||||||
(acc, curr) => {
|
Record<string, RouteConfig<ParamListBase, string, ScreenOptions>>
|
||||||
if (curr.name in acc) {
|
>((acc, curr) => {
|
||||||
throw new Error(
|
if (curr.name in acc) {
|
||||||
`A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named '${curr.name}')`
|
throw new Error(
|
||||||
);
|
`A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named '${curr.name}')`
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
acc[curr.name] = curr;
|
acc[curr.name] = curr;
|
||||||
return acc;
|
return acc;
|
||||||
},
|
}, {});
|
||||||
{} as { [key: string]: RouteConfig<ParamListBase, string, ScreenOptions> }
|
|
||||||
);
|
|
||||||
|
|
||||||
const routeNames = Object.keys(screens);
|
const routeNames = Object.keys(screens);
|
||||||
const routeParamList = routeNames.reduce(
|
const routeParamList = routeNames.reduce<Record<string, object | undefined>>(
|
||||||
(acc, curr) => {
|
(acc, curr) => {
|
||||||
acc[curr] = screens[curr].initialParams;
|
const { initialParams } = screens[curr];
|
||||||
|
const initialParamsFromParams =
|
||||||
|
route && route.params && route.params.screen === curr
|
||||||
|
? route.params.params
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
acc[curr] =
|
||||||
|
initialParams !== undefined || initialParamsFromParams !== undefined
|
||||||
|
? {
|
||||||
|
...initialParams,
|
||||||
|
...initialParamsFromParams,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{} as { [key: string]: object | undefined }
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!routeNames.length) {
|
if (!routeNames.length) {
|
||||||
@@ -130,6 +166,17 @@ export default function useNavigationBuilder<
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isStateValid = React.useCallback(
|
||||||
|
state => state.type === undefined || state.type === router.type,
|
||||||
|
[router.type]
|
||||||
|
);
|
||||||
|
|
||||||
|
const isStateInitialized = React.useCallback(
|
||||||
|
state =>
|
||||||
|
state !== undefined && state.stale === false && isStateValid(state),
|
||||||
|
[isStateValid]
|
||||||
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
state: currentState,
|
state: currentState,
|
||||||
getState: getCurrentState,
|
getState: getCurrentState,
|
||||||
@@ -152,7 +199,7 @@ export default function useNavigationBuilder<
|
|||||||
// Otherwise assume that the state was provided as initial state
|
// Otherwise assume that the state was provided as initial state
|
||||||
// So we need to rehydrate it to make it usable
|
// So we need to rehydrate it to make it usable
|
||||||
initializedStateRef.current =
|
initializedStateRef.current =
|
||||||
currentState === undefined
|
currentState === undefined || !isStateValid(currentState)
|
||||||
? router.getInitialState({
|
? router.getInitialState({
|
||||||
routeNames,
|
routeNames,
|
||||||
routeParamList,
|
routeParamList,
|
||||||
@@ -171,32 +218,57 @@ export default function useNavigationBuilder<
|
|||||||
// If the state isn't initialized, or stale, use the state we initialized instead
|
// If the state isn't initialized, or stale, use the state we initialized instead
|
||||||
// The state won't update until there's a change needed in the state we have initalized locally
|
// The state won't update until there's a change needed in the state we have initalized locally
|
||||||
// So it'll be `undefined` or stale untill the first navigation event happens
|
// So it'll be `undefined` or stale untill the first navigation event happens
|
||||||
currentState === undefined || currentState.stale !== false
|
isStateInitialized(currentState)
|
||||||
? (initializedStateRef.current as State)
|
? (currentState as State)
|
||||||
: (currentState as State);
|
: (initializedStateRef.current as State);
|
||||||
|
|
||||||
|
let nextState: State = state;
|
||||||
|
|
||||||
if (!isArrayEqual(state.routeNames, routeNames)) {
|
if (!isArrayEqual(state.routeNames, routeNames)) {
|
||||||
// When the list of route names change, the router should handle it to remove invalid routes
|
// When the list of route names change, the router should handle it to remove invalid routes
|
||||||
const nextState = router.getStateForRouteNamesChange(state, {
|
nextState = router.getStateForRouteNamesChange(state, {
|
||||||
routeNames,
|
routeNames,
|
||||||
routeParamList,
|
routeParamList,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (state !== nextState) {
|
|
||||||
// If the state needs to be updated, we'll schedule an update with React
|
|
||||||
// setState in render seems hacky, but that's how React docs implement getDerivedPropsFromState
|
|
||||||
// https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops
|
|
||||||
performTransaction(() => {
|
|
||||||
setState(nextState);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// The up-to-date state will come in next render, but we don't need to wait for it
|
|
||||||
// We can't use the outdated state since the screens have changed, which will cause error due to mismatched config
|
|
||||||
// So we override the state objec we return to use the latest state as soon as possible
|
|
||||||
state = nextState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
previousRouteRef.current &&
|
||||||
|
route &&
|
||||||
|
route.params &&
|
||||||
|
typeof route.params.screen === 'string' &&
|
||||||
|
route.params !== previousRouteRef.current.params
|
||||||
|
) {
|
||||||
|
// If the route was updated with new name and/or params, we should navigate there
|
||||||
|
// The update should be limited to current navigator only, so we call the router manually
|
||||||
|
const updatedState = router.getStateForAction(
|
||||||
|
state,
|
||||||
|
navigate(route.params.screen, route.params.params)
|
||||||
|
);
|
||||||
|
|
||||||
|
nextState =
|
||||||
|
updatedState !== null
|
||||||
|
? router.getRehydratedState(updatedState, {
|
||||||
|
routeNames,
|
||||||
|
routeParamList,
|
||||||
|
})
|
||||||
|
: state;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state !== nextState) {
|
||||||
|
// If the state needs to be updated, we'll schedule an update with React
|
||||||
|
// setState in render seems hacky, but that's how React docs implement getDerivedPropsFromState
|
||||||
|
// https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops
|
||||||
|
performTransaction(() => {
|
||||||
|
setState(nextState);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// The up-to-date state will come in next render, but we don't need to wait for it
|
||||||
|
// We can't use the outdated state since the screens have changed, which will cause error due to mismatched config
|
||||||
|
// So we override the state objec we return to use the latest state as soon as possible
|
||||||
|
state = nextState;
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
// We need to clean up state for this navigator on unmount
|
// We need to clean up state for this navigator on unmount
|
||||||
@@ -210,10 +282,10 @@ export default function useNavigationBuilder<
|
|||||||
const getState = React.useCallback((): State => {
|
const getState = React.useCallback((): State => {
|
||||||
const currentState = getCurrentState();
|
const currentState = getCurrentState();
|
||||||
|
|
||||||
return currentState === undefined || currentState.stale !== false
|
return isStateInitialized(currentState)
|
||||||
? (initializedStateRef.current as State)
|
? (currentState as State)
|
||||||
: (currentState as State);
|
: (initializedStateRef.current as State);
|
||||||
}, [getCurrentState]);
|
}, [getCurrentState, isStateInitialized]);
|
||||||
|
|
||||||
const emitter = useEventEmitter();
|
const emitter = useEventEmitter();
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ type Options<State extends NavigationState> = {
|
|||||||
navigation: NavigationHelpers<ParamListBase> &
|
navigation: NavigationHelpers<ParamListBase> &
|
||||||
Partial<NavigationProp<ParamListBase, string, any, any, any>>;
|
Partial<NavigationProp<ParamListBase, string, any, any, any>>;
|
||||||
setOptions: (
|
setOptions: (
|
||||||
cb: (options: { [key: string]: object }) => { [key: string]: object }
|
cb: (options: Record<string, object>) => Record<string, object>
|
||||||
) => void;
|
) => void;
|
||||||
router: Router<State, NavigationAction>;
|
router: Router<State, NavigationAction>;
|
||||||
emitter: NavigationEventEmitter;
|
emitter: NavigationEventEmitter;
|
||||||
@@ -66,11 +66,9 @@ export default function useNavigationCache<
|
|||||||
cache.current = state.routes.reduce<NavigationCache<State, ScreenOptions>>(
|
cache.current = state.routes.reduce<NavigationCache<State, ScreenOptions>>(
|
||||||
(acc, route, index) => {
|
(acc, route, index) => {
|
||||||
const previous = cache.current[route.key];
|
const previous = cache.current[route.key];
|
||||||
const isFirst = route.key === state.routes[0].key;
|
|
||||||
|
|
||||||
if (previous && previous.isFirstRouteInParent() === isFirst) {
|
if (previous) {
|
||||||
// If a cached navigation object already exists and has same `isFirstRouteInParent`, reuse it
|
// If a cached navigation object already exists, reuse it
|
||||||
// This method could return different result if the index of the route changes somehow
|
|
||||||
acc[route.key] = previous;
|
acc[route.key] = previous;
|
||||||
} else {
|
} else {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
@@ -89,13 +87,13 @@ export default function useNavigationCache<
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const helpers = Object.keys(actions).reduce(
|
const helpers = Object.keys(actions).reduce<Record<string, () => void>>(
|
||||||
(acc, name) => {
|
(acc, name) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
acc[name] = (...args: any) => dispatch(actions[name](...args));
|
acc[name] = (...args: any) => dispatch(actions[name](...args));
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{} as { [key: string]: () => void }
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
acc[route.key] = {
|
acc[route.key] = {
|
||||||
@@ -121,7 +119,6 @@ export default function useNavigationCache<
|
|||||||
// This makes sure that we return the focus state in the whole tree, not just this navigator
|
// This makes sure that we return the focus state in the whole tree, not just this navigator
|
||||||
return navigation ? navigation.isFocused() : true;
|
return navigation ? navigation.isFocused() : true;
|
||||||
},
|
},
|
||||||
isFirstRouteInParent: () => isFirst,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ type Options<State extends NavigationState, Action extends NavigationAction> = {
|
|||||||
export default function useNavigationHelpers<
|
export default function useNavigationHelpers<
|
||||||
State extends NavigationState,
|
State extends NavigationState,
|
||||||
Action extends NavigationAction,
|
Action extends NavigationAction,
|
||||||
EventMap extends { [key: string]: any }
|
EventMap extends Record<string, any>
|
||||||
>({ onAction, getState, emitter, router }: Options<State, Action>) {
|
>({ onAction, getState, emitter, router }: Options<State, Action>) {
|
||||||
const resetRoot = React.useContext(ResetRootContext);
|
const resetRoot = React.useContext(ResetRootContext);
|
||||||
const parentNavigationHelpers = React.useContext(NavigationContext);
|
const parentNavigationHelpers = React.useContext(NavigationContext);
|
||||||
@@ -55,13 +55,13 @@ export default function useNavigationHelpers<
|
|||||||
...CommonActions,
|
...CommonActions,
|
||||||
};
|
};
|
||||||
|
|
||||||
const helpers = Object.keys(actions).reduce(
|
const helpers = Object.keys(actions).reduce<Record<string, () => void>>(
|
||||||
(acc, name) => {
|
(acc, name) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
acc[name] = (...args: any) => dispatch(actions[name](...args));
|
acc[name] = (...args: any) => dispatch(actions[name](...args));
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{} as { [key: string]: () => void }
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export default function useOnGetState({
|
|||||||
const route = React.useContext(NavigationRouteContext);
|
const route = React.useContext(NavigationRouteContext);
|
||||||
const key = route ? route.key : 'root';
|
const key = route ? route.key : 'root';
|
||||||
|
|
||||||
const getter = React.useCallback(() => {
|
const getRehydratedState = React.useCallback(() => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
@@ -26,6 +26,6 @@ export default function useOnGetState({
|
|||||||
}, [getState, getStateForRoute]);
|
}, [getState, getStateForRoute]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
return addStateGetter && addStateGetter(key, getter);
|
return addStateGetter && addStateGetter(key, getRehydratedState);
|
||||||
}, [addStateGetter, getter, key]);
|
}, [addStateGetter, getRehydratedState, key]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export default function useStateGetters() {
|
|||||||
const stateGetters = React.useRef<Record<string, NavigatorStateGetter>>({});
|
const stateGetters = React.useRef<Record<string, NavigatorStateGetter>>({});
|
||||||
|
|
||||||
const getStateForRoute = React.useCallback(
|
const getStateForRoute = React.useCallback(
|
||||||
routeKey =>
|
(routeKey: string) =>
|
||||||
stateGetters.current[routeKey] === undefined
|
stateGetters.current[routeKey] === undefined
|
||||||
? undefined
|
? undefined
|
||||||
: stateGetters.current[routeKey](),
|
: stateGetters.current[routeKey](),
|
||||||
|
|||||||
@@ -3,6 +3,84 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.22](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.21...@react-navigation/drawer@5.0.0-alpha.22) (2019-11-10)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/drawer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.21](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.20...@react-navigation/drawer@5.0.0-alpha.21) (2019-11-08)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/drawer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.20](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.19...@react-navigation/drawer@5.0.0-alpha.20) (2019-11-04)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/drawer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.19](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.18...@react-navigation/drawer@5.0.0-alpha.19) (2019-11-02)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/drawer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.18](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.17...@react-navigation/drawer@5.0.0-alpha.18) (2019-10-30)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* hide screen from screen reader when drawer is open ([#147](https://github.com/react-navigation/navigation-ex/issues/147)) ([fb749ac](https://github.com/react-navigation/navigation-ex/commit/fb749ac))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add an 'unmountInactiveScreens' option ([12d597f](https://github.com/react-navigation/navigation-ex/commit/12d597f))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.17](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.16...@react-navigation/drawer@5.0.0-alpha.17) (2019-10-29)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/drawer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.16](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.15...@react-navigation/drawer@5.0.0-alpha.16) (2019-10-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* navigation drawer sometimes not closing when pressed outside ([0d8cdc8](https://github.com/react-navigation/navigation-ex/commit/0d8cdc8))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.14...@react-navigation/drawer@5.0.0-alpha.15) (2019-10-17)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* fix passing content options in drawer ([cab6160](https://github.com/react-navigation/navigation-ex/commit/cab6160))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.13...@react-navigation/drawer@5.0.0-alpha.14) (2019-10-15)
|
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.13...@react-navigation/drawer@5.0.0-alpha.14) (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"material",
|
"material",
|
||||||
"drawer"
|
"drawer"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.14",
|
"version": "5.0.0-alpha.22",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
"@react-navigation/routers": "^5.0.0-alpha.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
@@ -46,8 +46,8 @@
|
|||||||
"react-native-gesture-handler": "^1.3.0",
|
"react-native-gesture-handler": "^1.3.0",
|
||||||
"react-native-reanimated": "^1.3.0",
|
"react-native-reanimated": "^1.3.0",
|
||||||
"react-native-safe-area-context": "^0.3.6",
|
"react-native-safe-area-context": "^0.3.6",
|
||||||
"react-native-screens": "^2.0.0-alpha.3",
|
"react-native-screens": "^2.0.0-alpha.8",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.7.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
"react-native-gesture-handler": "^1.0.0",
|
"react-native-gesture-handler": "^1.0.0",
|
||||||
"react-native-reanimated": "^1.0.0",
|
"react-native-reanimated": "^1.0.0",
|
||||||
"react-native-safe-area-context": "^0.3.6",
|
"react-native-safe-area-context": "^0.3.6",
|
||||||
"react-native-screens": "^1.0.0-alpha.0 || ^2.0.0-alpha.3"
|
"react-native-screens": "^1.0.0-alpha.0 || ^2.0.0-alpha.0"
|
||||||
},
|
},
|
||||||
"@react-native-community/bob": {
|
"@react-native-community/bob": {
|
||||||
"source": "src",
|
"source": "src",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {
|
import {
|
||||||
createNavigator,
|
createNavigatorFactory,
|
||||||
useNavigationBuilder,
|
useNavigationBuilder,
|
||||||
DefaultNavigatorOptions,
|
DefaultNavigatorOptions,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/core';
|
||||||
@@ -48,6 +48,7 @@ function DrawerNavigator({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createNavigator<DrawerNavigationOptions, typeof DrawerNavigator>(
|
export default createNavigatorFactory<
|
||||||
DrawerNavigator
|
DrawerNavigationOptions,
|
||||||
);
|
typeof DrawerNavigator
|
||||||
|
>(DrawerNavigator);
|
||||||
|
|||||||
@@ -67,16 +67,16 @@ export type DrawerNavigationConfig<T = DrawerContentOptions> = {
|
|||||||
* Whether a screen should be unmounted when navigating away from it.
|
* Whether a screen should be unmounted when navigating away from it.
|
||||||
* Defaults to `false`.
|
* Defaults to `false`.
|
||||||
*/
|
*/
|
||||||
unmountInactiveRoutes?: boolean;
|
unmountInactiveScreens?: boolean;
|
||||||
/**
|
/**
|
||||||
* Custom component used to render as the content of the drawer, for example, navigation items.
|
* Function that returns React element to render as the content of the drawer, for example, navigation items.
|
||||||
* Defaults to `DrawerItems`.
|
* Defaults to `DrawerContent`.
|
||||||
*/
|
*/
|
||||||
contentComponent: React.ComponentType<DrawerContentComponentProps<T>>;
|
drawerContent: (props: DrawerContentComponentProps<T>) => React.ReactNode;
|
||||||
/**
|
/**
|
||||||
* Options for the content component which will be passed as props.
|
* Options for the content component which will be passed as props.
|
||||||
*/
|
*/
|
||||||
contentOptions?: T;
|
drawerContentOptions?: T;
|
||||||
/**
|
/**
|
||||||
* Style object for the component wrapping the screen content.
|
* Style object for the component wrapping the screen content.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
Keyboard,
|
Keyboard,
|
||||||
StatusBar,
|
StatusBar,
|
||||||
StyleProp,
|
StyleProp,
|
||||||
|
View,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import {
|
import {
|
||||||
PanGestureHandler,
|
PanGestureHandler,
|
||||||
@@ -428,7 +429,14 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
x: this.touchX,
|
x: this.touchX,
|
||||||
translationX: this.gestureX,
|
translationX: this.gestureX,
|
||||||
velocityX: this.velocityX,
|
velocityX: this.velocityX,
|
||||||
state: this.gestureState,
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
private handleGestureStateChange = event([
|
||||||
|
{
|
||||||
|
nativeEvent: {
|
||||||
|
state: (s: Animated.Value<number>) => set(this.gestureState, s),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@@ -519,7 +527,7 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
activeOffsetX={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}
|
activeOffsetX={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}
|
||||||
failOffsetY={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}
|
failOffsetY={[-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM]}
|
||||||
onGestureEvent={this.handleGestureEvent}
|
onGestureEvent={this.handleGestureEvent}
|
||||||
onHandlerStateChange={this.handleGestureEvent}
|
onHandlerStateChange={this.handleGestureStateChange}
|
||||||
hitSlop={hitSlop}
|
hitSlop={hitSlop}
|
||||||
enabled={!locked}
|
enabled={!locked}
|
||||||
{...gestureHandlerProps}
|
{...gestureHandlerProps}
|
||||||
@@ -537,7 +545,13 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
sceneContainerStyle as any,
|
sceneContainerStyle as any,
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{renderSceneContent({ progress: this.progress })}
|
<View
|
||||||
|
accessibilityElementsHidden={open}
|
||||||
|
importantForAccessibility={open ? 'no-hide-descendants' : 'auto'}
|
||||||
|
style={styles.content}
|
||||||
|
>
|
||||||
|
{renderSceneContent({ progress: this.progress })}
|
||||||
|
</View>
|
||||||
<TapGestureHandler onHandlerStateChange={this.handleTapStateChange}>
|
<TapGestureHandler onHandlerStateChange={this.handleTapStateChange}>
|
||||||
<Animated.View
|
<Animated.View
|
||||||
style={[
|
style={[
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
DrawerDescriptorMap,
|
DrawerDescriptorMap,
|
||||||
DrawerNavigationConfig,
|
DrawerNavigationConfig,
|
||||||
DrawerNavigationHelpers,
|
DrawerNavigationHelpers,
|
||||||
|
DrawerContentComponentProps,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
type Props = Omit<DrawerNavigationConfig, 'overlayColor'> & {
|
type Props = Omit<DrawerNavigationConfig, 'overlayColor'> & {
|
||||||
@@ -64,7 +65,9 @@ const getDefaultDrawerWidth = ({
|
|||||||
export default class DrawerView extends React.PureComponent<Props, State> {
|
export default class DrawerView extends React.PureComponent<Props, State> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
lazy: true,
|
lazy: true,
|
||||||
contentComponent: DrawerContent,
|
drawerContent: (props: DrawerContentComponentProps) => (
|
||||||
|
<DrawerContent {...props} />
|
||||||
|
),
|
||||||
drawerPosition: I18nManager.isRTL ? 'right' : 'left',
|
drawerPosition: I18nManager.isRTL ? 'right' : 'left',
|
||||||
keyboardDismissMode: 'on-drag',
|
keyboardDismissMode: 'on-drag',
|
||||||
overlayColor: 'rgba(0, 0, 0, 0.5)',
|
overlayColor: 'rgba(0, 0, 0, 0.5)',
|
||||||
@@ -135,58 +138,52 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
|||||||
navigation,
|
navigation,
|
||||||
descriptors,
|
descriptors,
|
||||||
drawerPosition,
|
drawerPosition,
|
||||||
contentComponent: ContentComponent,
|
drawerContent,
|
||||||
|
drawerContentOptions,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return drawerContent({
|
||||||
<ContentComponent
|
...drawerContentOptions,
|
||||||
progress={progress}
|
progress: progress,
|
||||||
state={state}
|
state: state,
|
||||||
navigation={navigation}
|
navigation: navigation,
|
||||||
descriptors={descriptors}
|
descriptors: descriptors,
|
||||||
drawerPosition={drawerPosition}
|
drawerPosition: drawerPosition,
|
||||||
/>
|
});
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private renderContent = () => {
|
private renderContent = () => {
|
||||||
let { lazy, state, descriptors, unmountInactiveRoutes } = this.props;
|
let { lazy, state, descriptors, unmountInactiveScreens } = this.props;
|
||||||
|
|
||||||
const { loaded } = this.state;
|
const { loaded } = this.state;
|
||||||
|
|
||||||
if (unmountInactiveRoutes) {
|
return (
|
||||||
const activeKey = state.routes[state.index].key;
|
<ScreenContainer style={styles.content}>
|
||||||
const descriptor = descriptors[activeKey];
|
{state.routes.map((route, index) => {
|
||||||
|
if (unmountInactiveScreens && index !== state.index) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return descriptor.render();
|
if (lazy && !loaded.includes(index)) {
|
||||||
} else {
|
// Don't render a screen if we've never navigated to it
|
||||||
return (
|
return null;
|
||||||
<ScreenContainer style={styles.content}>
|
}
|
||||||
{state.routes.map((route, index) => {
|
|
||||||
if (lazy && !loaded.includes(index)) {
|
|
||||||
// Don't render a screen if we've never navigated to it
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isFocused = state.index === index;
|
const isFocused = state.index === index;
|
||||||
const descriptor = descriptors[route.key];
|
const descriptor = descriptors[route.key];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ResourceSavingScene
|
<ResourceSavingScene
|
||||||
key={route.key}
|
key={route.key}
|
||||||
style={[
|
style={[StyleSheet.absoluteFill, { opacity: isFocused ? 1 : 0 }]}
|
||||||
StyleSheet.absoluteFill,
|
isVisible={isFocused}
|
||||||
{ opacity: isFocused ? 1 : 0 },
|
>
|
||||||
]}
|
{descriptor.render()}
|
||||||
isVisible={isFocused}
|
</ResourceSavingScene>
|
||||||
>
|
);
|
||||||
{descriptor.render()}
|
})}
|
||||||
</ResourceSavingScene>
|
</ScreenContainer>
|
||||||
);
|
);
|
||||||
})}
|
|
||||||
</ScreenContainer>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private setDrawerGestureRef = (ref: PanGestureHandler | null) => {
|
private setDrawerGestureRef = (ref: PanGestureHandler | null) => {
|
||||||
|
|||||||
@@ -3,6 +3,76 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.21](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.20...@react-navigation/example@5.0.0-alpha.21) (2019-11-10)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/example
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.20](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.19...@react-navigation/example@5.0.0-alpha.20) (2019-11-08)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/example
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.19](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.18...@react-navigation/example@5.0.0-alpha.19) (2019-11-04)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/example
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.18](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.17...@react-navigation/example@5.0.0-alpha.18) (2019-11-02)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* minor tweaks for web and fix example ([67fd69a](https://github.com/satya164/navigation-ex/commit/67fd69a))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.17](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.16...@react-navigation/example@5.0.0-alpha.17) (2019-10-29)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* improve type annotation for screens ([8f16085](https://github.com/satya164/navigation-ex/commit/8f16085))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.16](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.15...@react-navigation/example@5.0.0-alpha.16) (2019-10-22)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/example
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.15](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.14...@react-navigation/example@5.0.0-alpha.15) (2019-10-22)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/example
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.14](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.13...@react-navigation/example@5.0.0-alpha.14) (2019-10-17)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/example
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.12...@react-navigation/example@5.0.0-alpha.13) (2019-10-15)
|
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.12...@react-navigation/example@5.0.0-alpha.13) (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ target 'ReactNavigationExample' do
|
|||||||
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
|
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
|
||||||
pod 'RNGestureHandler', :podspec => '../node_modules/react-native-gesture-handler/RNGestureHandler.podspec'
|
pod 'RNGestureHandler', :podspec => '../node_modules/react-native-gesture-handler/RNGestureHandler.podspec'
|
||||||
pod 'RNReanimated', :podspec => '../node_modules/react-native-reanimated/RNReanimated.podspec'
|
pod 'RNReanimated', :podspec => '../node_modules/react-native-reanimated/RNReanimated.podspec'
|
||||||
pod 'RNScreens', :podspec => '../node_modules/react-native-screens/RNScreens.podspec'
|
pod 'RNScreens', :path => '../node_modules/react-native-screens/RNScreens.podspec'
|
||||||
|
|
||||||
use_unimodules!
|
use_unimodules!
|
||||||
pod 'react-native-safe-area-context', :path => '../node_modules/react-native-safe-area-context'
|
pod 'react-native-safe-area-context', :path => '../node_modules/react-native-safe-area-context'
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ PODS:
|
|||||||
- React
|
- React
|
||||||
- RNReanimated (1.2.0):
|
- RNReanimated (1.2.0):
|
||||||
- React
|
- React
|
||||||
- RNScreens (2.0.0-alpha.4):
|
- RNScreens (2.0.0-alpha.8):
|
||||||
- React
|
- React
|
||||||
- UMBarCodeScannerInterface (4.0.0)
|
- UMBarCodeScannerInterface (4.0.0)
|
||||||
- UMCameraInterface (4.0.0)
|
- UMCameraInterface (4.0.0)
|
||||||
@@ -159,7 +159,7 @@ DEPENDENCIES:
|
|||||||
- yoga (from `../node_modules/react-native/ReactCommon/yoga`)
|
- yoga (from `../node_modules/react-native/ReactCommon/yoga`)
|
||||||
|
|
||||||
SPEC REPOS:
|
SPEC REPOS:
|
||||||
https://github.com/cocoapods/specs.git:
|
trunk:
|
||||||
- boost-for-react-native
|
- boost-for-react-native
|
||||||
|
|
||||||
EXTERNAL SOURCES:
|
EXTERNAL SOURCES:
|
||||||
@@ -208,7 +208,7 @@ EXTERNAL SOURCES:
|
|||||||
RNReanimated:
|
RNReanimated:
|
||||||
:podspec: "../node_modules/react-native-reanimated/RNReanimated.podspec"
|
:podspec: "../node_modules/react-native-reanimated/RNReanimated.podspec"
|
||||||
RNScreens:
|
RNScreens:
|
||||||
:podspec: "../node_modules/react-native-screens/RNScreens.podspec"
|
:path: "../node_modules/react-native-screens/RNScreens.podspec"
|
||||||
UMBarCodeScannerInterface:
|
UMBarCodeScannerInterface:
|
||||||
:path: !ruby/object:Pathname
|
:path: !ruby/object:Pathname
|
||||||
path: "../node_modules/unimodules-barcode-scanner-interface/ios"
|
path: "../node_modules/unimodules-barcode-scanner-interface/ios"
|
||||||
@@ -267,7 +267,7 @@ SPEC CHECKSUMS:
|
|||||||
react-native-safe-area-context: e380a6f783ccaec848e2f3cc8eb205a62362950d
|
react-native-safe-area-context: e380a6f783ccaec848e2f3cc8eb205a62362950d
|
||||||
RNGestureHandler: 5329a942fce3d41c68b84c2c2276ce06a696d8b0
|
RNGestureHandler: 5329a942fce3d41c68b84c2c2276ce06a696d8b0
|
||||||
RNReanimated: 1b52415c4302f198cb581282a0166690bad62c43
|
RNReanimated: 1b52415c4302f198cb581282a0166690bad62c43
|
||||||
RNScreens: 84be1a2369a580beb2fea0755cc62ef16b83fffe
|
RNScreens: bfa9143ca291bcf3804c932f77b9617ff324704f
|
||||||
UMBarCodeScannerInterface: d5a6fdc98ed6241225b0a8432a7f4e2b397668bc
|
UMBarCodeScannerInterface: d5a6fdc98ed6241225b0a8432a7f4e2b397668bc
|
||||||
UMCameraInterface: 68870a3197fee85bd5afca5609ba4a5b7257d19d
|
UMCameraInterface: 68870a3197fee85bd5afca5609ba4a5b7257d19d
|
||||||
UMConstantsInterface: d25b8e8887ca7aaf568c06caf08f4d40734ee4ef
|
UMConstantsInterface: d25b8e8887ca7aaf568c06caf08f4d40734ee4ef
|
||||||
@@ -282,6 +282,6 @@ SPEC CHECKSUMS:
|
|||||||
UMTaskManagerInterface: 1e70fe58b872355f0ecb44fb81bb1a16484047f0
|
UMTaskManagerInterface: 1e70fe58b872355f0ecb44fb81bb1a16484047f0
|
||||||
yoga: 684513b14b03201579ba3cee20218c9d1298b0cc
|
yoga: 684513b14b03201579ba3cee20218c9d1298b0cc
|
||||||
|
|
||||||
PODFILE CHECKSUM: 1276a2dd000c142ccc03272023bb8a6b2d5b9933
|
PODFILE CHECKSUM: 277599ab8fceae1c57f639a14203691239c429ab
|
||||||
|
|
||||||
COCOAPODS: 1.7.5
|
COCOAPODS: 1.8.4
|
||||||
|
|||||||
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 6.7 KiB |
|
After Width: | Height: | Size: 140 B |
|
After Width: | Height: | Size: 208 B |
|
After Width: | Height: | Size: 337 B |
|
After Width: | Height: | Size: 435 B |
|
After Width: | Height: | Size: 982 B |
|
After Width: | Height: | Size: 589 B |
|
After Width: | Height: | Size: 894 B |
|
After Width: | Height: | Size: 748 B |
|
After Width: | Height: | Size: 713 B |
|
After Width: | Height: | Size: 1017 B |
|
After Width: | Height: | Size: 1.8 KiB |
39
packages/example/ios/ReactNavigationExample/Images.xcassets/AppIcon.appiconset/Contents.json
Normal file → Executable file
@@ -1,38 +1 @@
|
|||||||
{
|
{"images":[{"size":"60x60","expected-size":"180","filename":"180.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"40x40","expected-size":"80","filename":"80.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"40x40","expected-size":"120","filename":"120.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"60x60","expected-size":"120","filename":"120.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"57x57","expected-size":"57","filename":"57.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"1x"},{"size":"29x29","expected-size":"58","filename":"58.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"29x29","expected-size":"29","filename":"29.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"1x"},{"size":"29x29","expected-size":"87","filename":"87.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"57x57","expected-size":"114","filename":"114.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"20x20","expected-size":"40","filename":"40.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"2x"},{"size":"20x20","expected-size":"60","filename":"60.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"iphone","scale":"3x"},{"size":"1024x1024","filename":"1024.png","expected-size":"1024","idiom":"ios-marketing","folder":"Assets.xcassets/AppIcon.appiconset/","scale":"1x"},{"size":"40x40","expected-size":"80","filename":"80.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"72x72","expected-size":"72","filename":"72.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"76x76","expected-size":"152","filename":"152.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"50x50","expected-size":"100","filename":"100.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"29x29","expected-size":"58","filename":"58.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"76x76","expected-size":"76","filename":"76.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"29x29","expected-size":"29","filename":"29.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"50x50","expected-size":"50","filename":"50.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"72x72","expected-size":"144","filename":"144.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"40x40","expected-size":"40","filename":"40.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"83.5x83.5","expected-size":"167","filename":"167.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"},{"size":"20x20","expected-size":"20","filename":"20.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"1x"},{"size":"20x20","expected-size":"40","filename":"40.png","folder":"Assets.xcassets/AppIcon.appiconset/","idiom":"ipad","scale":"2x"}]}
|
||||||
"images" : [
|
|
||||||
{
|
|
||||||
"idiom" : "iphone",
|
|
||||||
"size" : "29x29",
|
|
||||||
"scale" : "2x"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom" : "iphone",
|
|
||||||
"size" : "29x29",
|
|
||||||
"scale" : "3x"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom" : "iphone",
|
|
||||||
"size" : "40x40",
|
|
||||||
"scale" : "2x"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom" : "iphone",
|
|
||||||
"size" : "40x40",
|
|
||||||
"scale" : "3x"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom" : "iphone",
|
|
||||||
"size" : "60x60",
|
|
||||||
"scale" : "2x"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idiom" : "iphone",
|
|
||||||
"size" : "60x60",
|
|
||||||
"scale" : "3x"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"info" : {
|
|
||||||
"version" : 1,
|
|
||||||
"author" : "xcode"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@react-navigation/example",
|
"name": "@react-navigation/example",
|
||||||
"description": "Demo app to showcase various functionality of React Navigation",
|
"description": "Demo app to showcase various functionality of React Navigation",
|
||||||
"version": "5.0.0-alpha.13",
|
"version": "5.0.0-alpha.21",
|
||||||
"private": true,
|
"private": true,
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
"nohoist": [
|
"nohoist": [
|
||||||
@@ -27,10 +27,11 @@
|
|||||||
"react-dom": "~16.8.3",
|
"react-dom": "~16.8.3",
|
||||||
"react-native": "~0.59.10",
|
"react-native": "~0.59.10",
|
||||||
"react-native-gesture-handler": "~1.3.0",
|
"react-native-gesture-handler": "~1.3.0",
|
||||||
"react-native-paper": "^3.0.0-alpha.3",
|
"react-native-paper": "^3.1.1",
|
||||||
"react-native-reanimated": "~1.2.0",
|
"react-native-reanimated": "~1.2.0",
|
||||||
|
"react-native-reanimated-web": "npm:react-native-reanimated@^1.3.2",
|
||||||
"react-native-safe-area-context": "~0.3.6",
|
"react-native-safe-area-context": "~0.3.6",
|
||||||
"react-native-screens": "2.0.0-alpha.4",
|
"react-native-screens": "^2.0.0-alpha.8",
|
||||||
"react-native-tab-view": "2.10.0",
|
"react-native-tab-view": "2.10.0",
|
||||||
"react-native-unimodules": "^0.7.0-rc.1",
|
"react-native-unimodules": "^0.7.0-rc.1",
|
||||||
"react-native-web": "^0.11.7",
|
"react-native-web": "^0.11.7",
|
||||||
@@ -44,8 +45,8 @@
|
|||||||
"@types/react": "^16.9.4",
|
"@types/react": "^16.9.4",
|
||||||
"@types/react-native": "^0.60.19",
|
"@types/react-native": "^0.60.19",
|
||||||
"babel-preset-expo": "^7.0.0",
|
"babel-preset-expo": "^7.0.0",
|
||||||
"expo-cli": "^3.3.0",
|
"expo-cli": "^3.4.1",
|
||||||
"jetifier": "^1.6.4",
|
"jetifier": "^1.6.4",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.7.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,26 +32,26 @@ const BottomTabs = createBottomTabNavigator<BottomTabParams>();
|
|||||||
|
|
||||||
export default function BottomTabsScreen() {
|
export default function BottomTabsScreen() {
|
||||||
return (
|
return (
|
||||||
<BottomTabs.Navigator>
|
<BottomTabs.Navigator
|
||||||
|
screenOptions={{
|
||||||
|
tabBarButton: props => <TouchableBounce {...props} />,
|
||||||
|
}}
|
||||||
|
>
|
||||||
<BottomTabs.Screen
|
<BottomTabs.Screen
|
||||||
name="article"
|
name="article"
|
||||||
options={{
|
options={{
|
||||||
title: 'Article',
|
title: 'Article',
|
||||||
tabBarIcon: getTabBarIcon('file-document-box'),
|
tabBarIcon: getTabBarIcon('file-document-box'),
|
||||||
tabBarButtonComponent: TouchableBounce,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{props => (
|
{props => <SimpleStackScreen {...props} headerMode="none" />}
|
||||||
<SimpleStackScreen {...props} options={{ headerMode: 'none' }} />
|
|
||||||
)}
|
|
||||||
</BottomTabs.Screen>
|
</BottomTabs.Screen>
|
||||||
<BottomTabs.Screen
|
<BottomTabs.Screen
|
||||||
name="chat"
|
name="chat"
|
||||||
component={Chat}
|
component={Chat}
|
||||||
options={{
|
options={{
|
||||||
title: 'Chat',
|
tabBarLabel: 'Chat',
|
||||||
tabBarIcon: getTabBarIcon('message-reply'),
|
tabBarIcon: getTabBarIcon('message-reply'),
|
||||||
tabBarButtonComponent: TouchableBounce,
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<BottomTabs.Screen
|
<BottomTabs.Screen
|
||||||
@@ -60,7 +60,6 @@ export default function BottomTabsScreen() {
|
|||||||
options={{
|
options={{
|
||||||
title: 'Contacts',
|
title: 'Contacts',
|
||||||
tabBarIcon: getTabBarIcon('contacts'),
|
tabBarIcon: getTabBarIcon('contacts'),
|
||||||
tabBarButtonComponent: TouchableBounce,
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<BottomTabs.Screen
|
<BottomTabs.Screen
|
||||||
@@ -69,7 +68,6 @@ export default function BottomTabsScreen() {
|
|||||||
options={{
|
options={{
|
||||||
title: 'Albums',
|
title: 'Albums',
|
||||||
tabBarIcon: getTabBarIcon('image-album'),
|
tabBarIcon: getTabBarIcon('image-album'),
|
||||||
tabBarButtonComponent: TouchableBounce,
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</BottomTabs.Navigator>
|
</BottomTabs.Navigator>
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ export default function MaterialBottomTabsScreen() {
|
|||||||
tabBarColor: '#C9E7F8',
|
tabBarColor: '#C9E7F8',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{props => (
|
{props => <SimpleStackScreen {...props} headerMode="none" />}
|
||||||
<SimpleStackScreen {...props} options={{ headerMode: 'none' }} />
|
|
||||||
)}
|
|
||||||
</MaterialBottomTabs.Screen>
|
</MaterialBottomTabs.Screen>
|
||||||
<MaterialBottomTabs.Screen
|
<MaterialBottomTabs.Screen
|
||||||
name="chat"
|
name="chat"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|||||||
import { View, StyleSheet } from 'react-native';
|
import { View, StyleSheet } from 'react-native';
|
||||||
import { Button } from 'react-native-paper';
|
import { Button } from 'react-native-paper';
|
||||||
// eslint-disable-next-line import/no-unresolved
|
// eslint-disable-next-line import/no-unresolved
|
||||||
import { useScreens } from 'react-native-screens';
|
import { enableScreens } from 'react-native-screens';
|
||||||
import {
|
import {
|
||||||
RouteProp,
|
RouteProp,
|
||||||
ParamListBase,
|
ParamListBase,
|
||||||
@@ -124,8 +124,7 @@ export default function NativeStackScreen({ navigation }: Props) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
enableScreens(true);
|
||||||
useScreens(true);
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
buttons: {
|
buttons: {
|
||||||
|
|||||||
23
packages/example/src/Screens/NativeStack.web.tsx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { View, Text, StyleSheet } from 'react-native';
|
||||||
|
|
||||||
|
export default function NativeStack() {
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<Text style={styles.text}>Not supported on Web :(</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
flex: 1,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
backgroundColor: '#eceff1',
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
fontSize: 16,
|
||||||
|
color: '#999',
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -5,7 +5,6 @@ import { RouteProp, ParamListBase } from '@react-navigation/core';
|
|||||||
import {
|
import {
|
||||||
createStackNavigator,
|
createStackNavigator,
|
||||||
StackNavigationProp,
|
StackNavigationProp,
|
||||||
StackNavigationOptions,
|
|
||||||
} from '@react-navigation/stack';
|
} from '@react-navigation/stack';
|
||||||
import Article from '../Shared/Article';
|
import Article from '../Shared/Article';
|
||||||
import Albums from '../Shared/Albums';
|
import Albums from '../Shared/Albums';
|
||||||
@@ -77,18 +76,17 @@ const AlbumsScreen = ({
|
|||||||
|
|
||||||
const SimpleStack = createStackNavigator<SimpleStackParams>();
|
const SimpleStack = createStackNavigator<SimpleStackParams>();
|
||||||
|
|
||||||
type Props = {
|
type Props = Partial<React.ComponentProps<typeof SimpleStack.Navigator>> & {
|
||||||
options?: StackNavigationOptions;
|
|
||||||
navigation: StackNavigationProp<ParamListBase>;
|
navigation: StackNavigationProp<ParamListBase>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function SimpleStackScreen({ navigation, options }: Props) {
|
export default function SimpleStackScreen({ navigation, ...rest }: Props) {
|
||||||
navigation.setOptions({
|
navigation.setOptions({
|
||||||
headerShown: false,
|
headerShown: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SimpleStack.Navigator {...options}>
|
<SimpleStack.Navigator {...rest}>
|
||||||
<SimpleStack.Screen
|
<SimpleStack.Screen
|
||||||
name="article"
|
name="article"
|
||||||
component={ArticleScreen}
|
component={ArticleScreen}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ module.exports = async function(env, argv) {
|
|||||||
config.module.rules.push({
|
config.module.rules.push({
|
||||||
test: /\.(js|ts|tsx)$/,
|
test: /\.(js|ts|tsx)$/,
|
||||||
include: /packages\/.+/,
|
include: /packages\/.+/,
|
||||||
|
exclude: /node_modules/,
|
||||||
use: 'babel-loader',
|
use: 'babel-loader',
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -17,25 +18,23 @@ module.exports = async function(env, argv) {
|
|||||||
p => !(p instanceof ModuleScopePlugin)
|
p => !(p instanceof ModuleScopePlugin)
|
||||||
);
|
);
|
||||||
|
|
||||||
config.resolve.alias['react'] = path.resolve(
|
Object.assign(config.resolve.alias, {
|
||||||
__dirname,
|
react: path.resolve(__dirname, 'node_modules', 'react'),
|
||||||
'node_modules',
|
'react-native': path.resolve(__dirname, 'node_modules', 'react-native-web'),
|
||||||
'react'
|
'react-native-web': path.resolve(
|
||||||
);
|
__dirname,
|
||||||
config.resolve.alias['react-native'] = path.resolve(
|
'node_modules',
|
||||||
__dirname,
|
'react-native-web'
|
||||||
'node_modules',
|
),
|
||||||
'react-native-web'
|
'react-native-reanimated': path.resolve(
|
||||||
);
|
__dirname,
|
||||||
config.resolve.alias['react-native-web'] = path.resolve(
|
'node_modules',
|
||||||
__dirname,
|
'react-native-reanimated-web'
|
||||||
'node_modules',
|
),
|
||||||
'react-native-web'
|
'@expo/vector-icons/MaterialCommunityIcons': require.resolve(
|
||||||
);
|
'@expo/vector-icons/MaterialCommunityIcons'
|
||||||
|
),
|
||||||
config.resolve.alias[
|
});
|
||||||
'@expo/vector-icons/MaterialCommunityIcons'
|
|
||||||
] = require.resolve('@expo/vector-icons/MaterialCommunityIcons');
|
|
||||||
|
|
||||||
fs.readdirSync(path.join(__dirname, '..')).forEach(name => {
|
fs.readdirSync(path.join(__dirname, '..')).forEach(name => {
|
||||||
config.resolve.alias[`@react-navigation/${name}`] = path.resolve(
|
config.resolve.alias[`@react-navigation/${name}`] = path.resolve(
|
||||||
|
|||||||
@@ -3,6 +3,65 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.20](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.19...@react-navigation/material-bottom-tabs@5.0.0-alpha.20) (2019-11-10)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.19](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.18...@react-navigation/material-bottom-tabs@5.0.0-alpha.19) (2019-11-08)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.18](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.17...@react-navigation/material-bottom-tabs@5.0.0-alpha.18) (2019-11-04)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.17](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.16...@react-navigation/material-bottom-tabs@5.0.0-alpha.17) (2019-10-30)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.16](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.15...@react-navigation/material-bottom-tabs@5.0.0-alpha.16) (2019-10-29)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.14...@react-navigation/material-bottom-tabs@5.0.0-alpha.15) (2019-10-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* navigation drawer sometimes not closing when pressed outside ([0d8cdc8](https://github.com/react-navigation/navigation-ex/commit/0d8cdc8))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.13...@react-navigation/material-bottom-tabs@5.0.0-alpha.14) (2019-10-17)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.12...@react-navigation/material-bottom-tabs@5.0.0-alpha.13) (2019-10-15)
|
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.12...@react-navigation/material-bottom-tabs@5.0.0-alpha.13) (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"material",
|
"material",
|
||||||
"tab"
|
"tab"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.13",
|
"version": "5.0.0-alpha.20",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
"@react-navigation/routers": "^5.0.0-alpha.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
@@ -44,15 +44,15 @@
|
|||||||
"del-cli": "^3.0.0",
|
"del-cli": "^3.0.0",
|
||||||
"react": "~16.8.3",
|
"react": "~16.8.3",
|
||||||
"react-native": "~0.59.10",
|
"react-native": "~0.59.10",
|
||||||
"react-native-paper": "^3.0.0-alpha.3",
|
"react-native-paper": "^3.1.1",
|
||||||
"react-native-vector-icons": "^6.6.0",
|
"react-native-vector-icons": "^6.6.0",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.7.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||||
"react": "*",
|
"react": "*",
|
||||||
"react-native": "*",
|
"react-native": "*",
|
||||||
"react-native-paper": "^3.0.0-alpha.3",
|
"react-native-paper": "^3.0.0",
|
||||||
"react-native-vector-icons": "^6.0.0"
|
"react-native-vector-icons": "^6.0.0"
|
||||||
},
|
},
|
||||||
"@react-native-community/bob": {
|
"@react-native-community/bob": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {
|
import {
|
||||||
useNavigationBuilder,
|
useNavigationBuilder,
|
||||||
createNavigator,
|
createNavigatorFactory,
|
||||||
DefaultNavigatorOptions,
|
DefaultNavigatorOptions,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/core';
|
||||||
import {
|
import {
|
||||||
@@ -50,7 +50,7 @@ function MaterialBottomTabNavigator({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createNavigator<
|
export default createNavigatorFactory<
|
||||||
MaterialBottomTabNavigationOptions,
|
MaterialBottomTabNavigationOptions,
|
||||||
typeof MaterialBottomTabNavigator
|
typeof MaterialBottomTabNavigator
|
||||||
>(MaterialBottomTabNavigator);
|
>(MaterialBottomTabNavigator);
|
||||||
|
|||||||
@@ -96,6 +96,16 @@ export type MaterialBottomTabDescriptorMap = {
|
|||||||
export type MaterialBottomTabNavigationConfig = Partial<
|
export type MaterialBottomTabNavigationConfig = Partial<
|
||||||
Omit<
|
Omit<
|
||||||
React.ComponentProps<typeof BottomNavigation>,
|
React.ComponentProps<typeof BottomNavigation>,
|
||||||
'navigationState' | 'onIndexChange' | 'renderScene'
|
| 'navigationState'
|
||||||
|
| 'onIndexChange'
|
||||||
|
| 'onTabPress'
|
||||||
|
| 'renderScene'
|
||||||
|
| 'renderLabel'
|
||||||
|
| 'renderIcon'
|
||||||
|
| 'getAccessibilityLabel'
|
||||||
|
| 'getBadge'
|
||||||
|
| 'getColor'
|
||||||
|
| 'getLabelText'
|
||||||
|
| 'getTestID'
|
||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import * as React from 'react';
|
|||||||
import { StyleSheet } from 'react-native';
|
import { StyleSheet } from 'react-native';
|
||||||
import { BottomNavigation } from 'react-native-paper';
|
import { BottomNavigation } from 'react-native-paper';
|
||||||
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||||
import { Route } from '@react-navigation/core';
|
|
||||||
import { TabNavigationState, TabActions } from '@react-navigation/routers';
|
import { TabNavigationState, TabActions } from '@react-navigation/routers';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -17,7 +16,7 @@ type Props = MaterialBottomTabNavigationConfig & {
|
|||||||
descriptors: MaterialBottomTabDescriptorMap;
|
descriptors: MaterialBottomTabDescriptorMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Scene = { route: Route<string> };
|
type Scene = { route: { key: string } };
|
||||||
|
|
||||||
export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
||||||
private getColor = ({ route }: Scene) => {
|
private getColor = ({ route }: Scene) => {
|
||||||
@@ -35,7 +34,7 @@ export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
|||||||
? options.tabBarLabel
|
? options.tabBarLabel
|
||||||
: typeof options.title === 'string'
|
: typeof options.title === 'string'
|
||||||
? options.title
|
? options.title
|
||||||
: route.name;
|
: ((route as any) as { name: string }).name;
|
||||||
};
|
};
|
||||||
|
|
||||||
private getAccessibilityLabel = ({ route }: Scene) => {
|
private getAccessibilityLabel = ({ route }: Scene) => {
|
||||||
@@ -49,9 +48,9 @@ export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
|||||||
const label = this.getLabelText({ route });
|
const label = this.getLabelText({ route });
|
||||||
|
|
||||||
if (typeof label === 'string') {
|
if (typeof label === 'string') {
|
||||||
return `${label}, tab, ${state.routes.indexOf(route) + 1} of ${
|
return `${label}, tab, ${state.routes.findIndex(
|
||||||
state.routes.length
|
r => r.key === route.key
|
||||||
}`;
|
) + 1} of ${state.routes.length}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -75,7 +74,7 @@ export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
|||||||
focused,
|
focused,
|
||||||
color,
|
color,
|
||||||
}: {
|
}: {
|
||||||
route: Route<string>;
|
route: { key: string };
|
||||||
focused: boolean;
|
focused: boolean;
|
||||||
color: string;
|
color: string;
|
||||||
}) => {
|
}) => {
|
||||||
|
|||||||
@@ -3,6 +3,46 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.17](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.16...@react-navigation/material-top-tabs@5.0.0-alpha.17) (2019-11-10)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.16](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.15...@react-navigation/material-top-tabs@5.0.0-alpha.16) (2019-11-08)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.14...@react-navigation/material-top-tabs@5.0.0-alpha.15) (2019-11-04)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.13...@react-navigation/material-top-tabs@5.0.0-alpha.14) (2019-10-30)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.12...@react-navigation/material-top-tabs@5.0.0-alpha.13) (2019-10-29)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.11...@react-navigation/material-top-tabs@5.0.0-alpha.12) (2019-10-15)
|
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.11...@react-navigation/material-top-tabs@5.0.0-alpha.12) (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"material",
|
"material",
|
||||||
"tab"
|
"tab"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.12",
|
"version": "5.0.0-alpha.17",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
"@react-navigation/routers": "^5.0.0-alpha.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
"react-native-gesture-handler": "^1.3.0",
|
"react-native-gesture-handler": "^1.3.0",
|
||||||
"react-native-reanimated": "^1.3.0",
|
"react-native-reanimated": "^1.3.0",
|
||||||
"react-native-tab-view": "^2.10.0",
|
"react-native-tab-view": "^2.10.0",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.7.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {
|
import {
|
||||||
useNavigationBuilder,
|
useNavigationBuilder,
|
||||||
createNavigator,
|
createNavigatorFactory,
|
||||||
DefaultNavigatorOptions,
|
DefaultNavigatorOptions,
|
||||||
} from '@react-navigation/core';
|
} from '@react-navigation/core';
|
||||||
import {
|
import {
|
||||||
@@ -49,7 +49,7 @@ function MaterialTopTabNavigator({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createNavigator<
|
export default createNavigatorFactory<
|
||||||
MaterialTopTabNavigationOptions,
|
MaterialTopTabNavigationOptions,
|
||||||
typeof MaterialTopTabNavigator
|
typeof MaterialTopTabNavigator
|
||||||
>(MaterialTopTabNavigator);
|
>(MaterialTopTabNavigator);
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ export type MaterialTopTabNavigationConfig = Partial<
|
|||||||
>
|
>
|
||||||
> & {
|
> & {
|
||||||
/**
|
/**
|
||||||
* Component to render for routes that haven't been rendered yet.
|
* Function that returns a React element to render for routes that haven't been rendered yet.
|
||||||
* Receives an object containing the route as the prop.
|
* Receives an object containing the route as the prop.
|
||||||
* The lazy prop also needs to be enabled.
|
* The lazy prop also needs to be enabled.
|
||||||
*
|
*
|
||||||
@@ -127,11 +127,11 @@ export type MaterialTopTabNavigationConfig = Partial<
|
|||||||
*
|
*
|
||||||
* By default, this renders null.
|
* By default, this renders null.
|
||||||
*/
|
*/
|
||||||
lazyPlaceholderComponent?: React.ComponentType<{ route: Route<string> }>;
|
lazyPlaceholder?: (props: { route: Route<string> }) => React.ReactNode;
|
||||||
/**
|
/**
|
||||||
* Custom tab bar component.
|
* Function that returns a React element to display as the tab bar.
|
||||||
*/
|
*/
|
||||||
tabBarComponent?: React.ComponentType<MaterialTopTabBarProps>;
|
tabBar?: (props: MaterialTopTabBarProps) => React.ReactNode;
|
||||||
/**
|
/**
|
||||||
* Options for the tab bar which will be passed as props to the tab bar component.
|
* Options for the tab bar which will be passed as props to the tab bar component.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
MaterialTopTabDescriptorMap,
|
MaterialTopTabDescriptorMap,
|
||||||
MaterialTopTabNavigationConfig,
|
MaterialTopTabNavigationConfig,
|
||||||
MaterialTopTabNavigationHelpers,
|
MaterialTopTabNavigationHelpers,
|
||||||
|
MaterialTopTabBarProps,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
type Props = MaterialTopTabNavigationConfig & {
|
type Props = MaterialTopTabNavigationConfig & {
|
||||||
@@ -23,10 +24,10 @@ export default class MaterialTopTabView extends React.PureComponent<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private renderLazyPlaceholder = (props: { route: Route<string> }) => {
|
private renderLazyPlaceholder = (props: { route: Route<string> }) => {
|
||||||
const { lazyPlaceholderComponent: LazyPlaceholder } = this.props;
|
const { lazyPlaceholder } = this.props;
|
||||||
|
|
||||||
if (LazyPlaceholder != null) {
|
if (lazyPlaceholder != null) {
|
||||||
return <LazyPlaceholder {...props} />;
|
return lazyPlaceholder(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -99,30 +100,30 @@ export default class MaterialTopTabView extends React.PureComponent<Props> {
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
navigation,
|
navigation,
|
||||||
tabBarComponent: TabBarComponent = MaterialTopTabBar,
|
tabBar = (props: MaterialTopTabBarProps) => (
|
||||||
|
<MaterialTopTabBar {...props} />
|
||||||
|
),
|
||||||
tabBarPosition,
|
tabBarPosition,
|
||||||
tabBarOptions,
|
tabBarOptions,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
if (TabBarComponent === null || !tabBarVisible) {
|
if (tabBarVisible === false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return tabBar({
|
||||||
<TabBarComponent
|
...tabBarOptions,
|
||||||
{...tabBarOptions}
|
...props,
|
||||||
{...props}
|
tabBarPosition: tabBarPosition,
|
||||||
tabBarPosition={tabBarPosition}
|
state: state,
|
||||||
state={state}
|
navigation: navigation,
|
||||||
navigation={navigation}
|
descriptors: descriptors,
|
||||||
descriptors={descriptors}
|
getAccessibilityLabel: this.getAccessibilityLabel,
|
||||||
getAccessibilityLabel={this.getAccessibilityLabel}
|
getLabelText: this.getLabelText,
|
||||||
getLabelText={this.getLabelText}
|
getTestID: this.getTestID,
|
||||||
getTestID={this.getTestID}
|
onTabPress: this.handleTabPress,
|
||||||
onTabPress={this.handleTabPress}
|
onTabLongPress: this.handleTabLongPress,
|
||||||
onTabLongPress={this.handleTabLongPress}
|
});
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private handleSwipeStart = () =>
|
private handleSwipeStart = () =>
|
||||||
@@ -138,8 +139,8 @@ export default class MaterialTopTabView extends React.PureComponent<Props> {
|
|||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
lazyPlaceholderComponent,
|
lazyPlaceholder,
|
||||||
tabBarComponent,
|
tabBar,
|
||||||
tabBarOptions,
|
tabBarOptions,
|
||||||
/* eslint-enable @typescript-eslint/no-unused-vars */
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
||||||
state,
|
state,
|
||||||
|
|||||||
@@ -3,6 +3,112 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.11...@react-navigation/native-stack@5.0.0-alpha.12) (2019-11-10)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/native-stack
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.11](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.10...@react-navigation/native-stack@5.0.0-alpha.11) (2019-11-08)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/native-stack
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.10](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.9...@react-navigation/native-stack@5.0.0-alpha.10) (2019-11-04)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* popToTop on tab press in native stack ([301c35e](https://github.com/react-navigation/navigation-ex/commit/301c35e))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.9](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.8...@react-navigation/native-stack@5.0.0-alpha.9) (2019-11-04)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/native-stack
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.8](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.7...@react-navigation/native-stack@5.0.0-alpha.8) (2019-11-02)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add headerBackTitleVisible to navigation options in native stack ([77f29d3](https://github.com/react-navigation/navigation-ex/commit/77f29d3))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.7](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.6...@react-navigation/native-stack@5.0.0-alpha.7) (2019-11-02)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* remove top margin from screen in native stack on Android ([5cd6940](https://github.com/react-navigation/navigation-ex/commit/5cd6940))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.6](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.5...@react-navigation/native-stack@5.0.0-alpha.6) (2019-10-30)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/native-stack
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.5](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.4...@react-navigation/native-stack@5.0.0-alpha.5) (2019-10-29)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/native-stack
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.4](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.3...@react-navigation/native-stack@5.0.0-alpha.4) (2019-10-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **native-stack:** add support for large title attributes ([#135](https://github.com/react-navigation/navigation-ex/issues/135)) ([6cf1a04](https://github.com/react-navigation/navigation-ex/commit/6cf1a04))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.3](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.2...@react-navigation/native-stack@5.0.0-alpha.3) (2019-10-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* remove top margin when header is hidden in native stack. fixes [#131](https://github.com/react-navigation/navigation-ex/issues/131) ([fb726ee](https://github.com/react-navigation/navigation-ex/commit/fb726ee))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.2](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native-stack@5.0.0-alpha.1...@react-navigation/native-stack@5.0.0-alpha.2) (2019-10-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* fix header font size config in native stack ([#128](https://github.com/react-navigation/navigation-ex/issues/128)) ([477c088](https://github.com/react-navigation/navigation-ex/commit/477c088))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 5.0.0-alpha.1 (2019-10-15)
|
# 5.0.0-alpha.1 (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"react-native",
|
"react-native",
|
||||||
"react-navigation"
|
"react-navigation"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.1",
|
"version": "5.0.0-alpha.12",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -29,19 +29,19 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
"@react-navigation/routers": "^5.0.0-alpha.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
"del-cli": "^2.0.0",
|
"del-cli": "^2.0.0",
|
||||||
"react-native-screens": "^2.0.0-alpha.3",
|
"react-native-screens": "^2.0.0-alpha.8",
|
||||||
"typescript": "^3.5.3"
|
"typescript": "^3.7.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||||
"react": "*",
|
"react": "*",
|
||||||
"react-native": "*",
|
"react-native": "*",
|
||||||
"react-native-screens": "^2.0.0-alpha.3"
|
"react-native-screens": "^2.0.0-alpha.8"
|
||||||
},
|
},
|
||||||
"@react-native-community/bob": {
|
"@react-native-community/bob": {
|
||||||
"source": "src",
|
"source": "src",
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { createNavigator, useNavigationBuilder } from '@react-navigation/core';
|
import {
|
||||||
|
createNavigatorFactory,
|
||||||
|
useNavigationBuilder,
|
||||||
|
EventArg,
|
||||||
|
} from '@react-navigation/core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
StackRouter,
|
StackRouter,
|
||||||
StackNavigationState,
|
StackNavigationState,
|
||||||
StackRouterOptions,
|
StackRouterOptions,
|
||||||
|
StackActions,
|
||||||
} from '@react-navigation/routers';
|
} from '@react-navigation/routers';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -36,6 +41,28 @@ function NativeStackNavigator(props: NativeStackNavigatorProps) {
|
|||||||
screenOptions,
|
screenOptions,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
React.useEffect(
|
||||||
|
() =>
|
||||||
|
navigation.addListener &&
|
||||||
|
navigation.addListener('tabPress', (e: EventArg<'tabPress'>) => {
|
||||||
|
const isFocused = navigation.isFocused();
|
||||||
|
|
||||||
|
// Run the operation in the next frame so we're sure all listeners have been run
|
||||||
|
// This is necessary to know if preventDefault() has been called
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (state.index > 0 && isFocused && !e.defaultPrevented) {
|
||||||
|
// When user taps on already focused tab and we're inside the tab,
|
||||||
|
// reset the stack to replicate native behaviour
|
||||||
|
navigation.dispatch({
|
||||||
|
...StackActions.popToTop(),
|
||||||
|
target: state.key,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
[navigation, state.index, state.key]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StackView
|
<StackView
|
||||||
state={state}
|
state={state}
|
||||||
@@ -46,7 +73,7 @@ function NativeStackNavigator(props: NativeStackNavigatorProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createNavigator<
|
export default createNavigatorFactory<
|
||||||
NativeStackNavigationOptions,
|
NativeStackNavigationOptions,
|
||||||
typeof NativeStackNavigator
|
typeof NativeStackNavigator
|
||||||
>(NativeStackNavigator);
|
>(NativeStackNavigator);
|
||||||
|
|||||||
@@ -65,6 +65,13 @@ export type NativeStackNavigationOptions = {
|
|||||||
* @platform ios
|
* @platform ios
|
||||||
*/
|
*/
|
||||||
headerBackTitle?: string;
|
headerBackTitle?: string;
|
||||||
|
/**
|
||||||
|
* Whether the back button title should be visible or not. Defaults to `true`.
|
||||||
|
* Only supported on iOS.
|
||||||
|
*
|
||||||
|
* @platform ios
|
||||||
|
*/
|
||||||
|
headerBackTitleVisible?: boolean;
|
||||||
/**
|
/**
|
||||||
* Whether to show the header.
|
* Whether to show the header.
|
||||||
*/
|
*/
|
||||||
@@ -123,6 +130,19 @@ export type NativeStackNavigationOptions = {
|
|||||||
fontSize?: number;
|
fontSize?: number;
|
||||||
color?: string;
|
color?: string;
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* Style object for header large title. Supported properties:
|
||||||
|
* - fontFamily
|
||||||
|
* - fontSize
|
||||||
|
*
|
||||||
|
* Only supported on iOS.
|
||||||
|
*
|
||||||
|
* @platform ios
|
||||||
|
*/
|
||||||
|
headerLargeTitleStyle?: {
|
||||||
|
fontFamily?: string;
|
||||||
|
fontSize?: number;
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* Style object for header back title. Supported properties:
|
* Style object for header back title. Supported properties:
|
||||||
* - fontFamily
|
* - fontFamily
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export default function HeaderConfig(props: Props) {
|
|||||||
headerRight,
|
headerRight,
|
||||||
headerTitle,
|
headerTitle,
|
||||||
headerBackTitle,
|
headerBackTitle,
|
||||||
|
headerBackTitleVisible = true,
|
||||||
headerHideBackButton,
|
headerHideBackButton,
|
||||||
headerHideShadow,
|
headerHideShadow,
|
||||||
headerTintColor,
|
headerTintColor,
|
||||||
@@ -27,6 +28,7 @@ export default function HeaderConfig(props: Props) {
|
|||||||
headerTranslucent,
|
headerTranslucent,
|
||||||
headerStyle = {},
|
headerStyle = {},
|
||||||
headerTitleStyle = {},
|
headerTitleStyle = {},
|
||||||
|
headerLargeTitleStyle = {},
|
||||||
headerBackTitleStyle = {},
|
headerBackTitleStyle = {},
|
||||||
headerShown,
|
headerShown,
|
||||||
gestureEnabled,
|
gestureEnabled,
|
||||||
@@ -46,18 +48,20 @@ export default function HeaderConfig(props: Props) {
|
|||||||
: route.name
|
: route.name
|
||||||
}
|
}
|
||||||
titleFontFamily={headerTitleStyle.fontFamily}
|
titleFontFamily={headerTitleStyle.fontFamily}
|
||||||
titleFontSize={headerTitleStyle.fontFamily}
|
titleFontSize={headerTitleStyle.fontSize}
|
||||||
titleColor={
|
titleColor={
|
||||||
headerTitleStyle.color !== undefined
|
headerTitleStyle.color !== undefined
|
||||||
? headerTitleStyle.color
|
? headerTitleStyle.color
|
||||||
: headerTintColor
|
: headerTintColor
|
||||||
}
|
}
|
||||||
backTitle={headerBackTitle}
|
backTitle={headerBackTitleVisible ? headerBackTitle : ''}
|
||||||
backTitleFontFamily={headerBackTitleStyle.fontFamily}
|
backTitleFontFamily={headerBackTitleStyle.fontFamily}
|
||||||
backTitleFontSize={headerBackTitleStyle.fontSize}
|
backTitleFontSize={headerBackTitleStyle.fontSize}
|
||||||
color={headerTintColor}
|
color={headerTintColor}
|
||||||
gestureEnabled={gestureEnabled === undefined ? true : gestureEnabled}
|
gestureEnabled={gestureEnabled === undefined ? true : gestureEnabled}
|
||||||
largeTitle={headerLargeTitle}
|
largeTitle={headerLargeTitle}
|
||||||
|
largeTitleFontFamily={headerLargeTitleStyle.fontFamily}
|
||||||
|
largeTitleFontSize={headerLargeTitleStyle.fontSize}
|
||||||
backgroundColor={headerStyle.backgroundColor}
|
backgroundColor={headerStyle.backgroundColor}
|
||||||
>
|
>
|
||||||
{headerRight !== undefined ? (
|
{headerRight !== undefined ? (
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { View, StyleSheet, Platform } from 'react-native';
|
import { View, StyleSheet } from 'react-native';
|
||||||
import { StackNavigationState, StackActions } from '@react-navigation/routers';
|
import { StackNavigationState, StackActions } from '@react-navigation/routers';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
ScreenStack,
|
ScreenStack,
|
||||||
Screen,
|
Screen as ScreenComponent,
|
||||||
|
ScreenProps,
|
||||||
// eslint-disable-next-line import/no-unresolved
|
// eslint-disable-next-line import/no-unresolved
|
||||||
} from 'react-native-screens';
|
} from 'react-native-screens';
|
||||||
import HeaderConfig from './HeaderConfig';
|
import HeaderConfig from './HeaderConfig';
|
||||||
@@ -14,6 +15,14 @@ import {
|
|||||||
NativeStackDescriptorMap,
|
NativeStackDescriptorMap,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
|
const Screen = (ScreenComponent as unknown) as React.ComponentType<
|
||||||
|
ScreenProps & {
|
||||||
|
stackPresentation?: 'push' | 'modal' | 'transparentModal';
|
||||||
|
stackAnimation?: 'default' | 'fade' | 'none';
|
||||||
|
onDismissed?: () => void;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
state: StackNavigationState;
|
state: StackNavigationState;
|
||||||
navigation: NativeStackNavigationHelpers;
|
navigation: NativeStackNavigationHelpers;
|
||||||
@@ -28,7 +37,6 @@ export default function StackView({ state, navigation, descriptors }: Props) {
|
|||||||
const { presentation = 'push', animation, contentStyle } = options;
|
const { presentation = 'push', animation, contentStyle } = options;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// @ts-ignore
|
|
||||||
<Screen
|
<Screen
|
||||||
key={route.key}
|
key={route.key}
|
||||||
style={StyleSheet.absoluteFill}
|
style={StyleSheet.absoluteFill}
|
||||||
@@ -55,7 +63,6 @@ const styles = StyleSheet.create({
|
|||||||
content: {
|
content: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
backgroundColor: '#eee',
|
backgroundColor: '#eee',
|
||||||
marginTop: Platform.OS === 'android' ? 56 : 0,
|
|
||||||
},
|
},
|
||||||
scenes: {
|
scenes: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
|||||||
@@ -3,6 +3,36 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.15](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native@5.0.0-alpha.14...@react-navigation/native@5.0.0-alpha.15) (2019-11-08)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* don't call getNode if ref is already scrollable ([#162](https://github.com/react-navigation/navigation-ex/issues/162)) ([66551f2](https://github.com/react-navigation/navigation-ex/commit/66551f2))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native@5.0.0-alpha.13...@react-navigation/native@5.0.0-alpha.14) (2019-10-30)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* support scroll to top in navigators nested in tab ([50dea65](https://github.com/react-navigation/navigation-ex/commit/50dea65))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native@5.0.0-alpha.12...@react-navigation/native@5.0.0-alpha.13) (2019-10-22)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/native
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native@5.0.0-alpha.11...@react-navigation/native@5.0.0-alpha.12) (2019-10-15)
|
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native@5.0.0-alpha.11...@react-navigation/native@5.0.0-alpha.12) (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
"ios",
|
"ios",
|
||||||
"android"
|
"android"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.12",
|
"version": "5.0.0-alpha.15",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
"del-cli": "^3.0.0",
|
"del-cli": "^3.0.0",
|
||||||
"react": "~16.8.3",
|
"react": "~16.8.3",
|
||||||
"react-native": "~0.59.10",
|
"react-native": "~0.59.10",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.7.2"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
type Config = {
|
type Config = {
|
||||||
[routeName: string]:
|
[routeName: string]:
|
||||||
| string
|
| string
|
||||||
| { path: string; parse?: { [key: string]: (value: string) => any } };
|
| { path: string; parse?: Record<string, (value: string) => any> };
|
||||||
};
|
};
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { useNavigation, EventArg } from '@react-navigation/core';
|
import { useNavigation, useRoute, EventArg } from '@react-navigation/core';
|
||||||
|
|
||||||
type ScrollOptions = { y?: number; animated?: boolean };
|
type ScrollOptions = { y?: number; animated?: boolean };
|
||||||
|
|
||||||
@@ -19,13 +19,23 @@ function getScrollableNode(ref: React.RefObject<ScrollableWrapper>) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('getScrollResponder' in ref.current) {
|
if (
|
||||||
|
'scrollToTop' in ref.current ||
|
||||||
|
'scrollTo' in ref.current ||
|
||||||
|
'scrollToOffset' in ref.current ||
|
||||||
|
'scrollResponderScrollTo' in ref.current
|
||||||
|
) {
|
||||||
|
// This is already a scrollable node.
|
||||||
|
return ref.current;
|
||||||
|
} else if ('getScrollResponder' in ref.current) {
|
||||||
// If the view is a wrapper like FlatList, SectionList etc.
|
// If the view is a wrapper like FlatList, SectionList etc.
|
||||||
// We need to use `getScrollResponder` to get access to the scroll responder
|
// We need to use `getScrollResponder` to get access to the scroll responder
|
||||||
return ref.current.getScrollResponder();
|
return ref.current.getScrollResponder();
|
||||||
} else if ('getNode' in ref.current) {
|
} else if ('getNode' in ref.current) {
|
||||||
// When a `ScrollView` is wraped in `Animated.createAnimatedComponent`
|
// When a `ScrollView` is wraped in `Animated.createAnimatedComponent`
|
||||||
// we need to use `getNode` to get the ref to the actual scrollview
|
// we need to use `getNode` to get the ref to the actual scrollview.
|
||||||
|
// Note that `getNode` is deprecated in newer versions of react-native
|
||||||
|
// this is why we check if we already have a scrollable node above.
|
||||||
return ref.current.getNode();
|
return ref.current.getNode();
|
||||||
} else {
|
} else {
|
||||||
return ref.current;
|
return ref.current;
|
||||||
@@ -36,22 +46,42 @@ export default function useScrollToTop(
|
|||||||
ref: React.RefObject<ScrollableWrapper>
|
ref: React.RefObject<ScrollableWrapper>
|
||||||
) {
|
) {
|
||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
React.useEffect(
|
React.useEffect(() => {
|
||||||
() =>
|
let current = navigation;
|
||||||
// @ts-ignore
|
|
||||||
|
// The screen might be inside another navigator such as stack nested in tabs
|
||||||
|
// We need to find the closest tab navigator and add the listener there
|
||||||
|
while (current && current.dangerouslyGetState().type !== 'tab') {
|
||||||
|
current = current.dangerouslyGetParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const unsubscribe = current.addListener(
|
||||||
// We don't wanna import tab types here to avoid extra deps
|
// We don't wanna import tab types here to avoid extra deps
|
||||||
// in addition, there are multiple tab implementations
|
// in addition, there are multiple tab implementations
|
||||||
navigation.addListener('tabPress', (e: EventArg<'tabPress'>) => {
|
// @ts-ignore
|
||||||
|
'tabPress',
|
||||||
|
(e: EventArg<'tabPress'>) => {
|
||||||
|
// We should scroll to top only when the screen is focused
|
||||||
const isFocused = navigation.isFocused();
|
const isFocused = navigation.isFocused();
|
||||||
|
|
||||||
|
// In a nested stack navigator, tab press resets the stack to first screen
|
||||||
|
// So we should scroll to top only when we are on first screen
|
||||||
|
const isFirst =
|
||||||
|
navigation === current ||
|
||||||
|
navigation.dangerouslyGetState().routes[0].key === route.key;
|
||||||
|
|
||||||
// Run the operation in the next frame so we're sure all listeners have been run
|
// Run the operation in the next frame so we're sure all listeners have been run
|
||||||
// This is necessary to know if preventDefault() has been called
|
// This is necessary to know if preventDefault() has been called
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
const scrollable = getScrollableNode(ref);
|
const scrollable = getScrollableNode(ref);
|
||||||
|
|
||||||
if (isFocused && !e.defaultPrevented && scrollable) {
|
if (isFocused && isFirst && scrollable && !e.defaultPrevented) {
|
||||||
// When user taps on already focused tab, scroll to top
|
|
||||||
if ('scrollToTop' in scrollable) {
|
if ('scrollToTop' in scrollable) {
|
||||||
scrollable.scrollToTop();
|
scrollable.scrollToTop();
|
||||||
} else if ('scrollTo' in scrollable) {
|
} else if ('scrollTo' in scrollable) {
|
||||||
@@ -63,7 +93,9 @@ export default function useScrollToTop(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}),
|
}
|
||||||
[navigation, ref]
|
);
|
||||||
);
|
|
||||||
|
return unsubscribe;
|
||||||
|
}, [navigation, ref, route.key]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,55 @@
|
|||||||
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.
|
||||||
|
|
||||||
|
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/routers@5.0.0-alpha.13...@react-navigation/routers@5.0.0-alpha.14) (2019-11-10)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/routers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/routers@5.0.0-alpha.12...@react-navigation/routers@5.0.0-alpha.13) (2019-11-08)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* handle invalid initialRouteName gracefully ([b5d9ad9](https://github.com/react-navigation/navigation-ex/commit/b5d9ad9))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/routers@5.0.0-alpha.11...@react-navigation/routers@5.0.0-alpha.12) (2019-11-04)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* close drawer on back button press ([3a4c38b](https://github.com/react-navigation/navigation-ex/commit/3a4c38b))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.11](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/routers@5.0.0-alpha.10...@react-navigation/routers@5.0.0-alpha.11) (2019-10-30)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/routers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.10](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/routers@5.0.0-alpha.9...@react-navigation/routers@5.0.0-alpha.10) (2019-10-29)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* use index of first route when rehydrating tab state ([7635373](https://github.com/react-navigation/navigation-ex/commit/7635373))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.9](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/routers@5.0.0-alpha.8...@react-navigation/routers@5.0.0-alpha.9) (2019-10-03)
|
# [5.0.0-alpha.9](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/routers@5.0.0-alpha.8...@react-navigation/routers@5.0.0-alpha.9) (2019-10-03)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/routers
|
**Note:** Version bump only for package @react-navigation/routers
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ yarn add @react-navigation/core @react-navigation/routers
|
|||||||
A basic custom navigator bundling a router and a view looks like this:
|
A basic custom navigator bundling a router and a view looks like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { useNavigationBuilder } from '@react-navigation/core';
|
import { createNavigatorFactory, useNavigationBuilder } from '@react-navigation/core';
|
||||||
import { StackRouter } from '@react-navigation/routers';
|
import { StackRouter } from '@react-navigation/routers';
|
||||||
|
|
||||||
function StackNavigator({ initialRouteName, children, ...rest }) {
|
function StackNavigator({ initialRouteName, children, ...rest }) {
|
||||||
@@ -36,5 +36,5 @@ function StackNavigator({ initialRouteName, children, ...rest }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createNavigator(StackNavigator);
|
export default createNavigatorFactory(StackNavigator);
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ it('gets initial state from route names and params with initialRouteName', () =>
|
|||||||
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ it('gets initial state from route names and params without initialRouteName', ()
|
|||||||
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -85,6 +87,29 @@ it('gets rehydrated state from partial state', () => {
|
|||||||
{ key: 'qux-1', name: 'qux', params: { name: 'Jane' } },
|
{ key: 'qux-1', name: 'qux', params: { name: 'Jane' } },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
router.getRehydratedState(
|
||||||
|
{
|
||||||
|
routes: [{ key: 'baz-0', name: 'baz' }],
|
||||||
|
},
|
||||||
|
options
|
||||||
|
)
|
||||||
|
).toEqual({
|
||||||
|
index: 1,
|
||||||
|
key: 'drawer-test',
|
||||||
|
isDrawerOpen: false,
|
||||||
|
routeKeyHistory: [],
|
||||||
|
routeNames: ['bar', 'baz', 'qux'],
|
||||||
|
routes: [
|
||||||
|
{ key: 'bar-test', name: 'bar' },
|
||||||
|
{ key: 'baz-0', name: 'baz', params: { answer: 42 } },
|
||||||
|
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||||
|
],
|
||||||
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -111,6 +136,7 @@ it('gets rehydrated state from partial state', () => {
|
|||||||
{ key: 'qux-2', name: 'qux', params: { name: 'Jane' } },
|
{ key: 'qux-2', name: 'qux', params: { name: 'Jane' } },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -122,7 +148,7 @@ it('gets rehydrated state from partial state', () => {
|
|||||||
options
|
options
|
||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
index: 0,
|
index: 2,
|
||||||
key: 'drawer-test',
|
key: 'drawer-test',
|
||||||
isDrawerOpen: false,
|
isDrawerOpen: false,
|
||||||
routeKeyHistory: [],
|
routeKeyHistory: [],
|
||||||
@@ -133,6 +159,7 @@ it('gets rehydrated state from partial state', () => {
|
|||||||
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -157,6 +184,7 @@ it('gets rehydrated state from partial state', () => {
|
|||||||
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -175,6 +203,7 @@ it("doesn't rehydrate state if it's not stale", () => {
|
|||||||
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||||
],
|
],
|
||||||
stale: false as const,
|
stale: false as const,
|
||||||
|
type: 'drawer' as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -192,6 +221,7 @@ it('handles navigate action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -203,6 +233,7 @@ it('handles navigate action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -222,6 +253,7 @@ it('handles navigate action with open drawer', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -233,6 +265,7 @@ it('handles navigate action with open drawer', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -252,6 +285,7 @@ it('handles open drawer action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -263,6 +297,7 @@ it('handles open drawer action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -273,6 +308,7 @@ it('handles open drawer action', () => {
|
|||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
stale: false as const,
|
stale: false as const,
|
||||||
|
type: 'drawer' as const,
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -293,6 +329,7 @@ it('handles close drawer action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -304,6 +341,7 @@ it('handles close drawer action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -314,6 +352,7 @@ it('handles close drawer action', () => {
|
|||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
stale: false as const,
|
stale: false as const,
|
||||||
|
type: 'drawer' as const,
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -334,6 +373,7 @@ it('handles toggle drawer action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -345,6 +385,7 @@ it('handles toggle drawer action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -357,6 +398,7 @@ it('handles toggle drawer action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -368,6 +410,7 @@ it('handles toggle drawer action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -392,6 +435,7 @@ it('updates route key history on focus change', () => {
|
|||||||
{ key: 'qux-0', name: 'qux', params: { name: 'Jane' } },
|
{ key: 'qux-0', name: 'qux', params: { name: 'Jane' } },
|
||||||
],
|
],
|
||||||
stale: false as const,
|
stale: false as const,
|
||||||
|
type: 'drawer' as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(router.getStateForRouteFocus(state, 'bar-0').routeKeyHistory).toEqual(
|
expect(router.getStateForRouteFocus(state, 'bar-0').routeKeyHistory).toEqual(
|
||||||
@@ -420,6 +464,7 @@ it('closes drawer on focus change', () => {
|
|||||||
{ key: 'qux-0', name: 'qux' },
|
{ key: 'qux-0', name: 'qux' },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
},
|
},
|
||||||
'baz-0'
|
'baz-0'
|
||||||
)
|
)
|
||||||
@@ -435,6 +480,7 @@ it('closes drawer on focus change', () => {
|
|||||||
{ key: 'qux-0', name: 'qux' },
|
{ key: 'qux-0', name: 'qux' },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -451,6 +497,7 @@ it('closes drawer on focus change', () => {
|
|||||||
{ key: 'qux-0', name: 'qux' },
|
{ key: 'qux-0', name: 'qux' },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
},
|
},
|
||||||
'baz-0'
|
'baz-0'
|
||||||
)
|
)
|
||||||
@@ -466,5 +513,6 @@ it('closes drawer on focus change', () => {
|
|||||||
{ key: 'qux-0', name: 'qux' },
|
{ key: 'qux-0', name: 'qux' },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ it('gets initial state from route names and params with initialRouteName', () =>
|
|||||||
routeNames: ['bar', 'baz', 'qux'],
|
routeNames: ['bar', 'baz', 'qux'],
|
||||||
routes: [{ key: 'baz-test', name: 'baz', params: { answer: 42 } }],
|
routes: [{ key: 'baz-test', name: 'baz', params: { answer: 42 } }],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -40,6 +41,7 @@ it('gets initial state from route names and params without initialRouteName', ()
|
|||||||
routeNames: ['bar', 'baz', 'qux'],
|
routeNames: ['bar', 'baz', 'qux'],
|
||||||
routes: [{ key: 'bar-test', name: 'bar' }],
|
routes: [{ key: 'bar-test', name: 'bar' }],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -70,6 +72,7 @@ it('gets rehydrated state from partial state', () => {
|
|||||||
{ key: 'qux-1', name: 'qux', params: { name: 'Jane' } },
|
{ key: 'qux-1', name: 'qux', params: { name: 'Jane' } },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -94,6 +97,7 @@ it('gets rehydrated state from partial state', () => {
|
|||||||
{ key: 'qux-2', name: 'qux', params: { name: 'Jane' } },
|
{ key: 'qux-2', name: 'qux', params: { name: 'Jane' } },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -110,6 +114,7 @@ it('gets rehydrated state from partial state', () => {
|
|||||||
routeNames: ['bar', 'baz', 'qux'],
|
routeNames: ['bar', 'baz', 'qux'],
|
||||||
routes: [{ key: 'bar-test', name: 'bar' }],
|
routes: [{ key: 'bar-test', name: 'bar' }],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -122,6 +127,7 @@ it("doesn't rehydrate state if it's not stale", () => {
|
|||||||
routeNames: ['bar', 'baz', 'qux'],
|
routeNames: ['bar', 'baz', 'qux'],
|
||||||
routes: [{ key: 'bar-test', name: 'bar' }],
|
routes: [{ key: 'bar-test', name: 'bar' }],
|
||||||
stale: false as const,
|
stale: false as const,
|
||||||
|
type: 'stack' as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -147,6 +153,7 @@ it('gets state on route names change', () => {
|
|||||||
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
routeNames: ['qux', 'baz', 'foo', 'fiz'],
|
routeNames: ['qux', 'baz', 'foo', 'fiz'],
|
||||||
@@ -165,6 +172,7 @@ it('gets state on route names change', () => {
|
|||||||
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
{ key: 'qux-test', name: 'qux', params: { name: 'Jane' } },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -178,6 +186,7 @@ it('gets state on route names change', () => {
|
|||||||
{ key: 'bar-test', name: 'bar' },
|
{ key: 'bar-test', name: 'bar' },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
routeNames: ['baz', 'qux'],
|
routeNames: ['baz', 'qux'],
|
||||||
@@ -192,6 +201,7 @@ it('gets state on route names change', () => {
|
|||||||
routeNames: ['baz', 'qux'],
|
routeNames: ['baz', 'qux'],
|
||||||
routes: [{ key: 'baz-test', name: 'baz', params: { name: 'John' } }],
|
routes: [{ key: 'baz-test', name: 'baz', params: { name: 'John' } }],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -209,6 +219,7 @@ it('gets state on route names change with initialRouteName', () => {
|
|||||||
{ key: 'bar-test', name: 'bar' },
|
{ key: 'bar-test', name: 'bar' },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
routeNames: ['baz', 'qux'],
|
routeNames: ['baz', 'qux'],
|
||||||
@@ -223,6 +234,7 @@ it('gets state on route names change with initialRouteName', () => {
|
|||||||
routeNames: ['baz', 'qux'],
|
routeNames: ['baz', 'qux'],
|
||||||
routes: [{ key: 'qux-test', name: 'qux' }],
|
routes: [{ key: 'qux-test', name: 'qux' }],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -233,6 +245,7 @@ it('handles navigate action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -242,6 +255,7 @@ it('handles navigate action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 2,
|
index: 2,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -260,6 +274,7 @@ it('handles navigate action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -269,6 +284,7 @@ it('handles navigate action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -279,6 +295,7 @@ it('handles navigate action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -291,6 +308,7 @@ it('handles navigate action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -304,6 +322,7 @@ it('handles navigate action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -317,6 +336,7 @@ it('handles navigate action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -330,6 +350,7 @@ it('handles navigate action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -342,6 +363,7 @@ it('handles navigate action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -352,6 +374,7 @@ it('handles navigate action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -361,6 +384,7 @@ it('handles navigate action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 2,
|
index: 2,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -379,6 +403,7 @@ it('handles go back action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -388,6 +413,7 @@ it('handles go back action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -398,6 +424,7 @@ it('handles go back action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -415,6 +442,7 @@ it('handles pop action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 2,
|
index: 2,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -428,6 +456,7 @@ it('handles pop action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -438,6 +467,7 @@ it('handles pop action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 2,
|
index: 2,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -451,6 +481,7 @@ it('handles pop action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -461,6 +492,7 @@ it('handles pop action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 2,
|
index: 2,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -478,6 +510,7 @@ it('handles pop action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -488,6 +521,7 @@ it('handles pop action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -505,6 +539,7 @@ it('handles pop to top action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 2,
|
index: 2,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -518,6 +553,7 @@ it('handles pop to top action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -532,6 +568,7 @@ it('handles push action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 2,
|
index: 2,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -541,6 +578,7 @@ it('handles push action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 3,
|
index: 3,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -551,6 +589,7 @@ it('handles push action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 2,
|
index: 2,
|
||||||
routeNames: ['baz', 'bar', 'qux'],
|
routeNames: ['baz', 'bar', 'qux'],
|
||||||
@@ -576,6 +615,7 @@ it('changes index on focus change', () => {
|
|||||||
{ key: 'qux-0', name: 'qux' },
|
{ key: 'qux-0', name: 'qux' },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
},
|
},
|
||||||
'baz-0'
|
'baz-0'
|
||||||
)
|
)
|
||||||
@@ -585,6 +625,7 @@ it('changes index on focus change', () => {
|
|||||||
routeNames: ['bar', 'baz', 'qux'],
|
routeNames: ['bar', 'baz', 'qux'],
|
||||||
routes: [{ key: 'bar-0', name: 'bar' }, { key: 'baz-0', name: 'baz' }],
|
routes: [{ key: 'bar-0', name: 'bar' }, { key: 'baz-0', name: 'baz' }],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
});
|
});
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
@@ -593,6 +634,7 @@ it('changes index on focus change', () => {
|
|||||||
routeNames: ['bar', 'baz', 'qux'],
|
routeNames: ['bar', 'baz', 'qux'],
|
||||||
routes: [{ key: 'bar-0', name: 'bar' }, { key: 'baz-0', name: 'baz' }],
|
routes: [{ key: 'bar-0', name: 'bar' }, { key: 'baz-0', name: 'baz' }],
|
||||||
stale: false as const,
|
stale: false as const,
|
||||||
|
type: 'stack' as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(router.getStateForRouteFocus(state, 'qux-0')).toEqual(state);
|
expect(router.getStateForRouteFocus(state, 'qux-0')).toEqual(state);
|
||||||
|
|||||||