mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-01-18 01:48:34 +08:00
Compare commits
57 Commits
@react-nav
...
@react-nav
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
01277575f2 | ||
|
|
386d1c0888 | ||
|
|
9d9fe31f02 | ||
|
|
0a5fb3e268 | ||
|
|
1d7a37cd4a | ||
|
|
2b57702a62 | ||
|
|
c7da1e4145 | ||
|
|
6a0ca90873 | ||
|
|
e9a1cfcec3 | ||
|
|
b71f4e52a3 | ||
|
|
9ce8ec59fb | ||
|
|
d685e78fa9 | ||
|
|
7a901af5b5 | ||
|
|
ba3f718ab3 | ||
|
|
42beb660ca | ||
|
|
e789846692 | ||
|
|
b32cda2446 | ||
|
|
708dde0e47 |
@@ -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: .
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"@react-navigation/routers",
|
"@react-navigation/routers",
|
||||||
"@react-navigation/compat",
|
"@react-navigation/compat",
|
||||||
"@react-navigation/stack",
|
"@react-navigation/stack",
|
||||||
|
"@react-navigation/native-stack",
|
||||||
"@react-navigation/drawer",
|
"@react-navigation/drawer",
|
||||||
"@react-navigation/bottom-tabs",
|
"@react-navigation/bottom-tabs",
|
||||||
"@react-navigation/material-top-tabs",
|
"@react-navigation/material-top-tabs",
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,6 +5,8 @@
|
|||||||
.expo
|
.expo
|
||||||
.gradle
|
.gradle
|
||||||
|
|
||||||
|
local.properties
|
||||||
|
|
||||||
/coverage/
|
/coverage/
|
||||||
/types/
|
/types/
|
||||||
/dist/
|
/dist/
|
||||||
|
|||||||
@@ -41,8 +41,8 @@
|
|||||||
"typescript": "^3.6.3"
|
"typescript": "^3.6.3"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"react": "16.8.3",
|
"react": "~16.8.3",
|
||||||
"react-native": "0.59.10"
|
"react-native": "~0.59.10"
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
|
|||||||
@@ -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.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)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* improve keyboard handling with bottom tab bar ([42beb66](https://github.com/react-navigation/navigation-ex/commit/42beb66))
|
||||||
|
* make it possible to run the example on web ([7a901af](https://github.com/react-navigation/navigation-ex/commit/7a901af))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* initial version of native stack ([#102](https://github.com/react-navigation/navigation-ex/issues/102)) ([ba3f718](https://github.com/react-navigation/navigation-ex/commit/ba3f718))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.12...@react-navigation/bottom-tabs@5.0.0-alpha.13) (2019-10-06)
|
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.12...@react-navigation/bottom-tabs@5.0.0-alpha.13) (2019-10-06)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||||
|
|||||||
@@ -37,8 +37,13 @@ cd ..
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
import { MaterialCommunityIcons } from 'react-native-vector-icons';
|
||||||
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
||||||
|
|
||||||
|
const getTabBarIcon = name => ({ color, size }) => (
|
||||||
|
<MaterialCommunityIcons name={name} color={color} size={size} />
|
||||||
|
);
|
||||||
|
|
||||||
const BottomTabs = createBottomTabNavigator();
|
const BottomTabs = createBottomTabNavigator();
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
@@ -49,7 +54,7 @@ export default function App() {
|
|||||||
component={Article}
|
component={Article}
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Article',
|
tabBarLabel: 'Article',
|
||||||
tabBarIcon: 'chrome-reader-mode',
|
tabBarIcon: getTabBarIcon('file-document-box'),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<BottomTabs.Screen
|
<BottomTabs.Screen
|
||||||
@@ -57,7 +62,7 @@ export default function App() {
|
|||||||
component={Chat}
|
component={Chat}
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Chat',
|
tabBarLabel: 'Chat',
|
||||||
tabBarIcon: 'chat-bubble',
|
tabBarIcon: getTabBarIcon('message-reply'),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<BottomTabs.Screen
|
<BottomTabs.Screen
|
||||||
@@ -65,7 +70,7 @@ export default function App() {
|
|||||||
component={Contacts}
|
component={Contacts}
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Contacts',
|
tabBarLabel: 'Contacts',
|
||||||
tabBarIcon: 'contacts',
|
tabBarIcon: getTabBarIcon('contacts'),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</BottomTabs.Navigator>
|
</BottomTabs.Navigator>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"android",
|
"android",
|
||||||
"tab"
|
"tab"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.13",
|
"version": "5.0.0-alpha.17",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -33,15 +33,15 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
"@react-navigation/routers": "^5.0.0-alpha.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
"@types/react": "^16.9.4",
|
"@types/react": "^16.9.4",
|
||||||
"@types/react-native": "^0.60.17",
|
"@types/react-native": "^0.60.17",
|
||||||
"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-safe-area-context": "^0.3.6",
|
"react-native-safe-area-context": "^0.3.6",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.6.3"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -66,26 +66,22 @@ export type BottomTabNavigationOptions = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Title string of a tab displayed in the tab bar or React Element
|
* Title string of a tab displayed in the tab bar or React Element
|
||||||
* or a function that given { focused: boolean, tintColor: string } returns a React.Node, to display in tab bar.
|
* or a function that given { focused: boolean, color: string } returns a React.Node, to display in tab bar.
|
||||||
* When undefined, scene title is used. To hide, see tabBarOptions.showLabel in the previous section.
|
* When undefined, scene title is used. To hide, see tabBarOptions.showLabel in the previous section.
|
||||||
*/
|
*/
|
||||||
tabBarLabel?:
|
tabBarLabel?:
|
||||||
| React.ReactNode
|
| React.ReactNode
|
||||||
| ((props: {
|
| ((props: { focused: boolean; color: string }) => React.ReactNode);
|
||||||
focused: boolean;
|
|
||||||
tintColor: string;
|
|
||||||
horizontal: boolean;
|
|
||||||
}) => React.ReactNode);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* React Element or a function that given { focused: boolean, tintColor: 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.
|
||||||
*/
|
*/
|
||||||
tabBarIcon?:
|
tabBarIcon?:
|
||||||
| React.ReactNode
|
| React.ReactNode
|
||||||
| ((props: {
|
| ((props: {
|
||||||
focused: boolean;
|
focused: boolean;
|
||||||
tintColor: string;
|
color: string;
|
||||||
horizontal: boolean;
|
size: number;
|
||||||
}) => React.ReactNode);
|
}) => React.ReactNode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,6 +123,11 @@ export type BottomTabNavigationConfig = {
|
|||||||
* Set it to `false` if you want to render all screens on initial render.
|
* Set it to `false` if you want to render all screens on initial render.
|
||||||
*/
|
*/
|
||||||
lazy?: boolean;
|
lazy?: boolean;
|
||||||
|
/**
|
||||||
|
* Whether a screen should be unmounted when navigating away from it.
|
||||||
|
* Defaults to `false`.
|
||||||
|
*/
|
||||||
|
unmountInactiveScreens?: boolean;
|
||||||
/**
|
/**
|
||||||
* Custom tab bar component.
|
* Custom tab bar component.
|
||||||
*/
|
*/
|
||||||
@@ -139,7 +140,7 @@ export type BottomTabNavigationConfig = {
|
|||||||
|
|
||||||
export type BottomTabBarOptions = {
|
export type BottomTabBarOptions = {
|
||||||
/**
|
/**
|
||||||
* Whether the tab bar gets hidden when the keyboard is shown.
|
* Whether the tab bar gets hidden when the keyboard is shown. Defaults to `false`.
|
||||||
*/
|
*/
|
||||||
keyboardHidesTabBar?: boolean;
|
keyboardHidesTabBar?: boolean;
|
||||||
/**
|
/**
|
||||||
@@ -220,16 +221,15 @@ export type BottomTabBarProps = BottomTabBarOptions & {
|
|||||||
}) =>
|
}) =>
|
||||||
| ((scene: {
|
| ((scene: {
|
||||||
focused: boolean;
|
focused: boolean;
|
||||||
tintColor: 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;
|
||||||
renderIcon: (props: {
|
renderIcon: (props: {
|
||||||
route: Route<string>;
|
route: Route<string>;
|
||||||
focused: boolean;
|
focused: boolean;
|
||||||
tintColor: string;
|
color: string;
|
||||||
horizontal: boolean;
|
size: number;
|
||||||
}) => React.ReactNode;
|
}) => React.ReactNode;
|
||||||
activeTintColor: string;
|
activeTintColor: string;
|
||||||
inactiveTintColor: string;
|
inactiveTintColor: string;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {
|
import {
|
||||||
|
View,
|
||||||
Animated,
|
Animated,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
Keyboard,
|
Keyboard,
|
||||||
@@ -32,7 +33,7 @@ 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> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
keyboardHidesTabBar: true,
|
keyboardHidesTabBar: false,
|
||||||
activeTintColor: '#007AFF',
|
activeTintColor: '#007AFF',
|
||||||
activeBackgroundColor: 'transparent',
|
activeBackgroundColor: 'transparent',
|
||||||
inactiveTintColor: '#8E8E93',
|
inactiveTintColor: '#8E8E93',
|
||||||
@@ -82,7 +83,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
this.setState({ keyboard: true }, () =>
|
this.setState({ keyboard: true }, () =>
|
||||||
Animated.timing(this.state.visible, {
|
Animated.timing(this.state.visible, {
|
||||||
toValue: 0,
|
toValue: 0,
|
||||||
duration: 150,
|
duration: 200,
|
||||||
useNativeDriver: true,
|
useNativeDriver: true,
|
||||||
}).start()
|
}).start()
|
||||||
);
|
);
|
||||||
@@ -90,10 +91,12 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
private handleKeyboardHide = () =>
|
private handleKeyboardHide = () =>
|
||||||
Animated.timing(this.state.visible, {
|
Animated.timing(this.state.visible, {
|
||||||
toValue: 1,
|
toValue: 1,
|
||||||
duration: 100,
|
duration: 250,
|
||||||
useNativeDriver: true,
|
useNativeDriver: true,
|
||||||
}).start(() => {
|
}).start(({ finished }) => {
|
||||||
this.setState({ keyboard: false });
|
if (finished) {
|
||||||
|
this.setState({ keyboard: false });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
private handleLayout = (e: LayoutChangeEvent) => {
|
private handleLayout = (e: LayoutChangeEvent) => {
|
||||||
@@ -134,7 +137,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
|
|
||||||
const label = this.props.getLabelText({ route });
|
const label = this.props.getLabelText({ route });
|
||||||
const horizontal = this.shouldUseHorizontalLabels();
|
const horizontal = this.shouldUseHorizontalLabels();
|
||||||
const tintColor = focused ? activeTintColor : inactiveTintColor;
|
const color = focused ? activeTintColor : inactiveTintColor;
|
||||||
|
|
||||||
if (typeof label === 'string') {
|
if (typeof label === 'string') {
|
||||||
return (
|
return (
|
||||||
@@ -142,7 +145,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
numberOfLines={1}
|
numberOfLines={1}
|
||||||
style={[
|
style={[
|
||||||
styles.label,
|
styles.label,
|
||||||
{ color: tintColor },
|
{ color },
|
||||||
showIcon && horizontal ? styles.labelBeside : styles.labelBeneath,
|
showIcon && horizontal ? styles.labelBeside : styles.labelBeneath,
|
||||||
labelStyle,
|
labelStyle,
|
||||||
]}
|
]}
|
||||||
@@ -154,11 +157,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,
|
|
||||||
tintColor,
|
|
||||||
orientation: horizontal ? 'horizontal' : 'vertical',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return label;
|
return label;
|
||||||
@@ -191,7 +190,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
return (
|
return (
|
||||||
<TabBarIcon
|
<TabBarIcon
|
||||||
route={route}
|
route={route}
|
||||||
horizontal={horizontal}
|
size={horizontal ? 17 : 24}
|
||||||
activeOpacity={activeOpacity}
|
activeOpacity={activeOpacity}
|
||||||
inactiveOpacity={inactiveOpacity}
|
inactiveOpacity={inactiveOpacity}
|
||||||
activeTintColor={activeTintColor}
|
activeTintColor={activeTintColor}
|
||||||
@@ -305,58 +304,59 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
|||||||
pointerEvents={
|
pointerEvents={
|
||||||
keyboardHidesTabBar && this.state.keyboard ? 'none' : 'auto'
|
keyboardHidesTabBar && this.state.keyboard ? 'none' : 'auto'
|
||||||
}
|
}
|
||||||
onLayout={this.handleLayout}
|
|
||||||
>
|
>
|
||||||
{routes.map((route, index) => {
|
<View style={styles.content} onLayout={this.handleLayout}>
|
||||||
const focused = index === state.index;
|
{routes.map((route, index) => {
|
||||||
const scene = { route, focused };
|
const focused = index === state.index;
|
||||||
const accessibilityLabel = getAccessibilityLabel({
|
const scene = { route, focused };
|
||||||
route,
|
const accessibilityLabel = getAccessibilityLabel({
|
||||||
});
|
route,
|
||||||
|
});
|
||||||
|
|
||||||
const accessibilityRole = getAccessibilityRole({
|
const accessibilityRole = getAccessibilityRole({
|
||||||
route,
|
route,
|
||||||
});
|
});
|
||||||
|
|
||||||
const accessibilityStates = getAccessibilityStates(scene);
|
const accessibilityStates = getAccessibilityStates(scene);
|
||||||
|
|
||||||
const testID = getTestID({ route });
|
const testID = getTestID({ route });
|
||||||
|
|
||||||
const backgroundColor = focused
|
const backgroundColor = focused
|
||||||
? activeBackgroundColor
|
? activeBackgroundColor
|
||||||
: inactiveBackgroundColor;
|
: inactiveBackgroundColor;
|
||||||
|
|
||||||
const ButtonComponent =
|
const ButtonComponent =
|
||||||
getButtonComponent({ route }) ||
|
getButtonComponent({ route }) ||
|
||||||
TouchableWithoutFeedbackWrapper;
|
TouchableWithoutFeedbackWrapper;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NavigationContext.Provider
|
<NavigationContext.Provider
|
||||||
key={route.key}
|
key={route.key}
|
||||||
value={descriptors[route.key].navigation}
|
value={descriptors[route.key].navigation}
|
||||||
>
|
|
||||||
<ButtonComponent
|
|
||||||
onPress={() => onTabPress({ route })}
|
|
||||||
onLongPress={() => onTabLongPress({ route })}
|
|
||||||
testID={testID}
|
|
||||||
accessibilityLabel={accessibilityLabel}
|
|
||||||
accessibilityRole={accessibilityRole}
|
|
||||||
accessibilityStates={accessibilityStates}
|
|
||||||
style={[
|
|
||||||
styles.tab,
|
|
||||||
{ backgroundColor },
|
|
||||||
this.shouldUseHorizontalLabels()
|
|
||||||
? styles.tabLandscape
|
|
||||||
: styles.tabPortrait,
|
|
||||||
tabStyle,
|
|
||||||
]}
|
|
||||||
>
|
>
|
||||||
{this.renderIcon(scene)}
|
<ButtonComponent
|
||||||
{this.renderLabel(scene)}
|
onPress={() => onTabPress({ route })}
|
||||||
</ButtonComponent>
|
onLongPress={() => onTabLongPress({ route })}
|
||||||
</NavigationContext.Provider>
|
testID={testID}
|
||||||
);
|
accessibilityLabel={accessibilityLabel}
|
||||||
})}
|
accessibilityRole={accessibilityRole}
|
||||||
|
accessibilityStates={accessibilityStates}
|
||||||
|
style={[
|
||||||
|
styles.tab,
|
||||||
|
{ backgroundColor },
|
||||||
|
this.shouldUseHorizontalLabels()
|
||||||
|
? styles.tabLandscape
|
||||||
|
: styles.tabPortrait,
|
||||||
|
tabStyle,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{this.renderIcon(scene)}
|
||||||
|
{this.renderLabel(scene)}
|
||||||
|
</ButtonComponent>
|
||||||
|
</NavigationContext.Provider>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
)}
|
)}
|
||||||
</SafeAreaConsumer>
|
</SafeAreaConsumer>
|
||||||
@@ -375,9 +375,12 @@ const styles = StyleSheet.create({
|
|||||||
backgroundColor: '#fff',
|
backgroundColor: '#fff',
|
||||||
borderTopWidth: StyleSheet.hairlineWidth,
|
borderTopWidth: StyleSheet.hairlineWidth,
|
||||||
borderTopColor: 'rgba(0, 0, 0, .3)',
|
borderTopColor: 'rgba(0, 0, 0, .3)',
|
||||||
flexDirection: 'row',
|
|
||||||
elevation: 8,
|
elevation: 8,
|
||||||
},
|
},
|
||||||
|
content: {
|
||||||
|
flex: 1,
|
||||||
|
flexDirection: 'row',
|
||||||
|
},
|
||||||
tab: {
|
tab: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
alignItems: isIos ? 'center' : 'stretch',
|
alignItems: isIos ? 'center' : 'stretch',
|
||||||
|
|||||||
@@ -64,13 +64,13 @@ export default class BottomTabView extends React.Component<Props, State> {
|
|||||||
private renderIcon = ({
|
private renderIcon = ({
|
||||||
route,
|
route,
|
||||||
focused,
|
focused,
|
||||||
tintColor,
|
color,
|
||||||
horizontal,
|
size,
|
||||||
}: {
|
}: {
|
||||||
route: Route<string>;
|
route: Route<string>;
|
||||||
focused: boolean;
|
focused: boolean;
|
||||||
tintColor: string;
|
color: string;
|
||||||
horizontal: boolean;
|
size: number;
|
||||||
}) => {
|
}) => {
|
||||||
const { descriptors } = this.props;
|
const { descriptors } = this.props;
|
||||||
const descriptor = descriptors[route.key];
|
const descriptor = descriptors[route.key];
|
||||||
@@ -78,7 +78,7 @@ export default class BottomTabView extends React.Component<Props, State> {
|
|||||||
|
|
||||||
if (options.tabBarIcon) {
|
if (options.tabBarIcon) {
|
||||||
return typeof options.tabBarIcon === 'function'
|
return typeof options.tabBarIcon === 'function'
|
||||||
? options.tabBarIcon({ focused, tintColor, horizontal })
|
? options.tabBarIcon({ focused, color, size })
|
||||||
: options.tabBarIcon;
|
: options.tabBarIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ export default class BottomTabView extends React.Component<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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 +203,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 +220,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 +248,7 @@ const styles = StyleSheet.create({
|
|||||||
pages: {
|
pages: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
},
|
},
|
||||||
|
content: {
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Route } from '@react-navigation/core';
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
route: Route<string>;
|
route: Route<string>;
|
||||||
horizontal: boolean;
|
size: number;
|
||||||
activeOpacity: number;
|
activeOpacity: number;
|
||||||
inactiveOpacity: number;
|
inactiveOpacity: number;
|
||||||
activeTintColor: string;
|
activeTintColor: string;
|
||||||
@@ -12,8 +12,8 @@ type Props = {
|
|||||||
renderIcon: (props: {
|
renderIcon: (props: {
|
||||||
route: Route<string>;
|
route: Route<string>;
|
||||||
focused: boolean;
|
focused: boolean;
|
||||||
tintColor: string;
|
color: string;
|
||||||
horizontal: boolean;
|
size: number;
|
||||||
}) => React.ReactNode;
|
}) => React.ReactNode;
|
||||||
style: StyleProp<ViewStyle>;
|
style: StyleProp<ViewStyle>;
|
||||||
};
|
};
|
||||||
@@ -25,7 +25,7 @@ export default function TabBarIcon({
|
|||||||
activeTintColor,
|
activeTintColor,
|
||||||
inactiveTintColor,
|
inactiveTintColor,
|
||||||
renderIcon,
|
renderIcon,
|
||||||
horizontal,
|
size,
|
||||||
style,
|
style,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
// We render the icon twice at the same position on top of each other:
|
// We render the icon twice at the same position on top of each other:
|
||||||
@@ -36,16 +36,16 @@ export default function TabBarIcon({
|
|||||||
{renderIcon({
|
{renderIcon({
|
||||||
route,
|
route,
|
||||||
focused: true,
|
focused: true,
|
||||||
horizontal,
|
size,
|
||||||
tintColor: activeTintColor,
|
color: activeTintColor,
|
||||||
})}
|
})}
|
||||||
</View>
|
</View>
|
||||||
<View style={[styles.icon, { opacity: inactiveOpacity }]}>
|
<View style={[styles.icon, { opacity: inactiveOpacity }]}>
|
||||||
{renderIcon({
|
{renderIcon({
|
||||||
route,
|
route,
|
||||||
focused: false,
|
focused: false,
|
||||||
horizontal,
|
size,
|
||||||
tintColor: inactiveTintColor,
|
color: inactiveTintColor,
|
||||||
})}
|
})}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -3,6 +3,44 @@
|
|||||||
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.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)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* initial version of native stack ([#102](https://github.com/react-navigation/navigation-ex/issues/102)) ([ba3f718](https://github.com/react-navigation/navigation-ex/commit/ba3f718))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.7](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.6...@react-navigation/compat@5.0.0-alpha.7) (2019-10-06)
|
# [5.0.0-alpha.7](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.6...@react-navigation/compat@5.0.0-alpha.7) (2019-10-06)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/compat
|
**Note:** Version bump only for package @react-navigation/compat
|
||||||
|
|||||||
@@ -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.7",
|
"version": "5.0.0-alpha.11",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -24,16 +24,16 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
"@react-navigation/routers": "^5.0.0-alpha.11"
|
||||||
},
|
},
|
||||||
"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.6.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||||
"react": "^16.8.3"
|
"react": "~16.8.3"
|
||||||
},
|
},
|
||||||
"@react-native-community/bob": {
|
"@react-native-community/bob": {
|
||||||
"source": "src",
|
"source": "src",
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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,63 @@
|
|||||||
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.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)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* initial version of native stack ([#102](https://github.com/react-navigation/navigation-ex/issues/102)) ([ba3f718](https://github.com/react-navigation/navigation-ex/commit/ba3f718))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.13...@react-navigation/core@5.0.0-alpha.14) (2019-10-06)
|
# [5.0.0-alpha.14](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.13...@react-navigation/core@5.0.0-alpha.14) (2019-10-06)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/core
|
**Note:** Version bump only for package @react-navigation/core
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"react-native",
|
"react-native",
|
||||||
"react-navigation"
|
"react-navigation"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.14",
|
"version": "5.0.0-alpha.19",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -40,13 +40,13 @@
|
|||||||
"@types/react": "^16.9.4",
|
"@types/react": "^16.9.4",
|
||||||
"@types/shortid": "^0.0.29",
|
"@types/shortid": "^0.0.29",
|
||||||
"del-cli": "^3.0.0",
|
"del-cli": "^3.0.0",
|
||||||
"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.6.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"react": "^16.8.3"
|
"react": "~16.8.3"
|
||||||
},
|
},
|
||||||
"@react-native-community/bob": {
|
"@react-native-community/bob": {
|
||||||
"source": "src",
|
"source": "src",
|
||||||
|
|||||||
@@ -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: [
|
||||||
|
|||||||
@@ -233,6 +233,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 +243,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'],
|
||||||
@@ -367,10 +369,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'],
|
||||||
@@ -106,6 +107,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 +205,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 +256,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 +268,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 +373,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 +426,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 +465,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 +480,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'],
|
||||||
@@ -470,6 +538,7 @@ it('updates route params with setParams applied to parent', () => {
|
|||||||
{ key: 'bar', name: 'bar' },
|
{ key: 'bar', name: 'bar' },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
});
|
});
|
||||||
|
|
||||||
act(() => setParams({ age: 25 }));
|
act(() => setParams({ age: 25 }));
|
||||||
@@ -484,6 +553,7 @@ it('updates route params with setParams applied to parent', () => {
|
|||||||
{ key: 'bar', name: 'bar' },
|
{ key: 'bar', name: 'bar' },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'test',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -516,6 +586,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 +594,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 +699,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'],
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
||||||
*
|
*
|
||||||
@@ -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> & {
|
||||||
/**
|
/**
|
||||||
@@ -376,7 +389,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 +407,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 +474,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 +527,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 =
|
||||||
|
|||||||
@@ -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(
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -3,6 +3,69 @@
|
|||||||
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.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)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* add flex: 1 to drawer content ([2b57702](https://github.com/react-navigation/navigation-ex/commit/2b57702))
|
||||||
|
* fix content component not rendering in drawer ([0a5fb3e](https://github.com/react-navigation/navigation-ex/commit/0a5fb3e))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* initial version of native stack ([#102](https://github.com/react-navigation/navigation-ex/issues/102)) ([ba3f718](https://github.com/react-navigation/navigation-ex/commit/ba3f718))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.12...@react-navigation/drawer@5.0.0-alpha.13) (2019-10-06)
|
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.12...@react-navigation/drawer@5.0.0-alpha.13) (2019-10-06)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/drawer
|
**Note:** Version bump only for package @react-navigation/drawer
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"material",
|
"material",
|
||||||
"drawer"
|
"drawer"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.13",
|
"version": "5.0.0-alpha.18",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -34,19 +34,19 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
"@react-navigation/routers": "^5.0.0-alpha.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
"@types/react": "^16.9.4",
|
"@types/react": "^16.9.4",
|
||||||
"@types/react-native": "^0.60.17",
|
"@types/react-native": "^0.60.17",
|
||||||
"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-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": "^1.0.0-alpha.22",
|
"react-native-screens": "^2.0.0-alpha.6",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.6.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
@@ -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"
|
"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",
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ export {
|
|||||||
/**
|
/**
|
||||||
* Views
|
* Views
|
||||||
*/
|
*/
|
||||||
export { default as DrawerNavigatorItems } from './views/DrawerNavigatorItems';
|
export { default as DrawerItem } from './views/DrawerItem';
|
||||||
export { default as DrawerSidebar } from './views/DrawerSidebar';
|
export { default as DrawerItemList } from './views/DrawerItemList';
|
||||||
|
export { default as DrawerContent } from './views/DrawerContent';
|
||||||
export { default as DrawerView } from './views/DrawerView';
|
export { default as DrawerView } from './views/DrawerView';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,5 +24,6 @@ export { default as DrawerGestureContext } from './utils/DrawerGestureContext';
|
|||||||
export {
|
export {
|
||||||
DrawerNavigationOptions,
|
DrawerNavigationOptions,
|
||||||
DrawerNavigationProp,
|
DrawerNavigationProp,
|
||||||
DrawerNavigationItemsProps,
|
DrawerContentOptions,
|
||||||
|
DrawerContentComponentProps,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|||||||
@@ -12,16 +12,11 @@ import { PanGestureHandler } from 'react-native-gesture-handler';
|
|||||||
|
|
||||||
export type Scene = {
|
export type Scene = {
|
||||||
route: Route<string>;
|
route: Route<string>;
|
||||||
index: number;
|
|
||||||
focused: boolean;
|
focused: boolean;
|
||||||
tintColor?: string;
|
color?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DrawerNavigationConfig = {
|
export type DrawerNavigationConfig<T = DrawerContentOptions> = {
|
||||||
/**
|
|
||||||
* Custom background color for the drawer. Defaults to `white`.
|
|
||||||
*/
|
|
||||||
drawerBackgroundColor: string;
|
|
||||||
/**
|
/**
|
||||||
* Position of the drawer on the screen. Defaults to `left`.
|
* Position of the drawer on the screen. Defaults to `left`.
|
||||||
*/
|
*/
|
||||||
@@ -33,11 +28,6 @@ export type DrawerNavigationConfig = {
|
|||||||
* - `slide`: Both the screen and the drawer slide on swipe to reveal the drawer.
|
* - `slide`: Both the screen and the drawer slide on swipe to reveal the drawer.
|
||||||
*/
|
*/
|
||||||
drawerType: 'front' | 'back' | 'slide';
|
drawerType: 'front' | 'back' | 'slide';
|
||||||
/**
|
|
||||||
* Number or a function which returns the width of the drawer.
|
|
||||||
* If a function is provided, it'll be called again when the screen's dimensions change.
|
|
||||||
*/
|
|
||||||
drawerWidth: number | (() => number);
|
|
||||||
/**
|
/**
|
||||||
* How far from the edge of the screen the swipe gesture should activate.
|
* How far from the edge of the screen the swipe gesture should activate.
|
||||||
*/
|
*/
|
||||||
@@ -77,54 +67,56 @@ export type DrawerNavigationConfig = {
|
|||||||
* 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.
|
* Custom component used to render as the content of the drawer, for example, navigation items.
|
||||||
* Defaults to `DrawerItems`.
|
* Defaults to `DrawerItems`.
|
||||||
*/
|
*/
|
||||||
contentComponent: React.ComponentType<ContentComponentProps>;
|
contentComponent: React.ComponentType<DrawerContentComponentProps<T>>;
|
||||||
/**
|
/**
|
||||||
* Options for the content component which will be passed as props.
|
* Options for the content component which will be passed as props.
|
||||||
*/
|
*/
|
||||||
contentOptions?: object;
|
contentOptions?: T;
|
||||||
/**
|
/**
|
||||||
* Style object for the component wrapping the screen content.
|
* Style object for the component wrapping the screen content.
|
||||||
*/
|
*/
|
||||||
sceneContainerStyle?: StyleProp<ViewStyle>;
|
sceneContainerStyle?: StyleProp<ViewStyle>;
|
||||||
style?: StyleProp<ViewStyle>;
|
/**
|
||||||
|
* Style object for the drawer component.
|
||||||
|
* You can pass a custom background color for a drawer or a custom width here.
|
||||||
|
*/
|
||||||
|
drawerStyle?: StyleProp<ViewStyle>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DrawerNavigationOptions = {
|
export type DrawerNavigationOptions = {
|
||||||
title?: string;
|
title?: string;
|
||||||
drawerLabel?:
|
drawerLabel?:
|
||||||
| string
|
| string
|
||||||
| ((props: { tintColor?: string; focused: boolean }) => React.ReactElement);
|
| ((props: { color: string; focused: boolean }) => React.ReactNode);
|
||||||
drawerIcon?: (props: {
|
drawerIcon?: (props: {
|
||||||
tintColor?: string;
|
color: string;
|
||||||
|
size: number;
|
||||||
focused: boolean;
|
focused: boolean;
|
||||||
}) => React.ReactElement;
|
}) => React.ReactNode;
|
||||||
drawerLockMode?: 'unlocked' | 'locked-closed' | 'locked-open';
|
drawerLockMode?: 'unlocked' | 'locked-closed' | 'locked-open';
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ContentComponentProps = DrawerNavigationItemsProps & {
|
export type DrawerContentComponentProps<T = DrawerContentOptions> = T & {
|
||||||
|
state: DrawerNavigationState;
|
||||||
navigation: NavigationHelpers<ParamListBase>;
|
navigation: NavigationHelpers<ParamListBase>;
|
||||||
descriptors: { [key: string]: any };
|
descriptors: DrawerDescriptorMap;
|
||||||
/**
|
/**
|
||||||
* Animated node which represents the current progress of the drawer's open state.
|
* Animated node which represents the current progress of the drawer's open state.
|
||||||
* `0` is closed, `1` is open.
|
* `0` is closed, `1` is open.
|
||||||
*/
|
*/
|
||||||
drawerOpenProgress: Animated.Node<number>;
|
progress: Animated.Node<number>;
|
||||||
|
/**
|
||||||
|
* Position of the drawer on the screen.
|
||||||
|
*/
|
||||||
|
drawerPosition: 'left' | 'right';
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DrawerNavigationItemsProps = {
|
export type DrawerContentOptions = {
|
||||||
/**
|
|
||||||
* The array of routes, can be modified or overridden to control what's shown in the drawer.
|
|
||||||
*/
|
|
||||||
items: Route<string>[];
|
|
||||||
/**
|
|
||||||
* Route key identifying the currently active route.
|
|
||||||
*/
|
|
||||||
activeItemKey?: string | null;
|
|
||||||
/**
|
/**
|
||||||
* Color for the icon and label in the active item in the drawer.
|
* Color for the icon and label in the active item in the drawer.
|
||||||
*/
|
*/
|
||||||
@@ -141,37 +133,22 @@ export type DrawerNavigationItemsProps = {
|
|||||||
* Background color for the inactive items in the drawer.
|
* Background color for the inactive items in the drawer.
|
||||||
*/
|
*/
|
||||||
inactiveBackgroundColor?: string;
|
inactiveBackgroundColor?: string;
|
||||||
/**
|
|
||||||
* Style object for the content section.
|
|
||||||
*/
|
|
||||||
itemsContainerStyle?: ViewStyle;
|
|
||||||
/**
|
/**
|
||||||
* Style object for the single item, which can contain an icon and/or a label.
|
* Style object for the single item, which can contain an icon and/or a label.
|
||||||
*/
|
*/
|
||||||
itemStyle?: StyleProp<ViewStyle>;
|
itemStyle?: StyleProp<ViewStyle>;
|
||||||
/**
|
/**
|
||||||
* Style object to overwrite `Text` style inside content section which renders a label.
|
* Style object to apply to the `Text` inside content section which renders a label.
|
||||||
*/
|
*/
|
||||||
labelStyle?: StyleProp<TextStyle>;
|
labelStyle?: StyleProp<TextStyle>;
|
||||||
/**
|
/**
|
||||||
* Style object to overwrite `Text` style of the active label.
|
* Style object for the content section.
|
||||||
*/
|
*/
|
||||||
activeLabelStyle?: StyleProp<TextStyle>;
|
contentContainerStyle?: StyleProp<ViewStyle>;
|
||||||
/**
|
/**
|
||||||
* Style object to overwrite `Text` style of the inactive label.
|
* Style object for the wrapper view.
|
||||||
*/
|
*/
|
||||||
inactiveLabelStyle?: StyleProp<TextStyle>;
|
style?: StyleProp<ViewStyle>;
|
||||||
/**
|
|
||||||
* Style object for the wrapper `View` of the icon.
|
|
||||||
*/
|
|
||||||
iconContainerStyle?: StyleProp<ViewStyle>;
|
|
||||||
/**
|
|
||||||
* Position of the drawer on the screen.
|
|
||||||
*/
|
|
||||||
drawerPosition: 'left' | 'right';
|
|
||||||
getLabel: (scene: Scene) => React.ReactNode;
|
|
||||||
renderIcon: (scene: Scene) => React.ReactNode;
|
|
||||||
onItemPress: (scene: { route: Route<string>; focused: boolean }) => void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DrawerNavigationEventMap = {
|
export type DrawerNavigationEventMap = {
|
||||||
|
|||||||
@@ -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={[
|
||||||
|
|||||||
36
packages/drawer/src/views/DrawerContent.tsx
Normal file
36
packages/drawer/src/views/DrawerContent.tsx
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { ScrollView, StyleSheet } from 'react-native';
|
||||||
|
import { useSafeArea } from 'react-native-safe-area-context';
|
||||||
|
import DrawerItemList from './DrawerItemList';
|
||||||
|
import { DrawerContentComponentProps } from '../types';
|
||||||
|
|
||||||
|
export default function DrawerContent({
|
||||||
|
contentContainerStyle,
|
||||||
|
style,
|
||||||
|
drawerPosition,
|
||||||
|
...rest
|
||||||
|
}: DrawerContentComponentProps) {
|
||||||
|
const insets = useSafeArea();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ScrollView
|
||||||
|
contentContainerStyle={[
|
||||||
|
{
|
||||||
|
paddingTop: insets.top + 4,
|
||||||
|
paddingLeft: drawerPosition === 'left' ? insets.left : 0,
|
||||||
|
paddingRight: drawerPosition === 'right' ? insets.right : 0,
|
||||||
|
},
|
||||||
|
contentContainerStyle,
|
||||||
|
]}
|
||||||
|
style={[styles.container, style]}
|
||||||
|
>
|
||||||
|
<DrawerItemList {...rest} />
|
||||||
|
</ScrollView>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
139
packages/drawer/src/views/DrawerItem.tsx
Normal file
139
packages/drawer/src/views/DrawerItem.tsx
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import {
|
||||||
|
Text,
|
||||||
|
View,
|
||||||
|
StyleSheet,
|
||||||
|
StyleProp,
|
||||||
|
ViewStyle,
|
||||||
|
TextStyle,
|
||||||
|
} from 'react-native';
|
||||||
|
import TouchableItem from './TouchableItem';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
/**
|
||||||
|
* The label text of the item.
|
||||||
|
*/
|
||||||
|
label:
|
||||||
|
| string
|
||||||
|
| ((props: { focused: boolean; color: string }) => React.ReactNode);
|
||||||
|
/**
|
||||||
|
* Icon to display for the `DrawerItem`.
|
||||||
|
*/
|
||||||
|
icon?: (props: {
|
||||||
|
focused: boolean;
|
||||||
|
size: number;
|
||||||
|
color: string;
|
||||||
|
}) => React.ReactNode;
|
||||||
|
/**
|
||||||
|
* Whether to highlight the drawer item as active.
|
||||||
|
*/
|
||||||
|
focused?: boolean;
|
||||||
|
/**
|
||||||
|
* Function to execute on press.
|
||||||
|
*/
|
||||||
|
onPress: () => void;
|
||||||
|
/**
|
||||||
|
* Color for the icon and label when the item is active.
|
||||||
|
*/
|
||||||
|
activeTintColor?: string;
|
||||||
|
/**
|
||||||
|
* Color for the icon and label when the item is inactive.
|
||||||
|
*/
|
||||||
|
inactiveTintColor?: string;
|
||||||
|
/**
|
||||||
|
* Background color for item when its active.
|
||||||
|
*/
|
||||||
|
activeBackgroundColor?: string;
|
||||||
|
/**
|
||||||
|
* Background color for item when its inactive.
|
||||||
|
*/
|
||||||
|
inactiveBackgroundColor?: string;
|
||||||
|
/**
|
||||||
|
* Style object for the label element.
|
||||||
|
*/
|
||||||
|
labelStyle?: StyleProp<TextStyle>;
|
||||||
|
/**
|
||||||
|
* Style object for the wrapper element.
|
||||||
|
*/
|
||||||
|
style?: StyleProp<ViewStyle>;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A component used to show an action item with an icon and a label in a navigation drawer.
|
||||||
|
*/
|
||||||
|
export default function DrawerItem({
|
||||||
|
icon,
|
||||||
|
label,
|
||||||
|
focused = false,
|
||||||
|
activeTintColor = '#6200ee',
|
||||||
|
inactiveTintColor = 'rgba(0, 0, 0, .68)',
|
||||||
|
activeBackgroundColor = 'rgba(98, 0, 238, 0.12)',
|
||||||
|
inactiveBackgroundColor = 'transparent',
|
||||||
|
style,
|
||||||
|
onPress,
|
||||||
|
...rest
|
||||||
|
}: Props) {
|
||||||
|
const { borderRadius = 4 } = StyleSheet.flatten(style || {});
|
||||||
|
const color = focused ? activeTintColor : inactiveTintColor;
|
||||||
|
const backgroundColor = focused
|
||||||
|
? activeBackgroundColor
|
||||||
|
: inactiveBackgroundColor;
|
||||||
|
|
||||||
|
const iconNode = icon ? icon({ size: 24, focused, color }) : null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
collapsable={false}
|
||||||
|
{...rest}
|
||||||
|
style={[styles.container, { borderRadius, backgroundColor }, style]}
|
||||||
|
>
|
||||||
|
<TouchableItem
|
||||||
|
borderless
|
||||||
|
delayPressIn={0}
|
||||||
|
onPress={onPress}
|
||||||
|
style={[styles.wrapper, { borderRadius }]}
|
||||||
|
accessibilityTraits={focused ? ['button', 'selected'] : 'button'}
|
||||||
|
accessibilityComponentType="button"
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityStates={focused ? ['selected'] : []}
|
||||||
|
>
|
||||||
|
<React.Fragment>
|
||||||
|
{iconNode}
|
||||||
|
{typeof label === 'function' ? (
|
||||||
|
label({ color, focused })
|
||||||
|
) : (
|
||||||
|
<Text
|
||||||
|
numberOfLines={1}
|
||||||
|
style={[
|
||||||
|
styles.label,
|
||||||
|
{
|
||||||
|
color,
|
||||||
|
fontWeight: '500',
|
||||||
|
marginLeft: iconNode ? 32 : 0,
|
||||||
|
marginVertical: 5,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</React.Fragment>
|
||||||
|
</TouchableItem>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
marginHorizontal: 10,
|
||||||
|
marginVertical: 4,
|
||||||
|
},
|
||||||
|
wrapper: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
padding: 8,
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
marginRight: 32,
|
||||||
|
},
|
||||||
|
});
|
||||||
67
packages/drawer/src/views/DrawerItemList.tsx
Normal file
67
packages/drawer/src/views/DrawerItemList.tsx
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { CommonActions } from '@react-navigation/core';
|
||||||
|
import {
|
||||||
|
DrawerActions,
|
||||||
|
DrawerNavigationState,
|
||||||
|
} from '@react-navigation/routers';
|
||||||
|
import DrawerItem from './DrawerItem';
|
||||||
|
import {
|
||||||
|
DrawerNavigationHelpers,
|
||||||
|
DrawerDescriptorMap,
|
||||||
|
DrawerContentOptions,
|
||||||
|
} from '../types';
|
||||||
|
|
||||||
|
type Props = Omit<DrawerContentOptions, 'contentContainerStyle' | 'style'> & {
|
||||||
|
state: DrawerNavigationState;
|
||||||
|
navigation: DrawerNavigationHelpers;
|
||||||
|
descriptors: DrawerDescriptorMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Component that renders the navigation list in the drawer.
|
||||||
|
*/
|
||||||
|
export default function DrawerItemList({
|
||||||
|
state,
|
||||||
|
navigation,
|
||||||
|
descriptors,
|
||||||
|
activeTintColor,
|
||||||
|
inactiveTintColor,
|
||||||
|
activeBackgroundColor,
|
||||||
|
inactiveBackgroundColor,
|
||||||
|
itemStyle,
|
||||||
|
labelStyle,
|
||||||
|
}: Props) {
|
||||||
|
return (state.routes.map((route, i) => {
|
||||||
|
const focused = i === state.index;
|
||||||
|
const { title, drawerLabel, drawerIcon } = descriptors[route.key].options;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DrawerItem
|
||||||
|
key={route.key}
|
||||||
|
label={
|
||||||
|
drawerLabel !== undefined
|
||||||
|
? drawerLabel
|
||||||
|
: title !== undefined
|
||||||
|
? title
|
||||||
|
: route.name
|
||||||
|
}
|
||||||
|
icon={drawerIcon}
|
||||||
|
focused={focused}
|
||||||
|
activeTintColor={activeTintColor}
|
||||||
|
inactiveTintColor={inactiveTintColor}
|
||||||
|
activeBackgroundColor={activeBackgroundColor}
|
||||||
|
inactiveBackgroundColor={inactiveBackgroundColor}
|
||||||
|
labelStyle={labelStyle}
|
||||||
|
style={itemStyle}
|
||||||
|
onPress={() => {
|
||||||
|
navigation.dispatch({
|
||||||
|
...(focused
|
||||||
|
? DrawerActions.closeDrawer()
|
||||||
|
: CommonActions.navigate(route.name)),
|
||||||
|
target: state.key,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}) as React.ReactNode) as React.ReactElement;
|
||||||
|
}
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
import * as React from 'react';
|
|
||||||
import { View, Text, StyleSheet } from 'react-native';
|
|
||||||
import { useSafeArea } from 'react-native-safe-area-context';
|
|
||||||
|
|
||||||
import TouchableItem from './TouchableItem';
|
|
||||||
import { DrawerNavigationItemsProps } from '../types';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Component that renders the navigation list in the drawer.
|
|
||||||
*/
|
|
||||||
const DrawerNavigatorItems = ({
|
|
||||||
items,
|
|
||||||
activeItemKey,
|
|
||||||
activeTintColor,
|
|
||||||
activeBackgroundColor,
|
|
||||||
inactiveTintColor,
|
|
||||||
inactiveBackgroundColor,
|
|
||||||
getLabel,
|
|
||||||
renderIcon,
|
|
||||||
onItemPress,
|
|
||||||
itemsContainerStyle,
|
|
||||||
itemStyle,
|
|
||||||
labelStyle,
|
|
||||||
activeLabelStyle,
|
|
||||||
inactiveLabelStyle,
|
|
||||||
iconContainerStyle,
|
|
||||||
drawerPosition,
|
|
||||||
}: DrawerNavigationItemsProps) => {
|
|
||||||
const insets = useSafeArea();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View style={[styles.container, itemsContainerStyle]}>
|
|
||||||
{items.map((route, index: number) => {
|
|
||||||
const focused = activeItemKey === route.key;
|
|
||||||
const color = focused ? activeTintColor : inactiveTintColor;
|
|
||||||
const backgroundColor = focused
|
|
||||||
? activeBackgroundColor
|
|
||||||
: inactiveBackgroundColor;
|
|
||||||
const scene = { route, index, focused, tintColor: color };
|
|
||||||
const icon = renderIcon(scene);
|
|
||||||
const label = getLabel(scene);
|
|
||||||
const accessibilityLabel =
|
|
||||||
typeof label === 'string' ? label : undefined;
|
|
||||||
const extraLabelStyle = focused ? activeLabelStyle : inactiveLabelStyle;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<TouchableItem
|
|
||||||
key={route.key}
|
|
||||||
accessible
|
|
||||||
accessibilityLabel={accessibilityLabel}
|
|
||||||
onPress={() => {
|
|
||||||
onItemPress({ route, focused });
|
|
||||||
}}
|
|
||||||
delayPressIn={0}
|
|
||||||
>
|
|
||||||
<View
|
|
||||||
style={[
|
|
||||||
{
|
|
||||||
backgroundColor,
|
|
||||||
marginLeft: drawerPosition === 'left' ? insets.left : 0,
|
|
||||||
marginRight: drawerPosition === 'right' ? insets.right : 0,
|
|
||||||
},
|
|
||||||
styles.item,
|
|
||||||
itemStyle,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{icon ? (
|
|
||||||
<View
|
|
||||||
style={[
|
|
||||||
styles.icon,
|
|
||||||
focused ? null : styles.inactiveIcon,
|
|
||||||
iconContainerStyle,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{icon}
|
|
||||||
</View>
|
|
||||||
) : null}
|
|
||||||
{typeof label === 'string' ? (
|
|
||||||
<Text
|
|
||||||
style={[styles.label, { color }, labelStyle, extraLabelStyle]}
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
</Text>
|
|
||||||
) : (
|
|
||||||
label
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
</TouchableItem>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Material design specs - https://material.io/guidelines/patterns/navigation-drawer.html#navigation-drawer-specs */
|
|
||||||
DrawerNavigatorItems.defaultProps = {
|
|
||||||
activeTintColor: '#2196f3',
|
|
||||||
activeBackgroundColor: 'rgba(0, 0, 0, .04)',
|
|
||||||
inactiveTintColor: 'rgba(0, 0, 0, .87)',
|
|
||||||
inactiveBackgroundColor: 'transparent',
|
|
||||||
};
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
container: {
|
|
||||||
paddingVertical: 4,
|
|
||||||
},
|
|
||||||
item: {
|
|
||||||
flexDirection: 'row',
|
|
||||||
alignItems: 'center',
|
|
||||||
},
|
|
||||||
icon: {
|
|
||||||
marginHorizontal: 16,
|
|
||||||
width: 24,
|
|
||||||
alignItems: 'center',
|
|
||||||
},
|
|
||||||
inactiveIcon: {
|
|
||||||
/*
|
|
||||||
* Icons have 0.54 opacity according to guidelines
|
|
||||||
* 100/87 * 54 ~= 62
|
|
||||||
*/
|
|
||||||
opacity: 0.62,
|
|
||||||
},
|
|
||||||
label: {
|
|
||||||
margin: 16,
|
|
||||||
fontWeight: 'bold',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default DrawerNavigatorItems;
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
import * as React from 'react';
|
|
||||||
import { StyleSheet, View, ViewStyle, StyleProp } from 'react-native';
|
|
||||||
import Animated from 'react-native-reanimated';
|
|
||||||
import { Route, CommonActions } from '@react-navigation/core';
|
|
||||||
import {
|
|
||||||
DrawerActions,
|
|
||||||
DrawerNavigationState,
|
|
||||||
} from '@react-navigation/routers';
|
|
||||||
|
|
||||||
import {
|
|
||||||
Scene,
|
|
||||||
ContentComponentProps,
|
|
||||||
DrawerDescriptorMap,
|
|
||||||
DrawerNavigationHelpers,
|
|
||||||
} from '../types';
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
contentComponent?: React.ComponentType<ContentComponentProps>;
|
|
||||||
contentOptions?: object;
|
|
||||||
state: DrawerNavigationState;
|
|
||||||
navigation: DrawerNavigationHelpers;
|
|
||||||
descriptors: DrawerDescriptorMap;
|
|
||||||
drawerOpenProgress: Animated.Node<number>;
|
|
||||||
drawerPosition: 'left' | 'right';
|
|
||||||
style?: StyleProp<ViewStyle>;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Component that renders the sidebar screen of the drawer.
|
|
||||||
*/
|
|
||||||
class DrawerSidebar extends React.PureComponent<Props> {
|
|
||||||
private getScreenOptions = (routeKey: string) => {
|
|
||||||
const descriptor = this.props.descriptors[routeKey];
|
|
||||||
|
|
||||||
if (!descriptor.options) {
|
|
||||||
throw new Error(
|
|
||||||
'Cannot access screen descriptor options from drawer sidebar'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return descriptor.options;
|
|
||||||
};
|
|
||||||
|
|
||||||
private getLabel = ({ focused, tintColor, route }: Scene) => {
|
|
||||||
const { drawerLabel, title } = this.getScreenOptions(route.key);
|
|
||||||
if (drawerLabel) {
|
|
||||||
return typeof drawerLabel === 'function'
|
|
||||||
? drawerLabel({ tintColor, focused })
|
|
||||||
: drawerLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof title === 'string') {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
return route.name;
|
|
||||||
};
|
|
||||||
|
|
||||||
private renderIcon = ({ focused, tintColor, route }: Scene) => {
|
|
||||||
const { drawerIcon } = this.getScreenOptions(route.key);
|
|
||||||
if (drawerIcon) {
|
|
||||||
return typeof drawerIcon === 'function'
|
|
||||||
? drawerIcon({ tintColor, focused })
|
|
||||||
: drawerIcon;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
private handleItemPress = ({
|
|
||||||
route,
|
|
||||||
focused,
|
|
||||||
}: {
|
|
||||||
route: Route<string>;
|
|
||||||
focused: boolean;
|
|
||||||
}) => {
|
|
||||||
const { state, navigation } = this.props;
|
|
||||||
|
|
||||||
navigation.dispatch({
|
|
||||||
...(focused
|
|
||||||
? DrawerActions.closeDrawer()
|
|
||||||
: CommonActions.navigate(route.name)),
|
|
||||||
target: state.key,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const ContentComponent = this.props.contentComponent;
|
|
||||||
|
|
||||||
if (!ContentComponent) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { state } = this.props;
|
|
||||||
|
|
||||||
if (typeof state.index !== 'number') {
|
|
||||||
throw new Error(
|
|
||||||
'The index of the route should be state in the navigation state'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View style={[styles.container, this.props.style]}>
|
|
||||||
<ContentComponent
|
|
||||||
{...this.props.contentOptions}
|
|
||||||
navigation={this.props.navigation}
|
|
||||||
descriptors={this.props.descriptors}
|
|
||||||
drawerOpenProgress={this.props.drawerOpenProgress}
|
|
||||||
items={state.routes}
|
|
||||||
activeItemKey={
|
|
||||||
state.routes[state.index] ? state.routes[state.index].key : null
|
|
||||||
}
|
|
||||||
getLabel={this.getLabel}
|
|
||||||
renderIcon={this.renderIcon}
|
|
||||||
onItemPress={this.handleItemPress}
|
|
||||||
drawerPosition={this.props.drawerPosition}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default DrawerSidebar;
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
container: {
|
|
||||||
flex: 1,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -1,30 +1,35 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { Dimensions, StyleSheet, I18nManager, Platform } from 'react-native';
|
import {
|
||||||
import { SafeAreaProvider, useSafeArea } from 'react-native-safe-area-context';
|
Dimensions,
|
||||||
|
StyleSheet,
|
||||||
|
I18nManager,
|
||||||
|
Platform,
|
||||||
|
ScaledSize,
|
||||||
|
} from 'react-native';
|
||||||
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
||||||
// 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 { PanGestureHandler, ScrollView } from 'react-native-gesture-handler';
|
import { PanGestureHandler } from 'react-native-gesture-handler';
|
||||||
import {
|
import {
|
||||||
DrawerNavigationState,
|
DrawerNavigationState,
|
||||||
DrawerActions,
|
DrawerActions,
|
||||||
} from '@react-navigation/routers';
|
} from '@react-navigation/routers';
|
||||||
|
|
||||||
import DrawerSidebar from './DrawerSidebar';
|
|
||||||
import DrawerGestureContext from '../utils/DrawerGestureContext';
|
import DrawerGestureContext from '../utils/DrawerGestureContext';
|
||||||
import ResourceSavingScene from './ResourceSavingScene';
|
import ResourceSavingScene from './ResourceSavingScene';
|
||||||
import DrawerNavigatorItems from './DrawerNavigatorItems';
|
import DrawerContent from './DrawerContent';
|
||||||
import Drawer from './Drawer';
|
import Drawer from './Drawer';
|
||||||
import {
|
import {
|
||||||
DrawerDescriptorMap,
|
DrawerDescriptorMap,
|
||||||
DrawerNavigationConfig,
|
DrawerNavigationConfig,
|
||||||
ContentComponentProps,
|
|
||||||
DrawerNavigationHelpers,
|
DrawerNavigationHelpers,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
type Props = DrawerNavigationConfig & {
|
type Props = Omit<DrawerNavigationConfig, 'overlayColor'> & {
|
||||||
state: DrawerNavigationState;
|
state: DrawerNavigationState;
|
||||||
navigation: DrawerNavigationHelpers;
|
navigation: DrawerNavigationHelpers;
|
||||||
descriptors: DrawerDescriptorMap;
|
descriptors: DrawerDescriptorMap;
|
||||||
|
overlayColor: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
@@ -32,17 +37,25 @@ type State = {
|
|||||||
drawerWidth: number;
|
drawerWidth: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const DefaultContentComponent = (props: ContentComponentProps) => {
|
const getDefaultDrawerWidth = ({
|
||||||
const insets = useSafeArea();
|
height,
|
||||||
|
width,
|
||||||
|
}: {
|
||||||
|
height: number;
|
||||||
|
width: number;
|
||||||
|
}) => {
|
||||||
|
/*
|
||||||
|
* Default drawer width is screen width - header height
|
||||||
|
* with a max width of 280 on mobile and 320 on tablet
|
||||||
|
* https://material.io/guidelines/patterns/navigation-drawer.html
|
||||||
|
*/
|
||||||
|
const smallerAxisSize = Math.min(height, width);
|
||||||
|
const isLandscape = width > height;
|
||||||
|
const isTablet = smallerAxisSize >= 600;
|
||||||
|
const appBarHeight = Platform.OS === 'ios' ? (isLandscape ? 32 : 44) : 56;
|
||||||
|
const maxWidth = isTablet ? 320 : 280;
|
||||||
|
|
||||||
return (
|
return Math.min(smallerAxisSize - appBarHeight, maxWidth);
|
||||||
<ScrollView
|
|
||||||
alwaysBounceVertical={false}
|
|
||||||
contentContainerStyle={{ marginTop: insets.top }}
|
|
||||||
>
|
|
||||||
<DrawerNavigatorItems {...props} />
|
|
||||||
</ScrollView>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,25 +64,10 @@ const DefaultContentComponent = (props: ContentComponentProps) => {
|
|||||||
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,
|
||||||
drawerWidth: () => {
|
contentComponent: DrawerContent,
|
||||||
/*
|
|
||||||
* Default drawer width is screen width - header height
|
|
||||||
* with a max width of 280 on mobile and 320 on tablet
|
|
||||||
* https://material.io/guidelines/patterns/navigation-drawer.html
|
|
||||||
*/
|
|
||||||
const { height, width } = Dimensions.get('window');
|
|
||||||
const smallerAxisSize = Math.min(height, width);
|
|
||||||
const isLandscape = width > height;
|
|
||||||
const isTablet = smallerAxisSize >= 600;
|
|
||||||
const appBarHeight = Platform.OS === 'ios' ? (isLandscape ? 32 : 44) : 56;
|
|
||||||
const maxWidth = isTablet ? 320 : 280;
|
|
||||||
|
|
||||||
return Math.min(smallerAxisSize - appBarHeight, maxWidth);
|
|
||||||
},
|
|
||||||
contentComponent: DefaultContentComponent,
|
|
||||||
drawerPosition: I18nManager.isRTL ? 'right' : 'left',
|
drawerPosition: I18nManager.isRTL ? 'right' : 'left',
|
||||||
keyboardDismissMode: 'on-drag',
|
keyboardDismissMode: 'on-drag',
|
||||||
drawerBackgroundColor: 'white',
|
overlayColor: 'rgba(0, 0, 0, 0.5)',
|
||||||
drawerType: 'front',
|
drawerType: 'front',
|
||||||
hideStatusBar: false,
|
hideStatusBar: false,
|
||||||
statusBarAnimation: 'slide',
|
statusBarAnimation: 'slide',
|
||||||
@@ -88,10 +86,7 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
|||||||
|
|
||||||
state: State = {
|
state: State = {
|
||||||
loaded: [this.props.state.index],
|
loaded: [this.props.state.index],
|
||||||
drawerWidth:
|
drawerWidth: getDefaultDrawerWidth(Dimensions.get('window')),
|
||||||
typeof this.props.drawerWidth === 'function'
|
|
||||||
? this.props.drawerWidth()
|
|
||||||
: this.props.drawerWidth,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@@ -126,11 +121,8 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
|||||||
navigation.emit({ type: 'drawerClose' });
|
navigation.emit({ type: 'drawerClose' });
|
||||||
};
|
};
|
||||||
|
|
||||||
private updateWidth = () => {
|
private updateWidth = ({ window }: { window: ScaledSize }) => {
|
||||||
const drawerWidth =
|
const drawerWidth = getDefaultDrawerWidth(window);
|
||||||
typeof this.props.drawerWidth === 'function'
|
|
||||||
? this.props.drawerWidth()
|
|
||||||
: this.props.drawerWidth;
|
|
||||||
|
|
||||||
if (this.state.drawerWidth !== drawerWidth) {
|
if (this.state.drawerWidth !== drawerWidth) {
|
||||||
this.setState({ drawerWidth });
|
this.setState({ drawerWidth });
|
||||||
@@ -138,47 +130,59 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private renderNavigationView = ({ progress }: any) => {
|
private renderNavigationView = ({ progress }: any) => {
|
||||||
return <DrawerSidebar drawerOpenProgress={progress} {...this.props} />;
|
const {
|
||||||
|
state,
|
||||||
|
navigation,
|
||||||
|
descriptors,
|
||||||
|
drawerPosition,
|
||||||
|
contentComponent: ContentComponent,
|
||||||
|
contentOptions,
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ContentComponent
|
||||||
|
progress={progress}
|
||||||
|
state={state}
|
||||||
|
navigation={navigation}
|
||||||
|
descriptors={descriptors}
|
||||||
|
drawerPosition={drawerPosition}
|
||||||
|
{...contentOptions}
|
||||||
|
/>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
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) => {
|
||||||
@@ -192,9 +196,9 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
|||||||
descriptors,
|
descriptors,
|
||||||
drawerType,
|
drawerType,
|
||||||
drawerPosition,
|
drawerPosition,
|
||||||
drawerBackgroundColor,
|
|
||||||
overlayColor,
|
overlayColor,
|
||||||
sceneContainerStyle,
|
sceneContainerStyle,
|
||||||
|
drawerStyle,
|
||||||
edgeWidth,
|
edgeWidth,
|
||||||
minSwipeDistance,
|
minSwipeDistance,
|
||||||
hideStatusBar,
|
hideStatusBar,
|
||||||
@@ -202,6 +206,8 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
|||||||
gestureHandlerProps,
|
gestureHandlerProps,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
const { drawerWidth } = this.state;
|
||||||
|
|
||||||
const activeKey = state.routes[state.index].key;
|
const activeKey = state.routes[state.index].key;
|
||||||
const { drawerLockMode } = descriptors[activeKey].options;
|
const { drawerLockMode } = descriptors[activeKey].options;
|
||||||
|
|
||||||
@@ -228,13 +234,8 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
|||||||
drawerType={drawerType}
|
drawerType={drawerType}
|
||||||
drawerPosition={drawerPosition}
|
drawerPosition={drawerPosition}
|
||||||
sceneContainerStyle={sceneContainerStyle}
|
sceneContainerStyle={sceneContainerStyle}
|
||||||
drawerStyle={{
|
drawerStyle={[{ width: drawerWidth }, drawerStyle]}
|
||||||
backgroundColor: drawerBackgroundColor || 'white',
|
overlayStyle={{ backgroundColor: overlayColor }}
|
||||||
width: this.state.drawerWidth,
|
|
||||||
}}
|
|
||||||
overlayStyle={{
|
|
||||||
backgroundColor: overlayColor || 'rgba(0, 0, 0, 0.5)',
|
|
||||||
}}
|
|
||||||
swipeEdgeWidth={edgeWidth}
|
swipeEdgeWidth={edgeWidth}
|
||||||
swipeDistanceThreshold={minSwipeDistance}
|
swipeDistanceThreshold={minSwipeDistance}
|
||||||
hideStatusBar={hideStatusBar}
|
hideStatusBar={hideStatusBar}
|
||||||
|
|||||||
@@ -3,6 +3,58 @@
|
|||||||
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/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)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* block GH interactions in Native Stack example ([#126](https://github.com/react-navigation/navigation-ex/issues/126)) ([386d1c0](https://github.com/react-navigation/navigation-ex/commit/386d1c0))
|
||||||
|
* make it possible to run the example on web ([7a901af](https://github.com/react-navigation/navigation-ex/commit/7a901af))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* initial version of native stack ([#102](https://github.com/react-navigation/navigation-ex/issues/102)) ([ba3f718](https://github.com/react-navigation/navigation-ex/commit/ba3f718))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.12](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.11...@react-navigation/example@5.0.0-alpha.12) (2019-10-06)
|
# [5.0.0-alpha.12](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.11...@react-navigation/example@5.0.0-alpha.12) (2019-10-06)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -151,6 +151,7 @@
|
|||||||
<orderEntry type="library" name="Gradle: com.facebook.soloader:soloader:0.6.0@aar" level="project" />
|
<orderEntry type="library" name="Gradle: com.facebook.soloader:soloader:0.6.0@aar" level="project" />
|
||||||
<orderEntry type="library" name="Gradle: io.nlopez.smartlocation:library:3.2.11@aar" level="project" />
|
<orderEntry type="library" name="Gradle: io.nlopez.smartlocation:library:3.2.11@aar" level="project" />
|
||||||
<orderEntry type="library" name="Gradle: com.facebook.fresco:fbcore:1.10.0@aar" level="project" />
|
<orderEntry type="library" name="Gradle: com.facebook.fresco:fbcore:1.10.0@aar" level="project" />
|
||||||
|
<orderEntry type="module" module-name="react-native-screens" />
|
||||||
<orderEntry type="module" module-name="react-native-reanimated" />
|
<orderEntry type="module" module-name="react-native-reanimated" />
|
||||||
<orderEntry type="module" module-name="react-native-gesture-handler" />
|
<orderEntry type="module" module-name="react-native-gesture-handler" />
|
||||||
<orderEntry type="module" module-name="expo-permissions" />
|
<orderEntry type="module" module-name="expo-permissions" />
|
||||||
|
|||||||
@@ -139,6 +139,8 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation project(':react-native-safe-area-context')
|
||||||
|
implementation project(':react-native-screens')
|
||||||
implementation project(':react-native-reanimated')
|
implementation project(':react-native-reanimated')
|
||||||
implementation project(':react-native-gesture-handler')
|
implementation project(':react-native-gesture-handler')
|
||||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.reactnavigationexample;
|
|||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
import com.facebook.react.ReactApplication;
|
import com.facebook.react.ReactApplication;
|
||||||
|
import com.th3rdwave.safeareacontext.SafeAreaContextPackage;
|
||||||
|
import com.swmansion.rnscreens.RNScreensPackage;
|
||||||
import com.swmansion.reanimated.ReanimatedPackage;
|
import com.swmansion.reanimated.ReanimatedPackage;
|
||||||
import com.facebook.react.ReactNativeHost;
|
import com.facebook.react.ReactNativeHost;
|
||||||
import com.facebook.react.ReactPackage;
|
import com.facebook.react.ReactPackage;
|
||||||
@@ -39,6 +41,8 @@ public class MainApplication extends Application implements ReactApplication {
|
|||||||
protected List<ReactPackage> getPackages() {
|
protected List<ReactPackage> getPackages() {
|
||||||
return Arrays.<ReactPackage>asList(
|
return Arrays.<ReactPackage>asList(
|
||||||
new MainReactPackage(),
|
new MainReactPackage(),
|
||||||
|
new SafeAreaContextPackage(),
|
||||||
|
new RNScreensPackage(),
|
||||||
new ReanimatedPackage(),
|
new ReanimatedPackage(),
|
||||||
new RNGestureHandlerPackage(),
|
new RNGestureHandlerPackage(),
|
||||||
new ModuleRegistryAdapter(mModuleRegistryProvider)
|
new ModuleRegistryAdapter(mModuleRegistryProvider)
|
||||||
|
|||||||
@@ -16,3 +16,6 @@
|
|||||||
# This option should only be used with decoupled projects. More details, visit
|
# This option should only be used with decoupled projects. More details, visit
|
||||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||||
# org.gradle.parallel=true
|
# org.gradle.parallel=true
|
||||||
|
|
||||||
|
android.useAndroidX=true
|
||||||
|
android.enableJetifier=true
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
## This file must *NOT* be checked into Version Control Systems,
|
|
||||||
# as it contains information specific to your local configuration.
|
|
||||||
#
|
|
||||||
# Location of the SDK. This is only used by Gradle.
|
|
||||||
# For customization when using a Version Control System, please read the
|
|
||||||
# header note.
|
|
||||||
#Wed Sep 18 15:42:44 CEST 2019
|
|
||||||
sdk.dir=/Users/osdnk/Library/Android/sdk
|
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
apply from: '../node_modules/react-native-unimodules/gradle.groovy'
|
apply from: '../node_modules/react-native-unimodules/gradle.groovy'
|
||||||
|
include ':react-native-safe-area-context'
|
||||||
|
project(':react-native-safe-area-context').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-safe-area-context/android')
|
||||||
|
include ':react-native-screens'
|
||||||
|
project(':react-native-screens').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-screens/android')
|
||||||
include ':react-native-reanimated'
|
include ':react-native-reanimated'
|
||||||
project(':react-native-reanimated').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-reanimated/android')
|
project(':react-native-reanimated').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-reanimated/android')
|
||||||
includeUnimodulesProjects()
|
includeUnimodulesProjects()
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ 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'
|
||||||
|
|
||||||
use_unimodules!
|
use_unimodules!
|
||||||
|
pod 'react-native-safe-area-context', :path => '../node_modules/react-native-safe-area-context'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
PODS:
|
PODS:
|
||||||
- boost-for-react-native (1.63.0)
|
- boost-for-react-native (1.63.0)
|
||||||
- DoubleConversion (1.1.6)
|
- DoubleConversion (1.1.6)
|
||||||
- EXAppLoaderProvider (6.0.0)
|
- EXAppLoaderProvider (7.0.0)
|
||||||
- EXConstants (6.0.0):
|
- EXConstants (7.0.0):
|
||||||
- UMConstantsInterface
|
- UMConstantsInterface
|
||||||
- UMCore
|
- UMCore
|
||||||
- EXFileSystem (6.0.2):
|
- EXFileSystem (7.0.0):
|
||||||
- UMCore
|
- UMCore
|
||||||
- UMFileSystemInterface
|
- UMFileSystemInterface
|
||||||
- EXFont (6.0.1):
|
- EXFont (7.0.0):
|
||||||
- UMCore
|
- UMCore
|
||||||
- UMFontInterface
|
- UMFontInterface
|
||||||
- EXKeepAwake (6.0.0):
|
- EXKeepAwake (7.0.0):
|
||||||
- UMCore
|
- UMCore
|
||||||
- EXLinearGradient (6.0.0):
|
- EXLinearGradient (7.0.0):
|
||||||
- UMCore
|
- UMCore
|
||||||
- EXLocation (6.0.0):
|
- EXLocation (7.0.0):
|
||||||
- UMCore
|
- UMCore
|
||||||
- UMPermissionsInterface
|
- UMPermissionsInterface
|
||||||
- UMTaskManagerInterface
|
- UMTaskManagerInterface
|
||||||
- EXPermissions (6.0.0):
|
- EXPermissions (7.0.0):
|
||||||
- UMCore
|
- UMCore
|
||||||
- UMPermissionsInterface
|
- UMPermissionsInterface
|
||||||
- EXSQLite (6.0.0):
|
- EXSQLite (7.0.0):
|
||||||
- UMCore
|
- UMCore
|
||||||
- UMFileSystemInterface
|
- UMFileSystemInterface
|
||||||
- EXWebBrowser (6.0.0):
|
- EXWebBrowser (7.0.1):
|
||||||
- UMCore
|
- UMCore
|
||||||
- Folly (2018.10.22.00):
|
- Folly (2018.10.22.00):
|
||||||
- boost-for-react-native
|
- boost-for-react-native
|
||||||
@@ -34,6 +34,8 @@ PODS:
|
|||||||
- glog (0.3.5)
|
- glog (0.3.5)
|
||||||
- React (0.59.10):
|
- React (0.59.10):
|
||||||
- React/Core (= 0.59.10)
|
- React/Core (= 0.59.10)
|
||||||
|
- react-native-safe-area-context (0.3.6):
|
||||||
|
- React
|
||||||
- React/Core (0.59.10):
|
- React/Core (0.59.10):
|
||||||
- yoga (= 0.59.10.React)
|
- yoga (= 0.59.10.React)
|
||||||
- React/CxxBridge (0.59.10):
|
- React/CxxBridge (0.59.10):
|
||||||
@@ -89,23 +91,25 @@ PODS:
|
|||||||
- React/RCTBlob
|
- React/RCTBlob
|
||||||
- RNGestureHandler (1.3.0):
|
- RNGestureHandler (1.3.0):
|
||||||
- React
|
- React
|
||||||
- RNReanimated (1.1.0):
|
- RNReanimated (1.2.0):
|
||||||
- React
|
- React
|
||||||
- UMBarCodeScannerInterface (3.0.0)
|
- RNScreens (2.0.0-alpha.6):
|
||||||
- UMCameraInterface (3.0.0)
|
- React
|
||||||
- UMConstantsInterface (3.0.0)
|
- UMBarCodeScannerInterface (4.0.0)
|
||||||
- UMCore (3.0.2)
|
- UMCameraInterface (4.0.0)
|
||||||
- UMFaceDetectorInterface (3.0.0)
|
- UMConstantsInterface (4.0.0)
|
||||||
- UMFileSystemInterface (3.0.0)
|
- UMCore (4.0.0)
|
||||||
- UMFontInterface (3.0.0)
|
- UMFaceDetectorInterface (4.0.0)
|
||||||
- UMImageLoaderInterface (3.0.0)
|
- UMFileSystemInterface (4.0.0)
|
||||||
- UMPermissionsInterface (3.0.0)
|
- UMFontInterface (4.0.0)
|
||||||
- UMReactNativeAdapter (3.0.0):
|
- UMImageLoaderInterface (4.0.0)
|
||||||
|
- UMPermissionsInterface (4.0.0)
|
||||||
|
- UMReactNativeAdapter (5.0.0-alpha.0):
|
||||||
- React
|
- React
|
||||||
- UMCore
|
- UMCore
|
||||||
- UMFontInterface
|
- UMFontInterface
|
||||||
- UMSensorsInterface (3.0.0)
|
- UMSensorsInterface (4.0.0)
|
||||||
- UMTaskManagerInterface (3.0.0)
|
- UMTaskManagerInterface (4.0.0)
|
||||||
- yoga (0.59.10.React)
|
- yoga (0.59.10.React)
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
@@ -122,6 +126,7 @@ DEPENDENCIES:
|
|||||||
- EXWebBrowser (from `../node_modules/expo-web-browser/ios`)
|
- EXWebBrowser (from `../node_modules/expo-web-browser/ios`)
|
||||||
- Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`)
|
- Folly (from `../node_modules/react-native/third-party-podspecs/Folly.podspec`)
|
||||||
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
|
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
|
||||||
|
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
|
||||||
- React/Core (from `../node_modules/react-native`)
|
- React/Core (from `../node_modules/react-native`)
|
||||||
- React/CxxBridge (from `../node_modules/react-native`)
|
- React/CxxBridge (from `../node_modules/react-native`)
|
||||||
- React/DevSupport (from `../node_modules/react-native`)
|
- React/DevSupport (from `../node_modules/react-native`)
|
||||||
@@ -138,6 +143,7 @@ DEPENDENCIES:
|
|||||||
- React/RCTWebSocket (from `../node_modules/react-native`)
|
- React/RCTWebSocket (from `../node_modules/react-native`)
|
||||||
- RNGestureHandler (from `../node_modules/react-native-gesture-handler/RNGestureHandler.podspec`)
|
- RNGestureHandler (from `../node_modules/react-native-gesture-handler/RNGestureHandler.podspec`)
|
||||||
- RNReanimated (from `../node_modules/react-native-reanimated/RNReanimated.podspec`)
|
- RNReanimated (from `../node_modules/react-native-reanimated/RNReanimated.podspec`)
|
||||||
|
- RNScreens (from `../node_modules/react-native-screens/RNScreens.podspec`)
|
||||||
- UMBarCodeScannerInterface (from `../node_modules/unimodules-barcode-scanner-interface/ios`)
|
- UMBarCodeScannerInterface (from `../node_modules/unimodules-barcode-scanner-interface/ios`)
|
||||||
- UMCameraInterface (from `../node_modules/unimodules-camera-interface/ios`)
|
- UMCameraInterface (from `../node_modules/unimodules-camera-interface/ios`)
|
||||||
- UMConstantsInterface (from `../node_modules/unimodules-constants-interface/ios`)
|
- UMConstantsInterface (from `../node_modules/unimodules-constants-interface/ios`)
|
||||||
@@ -147,13 +153,13 @@ DEPENDENCIES:
|
|||||||
- UMFontInterface (from `../node_modules/unimodules-font-interface/ios`)
|
- UMFontInterface (from `../node_modules/unimodules-font-interface/ios`)
|
||||||
- UMImageLoaderInterface (from `../node_modules/unimodules-image-loader-interface/ios`)
|
- UMImageLoaderInterface (from `../node_modules/unimodules-image-loader-interface/ios`)
|
||||||
- UMPermissionsInterface (from `../node_modules/unimodules-permissions-interface/ios`)
|
- UMPermissionsInterface (from `../node_modules/unimodules-permissions-interface/ios`)
|
||||||
- "UMReactNativeAdapter (from `../node_modules/@unimodules/react-native-adapter/ios`)"
|
- "UMReactNativeAdapter (from `../node_modules/react-native-unimodules/node_modules/@unimodules/react-native-adapter/ios`)"
|
||||||
- UMSensorsInterface (from `../node_modules/unimodules-sensors-interface/ios`)
|
- UMSensorsInterface (from `../node_modules/unimodules-sensors-interface/ios`)
|
||||||
- UMTaskManagerInterface (from `../node_modules/unimodules-task-manager-interface/ios`)
|
- UMTaskManagerInterface (from `../node_modules/unimodules-task-manager-interface/ios`)
|
||||||
- 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:
|
||||||
@@ -195,10 +201,14 @@ EXTERNAL SOURCES:
|
|||||||
:podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec"
|
:podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec"
|
||||||
React:
|
React:
|
||||||
:path: "../node_modules/react-native"
|
:path: "../node_modules/react-native"
|
||||||
|
react-native-safe-area-context:
|
||||||
|
:path: "../node_modules/react-native-safe-area-context"
|
||||||
RNGestureHandler:
|
RNGestureHandler:
|
||||||
:podspec: "../node_modules/react-native-gesture-handler/RNGestureHandler.podspec"
|
:podspec: "../node_modules/react-native-gesture-handler/RNGestureHandler.podspec"
|
||||||
RNReanimated:
|
RNReanimated:
|
||||||
:podspec: "../node_modules/react-native-reanimated/RNReanimated.podspec"
|
:podspec: "../node_modules/react-native-reanimated/RNReanimated.podspec"
|
||||||
|
RNScreens:
|
||||||
|
:podspec: "../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"
|
||||||
@@ -228,7 +238,7 @@ EXTERNAL SOURCES:
|
|||||||
path: "../node_modules/unimodules-permissions-interface/ios"
|
path: "../node_modules/unimodules-permissions-interface/ios"
|
||||||
UMReactNativeAdapter:
|
UMReactNativeAdapter:
|
||||||
:path: !ruby/object:Pathname
|
:path: !ruby/object:Pathname
|
||||||
path: "../node_modules/@unimodules/react-native-adapter/ios"
|
path: "../node_modules/react-native-unimodules/node_modules/@unimodules/react-native-adapter/ios"
|
||||||
UMSensorsInterface:
|
UMSensorsInterface:
|
||||||
:path: !ruby/object:Pathname
|
:path: !ruby/object:Pathname
|
||||||
path: "../node_modules/unimodules-sensors-interface/ios"
|
path: "../node_modules/unimodules-sensors-interface/ios"
|
||||||
@@ -241,35 +251,37 @@ EXTERNAL SOURCES:
|
|||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
|
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
|
||||||
DoubleConversion: bb338842f62ab1d708ceb63ec3d999f0f3d98ecd
|
DoubleConversion: bb338842f62ab1d708ceb63ec3d999f0f3d98ecd
|
||||||
EXAppLoaderProvider: 7a8185228d8ba9e689a0e2d6d957fe9bdd49c8a0
|
EXAppLoaderProvider: 5d348813a9cf09b03bbe5b8b55437bc1bfbddbd1
|
||||||
EXConstants: 5d81e84ca71b9a552529889cc798b4a04e9e22b3
|
EXConstants: 31e5318521be6175009af6ccd3e97dedf39da96a
|
||||||
EXFileSystem: 091907902fcec9f9182b656fdead41a82f30986a
|
EXFileSystem: 7e53a2c30a2eb6987ba6d5158ab908f947523228
|
||||||
EXFont: c862449210fc86aa11d24a202cb22c71a0d39609
|
EXFont: 71d07dc5d2153db7d1a23f1e0cc1b6341d55c432
|
||||||
EXKeepAwake: e7cb6516675052b12a7d23291e33078b4239653a
|
EXKeepAwake: d4caf9a1a7691126ade4ca0b76592e93250a8f29
|
||||||
EXLinearGradient: 40781b77e58f844c8dc4ad310dc9755b4d3792a7
|
EXLinearGradient: ebfd46cb98a46330213e4945b96227d98f624054
|
||||||
EXLocation: 4eb76115832f08b1e78003b335c210e18fa60424
|
EXLocation: 452a1d9edceb1b93deb86fd785236606d33742dd
|
||||||
EXPermissions: 99e52dc3e5f8e55153f1958004f6df2a30a1f2f5
|
EXPermissions: df10ad83df2f6b647aec304619354f8ab48d5f63
|
||||||
EXSQLite: 8dab6a5ab1b78be7925073d6071eb22095d4dda6
|
EXSQLite: ddc1e6727bd7d36e649f07590fe3ae5511c1f039
|
||||||
EXWebBrowser: def838b95aa9d396f9ce71ace4e614ee16e7ee30
|
EXWebBrowser: 18924c3d2a3a1aa95d413672f058beff589c80f4
|
||||||
Folly: de497beb10f102453a1afa9edbf8cf8a251890de
|
Folly: de497beb10f102453a1afa9edbf8cf8a251890de
|
||||||
glog: aefd1eb5dda2ab95ba0938556f34b98e2da3a60d
|
glog: aefd1eb5dda2ab95ba0938556f34b98e2da3a60d
|
||||||
React: 36d0768f9e93be2473b37e7fa64f92c1d5341eef
|
React: 36d0768f9e93be2473b37e7fa64f92c1d5341eef
|
||||||
|
react-native-safe-area-context: e380a6f783ccaec848e2f3cc8eb205a62362950d
|
||||||
RNGestureHandler: 5329a942fce3d41c68b84c2c2276ce06a696d8b0
|
RNGestureHandler: 5329a942fce3d41c68b84c2c2276ce06a696d8b0
|
||||||
RNReanimated: 7a52c90473b5e81c13408d40d797b98387eaddde
|
RNReanimated: 1b52415c4302f198cb581282a0166690bad62c43
|
||||||
UMBarCodeScannerInterface: 84ea2d6b58ff0dc27ef9b68bab71286be18ee020
|
RNScreens: 73691421e207a57b85af0fea931e620b05a35e89
|
||||||
UMCameraInterface: 26b26005d1756a0d5f4f04f1e168e39ea9154535
|
UMBarCodeScannerInterface: d5a6fdc98ed6241225b0a8432a7f4e2b397668bc
|
||||||
UMConstantsInterface: 038bacb19de12b6fd328c589122c8dc977cccf61
|
UMCameraInterface: 68870a3197fee85bd5afca5609ba4a5b7257d19d
|
||||||
UMCore: 733094f43f7244c60ce1f0592d00013ed68fa52c
|
UMConstantsInterface: d25b8e8887ca7aaf568c06caf08f4d40734ee4ef
|
||||||
UMFaceDetectorInterface: c9c3ae4cb045421283667a1698c2f31331f55e3f
|
UMCore: 402cee150324974974f5c32b5404d8af65e4cff5
|
||||||
UMFileSystemInterface: e9adc71027017de38eaf7d05fa58b2848ecb3797
|
UMFaceDetectorInterface: 7b4f1a92f0c726b58b086296048efe193b570678
|
||||||
UMFontInterface: f0c5846977ee8a93d7cfa8ae7e666772c727d195
|
UMFileSystemInterface: aadb9a67aa6470d7ebc06cf04dc54fee6781ac48
|
||||||
UMImageLoaderInterface: 36e54e570acc4d720856f03ceebc441f73ea472c
|
UMFontInterface: 2d3c128285086bbed3d2a650f1d698323ef3b25a
|
||||||
UMPermissionsInterface: 938d010c74c43fcefc9bb990633a7c5a1631267e
|
UMImageLoaderInterface: 2829a7571a12d2e754c73c55ffe7e327d8402c7d
|
||||||
UMReactNativeAdapter: 131ea2b944ade8035f0b54c6570c405f6000548d
|
UMPermissionsInterface: b6a6e96db0f4011a25aaca14e6022529dd3d6e4e
|
||||||
UMSensorsInterface: 0ed023ce9b96f2ca6fada7bda05b7760da60b293
|
UMReactNativeAdapter: e93109c6de5ea830d4a78d08f3a65b8d33a143a3
|
||||||
UMTaskManagerInterface: 8664abd37a00715727e60df9ecd65e42ba47b548
|
UMSensorsInterface: cf59dd7602764a2419e00167429be3e4be39c61d
|
||||||
|
UMTaskManagerInterface: 1e70fe58b872355f0ecb44fb81bb1a16484047f0
|
||||||
yoga: 684513b14b03201579ba3cee20218c9d1298b0cc
|
yoga: 684513b14b03201579ba3cee20218c9d1298b0cc
|
||||||
|
|
||||||
PODFILE CHECKSUM: 41592ff50a43d56f905dbf9c7eded4b358264eba
|
PODFILE CHECKSUM: 1276a2dd000c142ccc03272023bb8a6b2d5b9933
|
||||||
|
|
||||||
COCOAPODS: 1.7.5
|
COCOAPODS: 1.8.3
|
||||||
|
|||||||
@@ -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.12",
|
"version": "5.0.0-alpha.17",
|
||||||
"private": true,
|
"private": true,
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
"nohoist": [
|
"nohoist": [
|
||||||
@@ -11,9 +11,11 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "expo start",
|
"start": "expo start",
|
||||||
|
"web": "expo start --web",
|
||||||
"native": "react-native start",
|
"native": "react-native start",
|
||||||
"android": "react-native run-android",
|
"android": "react-native run-android",
|
||||||
"ios": "react-native run-ios"
|
"ios": "react-native run-ios",
|
||||||
|
"postinstall": "jetify"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@expo/vector-icons": "^10.0.0",
|
"@expo/vector-icons": "^10.0.0",
|
||||||
@@ -21,26 +23,29 @@
|
|||||||
"expo": "^35.0.0",
|
"expo": "^35.0.0",
|
||||||
"expo-asset": "~7.0.0",
|
"expo-asset": "~7.0.0",
|
||||||
"query-string": "^6.8.3",
|
"query-string": "^6.8.3",
|
||||||
"react": "^16.8.3",
|
"react": "~16.8.3",
|
||||||
"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-safe-area-context": "~0.3.6",
|
"react-native-safe-area-context": "~0.3.6",
|
||||||
"react-native-screens": "~1.0.0-alpha.23",
|
"react-native-screens": "^2.0.0-alpha.6",
|
||||||
"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",
|
||||||
"scheduler": "^0.16.1",
|
"scheduler": "^0.16.1",
|
||||||
"shortid": "^2.2.15",
|
"shortid": "^2.2.15",
|
||||||
"use-subscription": "^1.1.1"
|
"use-subscription": "^1.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.6.2",
|
"@babel/core": "^7.6.2",
|
||||||
|
"@expo/webpack-config": "^0.7.12",
|
||||||
"@types/react": "^16.9.4",
|
"@types/react": "^16.9.4",
|
||||||
"@types/react-native": "^0.60.17",
|
"@types/react-native": "^0.60.19",
|
||||||
"babel-preset-expo": "^7.0.0",
|
"babel-preset-expo": "^7.0.0",
|
||||||
"expo-cli": "^3.1.2",
|
"expo-cli": "^3.3.0",
|
||||||
|
"jetifier": "^1.6.4",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.6.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,24 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { MaterialIcons } from '@expo/vector-icons';
|
import { MaterialCommunityIcons } from '@expo/vector-icons';
|
||||||
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
||||||
// @ts-ignore
|
import TouchableBounce from '../Shared/TouchableBounce';
|
||||||
import TouchableBounce from 'react-native/Libraries/Components/Touchable/TouchableBounce';
|
|
||||||
import Albums from '../Shared/Albums';
|
import Albums from '../Shared/Albums';
|
||||||
import Contacts from '../Shared/Contacts';
|
import Contacts from '../Shared/Contacts';
|
||||||
import Chat from '../Shared/Chat';
|
import Chat from '../Shared/Chat';
|
||||||
import SimpleStackScreen from './SimpleStack';
|
import SimpleStackScreen from './SimpleStack';
|
||||||
|
|
||||||
const getTabBarIcon = (name: string) => ({
|
const getTabBarIcon = (name: string) => ({
|
||||||
tintColor,
|
color,
|
||||||
horizontal,
|
horizontal,
|
||||||
}: {
|
}: {
|
||||||
tintColor: string;
|
color: string;
|
||||||
horizontal: boolean;
|
horizontal: boolean;
|
||||||
}) => (
|
}) => (
|
||||||
<MaterialIcons name={name} color={tintColor} size={horizontal ? 17 : 24} />
|
<MaterialCommunityIcons
|
||||||
|
name={name}
|
||||||
|
color={color}
|
||||||
|
size={horizontal ? 17 : 24}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
type BottomTabParams = {
|
type BottomTabParams = {
|
||||||
@@ -34,20 +37,18 @@ export default function BottomTabsScreen() {
|
|||||||
name="article"
|
name="article"
|
||||||
options={{
|
options={{
|
||||||
title: 'Article',
|
title: 'Article',
|
||||||
tabBarIcon: getTabBarIcon('chrome-reader-mode'),
|
tabBarIcon: getTabBarIcon('file-document-box'),
|
||||||
tabBarButtonComponent: TouchableBounce,
|
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('chat-bubble'),
|
tabBarIcon: getTabBarIcon('message-reply'),
|
||||||
tabBarButtonComponent: TouchableBounce,
|
tabBarButtonComponent: TouchableBounce,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -65,7 +66,7 @@ export default function BottomTabsScreen() {
|
|||||||
component={Albums}
|
component={Albums}
|
||||||
options={{
|
options={{
|
||||||
title: 'Albums',
|
title: 'Albums',
|
||||||
tabBarIcon: getTabBarIcon('photo-album'),
|
tabBarIcon: getTabBarIcon('image-album'),
|
||||||
tabBarButtonComponent: TouchableBounce,
|
tabBarButtonComponent: TouchableBounce,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -24,20 +24,18 @@ export default function MaterialBottomTabsScreen() {
|
|||||||
name="article"
|
name="article"
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Article',
|
tabBarLabel: 'Article',
|
||||||
tabBarIcon: 'chrome-reader-mode',
|
tabBarIcon: 'file-document-box',
|
||||||
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"
|
||||||
component={Chat}
|
component={Chat}
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Chat',
|
tabBarLabel: 'Chat',
|
||||||
tabBarIcon: 'chat-bubble',
|
tabBarIcon: 'message-reply',
|
||||||
tabBarColor: '#9FD5C9',
|
tabBarColor: '#9FD5C9',
|
||||||
tabBarBadge: true,
|
tabBarBadge: true,
|
||||||
}}
|
}}
|
||||||
@@ -56,7 +54,7 @@ export default function MaterialBottomTabsScreen() {
|
|||||||
component={Albums}
|
component={Albums}
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Albums',
|
tabBarLabel: 'Albums',
|
||||||
tabBarIcon: 'photo-album',
|
tabBarIcon: 'image-album',
|
||||||
tabBarColor: '#FAD4D6',
|
tabBarColor: '#FAD4D6',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
23
packages/example/src/Screens/NativeStack.expo.tsx
Normal file
23
packages/example/src/Screens/NativeStack.expo.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}>Currently not supported on Expo :(</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
flex: 1,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
backgroundColor: '#eceff1',
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
fontSize: 16,
|
||||||
|
color: '#999',
|
||||||
|
},
|
||||||
|
});
|
||||||
138
packages/example/src/Screens/NativeStack.tsx
Normal file
138
packages/example/src/Screens/NativeStack.tsx
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { View, StyleSheet } from 'react-native';
|
||||||
|
import { Button } from 'react-native-paper';
|
||||||
|
// eslint-disable-next-line import/no-unresolved
|
||||||
|
import { useScreens } from 'react-native-screens';
|
||||||
|
import {
|
||||||
|
RouteProp,
|
||||||
|
ParamListBase,
|
||||||
|
useFocusEffect,
|
||||||
|
} from '@react-navigation/core';
|
||||||
|
import { DrawerNavigationProp } from '@react-navigation/drawer';
|
||||||
|
import { StackNavigationProp } from '@react-navigation/stack';
|
||||||
|
import {
|
||||||
|
createNativeStackNavigator,
|
||||||
|
NativeStackNavigationProp,
|
||||||
|
} from '@react-navigation/native-stack';
|
||||||
|
import Article from '../Shared/Article';
|
||||||
|
import Albums from '../Shared/Albums';
|
||||||
|
|
||||||
|
type NativeStackParams = {
|
||||||
|
article: { author: string };
|
||||||
|
album: undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
type NativeStackNavigation = NativeStackNavigationProp<NativeStackParams>;
|
||||||
|
|
||||||
|
const ArticleScreen = ({
|
||||||
|
navigation,
|
||||||
|
route,
|
||||||
|
}: {
|
||||||
|
navigation: NativeStackNavigation;
|
||||||
|
route: RouteProp<NativeStackParams, 'article'>;
|
||||||
|
}) => (
|
||||||
|
<React.Fragment>
|
||||||
|
<View style={styles.buttons}>
|
||||||
|
<Button
|
||||||
|
mode="contained"
|
||||||
|
onPress={() => navigation.push('album')}
|
||||||
|
style={styles.button}
|
||||||
|
>
|
||||||
|
Push album
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
mode="outlined"
|
||||||
|
onPress={() => navigation.goBack()}
|
||||||
|
style={styles.button}
|
||||||
|
>
|
||||||
|
Go back
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
<Article author={{ name: route.params.author }} />
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
|
||||||
|
const AlbumsScreen = ({
|
||||||
|
navigation,
|
||||||
|
}: {
|
||||||
|
navigation: NativeStackNavigation;
|
||||||
|
}) => (
|
||||||
|
<React.Fragment>
|
||||||
|
<View style={styles.buttons}>
|
||||||
|
<Button
|
||||||
|
mode="contained"
|
||||||
|
onPress={() => navigation.push('article', { author: 'Babel fish' })}
|
||||||
|
style={styles.button}
|
||||||
|
>
|
||||||
|
Push article
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
mode="outlined"
|
||||||
|
onPress={() => navigation.goBack()}
|
||||||
|
style={styles.button}
|
||||||
|
>
|
||||||
|
Go back
|
||||||
|
</Button>
|
||||||
|
</View>
|
||||||
|
<Albums />
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
|
||||||
|
const NativeStack = createNativeStackNavigator<NativeStackParams>();
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
navigation: StackNavigationProp<ParamListBase>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function NativeStackScreen({ navigation }: Props) {
|
||||||
|
navigation.setOptions({
|
||||||
|
headerShown: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
React.useCallback(() => {
|
||||||
|
const drawer = navigation.dangerouslyGetParent() as DrawerNavigationProp<
|
||||||
|
ParamListBase
|
||||||
|
>;
|
||||||
|
|
||||||
|
navigation.setOptions({ gestureEnabled: false });
|
||||||
|
drawer.setOptions({ drawerLockMode: 'locked-closed' });
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
navigation.setOptions({ gestureEnabled: true });
|
||||||
|
drawer.setOptions({ drawerLockMode: 'unlocked' });
|
||||||
|
};
|
||||||
|
}, [navigation])
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<NativeStack.Navigator>
|
||||||
|
<NativeStack.Screen
|
||||||
|
name="article"
|
||||||
|
component={ArticleScreen}
|
||||||
|
options={({ route }) => ({
|
||||||
|
title: `Article by ${route.params.author}`,
|
||||||
|
})}
|
||||||
|
initialParams={{ author: 'Gandalf' }}
|
||||||
|
/>
|
||||||
|
<NativeStack.Screen
|
||||||
|
name="album"
|
||||||
|
component={AlbumsScreen}
|
||||||
|
options={{ title: 'Album' }}
|
||||||
|
/>
|
||||||
|
</NativeStack.Navigator>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||||
|
useScreens(true);
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
buttons: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
padding: 8,
|
||||||
|
},
|
||||||
|
button: {
|
||||||
|
margin: 8,
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -76,18 +76,17 @@ const AlbumsScreen = ({
|
|||||||
|
|
||||||
const SimpleStack = createStackNavigator<SimpleStackParams>();
|
const SimpleStack = createStackNavigator<SimpleStackParams>();
|
||||||
|
|
||||||
type Props = {
|
type Props = Partial<React.ComponentProps<typeof SimpleStack.Navigator>> & {
|
||||||
options?: React.ComponentProps<typeof SimpleStack.Navigator>;
|
|
||||||
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}
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ export default function Albums() {
|
|||||||
// eslint-disable-next-line react/no-array-index-key
|
// eslint-disable-next-line react/no-array-index-key
|
||||||
<Image key={i} source={source} style={styles.cover} />
|
<Image key={i} source={source} style={styles.cover} />
|
||||||
))}
|
))}
|
||||||
|
{COVERS.map((source, i) => (
|
||||||
|
// eslint-disable-next-line react/no-array-index-key
|
||||||
|
<Image key={i + 'F'} source={source} style={styles.cover} />
|
||||||
|
))}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
4
packages/example/src/Shared/TouchableBounce.native.tsx
Normal file
4
packages/example/src/Shared/TouchableBounce.native.tsx
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// @ts-ignore
|
||||||
|
import TouchableBounce from 'react-native/Libraries/Components/Touchable/TouchableBounce';
|
||||||
|
|
||||||
|
export default TouchableBounce;
|
||||||
3
packages/example/src/Shared/TouchableBounce.tsx
Normal file
3
packages/example/src/Shared/TouchableBounce.tsx
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { TouchableOpacity } from 'react-native';
|
||||||
|
|
||||||
|
export default TouchableOpacity;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { ScrollView, AsyncStorage, YellowBox } from 'react-native';
|
import { ScrollView, AsyncStorage, YellowBox } from 'react-native';
|
||||||
import LinkingPrefixes from './LinkingPrefixes';
|
import { MaterialIcons } from '@expo/vector-icons';
|
||||||
import { Appbar, List } from 'react-native-paper';
|
import { Appbar, List } from 'react-native-paper';
|
||||||
import { Asset } from 'expo-asset';
|
import { Asset } from 'expo-asset';
|
||||||
import {
|
import {
|
||||||
@@ -22,7 +22,9 @@ import {
|
|||||||
StackNavigationProp,
|
StackNavigationProp,
|
||||||
} from '@react-navigation/stack';
|
} from '@react-navigation/stack';
|
||||||
|
|
||||||
|
import LinkingPrefixes from './LinkingPrefixes';
|
||||||
import SimpleStack from './Screens/SimpleStack';
|
import SimpleStack from './Screens/SimpleStack';
|
||||||
|
import NativeStack from './Screens/NativeStack';
|
||||||
import ModalPresentationStack from './Screens/ModalPresentationStack';
|
import ModalPresentationStack from './Screens/ModalPresentationStack';
|
||||||
import BottomTabs from './Screens/BottomTabs';
|
import BottomTabs from './Screens/BottomTabs';
|
||||||
import MaterialTopTabsScreen from './Screens/MaterialTopTabs';
|
import MaterialTopTabsScreen from './Screens/MaterialTopTabs';
|
||||||
@@ -33,17 +35,19 @@ import CompatAPI from './Screens/CompatAPI';
|
|||||||
YellowBox.ignoreWarnings(['Require cycle:', 'Warning: Async Storage']);
|
YellowBox.ignoreWarnings(['Require cycle:', 'Warning: Async Storage']);
|
||||||
|
|
||||||
type RootDrawerParamList = {
|
type RootDrawerParamList = {
|
||||||
root: undefined;
|
Root: undefined;
|
||||||
|
Another: undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
type RootStackParamList = {
|
type RootStackParamList = {
|
||||||
home: undefined;
|
Home: undefined;
|
||||||
} & {
|
} & {
|
||||||
[P in keyof typeof SCREENS]: undefined;
|
[P in keyof typeof SCREENS]: undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const SCREENS = {
|
const SCREENS = {
|
||||||
SimpleStack: { title: 'Simple Stack', component: SimpleStack },
|
SimpleStack: { title: 'Simple Stack', component: SimpleStack },
|
||||||
|
NativeStack: { title: 'Native Stack', component: NativeStack },
|
||||||
ModalPresentationStack: {
|
ModalPresentationStack: {
|
||||||
title: 'Modal Presentation Stack',
|
title: 'Modal Presentation Stack',
|
||||||
component: ModalPresentationStack,
|
component: ModalPresentationStack,
|
||||||
@@ -139,7 +143,15 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Drawer.Navigator>
|
<Drawer.Navigator>
|
||||||
<Drawer.Screen name="root" options={{ title: 'Examples' }}>
|
<Drawer.Screen
|
||||||
|
name="Root"
|
||||||
|
options={{
|
||||||
|
title: 'Examples',
|
||||||
|
drawerIcon: ({ size, color }) => (
|
||||||
|
<MaterialIcons size={size} color={color} name="folder" />
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
>
|
||||||
{({
|
{({
|
||||||
navigation,
|
navigation,
|
||||||
}: {
|
}: {
|
||||||
@@ -147,7 +159,7 @@ export default function App() {
|
|||||||
}) => (
|
}) => (
|
||||||
<Stack.Navigator>
|
<Stack.Navigator>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
name="home"
|
name="Home"
|
||||||
options={{
|
options={{
|
||||||
title: 'Examples',
|
title: 'Examples',
|
||||||
headerLeft: () => (
|
headerLeft: () => (
|
||||||
|
|||||||
50
packages/example/webpack.config.js
Normal file
50
packages/example/webpack.config.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const createExpoWebpackConfigAsync = require('@expo/webpack-config');
|
||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
||||||
|
|
||||||
|
module.exports = async function(env, argv) {
|
||||||
|
const config = await createExpoWebpackConfigAsync(env, argv);
|
||||||
|
|
||||||
|
config.module.rules.push({
|
||||||
|
test: /\.(js|ts|tsx)$/,
|
||||||
|
include: /packages\/.+/,
|
||||||
|
use: 'babel-loader',
|
||||||
|
});
|
||||||
|
|
||||||
|
config.resolve.plugins = config.resolve.plugins.filter(
|
||||||
|
p => !(p instanceof ModuleScopePlugin)
|
||||||
|
);
|
||||||
|
|
||||||
|
config.resolve.alias['react'] = path.resolve(
|
||||||
|
__dirname,
|
||||||
|
'node_modules',
|
||||||
|
'react'
|
||||||
|
);
|
||||||
|
config.resolve.alias['react-native'] = path.resolve(
|
||||||
|
__dirname,
|
||||||
|
'node_modules',
|
||||||
|
'react-native-web'
|
||||||
|
);
|
||||||
|
config.resolve.alias['react-native-web'] = path.resolve(
|
||||||
|
__dirname,
|
||||||
|
'node_modules',
|
||||||
|
'react-native-web'
|
||||||
|
);
|
||||||
|
|
||||||
|
config.resolve.alias[
|
||||||
|
'@expo/vector-icons/MaterialCommunityIcons'
|
||||||
|
] = require.resolve('@expo/vector-icons/MaterialCommunityIcons');
|
||||||
|
|
||||||
|
fs.readdirSync(path.join(__dirname, '..')).forEach(name => {
|
||||||
|
config.resolve.alias[`@react-navigation/${name}`] = path.resolve(
|
||||||
|
__dirname,
|
||||||
|
'..',
|
||||||
|
name,
|
||||||
|
'src'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return config;
|
||||||
|
};
|
||||||
@@ -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.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)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* make it possible to run the example on web ([7a901af](https://github.com/react-navigation/navigation-ex/commit/7a901af))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* initial version of native stack ([#102](https://github.com/react-navigation/navigation-ex/issues/102)) ([ba3f718](https://github.com/react-navigation/navigation-ex/commit/ba3f718))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.11...@react-navigation/material-bottom-tabs@5.0.0-alpha.12) (2019-10-06)
|
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.11...@react-navigation/material-bottom-tabs@5.0.0-alpha.12) (2019-10-06)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export default function App() {
|
|||||||
component={Article}
|
component={Article}
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Article',
|
tabBarLabel: 'Article',
|
||||||
tabBarIcon: 'chrome-reader-mode',
|
tabBarIcon: 'file-document-box',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<MaterialBottomTabs.Screen
|
<MaterialBottomTabs.Screen
|
||||||
@@ -35,7 +35,7 @@ export default function App() {
|
|||||||
component={Chat}
|
component={Chat}
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Chat',
|
tabBarLabel: 'Chat',
|
||||||
tabBarIcon: 'chat-bubble',
|
tabBarIcon: 'message-reply',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<MaterialBottomTabs.Screen
|
<MaterialBottomTabs.Screen
|
||||||
@@ -51,7 +51,7 @@ export default function App() {
|
|||||||
component={Albums}
|
component={Albums}
|
||||||
options={{
|
options={{
|
||||||
tabBarLabel: 'Albums',
|
tabBarLabel: 'Albums',
|
||||||
tabBarIcon: 'photo-album',
|
tabBarIcon: 'image-album',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</MaterialBottomTabs.Navigator>
|
</MaterialBottomTabs.Navigator>
|
||||||
|
|||||||
@@ -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.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
@@ -42,9 +42,9 @@
|
|||||||
"@types/react-native": "^0.60.17",
|
"@types/react-native": "^0.60.17",
|
||||||
"@types/react-native-vector-icons": "^6.4.4",
|
"@types/react-native-vector-icons": "^6.4.4",
|
||||||
"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.6.3"
|
||||||
},
|
},
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
"@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": {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export type MaterialBottomTabNavigationOptions = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* String referring to an icon in the `MaterialCommunityIcons` set, or a
|
* String referring to an icon in the `MaterialCommunityIcons` set, or a
|
||||||
* function that given { focused: boolean, tintColor: string } returns a React.Node to display in the navigation bar.
|
* function that given { focused: boolean, color: string } returns a React.Node to display in the navigation bar.
|
||||||
*/
|
*/
|
||||||
tabBarIcon?:
|
tabBarIcon?:
|
||||||
| string
|
| string
|
||||||
@@ -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'
|
||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import * as React from 'react';
|
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/MaterialIcons';
|
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,33 @@
|
|||||||
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/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)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* initial version of native stack ([#102](https://github.com/react-navigation/navigation-ex/issues/102)) ([ba3f718](https://github.com/react-navigation/navigation-ex/commit/ba3f718))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.11](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.10...@react-navigation/material-top-tabs@5.0.0-alpha.11) (2019-10-06)
|
# [5.0.0-alpha.11](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.10...@react-navigation/material-top-tabs@5.0.0-alpha.11) (2019-10-06)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"material",
|
"material",
|
||||||
"tab"
|
"tab"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.11",
|
"version": "5.0.0-alpha.14",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -34,15 +34,15 @@
|
|||||||
"clean": "del lib"
|
"clean": "del lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
"@react-navigation/routers": "^5.0.0-alpha.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
"@types/react": "^16.9.4",
|
"@types/react": "^16.9.4",
|
||||||
"@types/react-native": "^0.60.17",
|
"@types/react-native": "^0.60.17",
|
||||||
"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-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",
|
||||||
|
|||||||
@@ -64,19 +64,19 @@ export type MaterialTopTabNavigationOptions = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Title string of a tab displayed in the tab bar or React Element
|
* Title string of a tab displayed in the tab bar or React Element
|
||||||
* or a function that given { focused: boolean, tintColor: string } returns a React.Node, to display in tab bar.
|
* or a function that given { focused: boolean, color: string } returns a React.Node, to display in tab bar.
|
||||||
* When undefined, scene title is used. To hide, see tabBarOptions.showLabel in the previous section.
|
* When undefined, scene title is used. To hide, see tabBarOptions.showLabel in the previous section.
|
||||||
*/
|
*/
|
||||||
tabBarLabel?:
|
tabBarLabel?:
|
||||||
| React.ReactNode
|
| React.ReactNode
|
||||||
| ((props: { focused: boolean; tintColor: string }) => React.ReactNode);
|
| ((props: { focused: boolean; color: string }) => React.ReactNode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* React Element or a function that given { focused: boolean, tintColor: 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.
|
||||||
*/
|
*/
|
||||||
tabBarIcon?:
|
tabBarIcon?:
|
||||||
| React.ReactNode
|
| React.ReactNode
|
||||||
| ((props: { focused: boolean; tintColor: string }) => React.ReactNode);
|
| ((props: { focused: boolean; color: string }) => React.ReactNode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accessibility label for the tab button. This is read by the screen reader when the user taps the tab.
|
* Accessibility label for the tab button. This is read by the screen reader when the user taps the tab.
|
||||||
@@ -196,7 +196,7 @@ export type MaterialTopTabBarProps = MaterialTopTabBarOptions &
|
|||||||
getLabelText: (props: {
|
getLabelText: (props: {
|
||||||
route: Route<string>;
|
route: Route<string>;
|
||||||
}) =>
|
}) =>
|
||||||
| ((scene: { focused: boolean; tintColor: string }) => React.ReactNode)
|
| ((scene: { focused: boolean; color: string }) => React.ReactNode)
|
||||||
| React.ReactNode;
|
| React.ReactNode;
|
||||||
getAccessibilityLabel: (props: {
|
getAccessibilityLabel: (props: {
|
||||||
route: Route<string>;
|
route: Route<string>;
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export default class TabBarTop extends React.PureComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof label === 'function') {
|
if (typeof label === 'function') {
|
||||||
return label({ focused, tintColor: color });
|
return label({ focused, color });
|
||||||
}
|
}
|
||||||
|
|
||||||
return label;
|
return label;
|
||||||
@@ -79,7 +79,7 @@ export default class TabBarTop extends React.PureComponent<
|
|||||||
if (options.tabBarIcon !== undefined) {
|
if (options.tabBarIcon !== undefined) {
|
||||||
const icon =
|
const icon =
|
||||||
typeof options.tabBarIcon === 'function'
|
typeof options.tabBarIcon === 'function'
|
||||||
? options.tabBarIcon({ focused, tintColor: color })
|
? options.tabBarIcon({ focused, color })
|
||||||
: options.tabBarIcon;
|
: options.tabBarIcon;
|
||||||
|
|
||||||
return <View style={[styles.icon, iconStyle]}>{icon}</View>;
|
return <View style={[styles.icon, iconStyle]}>{icon}</View>;
|
||||||
|
|||||||
66
packages/native-stack/CHANGELOG.md
Normal file
66
packages/native-stack/CHANGELOG.md
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
# Change Log
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
# [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)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* increase hitSlop of back button on Android ([c7da1e4](https://github.com/react-navigation/navigation-ex/commit/c7da1e4))
|
||||||
|
* update supported options for native stack ([b71f4e5](https://github.com/react-navigation/navigation-ex/commit/b71f4e5))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* initial version of native stack ([#102](https://github.com/react-navigation/navigation-ex/issues/102)) ([ba3f718](https://github.com/react-navigation/navigation-ex/commit/ba3f718))
|
||||||
64
packages/native-stack/README.md
Normal file
64
packages/native-stack/README.md
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
# `@react-navigation/native-stack`
|
||||||
|
|
||||||
|
Stack navigator for React Native using native primitives for navigation. Uses [`react-native-screens`](https://github.com/kmagiera/react-native-screens) under the hood.
|
||||||
|
|
||||||
|
Expo is currently not supported as it includes an older version of `react-native-screens`.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Open a Terminal in your project's folder and run,
|
||||||
|
|
||||||
|
```sh
|
||||||
|
yarn add @react-navigation/core @react-navigation/native-stack
|
||||||
|
```
|
||||||
|
|
||||||
|
Now we need to install [`react-native-screens`](https://github.com/kmagiera/react-native-screens).
|
||||||
|
|
||||||
|
```sh
|
||||||
|
yarn add react-native-screens
|
||||||
|
```
|
||||||
|
|
||||||
|
To complete the linking on iOS, make sure you have [Cocoapods](https://cocoapods.org/) installed. Then run:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cd ios
|
||||||
|
pod install
|
||||||
|
cd ..
|
||||||
|
```
|
||||||
|
|
||||||
|
To finalize installation of `react-native-screens` for Android, add the following two lines to dependencies section in `android/app/build.gradle`:
|
||||||
|
|
||||||
|
```gradle
|
||||||
|
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
|
||||||
|
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
|
||||||
|
```
|
||||||
|
|
||||||
|
Make sure to enable `react-native-screens`. This needs to be done before our app renders. To do it, add the following code in your entry file (e.g. `App.js`):
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { useScreens } from 'react-native-screens';
|
||||||
|
|
||||||
|
useScreens();
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
||||||
|
|
||||||
|
const Stack = createNativeStackNavigator();
|
||||||
|
|
||||||
|
export default function App() {
|
||||||
|
return (
|
||||||
|
<Stack.Navigator>
|
||||||
|
<Stack.Screen name="home" component={Home} options={{ title: 'Home' }} />
|
||||||
|
<Stack.Screen name="feed" component={Feed} options={{ title: 'Feed' }} />
|
||||||
|
<Stack.Screen
|
||||||
|
name="profile"
|
||||||
|
component={Profile}
|
||||||
|
options={{ title: 'Profile' }}
|
||||||
|
/>
|
||||||
|
</Stack.Navigator>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
55
packages/native-stack/package.json
Normal file
55
packages/native-stack/package.json
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
{
|
||||||
|
"name": "@react-navigation/native-stack",
|
||||||
|
"description": "Native stack navigator component for iOS and Android",
|
||||||
|
"keywords": [
|
||||||
|
"react",
|
||||||
|
"react-native",
|
||||||
|
"react-navigation"
|
||||||
|
],
|
||||||
|
"version": "5.0.0-alpha.6",
|
||||||
|
"license": "MIT",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/react-navigation/navigation-ex.git",
|
||||||
|
"directory": "packages/native-stack"
|
||||||
|
},
|
||||||
|
"main": "lib/commonjs/index.js",
|
||||||
|
"react-native": "src/index.tsx",
|
||||||
|
"module": "lib/module/index.js",
|
||||||
|
"types": "lib/typescript/native-stack/src/index.d.ts",
|
||||||
|
"files": [
|
||||||
|
"src",
|
||||||
|
"lib"
|
||||||
|
],
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"prepare": "bob build",
|
||||||
|
"clean": "del lib"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@react-navigation/routers": "^5.0.0-alpha.11"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@react-native-community/bob": "^0.7.0",
|
||||||
|
"del-cli": "^2.0.0",
|
||||||
|
"react-native-screens": "^2.0.0-alpha.6",
|
||||||
|
"typescript": "^3.5.3"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||||
|
"react": "*",
|
||||||
|
"react-native": "*",
|
||||||
|
"react-native-screens": "^2.0.0-alpha.6"
|
||||||
|
},
|
||||||
|
"@react-native-community/bob": {
|
||||||
|
"source": "src",
|
||||||
|
"output": "lib",
|
||||||
|
"targets": [
|
||||||
|
"commonjs",
|
||||||
|
"module",
|
||||||
|
"typescript"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
14
packages/native-stack/src/index.tsx
Normal file
14
packages/native-stack/src/index.tsx
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Navigators
|
||||||
|
*/
|
||||||
|
export {
|
||||||
|
default as createNativeStackNavigator,
|
||||||
|
} from './navigators/createNativeStackNavigator';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Types
|
||||||
|
*/
|
||||||
|
export {
|
||||||
|
NativeStackNavigationOptions,
|
||||||
|
NativeStackNavigationProp,
|
||||||
|
} from './types';
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { createNavigator, useNavigationBuilder } from '@react-navigation/core';
|
||||||
|
|
||||||
|
import {
|
||||||
|
StackRouter,
|
||||||
|
StackNavigationState,
|
||||||
|
StackRouterOptions,
|
||||||
|
} from '@react-navigation/routers';
|
||||||
|
|
||||||
|
import {
|
||||||
|
screensEnabled,
|
||||||
|
// eslint-disable-next-line import/no-unresolved
|
||||||
|
} from 'react-native-screens';
|
||||||
|
import StackView from '../views/StackView';
|
||||||
|
import {
|
||||||
|
NativeStackNavigatorProps,
|
||||||
|
NativeStackNavigationOptions,
|
||||||
|
} from '../types';
|
||||||
|
|
||||||
|
function NativeStackNavigator(props: NativeStackNavigatorProps) {
|
||||||
|
if (!screensEnabled()) {
|
||||||
|
throw new Error(
|
||||||
|
'Native stack is only available if React Native Screens is enabled.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { initialRouteName, children, screenOptions, ...rest } = props;
|
||||||
|
const { state, descriptors, navigation } = useNavigationBuilder<
|
||||||
|
StackNavigationState,
|
||||||
|
StackRouterOptions,
|
||||||
|
NativeStackNavigationOptions,
|
||||||
|
{}
|
||||||
|
>(StackRouter, {
|
||||||
|
initialRouteName,
|
||||||
|
children,
|
||||||
|
screenOptions,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<StackView
|
||||||
|
state={state}
|
||||||
|
navigation={navigation}
|
||||||
|
descriptors={descriptors}
|
||||||
|
{...rest}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default createNavigator<
|
||||||
|
NativeStackNavigationOptions,
|
||||||
|
typeof NativeStackNavigator
|
||||||
|
>(NativeStackNavigator);
|
||||||
191
packages/native-stack/src/types.tsx
Normal file
191
packages/native-stack/src/types.tsx
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { StyleProp, ViewStyle } from 'react-native';
|
||||||
|
import {
|
||||||
|
DefaultNavigatorOptions,
|
||||||
|
Descriptor,
|
||||||
|
NavigationHelpers,
|
||||||
|
NavigationProp,
|
||||||
|
ParamListBase,
|
||||||
|
} from '@react-navigation/core';
|
||||||
|
import {
|
||||||
|
StackNavigationState,
|
||||||
|
StackRouterOptions,
|
||||||
|
} from '@react-navigation/routers';
|
||||||
|
|
||||||
|
export type NativeStackNavigationProp<
|
||||||
|
ParamList extends ParamListBase,
|
||||||
|
RouteName extends keyof ParamList = string
|
||||||
|
> = NavigationProp<
|
||||||
|
ParamList,
|
||||||
|
RouteName,
|
||||||
|
StackNavigationState,
|
||||||
|
NativeStackNavigationOptions,
|
||||||
|
{}
|
||||||
|
> & {
|
||||||
|
/**
|
||||||
|
* Push a new screen onto the stack.
|
||||||
|
*
|
||||||
|
* @param name Name of the route for the tab.
|
||||||
|
* @param [params] Params object for the route.
|
||||||
|
*/
|
||||||
|
push<RouteName extends keyof ParamList>(
|
||||||
|
...args: ParamList[RouteName] extends (undefined | any)
|
||||||
|
? [RouteName] | [RouteName, ParamList[RouteName]]
|
||||||
|
: [RouteName, ParamList[RouteName]]
|
||||||
|
): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pop a screen from the stack.
|
||||||
|
*/
|
||||||
|
pop(count?: number): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pop to the first route in the stack, dismissing all other screens.
|
||||||
|
*/
|
||||||
|
popToTop(): void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NativeStackNavigationHelpers = NavigationHelpers<ParamListBase, {}>;
|
||||||
|
|
||||||
|
export type NativeStackNavigationConfig = {};
|
||||||
|
|
||||||
|
export type NativeStackNavigationOptions = {
|
||||||
|
/**
|
||||||
|
* String that can be displayed in the header as a fallback for `headerTitle`.
|
||||||
|
*/
|
||||||
|
title?: string;
|
||||||
|
/**
|
||||||
|
* String to display in the header as title. Defaults to scene `title`.
|
||||||
|
*/
|
||||||
|
headerTitle?: string;
|
||||||
|
/**
|
||||||
|
* Title to display in the back button.
|
||||||
|
* Only supported on iOS.
|
||||||
|
*
|
||||||
|
* @platform ios
|
||||||
|
*/
|
||||||
|
headerBackTitle?: string;
|
||||||
|
/**
|
||||||
|
* Whether to show the header.
|
||||||
|
*/
|
||||||
|
headerShown?: boolean;
|
||||||
|
/**
|
||||||
|
* Boolean indicating whether the navigation bar is translucent.
|
||||||
|
* Only supported on iOS.
|
||||||
|
*
|
||||||
|
* @platform ios
|
||||||
|
*/
|
||||||
|
headerTranslucent?: boolean;
|
||||||
|
/**
|
||||||
|
* Boolean to set native property to prefer large title header (like in iOS setting).
|
||||||
|
* Only supported on iOS.
|
||||||
|
*
|
||||||
|
* @platform ios
|
||||||
|
*/
|
||||||
|
headerLargeTitle?: boolean;
|
||||||
|
/**
|
||||||
|
* Function which returns a React Element to display on the right side of the header.
|
||||||
|
*/
|
||||||
|
headerRight?: () => React.ReactNode;
|
||||||
|
/**
|
||||||
|
* Tint color for the header. Changes the color of back button and title.
|
||||||
|
*/
|
||||||
|
headerTintColor?: string;
|
||||||
|
/**
|
||||||
|
* Boolean indicating whether to hide the back button in header.
|
||||||
|
* Only supported on Android.
|
||||||
|
*
|
||||||
|
* @platform android
|
||||||
|
*/
|
||||||
|
headerHideBackButton?: boolean;
|
||||||
|
/**
|
||||||
|
* Boolean indicating whether to hide the elevation shadow on the header.
|
||||||
|
* Only supported on Android.
|
||||||
|
*
|
||||||
|
* @platform android
|
||||||
|
*/
|
||||||
|
headerHideShadow?: boolean;
|
||||||
|
/**
|
||||||
|
* Style object for header title. Supported properties:
|
||||||
|
* - backgroundColor
|
||||||
|
*/
|
||||||
|
headerStyle?: {
|
||||||
|
backgroundColor?: string;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Style object for header title. Supported properties:
|
||||||
|
* - fontFamily
|
||||||
|
* - fontSize
|
||||||
|
* - color
|
||||||
|
*/
|
||||||
|
headerTitleStyle?: {
|
||||||
|
fontFamily?: string;
|
||||||
|
fontSize?: number;
|
||||||
|
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:
|
||||||
|
* - fontFamily
|
||||||
|
* - fontSize
|
||||||
|
*
|
||||||
|
* Only supported on iOS.
|
||||||
|
*
|
||||||
|
* @platform ios
|
||||||
|
*/
|
||||||
|
headerBackTitleStyle?: {
|
||||||
|
fontFamily?: string;
|
||||||
|
fontSize?: number;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Style object for the scene content.
|
||||||
|
*/
|
||||||
|
contentStyle?: StyleProp<ViewStyle>;
|
||||||
|
/**
|
||||||
|
* Whether you can use gestures to dismiss this screen. Defaults to `true`.
|
||||||
|
* Only supported on iOS.
|
||||||
|
*
|
||||||
|
* @platform ios
|
||||||
|
*/
|
||||||
|
gestureEnabled?: boolean;
|
||||||
|
/**
|
||||||
|
* How should the screen be presented.
|
||||||
|
*/
|
||||||
|
presentation?: 'modal' | 'transparentModal' | 'push';
|
||||||
|
/**
|
||||||
|
* How should the screen should be animated.
|
||||||
|
* Only supported on Android.
|
||||||
|
*
|
||||||
|
* @platform android
|
||||||
|
*/
|
||||||
|
animation?: 'default' | 'fade' | 'none';
|
||||||
|
};
|
||||||
|
|
||||||
|
export type NativeStackNavigatorProps = DefaultNavigatorOptions<
|
||||||
|
NativeStackNavigationOptions
|
||||||
|
> &
|
||||||
|
StackRouterOptions &
|
||||||
|
NativeStackNavigationConfig;
|
||||||
|
|
||||||
|
export type NativeStackDescriptor = Descriptor<
|
||||||
|
ParamListBase,
|
||||||
|
string,
|
||||||
|
StackNavigationState,
|
||||||
|
NativeStackNavigationOptions
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type NativeStackDescriptorMap = {
|
||||||
|
[key: string]: NativeStackDescriptor;
|
||||||
|
};
|
||||||
71
packages/native-stack/src/views/HeaderConfig.tsx
Normal file
71
packages/native-stack/src/views/HeaderConfig.tsx
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import {
|
||||||
|
// @ts-ignore
|
||||||
|
ScreenStackHeaderConfig,
|
||||||
|
// @ts-ignore
|
||||||
|
ScreenStackHeaderRightView,
|
||||||
|
// eslint-disable-next-line import/no-unresolved
|
||||||
|
} from 'react-native-screens';
|
||||||
|
import { Route } from '@react-navigation/core';
|
||||||
|
import { NativeStackNavigationOptions } from '../types';
|
||||||
|
|
||||||
|
type Props = NativeStackNavigationOptions & {
|
||||||
|
route: Route<string>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function HeaderConfig(props: Props) {
|
||||||
|
const {
|
||||||
|
route,
|
||||||
|
title,
|
||||||
|
headerRight,
|
||||||
|
headerTitle,
|
||||||
|
headerBackTitle,
|
||||||
|
headerHideBackButton,
|
||||||
|
headerHideShadow,
|
||||||
|
headerTintColor,
|
||||||
|
headerLargeTitle,
|
||||||
|
headerTranslucent,
|
||||||
|
headerStyle = {},
|
||||||
|
headerTitleStyle = {},
|
||||||
|
headerLargeTitleStyle = {},
|
||||||
|
headerBackTitleStyle = {},
|
||||||
|
headerShown,
|
||||||
|
gestureEnabled,
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ScreenStackHeaderConfig
|
||||||
|
hidden={headerShown === false}
|
||||||
|
translucent={headerTranslucent === true}
|
||||||
|
hideShadow={headerHideShadow}
|
||||||
|
hideBackButton={headerHideBackButton}
|
||||||
|
title={
|
||||||
|
headerTitle !== undefined
|
||||||
|
? headerTitle
|
||||||
|
: title !== undefined
|
||||||
|
? title
|
||||||
|
: route.name
|
||||||
|
}
|
||||||
|
titleFontFamily={headerTitleStyle.fontFamily}
|
||||||
|
titleFontSize={headerTitleStyle.fontSize}
|
||||||
|
titleColor={
|
||||||
|
headerTitleStyle.color !== undefined
|
||||||
|
? headerTitleStyle.color
|
||||||
|
: headerTintColor
|
||||||
|
}
|
||||||
|
backTitle={headerBackTitle}
|
||||||
|
backTitleFontFamily={headerBackTitleStyle.fontFamily}
|
||||||
|
backTitleFontSize={headerBackTitleStyle.fontSize}
|
||||||
|
color={headerTintColor}
|
||||||
|
gestureEnabled={gestureEnabled === undefined ? true : gestureEnabled}
|
||||||
|
largeTitle={headerLargeTitle}
|
||||||
|
largeTitleFontFamily={headerLargeTitleStyle.fontFamily}
|
||||||
|
largeTitleFontSize={headerLargeTitleStyle.fontSize}
|
||||||
|
backgroundColor={headerStyle.backgroundColor}
|
||||||
|
>
|
||||||
|
{headerRight !== undefined ? (
|
||||||
|
<ScreenStackHeaderRightView>{headerRight()}</ScreenStackHeaderRightView>
|
||||||
|
) : null}
|
||||||
|
</ScreenStackHeaderConfig>
|
||||||
|
);
|
||||||
|
}
|
||||||
75
packages/native-stack/src/views/StackView.tsx
Normal file
75
packages/native-stack/src/views/StackView.tsx
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import { View, StyleSheet, Platform } from 'react-native';
|
||||||
|
import { StackNavigationState, StackActions } from '@react-navigation/routers';
|
||||||
|
|
||||||
|
import {
|
||||||
|
// @ts-ignore
|
||||||
|
ScreenStack,
|
||||||
|
Screen,
|
||||||
|
// eslint-disable-next-line import/no-unresolved
|
||||||
|
} from 'react-native-screens';
|
||||||
|
import HeaderConfig from './HeaderConfig';
|
||||||
|
import {
|
||||||
|
NativeStackNavigationHelpers,
|
||||||
|
NativeStackDescriptorMap,
|
||||||
|
} from '../types';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
state: StackNavigationState;
|
||||||
|
navigation: NativeStackNavigationHelpers;
|
||||||
|
descriptors: NativeStackDescriptorMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function StackView({ state, navigation, descriptors }: Props) {
|
||||||
|
return (
|
||||||
|
<ScreenStack style={styles.scenes}>
|
||||||
|
{state.routes.map(route => {
|
||||||
|
const { options, render: renderScene } = descriptors[route.key];
|
||||||
|
const { presentation = 'push', animation, contentStyle } = options;
|
||||||
|
|
||||||
|
return (
|
||||||
|
// @ts-ignore
|
||||||
|
<Screen
|
||||||
|
key={route.key}
|
||||||
|
style={StyleSheet.absoluteFill}
|
||||||
|
stackPresentation={presentation}
|
||||||
|
stackAnimation={animation}
|
||||||
|
onDismissed={() => {
|
||||||
|
navigation.dispatch({
|
||||||
|
...StackActions.pop(),
|
||||||
|
source: route.key,
|
||||||
|
target: state.key,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<HeaderConfig {...options} route={route} />
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
styles.content,
|
||||||
|
{
|
||||||
|
marginTop:
|
||||||
|
Platform.OS === 'android' && options.headerShown !== false
|
||||||
|
? 56
|
||||||
|
: 0,
|
||||||
|
},
|
||||||
|
contentStyle,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{renderScene()}
|
||||||
|
</View>
|
||||||
|
</Screen>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ScreenStack>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
content: {
|
||||||
|
flex: 1,
|
||||||
|
backgroundColor: '#eee',
|
||||||
|
},
|
||||||
|
scenes: {
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
3
packages/native-stack/tsconfig.json
Normal file
3
packages/native-stack/tsconfig.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig"
|
||||||
|
}
|
||||||
@@ -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.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)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* initial version of native stack ([#102](https://github.com/react-navigation/navigation-ex/issues/102)) ([ba3f718](https://github.com/react-navigation/navigation-ex/commit/ba3f718))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.11](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native@5.0.0-alpha.10...@react-navigation/native@5.0.0-alpha.11) (2019-10-06)
|
# [5.0.0-alpha.11](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native@5.0.0-alpha.10...@react-navigation/native@5.0.0-alpha.11) (2019-10-06)
|
||||||
|
|
||||||
**Note:** Version bump only for package @react-navigation/native
|
**Note:** Version bump only for package @react-navigation/native
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
"ios",
|
"ios",
|
||||||
"android"
|
"android"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.11",
|
"version": "5.0.0-alpha.14",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -34,8 +34,8 @@
|
|||||||
"@types/react": "^16.9.4",
|
"@types/react": "^16.9.4",
|
||||||
"@types/react-native": "^0.60.17",
|
"@types/react-native": "^0.60.17",
|
||||||
"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.6.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -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 };
|
||||||
|
|
||||||
@@ -36,22 +36,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 +83,9 @@ export default function useScrollToTop(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}),
|
}
|
||||||
[navigation, ref]
|
);
|
||||||
);
|
|
||||||
|
return unsubscribe;
|
||||||
|
}, [navigation, ref, route.key]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,25 @@
|
|||||||
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.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
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -25,6 +25,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: 'tab',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -50,6 +51,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: 'tab',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -82,6 +84,28 @@ 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: 'tab',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
router.getRehydratedState(
|
||||||
|
{
|
||||||
|
routes: [{ key: 'baz-0', name: 'baz' }],
|
||||||
|
},
|
||||||
|
options
|
||||||
|
)
|
||||||
|
).toEqual({
|
||||||
|
index: 1,
|
||||||
|
key: 'tab-test',
|
||||||
|
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: 'tab',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -107,6 +131,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: 'tab',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -118,7 +143,7 @@ it('gets rehydrated state from partial state', () => {
|
|||||||
options
|
options
|
||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
index: 0,
|
index: 2,
|
||||||
key: 'tab-test',
|
key: 'tab-test',
|
||||||
routeKeyHistory: [],
|
routeKeyHistory: [],
|
||||||
routeNames: ['bar', 'baz', 'qux'],
|
routeNames: ['bar', 'baz', 'qux'],
|
||||||
@@ -128,6 +153,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: 'tab',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -150,6 +176,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: 'tab',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -167,6 +194,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: 'tab' as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -193,6 +221,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: 'tab',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
routeNames: ['qux', 'baz', 'foo', 'fiz'],
|
routeNames: ['qux', 'baz', 'foo', 'fiz'],
|
||||||
@@ -214,6 +243,7 @@ it('gets state on route names change', () => {
|
|||||||
{ key: 'fiz-test', name: 'fiz', params: { fruit: 'apple' } },
|
{ key: 'fiz-test', name: 'fiz', params: { fruit: 'apple' } },
|
||||||
],
|
],
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -224,6 +254,7 @@ it('handles navigate action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -234,6 +265,7 @@ it('handles navigate action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -248,6 +280,7 @@ it('handles navigate action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -258,6 +291,7 @@ it('handles navigate action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -272,6 +306,7 @@ it('handles navigate action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -290,6 +325,7 @@ it('handles jump to action', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -300,6 +336,7 @@ it('handles jump to action', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -315,6 +352,7 @@ it('handles back action with backBehavior: history', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -325,6 +363,7 @@ it('handles back action with backBehavior: history', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -336,6 +375,7 @@ it('handles back action with backBehavior: history', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -354,6 +394,7 @@ it('handles back action with backBehavior: order', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -364,6 +405,7 @@ it('handles back action with backBehavior: order', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -375,6 +417,7 @@ it('handles back action with backBehavior: order', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -396,6 +439,7 @@ it('handles back action with backBehavior: initialRoute', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -406,6 +450,7 @@ it('handles back action with backBehavior: initialRoute', () => {
|
|||||||
)
|
)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -417,6 +462,7 @@ it('handles back action with backBehavior: initialRoute', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 1,
|
index: 1,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -435,6 +481,7 @@ it('handles back action with backBehavior: none', () => {
|
|||||||
router.getStateForAction(
|
router.getStateForAction(
|
||||||
{
|
{
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: 'root',
|
key: 'root',
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames: ['baz', 'bar'],
|
routeNames: ['baz', 'bar'],
|
||||||
@@ -460,6 +507,7 @@ it('updates route key history on navigate and jump to', () => {
|
|||||||
{ 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: 'tab',
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(state.routeKeyHistory).toEqual([]);
|
expect(state.routeKeyHistory).toEqual([]);
|
||||||
@@ -514,6 +562,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: 'tab' as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(router.getStateForRouteFocus(state, 'bar-0').routeKeyHistory).toEqual(
|
expect(router.getStateForRouteFocus(state, 'bar-0').routeKeyHistory).toEqual(
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"react-native",
|
"react-native",
|
||||||
"react-navigation"
|
"react-navigation"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.9",
|
"version": "5.0.0-alpha.11",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -17,7 +17,11 @@ export type DrawerActionType =
|
|||||||
|
|
||||||
export type DrawerRouterOptions = TabRouterOptions;
|
export type DrawerRouterOptions = TabRouterOptions;
|
||||||
|
|
||||||
export type DrawerNavigationState = TabNavigationState & {
|
export type DrawerNavigationState = Omit<TabNavigationState, 'type'> & {
|
||||||
|
/**
|
||||||
|
* Type of the router, in this case, it's drawer.
|
||||||
|
*/
|
||||||
|
type: 'drawer';
|
||||||
/**
|
/**
|
||||||
* Whether the drawer is open or closed.
|
* Whether the drawer is open or closed.
|
||||||
*/
|
*/
|
||||||
@@ -40,7 +44,7 @@ export const DrawerActions = {
|
|||||||
export default function DrawerRouter(
|
export default function DrawerRouter(
|
||||||
options: DrawerRouterOptions
|
options: DrawerRouterOptions
|
||||||
): Router<DrawerNavigationState, DrawerActionType | CommonAction> {
|
): Router<DrawerNavigationState, DrawerActionType | CommonAction> {
|
||||||
const router = TabRouter(options) as Router<
|
const router = (TabRouter(options) as unknown) as Router<
|
||||||
DrawerNavigationState,
|
DrawerNavigationState,
|
||||||
TabActionType | CommonAction
|
TabActionType | CommonAction
|
||||||
>;
|
>;
|
||||||
@@ -48,6 +52,8 @@ export default function DrawerRouter(
|
|||||||
return {
|
return {
|
||||||
...router,
|
...router,
|
||||||
|
|
||||||
|
type: 'drawer',
|
||||||
|
|
||||||
getInitialState({ routeNames, routeParamList }) {
|
getInitialState({ routeNames, routeParamList }) {
|
||||||
const index =
|
const index =
|
||||||
options.initialRouteName === undefined
|
options.initialRouteName === undefined
|
||||||
@@ -56,6 +62,7 @@ export default function DrawerRouter(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'drawer',
|
||||||
key: `drawer-${shortid()}`,
|
key: `drawer-${shortid()}`,
|
||||||
index,
|
index,
|
||||||
routeNames,
|
routeNames,
|
||||||
@@ -81,6 +88,7 @@ export default function DrawerRouter(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
type: 'drawer',
|
||||||
key: `drawer-${shortid()}`,
|
key: `drawer-${shortid()}`,
|
||||||
isDrawerOpen:
|
isDrawerOpen:
|
||||||
typeof partialState.isDrawerOpen === 'boolean'
|
typeof partialState.isDrawerOpen === 'boolean'
|
||||||
|
|||||||
@@ -29,7 +29,12 @@ export type StackActionType =
|
|||||||
|
|
||||||
export type StackRouterOptions = DefaultRouterOptions;
|
export type StackRouterOptions = DefaultRouterOptions;
|
||||||
|
|
||||||
export type StackNavigationState = NavigationState;
|
export type StackNavigationState = NavigationState & {
|
||||||
|
/**
|
||||||
|
* Type of the router, in this case, it's stack.
|
||||||
|
*/
|
||||||
|
type: 'stack';
|
||||||
|
};
|
||||||
|
|
||||||
export const StackActions = {
|
export const StackActions = {
|
||||||
push(name: string, params?: object): StackActionType {
|
push(name: string, params?: object): StackActionType {
|
||||||
@@ -47,6 +52,8 @@ export default function StackRouter(options: StackRouterOptions) {
|
|||||||
const router: Router<StackNavigationState, CommonAction | StackActionType> = {
|
const router: Router<StackNavigationState, CommonAction | StackActionType> = {
|
||||||
...BaseRouter,
|
...BaseRouter,
|
||||||
|
|
||||||
|
type: 'stack',
|
||||||
|
|
||||||
getInitialState({ routeNames, routeParamList }) {
|
getInitialState({ routeNames, routeParamList }) {
|
||||||
const initialRouteName =
|
const initialRouteName =
|
||||||
options.initialRouteName !== undefined
|
options.initialRouteName !== undefined
|
||||||
@@ -55,6 +62,7 @@ export default function StackRouter(options: StackRouterOptions) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: `stack-${shortid()}`,
|
key: `stack-${shortid()}`,
|
||||||
index: 0,
|
index: 0,
|
||||||
routeNames,
|
routeNames,
|
||||||
@@ -107,6 +115,7 @@ export default function StackRouter(options: StackRouterOptions) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'stack',
|
||||||
key: `stack-${shortid()}`,
|
key: `stack-${shortid()}`,
|
||||||
index: routes.length - 1,
|
index: routes.length - 1,
|
||||||
routeNames,
|
routeNames,
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ export type TabRouterOptions = DefaultRouterOptions & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type TabNavigationState = NavigationState & {
|
export type TabNavigationState = NavigationState & {
|
||||||
|
/**
|
||||||
|
* Type of the router, in this case, it's tab.
|
||||||
|
*/
|
||||||
|
type: 'tab';
|
||||||
/**
|
/**
|
||||||
* List of previously visited route keys.
|
* List of previously visited route keys.
|
||||||
*/
|
*/
|
||||||
@@ -54,6 +58,8 @@ export default function TabRouter({
|
|||||||
const router: Router<TabNavigationState, TabActionType | CommonAction> = {
|
const router: Router<TabNavigationState, TabActionType | CommonAction> = {
|
||||||
...BaseRouter,
|
...BaseRouter,
|
||||||
|
|
||||||
|
type: 'tab',
|
||||||
|
|
||||||
getInitialState({ routeNames, routeParamList }) {
|
getInitialState({ routeNames, routeParamList }) {
|
||||||
const index =
|
const index =
|
||||||
initialRouteName === undefined
|
initialRouteName === undefined
|
||||||
@@ -62,6 +68,7 @@ export default function TabRouter({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: `tab-${shortid()}`,
|
key: `tab-${shortid()}`,
|
||||||
index,
|
index,
|
||||||
routeNames,
|
routeNames,
|
||||||
@@ -105,17 +112,25 @@ export default function TabRouter({
|
|||||||
} as Route<string>;
|
} as Route<string>;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const index = Math.min(
|
||||||
|
Math.max(
|
||||||
|
typeof state.index === 'number'
|
||||||
|
? state.index
|
||||||
|
: routeNames.indexOf(state.routes[0].name),
|
||||||
|
0
|
||||||
|
),
|
||||||
|
routes.length - 1
|
||||||
|
);
|
||||||
|
|
||||||
const routeKeyHistory = state.routeKeyHistory
|
const routeKeyHistory = state.routeKeyHistory
|
||||||
? state.routeKeyHistory.filter(key => routes.find(r => r.key === key))
|
? state.routeKeyHistory.filter(key => routes.find(r => r.key === key))
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
stale: false,
|
stale: false,
|
||||||
|
type: 'tab',
|
||||||
key: `tab-${shortid()}`,
|
key: `tab-${shortid()}`,
|
||||||
index:
|
index,
|
||||||
typeof state.index === 'number' && state.index < routes.length
|
|
||||||
? state.index
|
|
||||||
: 0,
|
|
||||||
routeNames,
|
routeNames,
|
||||||
routeKeyHistory,
|
routeKeyHistory,
|
||||||
routes,
|
routes,
|
||||||
|
|||||||
@@ -3,6 +3,94 @@
|
|||||||
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.31](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.30...@react-navigation/stack@5.0.0-alpha.31) (2019-10-30)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @react-navigation/stack
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.30](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.29...@react-navigation/stack@5.0.0-alpha.30) (2019-10-29)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* keyboard manager in stack for fast swipe ([07bfc86](https://github.com/react-navigation/navigation-ex/commit/07bfc86))
|
||||||
|
* make clearKeyboardTimeout private ([876c318](https://github.com/react-navigation/navigation-ex/commit/876c318))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.29](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.28...@react-navigation/stack@5.0.0-alpha.29) (2019-10-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* conditions in gesture direction ([225e760](https://github.com/react-navigation/navigation-ex/commit/225e760))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.28](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.27...@react-navigation/stack@5.0.0-alpha.28) (2019-10-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* don't fire onOpen when screen is unmounting ([#137](https://github.com/react-navigation/navigation-ex/issues/137)) ([f22abb7](https://github.com/react-navigation/navigation-ex/commit/f22abb7)), closes [#136](https://github.com/react-navigation/navigation-ex/issues/136)
|
||||||
|
* don't keep unfocused header backgrounds visible ([031c4d2](https://github.com/react-navigation/navigation-ex/commit/031c4d2))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.27](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.26...@react-navigation/stack@5.0.0-alpha.27) (2019-10-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add an option to override safe area insets ([300791a](https://github.com/react-navigation/navigation-ex/commit/300791a))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.26](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.25...@react-navigation/stack@5.0.0-alpha.26) (2019-10-17)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* don't fade incoming background when fading header ([#127](https://github.com/react-navigation/navigation-ex/issues/127)) ([c6d0c19](https://github.com/react-navigation/navigation-ex/commit/c6d0c19))
|
||||||
|
* fix incorrect type ([731cf7d](https://github.com/react-navigation/navigation-ex/commit/731cf7d))
|
||||||
|
* use header height from style if specified ([442b95d](https://github.com/react-navigation/navigation-ex/commit/442b95d))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# [5.0.0-alpha.25](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.24...@react-navigation/stack@5.0.0-alpha.25) (2019-10-15)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* don't ignore descriptors change ([9d9fe31](https://github.com/react-navigation/navigation-ex/commit/9d9fe31))
|
||||||
|
* increase hitSlop of back button on Android ([c7da1e4](https://github.com/react-navigation/navigation-ex/commit/c7da1e4))
|
||||||
|
* interpolation in iOS modal presentation ([b32cda2](https://github.com/react-navigation/navigation-ex/commit/b32cda2))
|
||||||
|
* make modal presentation mode fullscreen on landscape ([#124](https://github.com/react-navigation/navigation-ex/issues/124)) ([e789846](https://github.com/react-navigation/navigation-ex/commit/e789846))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add a headerTitleAlign option to center or left align title ([6a0ca90](https://github.com/react-navigation/navigation-ex/commit/6a0ca90))
|
||||||
|
* export TransitionSpecs ([708dde0](https://github.com/react-navigation/navigation-ex/commit/708dde0))
|
||||||
|
* initial version of native stack ([#102](https://github.com/react-navigation/navigation-ex/issues/102)) ([ba3f718](https://github.com/react-navigation/navigation-ex/commit/ba3f718))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# [5.0.0-alpha.24](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.23...@react-navigation/stack@5.0.0-alpha.24) (2019-10-06)
|
# [5.0.0-alpha.24](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.23...@react-navigation/stack@5.0.0-alpha.24) (2019-10-06)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# `@react-navigation/stack`
|
# `@react-navigation/stack`
|
||||||
|
|
||||||
Bottom tab navigator for React Navigation following iOS design guidelines.
|
Stack navigator for React Navigation.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"android",
|
"android",
|
||||||
"stack"
|
"stack"
|
||||||
],
|
],
|
||||||
"version": "5.0.0-alpha.24",
|
"version": "5.0.0-alpha.31",
|
||||||
"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.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@react-native-community/bob": "^0.7.0",
|
"@react-native-community/bob": "^0.7.0",
|
||||||
@@ -41,12 +41,12 @@
|
|||||||
"@types/react": "^16.9.4",
|
"@types/react": "^16.9.4",
|
||||||
"@types/react-native": "^0.60.17",
|
"@types/react-native": "^0.60.17",
|
||||||
"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-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": "^1.0.0-alpha.22",
|
"react-native-screens": "^2.0.0-alpha.6",
|
||||||
"typescript": "^3.6.3"
|
"typescript": "^3.6.3"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
@@ -57,7 +57,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"
|
"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",
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ export function forModalPresentationIOS({
|
|||||||
layouts: { screen },
|
layouts: { screen },
|
||||||
insets,
|
insets,
|
||||||
}: StackCardInterpolationProps): StackCardInterpolatedStyle {
|
}: StackCardInterpolationProps): StackCardInterpolatedStyle {
|
||||||
const topOffset = 10;
|
const isLandscape = screen.width > screen.height;
|
||||||
|
const topOffset = isLandscape ? 0 : 10;
|
||||||
const statusBarHeight = insets.top;
|
const statusBarHeight = insets.top;
|
||||||
const aspectRatio = screen.height / screen.width;
|
const aspectRatio = screen.height / screen.width;
|
||||||
|
|
||||||
@@ -101,22 +102,29 @@ export function forModalPresentationIOS({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const overlayOpacity = interpolate(progress, {
|
const overlayOpacity = interpolate(progress, {
|
||||||
inputRange: [0, 1, 2],
|
inputRange: [0, 1, 1.0001, 2],
|
||||||
outputRange: [0, 0.3, 1],
|
outputRange: [0, 0.3, 1, 1],
|
||||||
});
|
});
|
||||||
|
|
||||||
const scale = interpolate(progress, {
|
const scale = isLandscape
|
||||||
inputRange: [0, 1, 2],
|
? 1
|
||||||
outputRange: [1, 1, screen.width ? 1 - (topOffset * 2) / screen.width : 1],
|
: interpolate(progress, {
|
||||||
});
|
inputRange: [0, 1, 2],
|
||||||
|
outputRange: [
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
screen.width ? 1 - (topOffset * 2) / screen.width : 1,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
const borderRadius =
|
const borderRadius = isLandscape
|
||||||
index === 0
|
? 0
|
||||||
? interpolate(progress, {
|
: index === 0
|
||||||
inputRange: [0, 1, 2],
|
? interpolate(progress, {
|
||||||
outputRange: [0, 0, 10],
|
inputRange: [0, 1, 2],
|
||||||
})
|
outputRange: [0, 0, 10],
|
||||||
: 10;
|
})
|
||||||
|
: 10;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cardStyle: {
|
cardStyle: {
|
||||||
|
|||||||
@@ -109,7 +109,12 @@ export function forFade({
|
|||||||
leftButtonStyle: { opacity },
|
leftButtonStyle: { opacity },
|
||||||
rightButtonStyle: { opacity },
|
rightButtonStyle: { opacity },
|
||||||
titleStyle: { opacity },
|
titleStyle: { opacity },
|
||||||
backgroundStyle: { opacity },
|
backgroundStyle: {
|
||||||
|
opacity: interpolate(progress, {
|
||||||
|
inputRange: [0, 1, 1.9, 2],
|
||||||
|
outputRange: [0, 1, 1, 0],
|
||||||
|
}),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as CardStyleInterpolators from './TransitionConfigs/CardStyleInterpolators';
|
import * as CardStyleInterpolators from './TransitionConfigs/CardStyleInterpolators';
|
||||||
import * as HeaderStyleInterpolators from './TransitionConfigs/HeaderStyleInterpolators';
|
import * as HeaderStyleInterpolators from './TransitionConfigs/HeaderStyleInterpolators';
|
||||||
|
import * as TransitionSpecs from './TransitionConfigs/TransitionSpecs';
|
||||||
import * as TransitionPresets from './TransitionConfigs/TransitionPresets';
|
import * as TransitionPresets from './TransitionConfigs/TransitionPresets';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,7 +25,12 @@ export { default as HeaderBackButton } from './views/Header/HeaderBackButton';
|
|||||||
/**
|
/**
|
||||||
* Transition presets
|
* Transition presets
|
||||||
*/
|
*/
|
||||||
export { CardStyleInterpolators, HeaderStyleInterpolators, TransitionPresets };
|
export {
|
||||||
|
CardStyleInterpolators,
|
||||||
|
HeaderStyleInterpolators,
|
||||||
|
TransitionSpecs,
|
||||||
|
TransitionPresets,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities
|
* Utilities
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user