mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-01-13 09:30:30 +08:00
Compare commits
58 Commits
@react-nav
...
@react-nav
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
5303e8ffb5 | ||
|
|
ba6b6ae025 | ||
|
|
16079d1050 | ||
|
|
b4a76814c6 | ||
|
|
8294efc8f4 | ||
|
|
a27ade8881 | ||
|
|
615b523d26 | ||
|
|
070c46ba64 | ||
|
|
d8394cf919 | ||
|
|
a7c4a4d7cd | ||
|
|
282b465ae1 | ||
|
|
6f5f4b7d35 | ||
|
|
d75915d1f3 | ||
|
|
832ed882bc | ||
|
|
8318c49331 | ||
|
|
ece6e3899e | ||
|
|
da944ccef9 | ||
|
|
bc3586ae3e | ||
|
|
19be2b4bbc | ||
|
|
a8851b730d | ||
|
|
7a5bcb446b | ||
|
|
1345a8fec6 | ||
|
|
7393464515 | ||
|
|
9810a06061 | ||
|
|
655a220137 | ||
|
|
e61f5941d7 | ||
|
|
8b78d617c0 | ||
|
|
1fd5a868a3 | ||
|
|
1153d5575b |
@@ -8,6 +8,7 @@
|
||||
"@react-navigation/routers",
|
||||
"@react-navigation/compat",
|
||||
"@react-navigation/stack",
|
||||
"@react-navigation/native-stack",
|
||||
"@react-navigation/drawer",
|
||||
"@react-navigation/bottom-tabs",
|
||||
"@react-navigation/material-top-tabs",
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,6 +5,8 @@
|
||||
.expo
|
||||
.gradle
|
||||
|
||||
local.properties
|
||||
|
||||
/coverage/
|
||||
/types/
|
||||
/dist/
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"git": {
|
||||
"commitMessage": "chore: release %s",
|
||||
"tagName": "v%s"
|
||||
},
|
||||
"github": {
|
||||
"release": true
|
||||
},
|
||||
"plugins": {
|
||||
"@release-it/conventional-changelog": {
|
||||
"preset": "angular"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
/* eslint-disable import/no-commonjs */
|
||||
|
||||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* eslint-disable import/no-commonjs */
|
||||
|
||||
module.exports = {
|
||||
extends: ['@commitlint/config-conventional'],
|
||||
};
|
||||
|
||||
25
package.json
25
package.json
@@ -23,27 +23,26 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/plugin-proposal-class-properties": "^7.5.5",
|
||||
"@babel/preset-env": "^7.5.5",
|
||||
"@babel/preset-env": "^7.6.2",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"@babel/preset-typescript": "^7.3.3",
|
||||
"@babel/runtime": "^7.5.5",
|
||||
"@commitlint/config-conventional": "^8.0.0",
|
||||
"@babel/preset-typescript": "^7.6.0",
|
||||
"@babel/runtime": "^7.6.2",
|
||||
"@commitlint/config-conventional": "^8.2.0",
|
||||
"@types/jest": "^24.0.13",
|
||||
"codecov": "^3.5.0",
|
||||
"commitlint": "^8.0.0",
|
||||
"codecov": "^3.6.1",
|
||||
"commitlint": "^8.2.0",
|
||||
"core-js": "^3.2.1",
|
||||
"eslint": "^5.16.0",
|
||||
"eslint-config-satya164": "^2.4.1",
|
||||
"husky": "^2.4.0",
|
||||
"eslint": "^6.5.1",
|
||||
"eslint-config-satya164": "^3.1.2",
|
||||
"husky": "^3.0.8",
|
||||
"jest": "^24.8.0",
|
||||
"lerna": "^3.16.4",
|
||||
"prettier": "^1.18.2",
|
||||
"typescript": "^3.5.3"
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
"resolutions": {
|
||||
"react": "16.8.3",
|
||||
"react-native": "0.59.10",
|
||||
"react-native-safe-area-view": "0.14.7"
|
||||
"react": "~16.8.3",
|
||||
"react-native": "~0.59.10"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
|
||||
@@ -3,6 +3,59 @@
|
||||
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.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)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.11...@react-navigation/bottom-tabs@5.0.0-alpha.12) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.11](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.10...@react-navigation/bottom-tabs@5.0.0-alpha.11) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/bottom-tabs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.10](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.9...@react-navigation/bottom-tabs@5.0.0-alpha.10) (2019-09-27)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* export BottomTabBar props type ([#109](https://github.com/react-navigation/navigation-ex/issues/109)) ([1fd5a86](https://github.com/react-navigation/navigation-ex/commit/1fd5a86))
|
||||
* export some more type aliases ([8b78d61](https://github.com/react-navigation/navigation-ex/commit/8b78d61))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.9](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/bottom-tabs@5.0.0-alpha.8...@react-navigation/bottom-tabs@5.0.0-alpha.9) (2019-09-17)
|
||||
|
||||
|
||||
|
||||
@@ -10,11 +10,40 @@ Open a Terminal in your project's folder and run,
|
||||
yarn add @react-navigation/core @react-navigation/bottom-tabs
|
||||
```
|
||||
|
||||
Now we need to install [`react-native-safe-area-context`](https://github.com/th3rdwave/react-native-safe-area-context).
|
||||
|
||||
If you are using Expo, to ensure that you get the compatible versions of the libraries, run:
|
||||
|
||||
```sh
|
||||
expo install react-native-safe-area-context
|
||||
```
|
||||
|
||||
If you are not using Expo, run the following:
|
||||
|
||||
```sh
|
||||
yarn add react-native-safe-area-context
|
||||
```
|
||||
|
||||
If you are using Expo, you are done. Otherwise, continue to the next steps.
|
||||
|
||||
To complete the linking on iOS, make sure you have [Cocoapods](https://cocoapods.org/) installed. Then run:
|
||||
|
||||
```sh
|
||||
cd ios
|
||||
pod install
|
||||
cd ..
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import { MaterialCommunityIcons } from 'react-native-vector-icons';
|
||||
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
||||
|
||||
const getTabBarIcon = name => ({ color, size }) => (
|
||||
<MaterialCommunityIcons name={name} color={color} size={size} />
|
||||
);
|
||||
|
||||
const BottomTabs = createBottomTabNavigator();
|
||||
|
||||
export default function App() {
|
||||
@@ -25,7 +54,7 @@ export default function App() {
|
||||
component={Article}
|
||||
options={{
|
||||
tabBarLabel: 'Article',
|
||||
tabBarIcon: 'chrome-reader-mode',
|
||||
tabBarIcon: getTabBarIcon('file-document-box'),
|
||||
}}
|
||||
/>
|
||||
<BottomTabs.Screen
|
||||
@@ -33,7 +62,7 @@ export default function App() {
|
||||
component={Chat}
|
||||
options={{
|
||||
tabBarLabel: 'Chat',
|
||||
tabBarIcon: 'chat-bubble',
|
||||
tabBarIcon: getTabBarIcon('message-reply'),
|
||||
}}
|
||||
/>
|
||||
<BottomTabs.Screen
|
||||
@@ -41,7 +70,7 @@ export default function App() {
|
||||
component={Contacts}
|
||||
options={{
|
||||
tabBarLabel: 'Contacts',
|
||||
tabBarIcon: 'contacts',
|
||||
tabBarIcon: getTabBarIcon('contacts'),
|
||||
}}
|
||||
/>
|
||||
</BottomTabs.Navigator>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"android",
|
||||
"tab"
|
||||
],
|
||||
"version": "5.0.0-alpha.9",
|
||||
"version": "5.0.0-alpha.14",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -33,22 +33,23 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/routers": "^5.0.0-alpha.7",
|
||||
"react-native-safe-area-view": "^0.14.6"
|
||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-native-community/bob": "^0.7.0",
|
||||
"@types/react": "^16.8.24",
|
||||
"@types/react-native": "^0.60.2",
|
||||
"del-cli": "^2.0.0",
|
||||
"react": "16.8.3",
|
||||
"react-native": "0.59.10",
|
||||
"typescript": "^3.5.3"
|
||||
"@types/react": "^16.9.4",
|
||||
"@types/react-native": "^0.60.17",
|
||||
"del-cli": "^3.0.0",
|
||||
"react": "~16.8.3",
|
||||
"react-native": "~0.59.10",
|
||||
"react-native-safe-area-context": "^0.3.6",
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||
"react": "*",
|
||||
"react-native": "*"
|
||||
"react-native": "*",
|
||||
"react-native-safe-area-context": "^0.3.6"
|
||||
},
|
||||
"@react-native-community/bob": {
|
||||
"source": "src",
|
||||
|
||||
@@ -13,4 +13,9 @@ export { default as BottomTabBar } from './views/BottomTabBar';
|
||||
/**
|
||||
* Types
|
||||
*/
|
||||
export { BottomTabNavigationOptions, BottomTabNavigationProp } from './types';
|
||||
export {
|
||||
BottomTabNavigationOptions,
|
||||
BottomTabNavigationProp,
|
||||
BottomTabBarProps,
|
||||
BottomTabBarOptions,
|
||||
} from './types';
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
TextStyle,
|
||||
ViewStyle,
|
||||
} from 'react-native';
|
||||
import SafeAreaView from 'react-native-safe-area-view';
|
||||
import {
|
||||
NavigationHelpers,
|
||||
NavigationProp,
|
||||
@@ -67,26 +66,26 @@ export type BottomTabNavigationOptions = {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
tabBarLabel?:
|
||||
| React.ReactNode
|
||||
| ((props: {
|
||||
focused: boolean;
|
||||
tintColor: string;
|
||||
horizontal: boolean;
|
||||
color: string;
|
||||
size: number;
|
||||
}) => 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?:
|
||||
| React.ReactNode
|
||||
| ((props: {
|
||||
focused: boolean;
|
||||
tintColor: string;
|
||||
horizontal: boolean;
|
||||
color: string;
|
||||
size: number;
|
||||
}) => React.ReactNode);
|
||||
|
||||
/**
|
||||
@@ -140,7 +139,7 @@ export type BottomTabNavigationConfig = {
|
||||
|
||||
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;
|
||||
/**
|
||||
@@ -221,7 +220,7 @@ export type BottomTabBarProps = BottomTabBarOptions & {
|
||||
}) =>
|
||||
| ((scene: {
|
||||
focused: boolean;
|
||||
tintColor: string;
|
||||
color: string;
|
||||
orientation: 'horizontal' | 'vertical';
|
||||
}) => React.ReactNode | undefined)
|
||||
| React.ReactNode;
|
||||
@@ -229,8 +228,9 @@ export type BottomTabBarProps = BottomTabBarOptions & {
|
||||
renderIcon: (props: {
|
||||
route: Route<string>;
|
||||
focused: boolean;
|
||||
tintColor: string;
|
||||
horizontal: boolean;
|
||||
color: string;
|
||||
size: number;
|
||||
}) => React.ReactNode;
|
||||
safeAreaInset?: React.ComponentProps<typeof SafeAreaView>['forceInset'];
|
||||
activeTintColor: string;
|
||||
inactiveTintColor: string;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
View,
|
||||
Animated,
|
||||
StyleSheet,
|
||||
Keyboard,
|
||||
@@ -8,8 +9,8 @@ import {
|
||||
ScaledSize,
|
||||
Dimensions,
|
||||
} from 'react-native';
|
||||
import SafeAreaView from 'react-native-safe-area-view';
|
||||
import { Route, NavigationContext } from '@react-navigation/core';
|
||||
import { SafeAreaConsumer } from 'react-native-safe-area-context';
|
||||
|
||||
import TabBarIcon from './TabBarIcon';
|
||||
import TouchableWithoutFeedbackWrapper from './TouchableWithoutFeedbackWrapper';
|
||||
@@ -22,11 +23,7 @@ type State = {
|
||||
visible: Animated.Value;
|
||||
};
|
||||
|
||||
type Props = BottomTabBarProps & {
|
||||
activeTintColor: string;
|
||||
inactiveTintColor: string;
|
||||
safeAreaInset: React.ComponentProps<typeof SafeAreaView>['forceInset'];
|
||||
};
|
||||
type Props = BottomTabBarProps;
|
||||
|
||||
const majorVersion = parseInt(Platform.Version as string, 10);
|
||||
const isIos = Platform.OS === 'ios';
|
||||
@@ -36,7 +33,7 @@ const DEFAULT_MAX_TAB_ITEM_WIDTH = 125;
|
||||
|
||||
export default class TabBarBottom extends React.Component<Props, State> {
|
||||
static defaultProps = {
|
||||
keyboardHidesTabBar: true,
|
||||
keyboardHidesTabBar: false,
|
||||
activeTintColor: '#007AFF',
|
||||
activeBackgroundColor: 'transparent',
|
||||
inactiveTintColor: '#8E8E93',
|
||||
@@ -45,9 +42,6 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
||||
showIcon: true,
|
||||
allowFontScaling: true,
|
||||
adaptive: isIOS11,
|
||||
safeAreaInset: { bottom: 'always', top: 'never' } as React.ComponentProps<
|
||||
typeof SafeAreaView
|
||||
>['forceInset'],
|
||||
};
|
||||
|
||||
state = {
|
||||
@@ -89,7 +83,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
||||
this.setState({ keyboard: true }, () =>
|
||||
Animated.timing(this.state.visible, {
|
||||
toValue: 0,
|
||||
duration: 150,
|
||||
duration: 200,
|
||||
useNativeDriver: true,
|
||||
}).start()
|
||||
);
|
||||
@@ -97,10 +91,12 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
||||
private handleKeyboardHide = () =>
|
||||
Animated.timing(this.state.visible, {
|
||||
toValue: 1,
|
||||
duration: 100,
|
||||
duration: 250,
|
||||
useNativeDriver: true,
|
||||
}).start(() => {
|
||||
this.setState({ keyboard: false });
|
||||
}).start(({ finished }) => {
|
||||
if (finished) {
|
||||
this.setState({ keyboard: false });
|
||||
}
|
||||
});
|
||||
|
||||
private handleLayout = (e: LayoutChangeEvent) => {
|
||||
@@ -141,7 +137,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
||||
|
||||
const label = this.props.getLabelText({ route });
|
||||
const horizontal = this.shouldUseHorizontalLabels();
|
||||
const tintColor = focused ? activeTintColor : inactiveTintColor;
|
||||
const color = focused ? activeTintColor : inactiveTintColor;
|
||||
|
||||
if (typeof label === 'string') {
|
||||
return (
|
||||
@@ -149,7 +145,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
||||
numberOfLines={1}
|
||||
style={[
|
||||
styles.label,
|
||||
{ color: tintColor },
|
||||
{ color },
|
||||
showIcon && horizontal ? styles.labelBeside : styles.labelBeneath,
|
||||
labelStyle,
|
||||
]}
|
||||
@@ -163,7 +159,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
||||
if (typeof label === 'function') {
|
||||
return label({
|
||||
focused,
|
||||
tintColor,
|
||||
color,
|
||||
orientation: horizontal ? 'horizontal' : 'vertical',
|
||||
});
|
||||
}
|
||||
@@ -198,7 +194,7 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
||||
return (
|
||||
<TabBarIcon
|
||||
route={route}
|
||||
horizontal={horizontal}
|
||||
size={horizontal ? 17 : 24}
|
||||
activeOpacity={activeOpacity}
|
||||
inactiveOpacity={inactiveOpacity}
|
||||
activeTintColor={activeTintColor}
|
||||
@@ -272,100 +268,102 @@ export default class TabBarBottom extends React.Component<Props, State> {
|
||||
getAccessibilityStates,
|
||||
getButtonComponent,
|
||||
getTestID,
|
||||
safeAreaInset,
|
||||
style,
|
||||
tabStyle,
|
||||
} = this.props;
|
||||
const { routes } = state;
|
||||
|
||||
const tabBarStyle = [
|
||||
styles.tabBar,
|
||||
// @ts-ignore
|
||||
this.shouldUseHorizontalLabels() && !Platform.isPad
|
||||
? styles.tabBarCompact
|
||||
: styles.tabBarRegular,
|
||||
style,
|
||||
];
|
||||
|
||||
return (
|
||||
<Animated.View
|
||||
style={[
|
||||
styles.container,
|
||||
keyboardHidesTabBar
|
||||
? // eslint-disable-next-line react-native/no-inline-styles
|
||||
<SafeAreaConsumer>
|
||||
{insets => (
|
||||
<Animated.View
|
||||
style={[
|
||||
styles.tabBar,
|
||||
keyboardHidesTabBar
|
||||
? {
|
||||
// When the keyboard is shown, slide down the tab bar
|
||||
transform: [
|
||||
{
|
||||
translateY: this.state.visible.interpolate({
|
||||
inputRange: [0, 1],
|
||||
outputRange: [this.state.layout.height, 0],
|
||||
}),
|
||||
},
|
||||
],
|
||||
// Absolutely position the tab bar so that the content is below it
|
||||
// This is needed to avoid gap at bottom when the tab bar is hidden
|
||||
position: this.state.keyboard ? 'absolute' : null,
|
||||
}
|
||||
: null,
|
||||
{
|
||||
// When the keyboard is shown, slide down the tab bar
|
||||
transform: [
|
||||
{
|
||||
translateY: this.state.visible.interpolate({
|
||||
inputRange: [0, 1],
|
||||
outputRange: [this.state.layout.height, 0],
|
||||
}),
|
||||
},
|
||||
],
|
||||
// Absolutely position the tab bar so that the content is below it
|
||||
// This is needed to avoid gap at bottom when the tab bar is hidden
|
||||
position: this.state.keyboard ? 'absolute' : null,
|
||||
}
|
||||
: null,
|
||||
]}
|
||||
pointerEvents={
|
||||
keyboardHidesTabBar && this.state.keyboard ? 'none' : 'auto'
|
||||
}
|
||||
onLayout={this.handleLayout}
|
||||
>
|
||||
<SafeAreaView style={tabBarStyle} forceInset={safeAreaInset}>
|
||||
{routes.map((route, index) => {
|
||||
const focused = index === state.index;
|
||||
const scene = { route, focused };
|
||||
const accessibilityLabel = getAccessibilityLabel({
|
||||
route,
|
||||
});
|
||||
height:
|
||||
// @ts-ignore
|
||||
(this.shouldUseHorizontalLabels() && !Platform.isPad
|
||||
? COMPACT_HEIGHT
|
||||
: DEFAULT_HEIGHT) + (insets ? insets.bottom : 0),
|
||||
paddingBottom: insets ? insets.bottom : 0,
|
||||
},
|
||||
style,
|
||||
]}
|
||||
pointerEvents={
|
||||
keyboardHidesTabBar && this.state.keyboard ? 'none' : 'auto'
|
||||
}
|
||||
>
|
||||
<View style={styles.content} onLayout={this.handleLayout}>
|
||||
{routes.map((route, index) => {
|
||||
const focused = index === state.index;
|
||||
const scene = { route, focused };
|
||||
const accessibilityLabel = getAccessibilityLabel({
|
||||
route,
|
||||
});
|
||||
|
||||
const accessibilityRole = getAccessibilityRole({
|
||||
route,
|
||||
});
|
||||
const accessibilityRole = getAccessibilityRole({
|
||||
route,
|
||||
});
|
||||
|
||||
const accessibilityStates = getAccessibilityStates(scene);
|
||||
const accessibilityStates = getAccessibilityStates(scene);
|
||||
|
||||
const testID = getTestID({ route });
|
||||
const testID = getTestID({ route });
|
||||
|
||||
const backgroundColor = focused
|
||||
? activeBackgroundColor
|
||||
: inactiveBackgroundColor;
|
||||
const backgroundColor = focused
|
||||
? activeBackgroundColor
|
||||
: inactiveBackgroundColor;
|
||||
|
||||
const ButtonComponent =
|
||||
getButtonComponent({ route }) || TouchableWithoutFeedbackWrapper;
|
||||
const ButtonComponent =
|
||||
getButtonComponent({ route }) ||
|
||||
TouchableWithoutFeedbackWrapper;
|
||||
|
||||
return (
|
||||
<NavigationContext.Provider
|
||||
key={route.key}
|
||||
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)}
|
||||
{this.renderLabel(scene)}
|
||||
</ButtonComponent>
|
||||
</NavigationContext.Provider>
|
||||
);
|
||||
})}
|
||||
</SafeAreaView>
|
||||
</Animated.View>
|
||||
return (
|
||||
<NavigationContext.Provider
|
||||
key={route.key}
|
||||
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)}
|
||||
{this.renderLabel(scene)}
|
||||
</ButtonComponent>
|
||||
</NavigationContext.Provider>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
</Animated.View>
|
||||
)}
|
||||
</SafeAreaConsumer>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -375,22 +373,17 @@ const COMPACT_HEIGHT = 29;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
tabBar: {
|
||||
backgroundColor: '#fff',
|
||||
borderTopWidth: StyleSheet.hairlineWidth,
|
||||
borderTopColor: 'rgba(0, 0, 0, .3)',
|
||||
flexDirection: 'row',
|
||||
},
|
||||
container: {
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
backgroundColor: '#fff',
|
||||
borderTopWidth: StyleSheet.hairlineWidth,
|
||||
borderTopColor: 'rgba(0, 0, 0, .3)',
|
||||
elevation: 8,
|
||||
},
|
||||
tabBarCompact: {
|
||||
height: COMPACT_HEIGHT,
|
||||
},
|
||||
tabBarRegular: {
|
||||
height: DEFAULT_HEIGHT,
|
||||
content: {
|
||||
flex: 1,
|
||||
flexDirection: 'row',
|
||||
},
|
||||
tab: {
|
||||
flex: 1,
|
||||
|
||||
@@ -9,6 +9,7 @@ import { Route, CommonActions } from '@react-navigation/core';
|
||||
import { TabNavigationState } from '@react-navigation/routers';
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import { ScreenContainer } from 'react-native-screens';
|
||||
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
||||
|
||||
import BottomTabBar from './BottomTabBar';
|
||||
import {
|
||||
@@ -63,13 +64,13 @@ export default class BottomTabView extends React.Component<Props, State> {
|
||||
private renderIcon = ({
|
||||
route,
|
||||
focused,
|
||||
tintColor,
|
||||
horizontal,
|
||||
color,
|
||||
size,
|
||||
}: {
|
||||
route: Route<string>;
|
||||
focused: boolean;
|
||||
tintColor: string;
|
||||
horizontal: boolean;
|
||||
color: string;
|
||||
size: number;
|
||||
}) => {
|
||||
const { descriptors } = this.props;
|
||||
const descriptor = descriptors[route.key];
|
||||
@@ -77,7 +78,7 @@ export default class BottomTabView extends React.Component<Props, State> {
|
||||
|
||||
if (options.tabBarIcon) {
|
||||
return typeof options.tabBarIcon === 'function'
|
||||
? options.tabBarIcon({ focused, tintColor, horizontal })
|
||||
? options.tabBarIcon({ focused, color, size })
|
||||
: options.tabBarIcon;
|
||||
}
|
||||
|
||||
@@ -198,29 +199,31 @@ export default class BottomTabView extends React.Component<Props, State> {
|
||||
const { loaded } = this.state;
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<ScreenContainer style={styles.pages}>
|
||||
{routes.map((route, index) => {
|
||||
if (lazy && !loaded.includes(index)) {
|
||||
// Don't render a screen if we've never navigated to it
|
||||
return null;
|
||||
}
|
||||
<SafeAreaProvider>
|
||||
<View style={styles.container}>
|
||||
<ScreenContainer style={styles.pages}>
|
||||
{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;
|
||||
|
||||
return (
|
||||
<ResourceSavingScene
|
||||
key={route.key}
|
||||
style={StyleSheet.absoluteFill}
|
||||
isVisible={isFocused}
|
||||
>
|
||||
{descriptors[route.key].render()}
|
||||
</ResourceSavingScene>
|
||||
);
|
||||
})}
|
||||
</ScreenContainer>
|
||||
{this.renderTabBar()}
|
||||
</View>
|
||||
return (
|
||||
<ResourceSavingScene
|
||||
key={route.key}
|
||||
style={StyleSheet.absoluteFill}
|
||||
isVisible={isFocused}
|
||||
>
|
||||
{descriptors[route.key].render()}
|
||||
</ResourceSavingScene>
|
||||
);
|
||||
})}
|
||||
</ScreenContainer>
|
||||
{this.renderTabBar()}
|
||||
</View>
|
||||
</SafeAreaProvider>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,12 +24,7 @@ export default class ResourceSavingScene extends React.Component<Props> {
|
||||
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
styles.container,
|
||||
style,
|
||||
// eslint-disable-next-line react-native/no-inline-styles
|
||||
{ opacity: isVisible ? 1 : 0 },
|
||||
]}
|
||||
style={[styles.container, style, { opacity: isVisible ? 1 : 0 }]}
|
||||
collapsable={false}
|
||||
removeClippedSubviews={
|
||||
// On iOS, set removeClippedSubviews to true only when not focused
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Route } from '@react-navigation/core';
|
||||
|
||||
type Props = {
|
||||
route: Route<string>;
|
||||
horizontal: boolean;
|
||||
size: number;
|
||||
activeOpacity: number;
|
||||
inactiveOpacity: number;
|
||||
activeTintColor: string;
|
||||
@@ -12,8 +12,8 @@ type Props = {
|
||||
renderIcon: (props: {
|
||||
route: Route<string>;
|
||||
focused: boolean;
|
||||
tintColor: string;
|
||||
horizontal: boolean;
|
||||
color: string;
|
||||
size: number;
|
||||
}) => React.ReactNode;
|
||||
style: StyleProp<ViewStyle>;
|
||||
};
|
||||
@@ -25,7 +25,7 @@ export default function TabBarIcon({
|
||||
activeTintColor,
|
||||
inactiveTintColor,
|
||||
renderIcon,
|
||||
horizontal,
|
||||
size,
|
||||
style,
|
||||
}: Props) {
|
||||
// We render the icon twice at the same position on top of each other:
|
||||
@@ -36,16 +36,16 @@ export default function TabBarIcon({
|
||||
{renderIcon({
|
||||
route,
|
||||
focused: true,
|
||||
horizontal,
|
||||
tintColor: activeTintColor,
|
||||
size,
|
||||
color: activeTintColor,
|
||||
})}
|
||||
</View>
|
||||
<View style={[styles.icon, { opacity: inactiveOpacity }]}>
|
||||
{renderIcon({
|
||||
route,
|
||||
focused: false,
|
||||
horizontal,
|
||||
tintColor: inactiveTintColor,
|
||||
size,
|
||||
color: inactiveTintColor,
|
||||
})}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -3,6 +3,49 @@
|
||||
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.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)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/compat
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.6](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.5...@react-navigation/compat@5.0.0-alpha.6) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/compat
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.5](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.4...@react-navigation/compat@5.0.0-alpha.5) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/compat
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.4](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.3...@react-navigation/compat@5.0.0-alpha.4) (2019-09-27)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/compat
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.3](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/compat@5.0.0-alpha.2...@react-navigation/compat@5.0.0-alpha.3) (2019-09-23)
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/compat",
|
||||
"description": "Compatibility layer to write navigator definitions in static configuration format",
|
||||
"version": "5.0.0-alpha.3",
|
||||
"version": "5.0.0-alpha.8",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -24,16 +24,16 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/routers": "^5.0.0-alpha.7"
|
||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^16.8.19",
|
||||
"react": "^16.8.3",
|
||||
"typescript": "^3.5.3"
|
||||
"@types/react": "^16.9.4",
|
||||
"react": "~16.8.3",
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||
"react": "^16.8.3"
|
||||
"react": "~16.8.3"
|
||||
},
|
||||
"@react-native-community/bob": {
|
||||
"source": "src",
|
||||
|
||||
@@ -3,6 +3,82 @@
|
||||
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.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)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/core
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.13](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.12...@react-navigation/core@5.0.0-alpha.13) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/core
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.11...@react-navigation/core@5.0.0-alpha.12) (2019-10-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* don't merge state with existing state during reset. fixes [#111](https://github.com/react-navigation/navigation-ex/issues/111) ([7393464](https://github.com/react-navigation/navigation-ex/commit/7393464))
|
||||
* don't throw when switching navigator. fixes [#91](https://github.com/react-navigation/navigation-ex/issues/91) ([19be2b4](https://github.com/react-navigation/navigation-ex/commit/19be2b4))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add a getRootState method ([#119](https://github.com/react-navigation/navigation-ex/issues/119)) ([7a5bcb4](https://github.com/react-navigation/navigation-ex/commit/7a5bcb4))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.11](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.10...@react-navigation/core@5.0.0-alpha.11) (2019-09-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fire blur event when a route is removed with a delay ([1153d55](https://github.com/react-navigation/navigation-ex/commit/1153d55)), closes [#110](https://github.com/react-navigation/navigation-ex/issues/110)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add a method to reset root navigator state ([e61f594](https://github.com/react-navigation/navigation-ex/commit/e61f594))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.10](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/core@5.0.0-alpha.9...@react-navigation/core@5.0.0-alpha.10) (2019-09-17)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/core
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"react-native",
|
||||
"react-navigation"
|
||||
],
|
||||
"version": "5.0.0-alpha.10",
|
||||
"version": "5.0.0-alpha.16",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -31,22 +31,22 @@
|
||||
"dependencies": {
|
||||
"escape-string-regexp": "^2.0.0",
|
||||
"query-string": "^6.8.3",
|
||||
"shortid": "^2.2.14",
|
||||
"use-subscription": "^1.0.0"
|
||||
"shortid": "^2.2.15",
|
||||
"use-subscription": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.4.5",
|
||||
"@babel/core": "^7.6.2",
|
||||
"@react-native-community/bob": "^0.7.0",
|
||||
"@types/react": "^16.8.19",
|
||||
"@types/react": "^16.9.4",
|
||||
"@types/shortid": "^0.0.29",
|
||||
"del-cli": "^2.0.0",
|
||||
"react": "^16.8.3",
|
||||
"del-cli": "^3.0.0",
|
||||
"react": "~16.8.3",
|
||||
"react-native-testing-library": "^1.9.1",
|
||||
"react-test-renderer": "16.8.3",
|
||||
"typescript": "^3.5.3"
|
||||
"react-test-renderer": "~16.8.3",
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.3"
|
||||
"react": "~16.8.3"
|
||||
},
|
||||
"@react-native-community/bob": {
|
||||
"source": "src",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import shortid from 'shortid';
|
||||
import { CommonAction, NavigationState } from './types';
|
||||
import { CommonAction, NavigationState, PartialState } from './types';
|
||||
|
||||
/**
|
||||
* Base router object that can be used when writing custom routers.
|
||||
@@ -9,7 +9,7 @@ const BaseRouter = {
|
||||
getStateForAction<State extends NavigationState>(
|
||||
state: State,
|
||||
action: CommonAction
|
||||
): State | null {
|
||||
): State | PartialState<State> | null {
|
||||
switch (action.type) {
|
||||
case 'REPLACE': {
|
||||
const index = action.source
|
||||
@@ -56,12 +56,7 @@ const BaseRouter = {
|
||||
}
|
||||
|
||||
case 'RESET':
|
||||
return {
|
||||
...state,
|
||||
...action.payload,
|
||||
key: state.key,
|
||||
routeNames: state.routeNames,
|
||||
};
|
||||
return action.payload as PartialState<State>;
|
||||
|
||||
default:
|
||||
return null;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
import { NavigationState, PartialState } from './types';
|
||||
|
||||
export type Action =
|
||||
|
||||
@@ -18,25 +18,30 @@ export const SingleNavigatorContext = React.createContext<
|
||||
* Component which ensures that there's only one navigator nested under it.
|
||||
*/
|
||||
export default function EnsureSingleNavigator({ children }: Props) {
|
||||
const [currentKey, setCurrentKey] = React.useState<string | undefined>();
|
||||
const navigatorKeyRef = React.useRef<string | undefined>();
|
||||
|
||||
const value = React.useMemo(
|
||||
() => ({
|
||||
register(key: string) {
|
||||
const currentKey = navigatorKeyRef.current;
|
||||
|
||||
if (currentKey !== undefined && key !== currentKey) {
|
||||
throw new Error(MULTIPLE_NAVIGATOR_ERROR);
|
||||
}
|
||||
|
||||
setCurrentKey(key);
|
||||
navigatorKeyRef.current = key;
|
||||
},
|
||||
unregister(key: string) {
|
||||
if (currentKey !== undefined && key !== currentKey) {
|
||||
throw new Error(MULTIPLE_NAVIGATOR_ERROR);
|
||||
const currentKey = navigatorKeyRef.current;
|
||||
|
||||
if (key !== currentKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
setCurrentKey(undefined);
|
||||
navigatorKeyRef.current = undefined;
|
||||
},
|
||||
}),
|
||||
[currentKey]
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import * as React from 'react';
|
||||
import { NavigationAction, NavigationHelpers, ParamListBase } from './types';
|
||||
import {
|
||||
NavigationAction,
|
||||
NavigationHelpers,
|
||||
NavigationState,
|
||||
ParamListBase,
|
||||
} from './types';
|
||||
|
||||
export type ChildActionListener = (
|
||||
action: NavigationAction,
|
||||
@@ -14,6 +19,8 @@ export type FocusedNavigationListener = <T>(
|
||||
callback: FocusedNavigationCallback<T>
|
||||
) => { handled: boolean; result: T };
|
||||
|
||||
export type NavigatorStateGetter = () => NavigationState;
|
||||
|
||||
/**
|
||||
* Context which holds the required helpers needed to build nested navigators.
|
||||
*/
|
||||
@@ -25,6 +32,7 @@ const NavigationBuilderContext = React.createContext<{
|
||||
addActionListener?: (listener: ChildActionListener) => void;
|
||||
addFocusedListener?: (listener: FocusedNavigationListener) => void;
|
||||
onRouteFocus?: (key: string) => void;
|
||||
addStateGetter?: (key: string, getter: NavigatorStateGetter) => void;
|
||||
trackAction: (action: NavigationAction) => void;
|
||||
}>({
|
||||
trackAction: () => undefined,
|
||||
|
||||
@@ -2,8 +2,10 @@ import * as React from 'react';
|
||||
import * as CommonActions from './CommonActions';
|
||||
import EnsureSingleNavigator from './EnsureSingleNavigator';
|
||||
import NavigationBuilderContext from './NavigationBuilderContext';
|
||||
import ResetRootContext from './ResetRootContext';
|
||||
import useFocusedListeners from './useFocusedListeners';
|
||||
import useDevTools from './useDevTools';
|
||||
import useStateGetters from './useStateGetters';
|
||||
|
||||
import {
|
||||
Route,
|
||||
@@ -23,7 +25,9 @@ const MISSING_CONTEXT_ERROR =
|
||||
export const NavigationStateContext = React.createContext<{
|
||||
state?: NavigationState | PartialState<NavigationState>;
|
||||
getState: () => NavigationState | PartialState<NavigationState> | undefined;
|
||||
setState: (state: NavigationState | undefined) => void;
|
||||
setState: (
|
||||
state: NavigationState | PartialState<NavigationState> | undefined
|
||||
) => void;
|
||||
key?: string;
|
||||
performTransaction: (action: () => void) => void;
|
||||
}>({
|
||||
@@ -86,8 +90,27 @@ const Container = React.forwardRef(function NavigationContainer(
|
||||
getPartialState(initialState)
|
||||
);
|
||||
|
||||
const navigationStateRef = React.useRef<State>();
|
||||
const transactionStateRef = React.useRef<State | null>(null);
|
||||
const isTransactionActiveRef = React.useRef<boolean>(false);
|
||||
const isFirstMountRef = React.useRef<boolean>(true);
|
||||
const skipTrackingRef = React.useRef<boolean>(false);
|
||||
|
||||
const reset = React.useCallback((state: NavigationState) => {
|
||||
skipTrackingRef.current = true;
|
||||
setNavigationState(state);
|
||||
}, []);
|
||||
|
||||
const { trackState, trackAction } = useDevTools({
|
||||
name: '@react-navigation',
|
||||
reset,
|
||||
state,
|
||||
});
|
||||
|
||||
const { listeners, addListener: addFocusedListener } = useFocusedListeners();
|
||||
|
||||
const { getStateForRoute, addStateGetter } = useStateGetters();
|
||||
|
||||
const dispatch = (
|
||||
action: NavigationAction | ((state: NavigationState) => NavigationAction)
|
||||
) => {
|
||||
@@ -106,13 +129,24 @@ const Container = React.forwardRef(function NavigationContainer(
|
||||
}
|
||||
};
|
||||
|
||||
const resetRoot = React.useCallback(
|
||||
(state: PartialState<NavigationState> | NavigationState) => {
|
||||
trackAction('@@RESET_ROOT');
|
||||
setNavigationState(state);
|
||||
},
|
||||
[trackAction]
|
||||
);
|
||||
|
||||
const getRootState = () => {
|
||||
return getStateForRoute('root');
|
||||
};
|
||||
|
||||
React.useImperativeHandle(ref, () => ({
|
||||
...(Object.keys(CommonActions) as Array<keyof typeof CommonActions>).reduce<
|
||||
any
|
||||
>((acc, name) => {
|
||||
acc[name] = (...args: any[]) =>
|
||||
dispatch(
|
||||
// eslint-disable-next-line import/namespace
|
||||
CommonActions[name](
|
||||
// @ts-ignore
|
||||
...args
|
||||
@@ -120,37 +154,19 @@ const Container = React.forwardRef(function NavigationContainer(
|
||||
);
|
||||
return acc;
|
||||
}, {}),
|
||||
resetRoot: (state: PartialState<NavigationState> | NavigationState) => {
|
||||
trackAction('@@RESET_ROOT');
|
||||
setNavigationState(state);
|
||||
},
|
||||
resetRoot,
|
||||
dispatch,
|
||||
canGoBack,
|
||||
getRootState,
|
||||
}));
|
||||
|
||||
const navigationStateRef = React.useRef<State>();
|
||||
const transactionStateRef = React.useRef<State | null>(null);
|
||||
const isTransactionActiveRef = React.useRef<boolean>(false);
|
||||
const isFirstMountRef = React.useRef<boolean>(true);
|
||||
const skipTrackingRef = React.useRef<boolean>(false);
|
||||
|
||||
const reset = React.useCallback((state: NavigationState) => {
|
||||
skipTrackingRef.current = true;
|
||||
setNavigationState(state);
|
||||
}, []);
|
||||
|
||||
const { trackState, trackAction } = useDevTools({
|
||||
name: '@react-navigation',
|
||||
reset,
|
||||
state,
|
||||
});
|
||||
|
||||
const builderContext = React.useMemo(
|
||||
() => ({
|
||||
addFocusedListener,
|
||||
addStateGetter,
|
||||
trackAction,
|
||||
}),
|
||||
[addFocusedListener, trackAction]
|
||||
[addFocusedListener, trackAction, addStateGetter]
|
||||
);
|
||||
|
||||
const performTransaction = React.useCallback((callback: () => void) => {
|
||||
@@ -220,7 +236,9 @@ const Container = React.forwardRef(function NavigationContainer(
|
||||
return (
|
||||
<NavigationBuilderContext.Provider value={builderContext}>
|
||||
<NavigationStateContext.Provider value={context}>
|
||||
<EnsureSingleNavigator>{children}</EnsureSingleNavigator>
|
||||
<ResetRootContext.Provider value={resetRoot}>
|
||||
<EnsureSingleNavigator>{children}</EnsureSingleNavigator>
|
||||
</ResetRootContext.Provider>
|
||||
</NavigationStateContext.Provider>
|
||||
</NavigationBuilderContext.Provider>
|
||||
);
|
||||
|
||||
15
packages/core/src/ResetRootContext.tsx
Normal file
15
packages/core/src/ResetRootContext.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import * as React from 'react';
|
||||
import { NavigationState, PartialState } from './types';
|
||||
|
||||
/**
|
||||
* Context which holds the method to reset root navigator state.
|
||||
*/
|
||||
const ResetRootContext = React.createContext<
|
||||
(state: PartialState<NavigationState> | NavigationState) => void
|
||||
>(() => {
|
||||
throw new Error(
|
||||
"We couldn't find a way to reset root state. Have you wrapped your app with 'NavigationContainer'?"
|
||||
);
|
||||
});
|
||||
|
||||
export default ResetRootContext;
|
||||
@@ -47,7 +47,7 @@ export default function SceneView<
|
||||
}, [getState, route.key]);
|
||||
|
||||
const setCurrentState = React.useCallback(
|
||||
(child: NavigationState | undefined) => {
|
||||
(child: NavigationState | PartialState<NavigationState> | undefined) => {
|
||||
const state = getState();
|
||||
|
||||
setState({
|
||||
|
||||
@@ -125,15 +125,5 @@ it('resets state to new state with RESET', () => {
|
||||
})
|
||||
);
|
||||
|
||||
expect(result).toEqual({ ...STATE, index: 0, routes });
|
||||
});
|
||||
|
||||
it('ignores key and routeNames when resetting with RESET', () => {
|
||||
const result = BaseRouter.getStateForAction(
|
||||
STATE,
|
||||
// @ts-ignore
|
||||
CommonActions.reset({ index: 2, key: 'foo', routeNames: ['test'] })
|
||||
);
|
||||
|
||||
expect(result).toEqual({ ...STATE, index: 2 });
|
||||
expect(result).toEqual({ index: 0, routes });
|
||||
});
|
||||
|
||||
@@ -321,3 +321,56 @@ it('handle resetting state with ref', () => {
|
||||
expect(onStateChange).toBeCalledTimes(1);
|
||||
expect(onStateChange).lastCalledWith(state);
|
||||
});
|
||||
|
||||
it('handle getRootState', () => {
|
||||
const TestNavigator = (props: any) => {
|
||||
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
||||
|
||||
return descriptors[state.routes[state.index].key].render();
|
||||
};
|
||||
|
||||
const ref = React.createRef<NavigationContainerRef>();
|
||||
|
||||
const element = (
|
||||
<NavigationContainer ref={ref}>
|
||||
<TestNavigator initialRouteName="foo">
|
||||
<Screen name="foo">
|
||||
{() => (
|
||||
<TestNavigator>
|
||||
<Screen name="qux" component={() => null} />
|
||||
<Screen name="lex" component={() => null} />
|
||||
</TestNavigator>
|
||||
)}
|
||||
</Screen>
|
||||
<Screen name="bar" component={() => null} />
|
||||
</TestNavigator>
|
||||
</NavigationContainer>
|
||||
);
|
||||
|
||||
render(element);
|
||||
|
||||
let state;
|
||||
if (ref.current) {
|
||||
state = ref.current.getRootState();
|
||||
}
|
||||
expect(state).toEqual({
|
||||
index: 0,
|
||||
key: '7',
|
||||
routeNames: ['foo', 'bar'],
|
||||
routes: [
|
||||
{
|
||||
key: 'foo',
|
||||
name: 'foo',
|
||||
state: {
|
||||
index: 0,
|
||||
key: '8',
|
||||
routeNames: ['qux', 'lex'],
|
||||
routes: [{ key: 'qux', name: 'qux' }, { key: 'lex', name: 'lex' }],
|
||||
stale: false,
|
||||
},
|
||||
},
|
||||
{ key: 'bar', name: 'bar' },
|
||||
],
|
||||
stale: false,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -108,7 +108,24 @@ export default function MockRouter(options: DefaultRouterOptions) {
|
||||
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:
|
||||
|
||||
@@ -5,7 +5,7 @@ import NavigationContainer from '../NavigationContainer';
|
||||
import useNavigationBuilder from '../useNavigationBuilder';
|
||||
import useNavigation from '../useNavigation';
|
||||
import MockRouter, { MockRouterKey } from './__fixtures__/MockRouter';
|
||||
import { NavigationState } from '../types';
|
||||
import { NavigationState, NavigationContainerRef } from '../types';
|
||||
|
||||
beforeEach(() => (MockRouterKey.current = 0));
|
||||
|
||||
@@ -523,6 +523,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', () => {
|
||||
const TestNavigator = (props: any): any => {
|
||||
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
|
||||
@@ -655,6 +729,7 @@ it('throws when a React Element is not the direct children', () => {
|
||||
);
|
||||
});
|
||||
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it("doesn't throw when direct children is Screen or empty element", () => {
|
||||
const TestNavigator = (props: any) => {
|
||||
useNavigationBuilder(MockRouter, props);
|
||||
@@ -694,3 +769,30 @@ it('throws when multiple screens with same name are defined', () => {
|
||||
"A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named 'foo')"
|
||||
);
|
||||
});
|
||||
|
||||
it('switches rendered navigators', () => {
|
||||
const TestNavigator = (props: any) => {
|
||||
useNavigationBuilder(MockRouter, props);
|
||||
return null;
|
||||
};
|
||||
|
||||
const root = render(
|
||||
<NavigationContainer>
|
||||
<TestNavigator key="a">
|
||||
<Screen name="foo" component={jest.fn()} />
|
||||
</TestNavigator>
|
||||
</NavigationContainer>
|
||||
);
|
||||
|
||||
expect(() =>
|
||||
root.update(
|
||||
<NavigationContainer>
|
||||
<TestNavigator key="b">
|
||||
<Screen name="foo" component={jest.fn()} />
|
||||
</TestNavigator>
|
||||
</NavigationContainer>
|
||||
)
|
||||
).not.toThrowError(
|
||||
'Another navigator is already registered for this container.'
|
||||
);
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import useNavigationBuilder from '../useNavigationBuilder';
|
||||
import NavigationContainer from '../NavigationContainer';
|
||||
import Screen from '../Screen';
|
||||
import MockRouter from './__fixtures__/MockRouter';
|
||||
import { Router, NavigationState } from '../types';
|
||||
|
||||
it('fires focus and blur events in root navigator', () => {
|
||||
const TestNavigator = React.forwardRef((props: any, ref: any): any => {
|
||||
@@ -200,6 +201,135 @@ it('fires focus and blur events in nested navigator', () => {
|
||||
expect(thirdFocusCallback).toBeCalledTimes(1);
|
||||
});
|
||||
|
||||
it('fires blur event when a route is removed with a delay', async () => {
|
||||
const TestRouter = (options: any): Router<NavigationState, any> => {
|
||||
const router = MockRouter(options);
|
||||
|
||||
return {
|
||||
...router,
|
||||
|
||||
getInitialState({ routeNames, routeParamList }) {
|
||||
const initialRouteName =
|
||||
options.initialRouteName !== undefined
|
||||
? options.initialRouteName
|
||||
: routeNames[0];
|
||||
|
||||
return {
|
||||
stale: false,
|
||||
key: 'stack',
|
||||
index: 0,
|
||||
routeNames,
|
||||
routes: [
|
||||
{
|
||||
key: initialRouteName,
|
||||
name: initialRouteName,
|
||||
params: routeParamList[initialRouteName],
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
|
||||
getStateForAction(state, action) {
|
||||
switch (action.type) {
|
||||
case 'PUSH':
|
||||
return {
|
||||
...state,
|
||||
index: state.index + 1,
|
||||
routes: [...state.routes, action.payload],
|
||||
};
|
||||
case 'POP': {
|
||||
const routes = state.routes.slice(0, -1);
|
||||
|
||||
return {
|
||||
...state,
|
||||
index: routes.length - 1,
|
||||
routes,
|
||||
};
|
||||
}
|
||||
default:
|
||||
return router.getStateForAction(state, action);
|
||||
}
|
||||
},
|
||||
|
||||
actionCreators: {
|
||||
push(payload) {
|
||||
return { type: 'PUSH', payload };
|
||||
},
|
||||
|
||||
pop() {
|
||||
return { type: 'POP' };
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const TestNavigator = React.forwardRef((props: any, ref: any): any => {
|
||||
const { state, navigation, descriptors } = useNavigationBuilder(
|
||||
TestRouter,
|
||||
props
|
||||
);
|
||||
|
||||
React.useImperativeHandle(ref, () => navigation, [navigation]);
|
||||
|
||||
const [previous, dispatch] = React.useReducer(
|
||||
(state, action) => {
|
||||
if (state.routes !== action.routes) {
|
||||
return { ...state, ...action };
|
||||
}
|
||||
|
||||
return state;
|
||||
},
|
||||
{ routes: state.routes, descriptors }
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
dispatch({ routes: state.routes, descriptors });
|
||||
}, [descriptors, state.routes]);
|
||||
|
||||
return previous.routes.map((route: any) =>
|
||||
previous.descriptors[route.key].render()
|
||||
);
|
||||
});
|
||||
|
||||
const blurCallback = jest.fn();
|
||||
|
||||
const First = () => null;
|
||||
|
||||
const Second = ({ navigation }: any) => {
|
||||
React.useEffect(() => navigation.addListener('blur', blurCallback), [
|
||||
navigation,
|
||||
]);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const navigation = React.createRef<any>();
|
||||
|
||||
const element = (
|
||||
<NavigationContainer>
|
||||
<TestNavigator ref={navigation}>
|
||||
<Screen name="first" component={First} />
|
||||
<Screen name="second" component={Second} />
|
||||
</TestNavigator>
|
||||
</NavigationContainer>
|
||||
);
|
||||
|
||||
render(element);
|
||||
|
||||
act(() =>
|
||||
navigation.current.push({
|
||||
name: 'second',
|
||||
key: 'second',
|
||||
})
|
||||
);
|
||||
|
||||
expect(blurCallback).toBeCalledTimes(0);
|
||||
|
||||
act(() => navigation.current.pop());
|
||||
|
||||
expect(blurCallback).toBeCalledTimes(1);
|
||||
});
|
||||
|
||||
it('fires custom events', () => {
|
||||
const eventName = 'someSuperCoolEvent';
|
||||
|
||||
|
||||
@@ -296,6 +296,7 @@ it("action doesn't bubble if target is specified", () => {
|
||||
expect(onStateChange).not.toBeCalled();
|
||||
});
|
||||
|
||||
// eslint-disable-next-line jest/expect-expect
|
||||
it("doesn't crash if no navigator handled the action", () => {
|
||||
const TestRouter = MockRouter;
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
import * as CommonActions from './CommonActions';
|
||||
import * as React from 'react';
|
||||
|
||||
@@ -170,7 +171,10 @@ export type Router<
|
||||
* @param state State object to apply the action on.
|
||||
* @param action Action object to apply.
|
||||
*/
|
||||
getStateForAction(state: State, action: Action): State | null;
|
||||
getStateForAction(
|
||||
state: State,
|
||||
action: Action
|
||||
): State | PartialState<State> | null;
|
||||
|
||||
/**
|
||||
* Whether the action should also change focus in parent navigator
|
||||
@@ -316,6 +320,13 @@ type NavigationHelpersCommon<
|
||||
*/
|
||||
reset(state: PartialState<State> | State): void;
|
||||
|
||||
/**
|
||||
* Reset the navigation state of the root navigator to the provided state.
|
||||
*
|
||||
* @param state Navigation state object.
|
||||
*/
|
||||
resetRoot(state: PartialState<NavigationState> | NavigationState): void;
|
||||
|
||||
/**
|
||||
* Go back to the previous route in history.
|
||||
*/
|
||||
@@ -527,6 +538,7 @@ export type NavigationContainerRef =
|
||||
* @param state Navigation state object.
|
||||
*/
|
||||
resetRoot(state: PartialState<NavigationState> | NavigationState): void;
|
||||
getRootState(): NavigationState;
|
||||
}
|
||||
| undefined
|
||||
| null;
|
||||
|
||||
@@ -3,6 +3,7 @@ import SceneView from './SceneView';
|
||||
import NavigationBuilderContext, {
|
||||
ChildActionListener,
|
||||
FocusedNavigationListener,
|
||||
NavigatorStateGetter,
|
||||
} from './NavigationBuilderContext';
|
||||
import { NavigationEventEmitter } from './useEventEmitter';
|
||||
import useNavigationCache from './useNavigationCache';
|
||||
@@ -35,6 +36,7 @@ type Options<State extends NavigationState, ScreenOptions extends object> = {
|
||||
setState: (state: State) => void;
|
||||
addActionListener: (listener: ChildActionListener) => void;
|
||||
addFocusedListener: (listener: FocusedNavigationListener) => void;
|
||||
addStateGetter: (key: string, getter: NavigatorStateGetter) => void;
|
||||
onRouteFocus: (key: string) => void;
|
||||
router: Router<State, NavigationAction>;
|
||||
emitter: NavigationEventEmitter;
|
||||
@@ -61,6 +63,7 @@ export default function useDescriptors<
|
||||
setState,
|
||||
addActionListener,
|
||||
addFocusedListener,
|
||||
addStateGetter,
|
||||
onRouteFocus,
|
||||
router,
|
||||
emitter,
|
||||
@@ -74,6 +77,7 @@ export default function useDescriptors<
|
||||
onAction,
|
||||
addActionListener,
|
||||
addFocusedListener,
|
||||
addStateGetter,
|
||||
onRouteFocus,
|
||||
trackAction,
|
||||
}),
|
||||
@@ -83,6 +87,7 @@ export default function useDescriptors<
|
||||
addActionListener,
|
||||
addFocusedListener,
|
||||
onRouteFocus,
|
||||
addStateGetter,
|
||||
trackAction,
|
||||
]
|
||||
);
|
||||
|
||||
@@ -18,6 +18,7 @@ type DevTools = {
|
||||
};
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
__REDUX_DEVTOOLS_EXTENSION__:
|
||||
|
||||
@@ -57,19 +57,19 @@ export default function useFocusEvents({ state, emitter }: Options) {
|
||||
return;
|
||||
}
|
||||
|
||||
state.routes.forEach((route, i) => {
|
||||
if (
|
||||
lastFocusedKey === undefined ||
|
||||
(route.key !== lastFocusedKey && route.key !== currentFocusedKey)
|
||||
) {
|
||||
// Only fire events after mount, or if focus state of this route changed
|
||||
return;
|
||||
}
|
||||
if (lastFocusedKey === undefined) {
|
||||
// Only fire events after initial mount
|
||||
return;
|
||||
}
|
||||
|
||||
emitter.emit({
|
||||
type: i === state.index ? 'focus' : 'blur',
|
||||
target: route.key,
|
||||
});
|
||||
emitter.emit({
|
||||
type: 'focus',
|
||||
target: currentFocusedKey,
|
||||
});
|
||||
}, [currentFocusedKey, emitter, navigation, state.index, state.routes]);
|
||||
|
||||
emitter.emit({
|
||||
type: 'blur',
|
||||
target: lastFocusedKey,
|
||||
});
|
||||
}, [currentFocusedKey, emitter, navigation]);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import * as React from 'react';
|
||||
import { NavigationStateContext } from './NavigationContainer';
|
||||
import NavigationRouteContext from './NavigationRouteContext';
|
||||
import Screen from './Screen';
|
||||
import { navigate } from './CommonActions';
|
||||
import useEventEmitter from './useEventEmitter';
|
||||
import useRegisterNavigator from './useRegisterNavigator';
|
||||
import useDescriptors from './useDescriptors';
|
||||
@@ -23,11 +25,20 @@ import {
|
||||
PrivateValueStore,
|
||||
NavigationAction,
|
||||
} from './types';
|
||||
import useStateGetters from './useStateGetters';
|
||||
import useOnGetState from './useOnGetState';
|
||||
|
||||
// This is to make TypeScript compiler happy
|
||||
// eslint-disable-next-line babel/no-unused-expressions
|
||||
PrivateValueStore;
|
||||
|
||||
type NavigatorRoute = {
|
||||
params?: {
|
||||
screen?: string;
|
||||
params?: object;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Compare two arrays with primitive values as the content.
|
||||
* We need to make sure that both values and order match.
|
||||
@@ -94,9 +105,24 @@ export default function useNavigationBuilder<
|
||||
) {
|
||||
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 { 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(
|
||||
@@ -116,7 +142,20 @@ export default function useNavigationBuilder<
|
||||
const routeNames = Object.keys(screens);
|
||||
const routeParamList = routeNames.reduce(
|
||||
(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;
|
||||
},
|
||||
{} as { [key: string]: object | undefined }
|
||||
@@ -173,28 +212,53 @@ export default function useNavigationBuilder<
|
||||
? (initializedStateRef.current as State)
|
||||
: (currentState as State);
|
||||
|
||||
let nextState: State = state;
|
||||
|
||||
if (!isArrayEqual(state.routeNames, routeNames)) {
|
||||
// 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,
|
||||
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(() => {
|
||||
return () => {
|
||||
// We need to clean up state for this navigator on unmount
|
||||
@@ -227,6 +291,8 @@ export default function useNavigationBuilder<
|
||||
addListener: addFocusedListener,
|
||||
} = useFocusedListeners();
|
||||
|
||||
const { getStateForRoute, addStateGetter } = useStateGetters();
|
||||
|
||||
const onAction = useOnAction({
|
||||
router,
|
||||
getState,
|
||||
@@ -254,6 +320,11 @@ export default function useNavigationBuilder<
|
||||
focusedListeners,
|
||||
});
|
||||
|
||||
useOnGetState({
|
||||
getState,
|
||||
getStateForRoute,
|
||||
});
|
||||
|
||||
const descriptors = useDescriptors<State, ScreenOptions>({
|
||||
state,
|
||||
screens,
|
||||
@@ -265,6 +336,7 @@ export default function useNavigationBuilder<
|
||||
onRouteFocus,
|
||||
addActionListener,
|
||||
addFocusedListener,
|
||||
addStateGetter,
|
||||
router,
|
||||
emitter,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as React from 'react';
|
||||
import * as CommonActions from './CommonActions';
|
||||
import NavigationContext from './NavigationContext';
|
||||
import ResetRootContext from './ResetRootContext';
|
||||
import { NavigationStateContext } from './NavigationContainer';
|
||||
import { NavigationEventEmitter } from './useEventEmitter';
|
||||
import {
|
||||
@@ -36,6 +37,7 @@ export default function useNavigationHelpers<
|
||||
Action extends NavigationAction,
|
||||
EventMap extends { [key: string]: any }
|
||||
>({ onAction, getState, emitter, router }: Options<State, Action>) {
|
||||
const resetRoot = React.useContext(ResetRootContext);
|
||||
const parentNavigationHelpers = React.useContext(NavigationContext);
|
||||
const { performTransaction } = React.useContext(NavigationStateContext);
|
||||
|
||||
@@ -65,6 +67,7 @@ export default function useNavigationHelpers<
|
||||
return {
|
||||
...parentNavigationHelpers,
|
||||
...helpers,
|
||||
resetRoot,
|
||||
dispatch,
|
||||
emit: emitter.emit,
|
||||
isFocused: parentNavigationHelpers
|
||||
@@ -83,6 +86,7 @@ export default function useNavigationHelpers<
|
||||
router,
|
||||
getState,
|
||||
parentNavigationHelpers,
|
||||
resetRoot,
|
||||
emitter.emit,
|
||||
performTransaction,
|
||||
onAction,
|
||||
|
||||
@@ -2,13 +2,18 @@ import * as React from 'react';
|
||||
import NavigationBuilderContext, {
|
||||
ChildActionListener,
|
||||
} from './NavigationBuilderContext';
|
||||
import { NavigationAction, NavigationState, Router } from './types';
|
||||
import {
|
||||
NavigationAction,
|
||||
NavigationState,
|
||||
PartialState,
|
||||
Router,
|
||||
} from './types';
|
||||
|
||||
type Options = {
|
||||
router: Router<NavigationState, NavigationAction>;
|
||||
key?: string;
|
||||
getState: () => NavigationState;
|
||||
setState: (state: NavigationState) => void;
|
||||
setState: (state: NavigationState | PartialState<NavigationState>) => void;
|
||||
listeners: ChildActionListener[];
|
||||
};
|
||||
|
||||
|
||||
31
packages/core/src/useOnGetState.tsx
Normal file
31
packages/core/src/useOnGetState.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import * as React from 'react';
|
||||
import NavigationBuilderContext from './NavigationBuilderContext';
|
||||
import { NavigationState } from './types';
|
||||
import NavigationRouteContext from './NavigationRouteContext';
|
||||
|
||||
export default function useOnGetState({
|
||||
getStateForRoute,
|
||||
getState,
|
||||
}: {
|
||||
getStateForRoute: (routeName: string) => NavigationState | undefined;
|
||||
getState: () => NavigationState;
|
||||
}) {
|
||||
const { addStateGetter } = React.useContext(NavigationBuilderContext);
|
||||
const route = React.useContext(NavigationRouteContext);
|
||||
const key = route ? route.key : 'root';
|
||||
|
||||
const getter = React.useCallback(() => {
|
||||
const state = getState();
|
||||
return {
|
||||
...state,
|
||||
routes: state.routes.map(route => ({
|
||||
...route,
|
||||
state: getStateForRoute(route.key),
|
||||
})),
|
||||
};
|
||||
}, [getState, getStateForRoute]);
|
||||
|
||||
React.useEffect(() => {
|
||||
return addStateGetter && addStateGetter(key, getter);
|
||||
}, [addStateGetter, getter, key]);
|
||||
}
|
||||
35
packages/core/src/useStateGetters.tsx
Normal file
35
packages/core/src/useStateGetters.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import * as React from 'react';
|
||||
import { NavigatorStateGetter } from './NavigationBuilderContext';
|
||||
|
||||
/**
|
||||
* Hook which lets child navigators add getters to be called for obtaining rehydrated state.
|
||||
*/
|
||||
|
||||
export default function useStateGetters() {
|
||||
const stateGetters = React.useRef<Record<string, NavigatorStateGetter>>({});
|
||||
|
||||
const getStateForRoute = React.useCallback(
|
||||
routeKey =>
|
||||
stateGetters.current[routeKey] === undefined
|
||||
? undefined
|
||||
: stateGetters.current[routeKey](),
|
||||
[stateGetters]
|
||||
);
|
||||
|
||||
const addStateGetter = React.useCallback(
|
||||
(key: string, getter: NavigatorStateGetter) => {
|
||||
stateGetters.current[key] = getter;
|
||||
|
||||
return () => {
|
||||
// @ts-ignore
|
||||
stateGetters.current[key] = undefined;
|
||||
};
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
return {
|
||||
getStateForRoute,
|
||||
addStateGetter,
|
||||
};
|
||||
}
|
||||
@@ -3,6 +3,69 @@
|
||||
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.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)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/drawer
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.12](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.11...@react-navigation/drawer@5.0.0-alpha.12) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/drawer
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.11](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.10...@react-navigation/drawer@5.0.0-alpha.11) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/drawer
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.10](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.9...@react-navigation/drawer@5.0.0-alpha.10) (2019-09-27)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* export some more type aliases ([8b78d61](https://github.com/react-navigation/navigation-ex/commit/8b78d61))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.9](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/drawer@5.0.0-alpha.8...@react-navigation/drawer@5.0.0-alpha.9) (2019-09-16)
|
||||
|
||||
|
||||
|
||||
@@ -10,44 +10,29 @@ Open a Terminal in your project's folder and run,
|
||||
yarn add @react-navigation/core @react-navigation/drawer
|
||||
```
|
||||
|
||||
Now we need to install [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler) and [`react-native-reanimated`](https://github.com/kmagiera/react-native-reanimated).
|
||||
Now we need to install [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler), [`react-native-reanimated`](https://github.com/kmagiera/react-native-reanimated) and [`react-native-safe-area-context`](https://github.com/th3rdwave/react-native-safe-area-context).
|
||||
|
||||
If you are using Expo, to ensure that you get the compatible versions of the libraries, run:
|
||||
|
||||
```sh
|
||||
expo install react-native-gesture-handler react-native-reanimated
|
||||
expo install react-native-gesture-handler react-native-reanimated react-native-safe-area-context
|
||||
```
|
||||
|
||||
If you are not using Expo, run the following:
|
||||
|
||||
```sh
|
||||
yarn add react-native-reanimated react-native-gesture-handler
|
||||
yarn add react-native-reanimated react-native-gesture-handler react-native-safe-area-context
|
||||
```
|
||||
|
||||
If you are using Expo, you are done. Otherwise, continue to the next steps.
|
||||
|
||||
Next, we need to link these libraries. The steps depends on your React Native version:
|
||||
To complete the linking on iOS, make sure you have [Cocoapods](https://cocoapods.org/) installed. Then run:
|
||||
|
||||
- **React Native 0.60 and higher**
|
||||
|
||||
On newer versions of React Native, [linking is automatic](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md).
|
||||
|
||||
To complete the linking on iOS, make sure you have [Cocoapods](https://cocoapods.org/) installed. Then run:
|
||||
|
||||
```sh
|
||||
cd ios
|
||||
pod install
|
||||
cd ..
|
||||
```
|
||||
|
||||
- **React Native 0.59**
|
||||
|
||||
If you're on an older React Native version, you need to manually link the dependencies. To do that, run:
|
||||
|
||||
```sh
|
||||
react-native link react-native-reanimated
|
||||
react-native link react-native-gesture-handler
|
||||
```
|
||||
```sh
|
||||
cd ios
|
||||
pod install
|
||||
cd ..
|
||||
```
|
||||
|
||||
**IMPORTANT:** There are additional steps required for `react-native-gesture-handler` on Android after linking (for all React Native versions). Check the [this guide](https://kmagiera.github.io/react-native-gesture-handler/docs/getting-started.html) to complete the installation.
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"material",
|
||||
"drawer"
|
||||
],
|
||||
"version": "5.0.0-alpha.9",
|
||||
"version": "5.0.0-alpha.15",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -34,20 +34,20 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/routers": "^5.0.0-alpha.7",
|
||||
"react-native-safe-area-view": "^0.14.6"
|
||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-native-community/bob": "^0.7.0",
|
||||
"@types/react": "^16.8.24",
|
||||
"@types/react-native": "^0.60.2",
|
||||
"del-cli": "^2.0.0",
|
||||
"react": "16.8.3",
|
||||
"react-native": "0.59.10",
|
||||
"@types/react": "^16.9.4",
|
||||
"@types/react-native": "^0.60.17",
|
||||
"del-cli": "^3.0.0",
|
||||
"react": "~16.8.3",
|
||||
"react-native": "~0.59.10",
|
||||
"react-native-gesture-handler": "^1.3.0",
|
||||
"react-native-reanimated": "^1.1.0",
|
||||
"react-native-screens": "^1.0.0-alpha.22",
|
||||
"typescript": "^3.5.3"
|
||||
"react-native-reanimated": "^1.3.0",
|
||||
"react-native-safe-area-context": "^0.3.6",
|
||||
"react-native-screens": "^2.0.0-alpha.3",
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||
@@ -55,7 +55,8 @@
|
||||
"react-native": "*",
|
||||
"react-native-gesture-handler": "^1.0.0",
|
||||
"react-native-reanimated": "^1.0.0",
|
||||
"react-native-screens": "^1.0.0-alpha.0"
|
||||
"react-native-safe-area-context": "^0.3.6",
|
||||
"react-native-screens": "^1.0.0-alpha.0 || ^2.0.0-alpha.3"
|
||||
},
|
||||
"@react-native-community/bob": {
|
||||
"source": "src",
|
||||
|
||||
@@ -8,8 +8,9 @@ export {
|
||||
/**
|
||||
* Views
|
||||
*/
|
||||
export { default as DrawerNavigatorItems } from './views/DrawerNavigatorItems';
|
||||
export { default as DrawerSidebar } from './views/DrawerSidebar';
|
||||
export { default as DrawerItem } from './views/DrawerItem';
|
||||
export { default as DrawerItemList } from './views/DrawerItemList';
|
||||
export { default as DrawerContent } from './views/DrawerContent';
|
||||
export { default as DrawerView } from './views/DrawerView';
|
||||
|
||||
/**
|
||||
@@ -20,4 +21,9 @@ export { default as DrawerGestureContext } from './utils/DrawerGestureContext';
|
||||
/**
|
||||
* Types
|
||||
*/
|
||||
export { DrawerNavigationOptions, DrawerNavigationProp } from './types';
|
||||
export {
|
||||
DrawerNavigationOptions,
|
||||
DrawerNavigationProp,
|
||||
DrawerContentOptions,
|
||||
DrawerContentComponentProps,
|
||||
} from './types';
|
||||
|
||||
@@ -12,16 +12,11 @@ import { PanGestureHandler } from 'react-native-gesture-handler';
|
||||
|
||||
export type Scene = {
|
||||
route: Route<string>;
|
||||
index: number;
|
||||
focused: boolean;
|
||||
tintColor?: string;
|
||||
color?: string;
|
||||
};
|
||||
|
||||
export type DrawerNavigationConfig = {
|
||||
/**
|
||||
* Custom background color for the drawer. Defaults to `white`.
|
||||
*/
|
||||
drawerBackgroundColor: string;
|
||||
export type DrawerNavigationConfig<T = DrawerContentOptions> = {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@@ -82,49 +72,51 @@ export type DrawerNavigationConfig = {
|
||||
* Custom component used to render as the content of the drawer, for example, navigation items.
|
||||
* Defaults to `DrawerItems`.
|
||||
*/
|
||||
contentComponent: React.ComponentType<ContentComponentProps>;
|
||||
contentComponent: React.ComponentType<DrawerContentComponentProps<T>>;
|
||||
/**
|
||||
* Options for the content component which will be passed as props.
|
||||
*/
|
||||
contentOptions?: object;
|
||||
contentOptions?: T;
|
||||
/**
|
||||
* Style object for the component wrapping the screen content.
|
||||
*/
|
||||
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 = {
|
||||
title?: string;
|
||||
drawerLabel?:
|
||||
| string
|
||||
| ((props: { tintColor?: string; focused: boolean }) => React.ReactElement);
|
||||
| ((props: { color: string; focused: boolean }) => React.ReactNode);
|
||||
drawerIcon?: (props: {
|
||||
tintColor?: string;
|
||||
color: string;
|
||||
size: number;
|
||||
focused: boolean;
|
||||
}) => React.ReactElement;
|
||||
}) => React.ReactNode;
|
||||
drawerLockMode?: 'unlocked' | 'locked-closed' | 'locked-open';
|
||||
};
|
||||
|
||||
export type ContentComponentProps = DrawerNavigationItemsProps & {
|
||||
export type DrawerContentComponentProps<T = DrawerContentOptions> = T & {
|
||||
state: DrawerNavigationState;
|
||||
navigation: NavigationHelpers<ParamListBase>;
|
||||
descriptors: { [key: string]: any };
|
||||
descriptors: DrawerDescriptorMap;
|
||||
/**
|
||||
* Animated node which represents the current progress of the drawer's open state.
|
||||
* `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 = {
|
||||
/**
|
||||
* 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;
|
||||
export type DrawerContentOptions = {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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>;
|
||||
/**
|
||||
* 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 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;
|
||||
style?: StyleProp<ViewStyle>;
|
||||
};
|
||||
|
||||
export type DrawerNavigationEventMap = {
|
||||
|
||||
@@ -578,7 +578,6 @@ export default class DrawerView extends React.PureComponent<Props> {
|
||||
style={[
|
||||
styles.container,
|
||||
right ? { right: offset } : { left: offset },
|
||||
// eslint-disable-next-line react-native/no-inline-styles
|
||||
{
|
||||
transform: [{ translateX: drawerTranslateX }],
|
||||
opacity: this.drawerOpacity,
|
||||
|
||||
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,120 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import { View, Text, StyleSheet } from 'react-native';
|
||||
import SafeAreaView from 'react-native-safe-area-view';
|
||||
|
||||
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) => (
|
||||
<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}
|
||||
>
|
||||
<SafeAreaView
|
||||
style={[{ backgroundColor }, styles.item, itemStyle]}
|
||||
forceInset={{
|
||||
[drawerPosition]: 'always',
|
||||
[drawerPosition === 'left' ? 'right' : 'left']: 'never',
|
||||
vertical: 'never',
|
||||
}}
|
||||
>
|
||||
{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
|
||||
)}
|
||||
</SafeAreaView>
|
||||
</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 { Dimensions, StyleSheet, I18nManager, Platform } from 'react-native';
|
||||
import {
|
||||
Dimensions,
|
||||
StyleSheet,
|
||||
I18nManager,
|
||||
Platform,
|
||||
ScaledSize,
|
||||
} from 'react-native';
|
||||
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import { ScreenContainer } from 'react-native-screens';
|
||||
import SafeAreaView from 'react-native-safe-area-view';
|
||||
import { PanGestureHandler, ScrollView } from 'react-native-gesture-handler';
|
||||
import { PanGestureHandler } from 'react-native-gesture-handler';
|
||||
import {
|
||||
DrawerNavigationState,
|
||||
DrawerActions,
|
||||
} from '@react-navigation/routers';
|
||||
|
||||
import DrawerSidebar from './DrawerSidebar';
|
||||
import DrawerGestureContext from '../utils/DrawerGestureContext';
|
||||
import ResourceSavingScene from './ResourceSavingScene';
|
||||
import DrawerNavigatorItems from './DrawerNavigatorItems';
|
||||
import DrawerContent from './DrawerContent';
|
||||
import Drawer from './Drawer';
|
||||
import {
|
||||
DrawerDescriptorMap,
|
||||
DrawerNavigationConfig,
|
||||
ContentComponentProps,
|
||||
DrawerNavigationHelpers,
|
||||
} from '../types';
|
||||
|
||||
type Props = DrawerNavigationConfig & {
|
||||
type Props = Omit<DrawerNavigationConfig, 'overlayColor'> & {
|
||||
state: DrawerNavigationState;
|
||||
navigation: DrawerNavigationHelpers;
|
||||
descriptors: DrawerDescriptorMap;
|
||||
overlayColor: string;
|
||||
};
|
||||
|
||||
type State = {
|
||||
@@ -32,13 +37,26 @@ type State = {
|
||||
drawerWidth: number;
|
||||
};
|
||||
|
||||
const DefaultContentComponent = (props: ContentComponentProps) => (
|
||||
<ScrollView alwaysBounceVertical={false}>
|
||||
<SafeAreaView forceInset={{ top: 'always', horizontal: 'never' }}>
|
||||
<DrawerNavigatorItems {...props} />
|
||||
</SafeAreaView>
|
||||
</ScrollView>
|
||||
);
|
||||
const getDefaultDrawerWidth = ({
|
||||
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 Math.min(smallerAxisSize - appBarHeight, maxWidth);
|
||||
};
|
||||
|
||||
/**
|
||||
* Component that renders the drawer.
|
||||
@@ -46,25 +64,10 @@ const DefaultContentComponent = (props: ContentComponentProps) => (
|
||||
export default class DrawerView extends React.PureComponent<Props, State> {
|
||||
static defaultProps = {
|
||||
lazy: true,
|
||||
drawerWidth: () => {
|
||||
/*
|
||||
* 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,
|
||||
contentComponent: DrawerContent,
|
||||
drawerPosition: I18nManager.isRTL ? 'right' : 'left',
|
||||
keyboardDismissMode: 'on-drag',
|
||||
drawerBackgroundColor: 'white',
|
||||
overlayColor: 'rgba(0, 0, 0, 0.5)',
|
||||
drawerType: 'front',
|
||||
hideStatusBar: false,
|
||||
statusBarAnimation: 'slide',
|
||||
@@ -83,10 +86,7 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
||||
|
||||
state: State = {
|
||||
loaded: [this.props.state.index],
|
||||
drawerWidth:
|
||||
typeof this.props.drawerWidth === 'function'
|
||||
? this.props.drawerWidth()
|
||||
: this.props.drawerWidth,
|
||||
drawerWidth: getDefaultDrawerWidth(Dimensions.get('window')),
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
@@ -121,11 +121,8 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
||||
navigation.emit({ type: 'drawerClose' });
|
||||
};
|
||||
|
||||
private updateWidth = () => {
|
||||
const drawerWidth =
|
||||
typeof this.props.drawerWidth === 'function'
|
||||
? this.props.drawerWidth()
|
||||
: this.props.drawerWidth;
|
||||
private updateWidth = ({ window }: { window: ScaledSize }) => {
|
||||
const drawerWidth = getDefaultDrawerWidth(window);
|
||||
|
||||
if (this.state.drawerWidth !== drawerWidth) {
|
||||
this.setState({ drawerWidth });
|
||||
@@ -133,7 +130,25 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
||||
};
|
||||
|
||||
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 = () => {
|
||||
@@ -163,7 +178,6 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
||||
key={route.key}
|
||||
style={[
|
||||
StyleSheet.absoluteFill,
|
||||
// eslint-disable-next-line react-native/no-inline-styles
|
||||
{ opacity: isFocused ? 1 : 0 },
|
||||
]}
|
||||
isVisible={isFocused}
|
||||
@@ -188,9 +202,9 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
||||
descriptors,
|
||||
drawerType,
|
||||
drawerPosition,
|
||||
drawerBackgroundColor,
|
||||
overlayColor,
|
||||
sceneContainerStyle,
|
||||
drawerStyle,
|
||||
edgeWidth,
|
||||
minSwipeDistance,
|
||||
hideStatusBar,
|
||||
@@ -198,6 +212,8 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
||||
gestureHandlerProps,
|
||||
} = this.props;
|
||||
|
||||
const { drawerWidth } = this.state;
|
||||
|
||||
const activeKey = state.routes[state.index].key;
|
||||
const { drawerLockMode } = descriptors[activeKey].options;
|
||||
|
||||
@@ -209,35 +225,32 @@ export default class DrawerView extends React.PureComponent<Props, State> {
|
||||
: state.isDrawerOpen;
|
||||
|
||||
return (
|
||||
<DrawerGestureContext.Provider value={this.drawerGestureRef}>
|
||||
<Drawer
|
||||
open={isOpen}
|
||||
locked={
|
||||
drawerLockMode === 'locked-open' ||
|
||||
drawerLockMode === 'locked-closed'
|
||||
}
|
||||
onOpen={this.handleDrawerOpen}
|
||||
onClose={this.handleDrawerClose}
|
||||
onGestureRef={this.setDrawerGestureRef}
|
||||
gestureHandlerProps={gestureHandlerProps}
|
||||
drawerType={drawerType}
|
||||
drawerPosition={drawerPosition}
|
||||
sceneContainerStyle={sceneContainerStyle}
|
||||
drawerStyle={{
|
||||
backgroundColor: drawerBackgroundColor || 'white',
|
||||
width: this.state.drawerWidth,
|
||||
}}
|
||||
overlayStyle={{
|
||||
backgroundColor: overlayColor || 'rgba(0, 0, 0, 0.5)',
|
||||
}}
|
||||
swipeEdgeWidth={edgeWidth}
|
||||
swipeDistanceThreshold={minSwipeDistance}
|
||||
hideStatusBar={hideStatusBar}
|
||||
statusBarAnimation={statusBarAnimation}
|
||||
renderDrawerContent={this.renderNavigationView}
|
||||
renderSceneContent={this.renderContent}
|
||||
/>
|
||||
</DrawerGestureContext.Provider>
|
||||
<SafeAreaProvider>
|
||||
<DrawerGestureContext.Provider value={this.drawerGestureRef}>
|
||||
<Drawer
|
||||
open={isOpen}
|
||||
locked={
|
||||
drawerLockMode === 'locked-open' ||
|
||||
drawerLockMode === 'locked-closed'
|
||||
}
|
||||
onOpen={this.handleDrawerOpen}
|
||||
onClose={this.handleDrawerClose}
|
||||
onGestureRef={this.setDrawerGestureRef}
|
||||
gestureHandlerProps={gestureHandlerProps}
|
||||
drawerType={drawerType}
|
||||
drawerPosition={drawerPosition}
|
||||
sceneContainerStyle={sceneContainerStyle}
|
||||
drawerStyle={[{ width: drawerWidth }, drawerStyle]}
|
||||
overlayStyle={{ backgroundColor: overlayColor }}
|
||||
swipeEdgeWidth={edgeWidth}
|
||||
swipeDistanceThreshold={minSwipeDistance}
|
||||
hideStatusBar={hideStatusBar}
|
||||
statusBarAnimation={statusBarAnimation}
|
||||
renderDrawerContent={this.renderNavigationView}
|
||||
renderSceneContent={this.renderContent}
|
||||
/>
|
||||
</DrawerGestureContext.Provider>
|
||||
</SafeAreaProvider>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,77 @@
|
||||
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.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)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* drop header: null in favor of more explitit headerShown option ([ba6b6ae](https://github.com/satya164/navigation-ex/commit/ba6b6ae))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.11](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.10...@react-navigation/example@5.0.0-alpha.11) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/example
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.10](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.9...@react-navigation/example@5.0.0-alpha.10) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/example
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.9](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.8...@react-navigation/example@5.0.0-alpha.9) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/example
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.8](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.7...@react-navigation/example@5.0.0-alpha.8) (2019-09-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* close drawer on navigate ([655a220](https://github.com/react-navigation/navigation-ex/commit/655a220))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.7](https://github.com/satya164/navigation-ex/compare/@react-navigation/example@5.0.0-alpha.6...@react-navigation/example@5.0.0-alpha.7) (2019-09-16)
|
||||
|
||||
|
||||
|
||||
19
packages/example/android/ReactNavigationExample.iml
Normal file
19
packages/example/android/ReactNavigationExample.iml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="ReactNavigationExample" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="java-gradle" name="Java-Gradle">
|
||||
<configuration>
|
||||
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
|
||||
<option name="BUILDABLE" value="false" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
180
packages/example/android/app/app.iml
Normal file
180
packages/example/android/app/app.iml
Normal file
@@ -0,0 +1,180 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
<option name="GRADLE_PROJECT_PATH" value=":app" />
|
||||
<option name="LAST_SUCCESSFUL_SYNC_AGP_VERSION" value="3.3.0" />
|
||||
<option name="LAST_KNOWN_AGP_VERSION" value="3.3.0" />
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||
<afterSyncTasks>
|
||||
<task>generateDebugSources</task>
|
||||
</afterSyncTasks>
|
||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/build/generated/res/rs/debug;file://$MODULE_DIR$/build/generated/res/resValues/debug" />
|
||||
<option name="TEST_RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" />
|
||||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/build/intermediates/javac/debugUnitTest/compileDebugUnitTestJavaWithJavac/classes" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/aidl_source_output_dir/debug/compileDebugAidl/out" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/renderscript_source_output_dir/debug/compileDebugRenderscript/out" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/react/debug" type="java-resource" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/aidl_source_output_dir/debugAndroidTest/compileDebugAndroidTestAidl/out" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/renderscript_source_output_dir/debugAndroidTest/compileDebugAndroidTestRenderscript/out" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/test/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 28 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:collections:28.0.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: android.arch.lifecycle:common:1.1.1@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: android.arch.core:common:1.1.1@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:support-annotations:28.0.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.facebook.infer.annotation:infer-annotation:0.11.2@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: javax.inject:javax.inject:1@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.google.code.findbugs:jsr305:3.0.2@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.squareup.okhttp3:okhttp-urlconnection:3.12.1@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.squareup.okhttp3:okhttp:3.12.1@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.squareup.okio:okio:1.15.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.facebook.device.yearclass:yearclass:2.1.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: commons-codec:commons-codec:1.10@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: commons-io:commons-io:1.4@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.github.bumptech.glide:disklrucache:4.9.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.github.bumptech.glide:annotations:4.9.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.parse.bolts:bolts-tasks:1.4.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.facebook.react:react-native:0.59.10@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:appcompat-v7:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.github.bumptech.glide:glide:4.9.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.google.android.gms:play-services-location:16.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.google.android.gms:play-services-base:16.0.1@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.google.android.gms:play-services-places-placereport:16.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.google.android.gms:play-services-tasks:16.0.1@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.google.android.gms:play-services-basement:16.0.1@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:support-v4:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:support-fragment:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:animated-vector-drawable:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:customtabs:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:support-core-ui:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:support-core-utils:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:support-vector-drawable:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:loader:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:support-media-compat:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:viewpager:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:coordinatorlayout:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:drawerlayout:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:slidingpanelayout:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:customview:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:swiperefreshlayout:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:asynclayoutinflater:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:support-compat:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:versionedparcelable:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:cursoradapter:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: android.arch.lifecycle:runtime:1.1.1@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:documentfile:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:localbroadcastmanager:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:print:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: android.arch.lifecycle:viewmodel:1.1.1@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.github.bumptech.glide:gifdecoder:4.9.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.android.support:interpolator:28.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: android.arch.lifecycle:livedata:1.1.1@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: android.arch.lifecycle:livedata-core:1.1.1@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: android.arch.core:runtime:1.1.1@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.facebook.fresco:fresco:1.10.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.facebook.fresco:imagepipeline-okhttp3:1.10.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.facebook.fresco:drawee:1.10.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.facebook.fresco:imagepipeline:1.10.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.facebook.fresco:imagepipeline-base:1.10.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: 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-gesture-handler" />
|
||||
<orderEntry type="module" module-name="expo-permissions" />
|
||||
<orderEntry type="module" module-name="unimodules-core" />
|
||||
<orderEntry type="module" module-name="unimodules-react-native-adapter" />
|
||||
<orderEntry type="module" module-name="expo-app-loader-provider" />
|
||||
<orderEntry type="module" module-name="expo-constants" />
|
||||
<orderEntry type="module" module-name="expo-file-system" />
|
||||
<orderEntry type="module" module-name="expo-font" />
|
||||
<orderEntry type="module" module-name="expo-keep-awake" />
|
||||
<orderEntry type="module" module-name="expo-linear-gradient" />
|
||||
<orderEntry type="module" module-name="expo-location" />
|
||||
<orderEntry type="module" module-name="expo-sqlite" />
|
||||
<orderEntry type="module" module-name="expo-web-browser" />
|
||||
<orderEntry type="module" module-name="unimodules-barcode-scanner-interface" />
|
||||
<orderEntry type="module" module-name="unimodules-camera-interface" />
|
||||
<orderEntry type="module" module-name="unimodules-constants-interface" />
|
||||
<orderEntry type="module" module-name="unimodules-face-detector-interface" />
|
||||
<orderEntry type="module" module-name="unimodules-file-system-interface" />
|
||||
<orderEntry type="module" module-name="unimodules-font-interface" />
|
||||
<orderEntry type="module" module-name="unimodules-image-loader-interface" />
|
||||
<orderEntry type="module" module-name="unimodules-permissions-interface" />
|
||||
<orderEntry type="module" module-name="unimodules-sensors-interface" />
|
||||
<orderEntry type="module" module-name="unimodules-task-manager-interface" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -139,6 +139,8 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':react-native-safe-area-context')
|
||||
implementation project(':react-native-screens')
|
||||
implementation project(':react-native-reanimated')
|
||||
implementation project(':react-native-gesture-handler')
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.reactnavigationexample;
|
||||
import android.app.Application;
|
||||
|
||||
import com.facebook.react.ReactApplication;
|
||||
import com.th3rdwave.safeareacontext.SafeAreaContextPackage;
|
||||
import com.swmansion.rnscreens.RNScreensPackage;
|
||||
import com.swmansion.reanimated.ReanimatedPackage;
|
||||
import com.facebook.react.ReactNativeHost;
|
||||
import com.facebook.react.ReactPackage;
|
||||
@@ -39,6 +41,8 @@ public class MainApplication extends Application implements ReactApplication {
|
||||
protected List<ReactPackage> getPackages() {
|
||||
return Arrays.<ReactPackage>asList(
|
||||
new MainReactPackage(),
|
||||
new SafeAreaContextPackage(),
|
||||
new RNScreensPackage(),
|
||||
new ReanimatedPackage(),
|
||||
new RNGestureHandlerPackage(),
|
||||
new ModuleRegistryAdapter(mModuleRegistryProvider)
|
||||
|
||||
@@ -16,3 +16,6 @@
|
||||
# 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
|
||||
# org.gradle.parallel=true
|
||||
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
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'
|
||||
project(':react-native-reanimated').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-reanimated/android')
|
||||
includeUnimodulesProjects()
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
"name": "@react-navigation/example",
|
||||
"slug": "react-navigation-example",
|
||||
"privacy": "public",
|
||||
"sdkVersion": "34.0.0",
|
||||
"sdkVersion": "35.0.0",
|
||||
"platforms": [
|
||||
"ios",
|
||||
"android",
|
||||
"web"
|
||||
],
|
||||
"version": "1.0.0",
|
||||
"orientation": "portrait",
|
||||
"icon": "./assets/icon.png",
|
||||
"splash": {
|
||||
"image": "./assets/splash.png",
|
||||
@@ -30,4 +29,4 @@
|
||||
},
|
||||
"displayName": "React Navigation Example",
|
||||
"name": "ReactNavigationExample"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* eslint-disable import/no-commonjs */
|
||||
|
||||
module.exports = function(api) {
|
||||
api.cache(true);
|
||||
return {
|
||||
|
||||
@@ -28,6 +28,9 @@ target 'ReactNavigationExample' do
|
||||
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
|
||||
pod 'RNGestureHandler', :podspec => '../node_modules/react-native-gesture-handler/RNGestureHandler.podspec'
|
||||
pod 'RNReanimated', :podspec => '../node_modules/react-native-reanimated/RNReanimated.podspec'
|
||||
pod 'RNScreens', :podspec => '../node_modules/react-native-screens/RNScreens.podspec'
|
||||
|
||||
use_unimodules!
|
||||
pod 'react-native-safe-area-context', :path => '../node_modules/react-native-safe-area-context'
|
||||
|
||||
end
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
PODS:
|
||||
- boost-for-react-native (1.63.0)
|
||||
- DoubleConversion (1.1.6)
|
||||
- EXAppLoaderProvider (6.0.0)
|
||||
- EXConstants (6.0.0):
|
||||
- EXAppLoaderProvider (7.0.0)
|
||||
- EXConstants (7.0.0):
|
||||
- UMConstantsInterface
|
||||
- UMCore
|
||||
- EXFileSystem (6.0.2):
|
||||
- EXFileSystem (7.0.0):
|
||||
- UMCore
|
||||
- UMFileSystemInterface
|
||||
- EXFont (6.0.1):
|
||||
- EXFont (7.0.0):
|
||||
- UMCore
|
||||
- UMFontInterface
|
||||
- EXKeepAwake (6.0.0):
|
||||
- EXKeepAwake (7.0.0):
|
||||
- UMCore
|
||||
- EXLinearGradient (6.0.0):
|
||||
- EXLinearGradient (7.0.0):
|
||||
- UMCore
|
||||
- EXLocation (6.0.0):
|
||||
- EXLocation (7.0.0):
|
||||
- UMCore
|
||||
- UMPermissionsInterface
|
||||
- UMTaskManagerInterface
|
||||
- EXPermissions (6.0.0):
|
||||
- EXPermissions (7.0.0):
|
||||
- UMCore
|
||||
- UMPermissionsInterface
|
||||
- EXSQLite (6.0.0):
|
||||
- EXSQLite (7.0.0):
|
||||
- UMCore
|
||||
- UMFileSystemInterface
|
||||
- EXWebBrowser (6.0.0):
|
||||
- EXWebBrowser (7.0.1):
|
||||
- UMCore
|
||||
- Folly (2018.10.22.00):
|
||||
- boost-for-react-native
|
||||
@@ -34,6 +34,8 @@ PODS:
|
||||
- glog (0.3.5)
|
||||
- React (0.59.10):
|
||||
- React/Core (= 0.59.10)
|
||||
- react-native-safe-area-context (0.3.6):
|
||||
- React
|
||||
- React/Core (0.59.10):
|
||||
- yoga (= 0.59.10.React)
|
||||
- React/CxxBridge (0.59.10):
|
||||
@@ -89,23 +91,25 @@ PODS:
|
||||
- React/RCTBlob
|
||||
- RNGestureHandler (1.3.0):
|
||||
- React
|
||||
- RNReanimated (1.1.0):
|
||||
- RNReanimated (1.2.0):
|
||||
- React
|
||||
- UMBarCodeScannerInterface (3.0.0)
|
||||
- UMCameraInterface (3.0.0)
|
||||
- UMConstantsInterface (3.0.0)
|
||||
- UMCore (3.0.2)
|
||||
- UMFaceDetectorInterface (3.0.0)
|
||||
- UMFileSystemInterface (3.0.0)
|
||||
- UMFontInterface (3.0.0)
|
||||
- UMImageLoaderInterface (3.0.0)
|
||||
- UMPermissionsInterface (3.0.0)
|
||||
- UMReactNativeAdapter (3.0.0):
|
||||
- RNScreens (2.0.0-alpha.4):
|
||||
- React
|
||||
- UMBarCodeScannerInterface (4.0.0)
|
||||
- UMCameraInterface (4.0.0)
|
||||
- UMConstantsInterface (4.0.0)
|
||||
- UMCore (4.0.0)
|
||||
- UMFaceDetectorInterface (4.0.0)
|
||||
- UMFileSystemInterface (4.0.0)
|
||||
- UMFontInterface (4.0.0)
|
||||
- UMImageLoaderInterface (4.0.0)
|
||||
- UMPermissionsInterface (4.0.0)
|
||||
- UMReactNativeAdapter (5.0.0-alpha.0):
|
||||
- React
|
||||
- UMCore
|
||||
- UMFontInterface
|
||||
- UMSensorsInterface (3.0.0)
|
||||
- UMTaskManagerInterface (3.0.0)
|
||||
- UMSensorsInterface (4.0.0)
|
||||
- UMTaskManagerInterface (4.0.0)
|
||||
- yoga (0.59.10.React)
|
||||
|
||||
DEPENDENCIES:
|
||||
@@ -122,6 +126,7 @@ DEPENDENCIES:
|
||||
- EXWebBrowser (from `../node_modules/expo-web-browser/ios`)
|
||||
- Folly (from `../node_modules/react-native/third-party-podspecs/Folly.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/CxxBridge (from `../node_modules/react-native`)
|
||||
- React/DevSupport (from `../node_modules/react-native`)
|
||||
@@ -138,6 +143,7 @@ DEPENDENCIES:
|
||||
- React/RCTWebSocket (from `../node_modules/react-native`)
|
||||
- RNGestureHandler (from `../node_modules/react-native-gesture-handler/RNGestureHandler.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`)
|
||||
- UMCameraInterface (from `../node_modules/unimodules-camera-interface/ios`)
|
||||
- UMConstantsInterface (from `../node_modules/unimodules-constants-interface/ios`)
|
||||
@@ -147,7 +153,7 @@ DEPENDENCIES:
|
||||
- UMFontInterface (from `../node_modules/unimodules-font-interface/ios`)
|
||||
- UMImageLoaderInterface (from `../node_modules/unimodules-image-loader-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`)
|
||||
- UMTaskManagerInterface (from `../node_modules/unimodules-task-manager-interface/ios`)
|
||||
- yoga (from `../node_modules/react-native/ReactCommon/yoga`)
|
||||
@@ -195,10 +201,14 @@ EXTERNAL SOURCES:
|
||||
:podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec"
|
||||
React:
|
||||
:path: "../node_modules/react-native"
|
||||
react-native-safe-area-context:
|
||||
:path: "../node_modules/react-native-safe-area-context"
|
||||
RNGestureHandler:
|
||||
:podspec: "../node_modules/react-native-gesture-handler/RNGestureHandler.podspec"
|
||||
RNReanimated:
|
||||
:podspec: "../node_modules/react-native-reanimated/RNReanimated.podspec"
|
||||
RNScreens:
|
||||
:podspec: "../node_modules/react-native-screens/RNScreens.podspec"
|
||||
UMBarCodeScannerInterface:
|
||||
:path: !ruby/object:Pathname
|
||||
path: "../node_modules/unimodules-barcode-scanner-interface/ios"
|
||||
@@ -228,7 +238,7 @@ EXTERNAL SOURCES:
|
||||
path: "../node_modules/unimodules-permissions-interface/ios"
|
||||
UMReactNativeAdapter:
|
||||
: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:
|
||||
:path: !ruby/object:Pathname
|
||||
path: "../node_modules/unimodules-sensors-interface/ios"
|
||||
@@ -241,35 +251,37 @@ EXTERNAL SOURCES:
|
||||
SPEC CHECKSUMS:
|
||||
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
|
||||
DoubleConversion: bb338842f62ab1d708ceb63ec3d999f0f3d98ecd
|
||||
EXAppLoaderProvider: 7a8185228d8ba9e689a0e2d6d957fe9bdd49c8a0
|
||||
EXConstants: 5d81e84ca71b9a552529889cc798b4a04e9e22b3
|
||||
EXFileSystem: 091907902fcec9f9182b656fdead41a82f30986a
|
||||
EXFont: c862449210fc86aa11d24a202cb22c71a0d39609
|
||||
EXKeepAwake: e7cb6516675052b12a7d23291e33078b4239653a
|
||||
EXLinearGradient: 40781b77e58f844c8dc4ad310dc9755b4d3792a7
|
||||
EXLocation: 4eb76115832f08b1e78003b335c210e18fa60424
|
||||
EXPermissions: 99e52dc3e5f8e55153f1958004f6df2a30a1f2f5
|
||||
EXSQLite: 8dab6a5ab1b78be7925073d6071eb22095d4dda6
|
||||
EXWebBrowser: def838b95aa9d396f9ce71ace4e614ee16e7ee30
|
||||
EXAppLoaderProvider: 5d348813a9cf09b03bbe5b8b55437bc1bfbddbd1
|
||||
EXConstants: 31e5318521be6175009af6ccd3e97dedf39da96a
|
||||
EXFileSystem: 7e53a2c30a2eb6987ba6d5158ab908f947523228
|
||||
EXFont: 71d07dc5d2153db7d1a23f1e0cc1b6341d55c432
|
||||
EXKeepAwake: d4caf9a1a7691126ade4ca0b76592e93250a8f29
|
||||
EXLinearGradient: ebfd46cb98a46330213e4945b96227d98f624054
|
||||
EXLocation: 452a1d9edceb1b93deb86fd785236606d33742dd
|
||||
EXPermissions: df10ad83df2f6b647aec304619354f8ab48d5f63
|
||||
EXSQLite: ddc1e6727bd7d36e649f07590fe3ae5511c1f039
|
||||
EXWebBrowser: 18924c3d2a3a1aa95d413672f058beff589c80f4
|
||||
Folly: de497beb10f102453a1afa9edbf8cf8a251890de
|
||||
glog: aefd1eb5dda2ab95ba0938556f34b98e2da3a60d
|
||||
React: 36d0768f9e93be2473b37e7fa64f92c1d5341eef
|
||||
react-native-safe-area-context: e380a6f783ccaec848e2f3cc8eb205a62362950d
|
||||
RNGestureHandler: 5329a942fce3d41c68b84c2c2276ce06a696d8b0
|
||||
RNReanimated: 7a52c90473b5e81c13408d40d797b98387eaddde
|
||||
UMBarCodeScannerInterface: 84ea2d6b58ff0dc27ef9b68bab71286be18ee020
|
||||
UMCameraInterface: 26b26005d1756a0d5f4f04f1e168e39ea9154535
|
||||
UMConstantsInterface: 038bacb19de12b6fd328c589122c8dc977cccf61
|
||||
UMCore: 733094f43f7244c60ce1f0592d00013ed68fa52c
|
||||
UMFaceDetectorInterface: c9c3ae4cb045421283667a1698c2f31331f55e3f
|
||||
UMFileSystemInterface: e9adc71027017de38eaf7d05fa58b2848ecb3797
|
||||
UMFontInterface: f0c5846977ee8a93d7cfa8ae7e666772c727d195
|
||||
UMImageLoaderInterface: 36e54e570acc4d720856f03ceebc441f73ea472c
|
||||
UMPermissionsInterface: 938d010c74c43fcefc9bb990633a7c5a1631267e
|
||||
UMReactNativeAdapter: 131ea2b944ade8035f0b54c6570c405f6000548d
|
||||
UMSensorsInterface: 0ed023ce9b96f2ca6fada7bda05b7760da60b293
|
||||
UMTaskManagerInterface: 8664abd37a00715727e60df9ecd65e42ba47b548
|
||||
RNReanimated: 1b52415c4302f198cb581282a0166690bad62c43
|
||||
RNScreens: 84be1a2369a580beb2fea0755cc62ef16b83fffe
|
||||
UMBarCodeScannerInterface: d5a6fdc98ed6241225b0a8432a7f4e2b397668bc
|
||||
UMCameraInterface: 68870a3197fee85bd5afca5609ba4a5b7257d19d
|
||||
UMConstantsInterface: d25b8e8887ca7aaf568c06caf08f4d40734ee4ef
|
||||
UMCore: 402cee150324974974f5c32b5404d8af65e4cff5
|
||||
UMFaceDetectorInterface: 7b4f1a92f0c726b58b086296048efe193b570678
|
||||
UMFileSystemInterface: aadb9a67aa6470d7ebc06cf04dc54fee6781ac48
|
||||
UMFontInterface: 2d3c128285086bbed3d2a650f1d698323ef3b25a
|
||||
UMImageLoaderInterface: 2829a7571a12d2e754c73c55ffe7e327d8402c7d
|
||||
UMPermissionsInterface: b6a6e96db0f4011a25aaca14e6022529dd3d6e4e
|
||||
UMReactNativeAdapter: e93109c6de5ea830d4a78d08f3a65b8d33a143a3
|
||||
UMSensorsInterface: cf59dd7602764a2419e00167429be3e4be39c61d
|
||||
UMTaskManagerInterface: 1e70fe58b872355f0ecb44fb81bb1a16484047f0
|
||||
yoga: 684513b14b03201579ba3cee20218c9d1298b0cc
|
||||
|
||||
PODFILE CHECKSUM: 41592ff50a43d56f905dbf9c7eded4b358264eba
|
||||
PODFILE CHECKSUM: 1276a2dd000c142ccc03272023bb8a6b2d5b9933
|
||||
|
||||
COCOAPODS: 1.7.5
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* eslint-disable import/no-commonjs, import/no-extraneous-dependencies */
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
@@ -36,7 +36,7 @@ module.exports = {
|
||||
'react-native',
|
||||
'react-native-gesture-handler',
|
||||
'react-native-reanimated',
|
||||
'react-native-safe-area-view',
|
||||
'react-native-safe-area-context',
|
||||
'react-native-screens',
|
||||
'react-native-paper',
|
||||
'react-native-tab-view',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/example",
|
||||
"description": "Demo app to showcase various functionality of React Navigation",
|
||||
"version": "5.0.0-alpha.7",
|
||||
"version": "5.0.0-alpha.14",
|
||||
"private": true,
|
||||
"workspaces": {
|
||||
"nohoist": [
|
||||
@@ -11,38 +11,41 @@
|
||||
},
|
||||
"scripts": {
|
||||
"start": "expo start",
|
||||
"web": "expo start --web",
|
||||
"native": "react-native start",
|
||||
"android": "react-native run-android",
|
||||
"ios": "react-native run-ios"
|
||||
"ios": "react-native run-ios",
|
||||
"postinstall": "jetify"
|
||||
},
|
||||
"dependencies": {
|
||||
"@expo/vector-icons": "^10.0.0",
|
||||
"@react-native-community/masked-view": "^0.1.1",
|
||||
"expo": "^34.0.1",
|
||||
"expo-asset": "~6.0.0",
|
||||
"expo": "^35.0.0",
|
||||
"expo-asset": "~7.0.0",
|
||||
"query-string": "^6.8.3",
|
||||
"react": "16.8.3",
|
||||
"react-dom": "^16.8.3",
|
||||
"react-native": "0.59.10",
|
||||
"react": "~16.8.3",
|
||||
"react-dom": "~16.8.3",
|
||||
"react-native": "~0.59.10",
|
||||
"react-native-gesture-handler": "~1.3.0",
|
||||
"react-native-paper": "^3.0.0-alpha.3",
|
||||
"react-native-reanimated": "~1.1.0",
|
||||
"react-native-screens": "1.0.0-alpha.22",
|
||||
"react-native-tab-view": "2.7.1",
|
||||
"react-native-unimodules": "~0.5.2",
|
||||
"scheduler": "^0.14.0",
|
||||
"shortid": "^2.2.14",
|
||||
"use-subscription": "^1.0.0"
|
||||
"react-native-paper": "^3.0.0-alpha.7",
|
||||
"react-native-reanimated": "~1.2.0",
|
||||
"react-native-safe-area-context": "~0.3.6",
|
||||
"react-native-screens": "2.0.0-alpha.4",
|
||||
"react-native-tab-view": "2.10.0",
|
||||
"react-native-unimodules": "^0.7.0-rc.1",
|
||||
"react-native-web": "^0.11.7",
|
||||
"scheduler": "^0.16.1",
|
||||
"shortid": "^2.2.15",
|
||||
"use-subscription": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.5.5",
|
||||
"@types/react": "^16.8.23",
|
||||
"@types/react-native": "^0.57.65",
|
||||
"babel-preset-expo": "^6.0.0",
|
||||
"expo-cli": "^3.0.10",
|
||||
"typescript": "^3.5.3"
|
||||
},
|
||||
"resolutions": {
|
||||
"react-native-safe-area-view": "0.14.7"
|
||||
"@babel/core": "^7.6.2",
|
||||
"@expo/webpack-config": "^0.7.12",
|
||||
"@types/react": "^16.9.4",
|
||||
"@types/react-native": "^0.60.19",
|
||||
"babel-preset-expo": "^7.0.0",
|
||||
"expo-cli": "^3.3.0",
|
||||
"jetifier": "^1.6.4",
|
||||
"typescript": "^3.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,13 @@ type AuthStackParams = {
|
||||
'sign-in': undefined;
|
||||
};
|
||||
|
||||
const SplashScreen = () => (
|
||||
<View style={styles.content}>
|
||||
<ActivityIndicator />
|
||||
</View>
|
||||
);
|
||||
const SplashScreen = () => {
|
||||
return (
|
||||
<View style={styles.content}>
|
||||
<ActivityIndicator />
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
const SignInScreen = ({
|
||||
setUserToken,
|
||||
@@ -74,7 +76,7 @@ export default function SimpleStackScreen({ navigation }: Props) {
|
||||
}, []);
|
||||
|
||||
navigation.setOptions({
|
||||
header: null,
|
||||
headerShown: false,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
/* eslint-disable import/namespace, import/default */
|
||||
|
||||
import * as React from 'react';
|
||||
import { MaterialIcons } from '@expo/vector-icons';
|
||||
import { MaterialCommunityIcons } from '@expo/vector-icons';
|
||||
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
||||
// @ts-ignore
|
||||
import TouchableBounce from 'react-native/Libraries/Components/Touchable/TouchableBounce';
|
||||
import TouchableBounce from '../Shared/TouchableBounce';
|
||||
import Albums from '../Shared/Albums';
|
||||
import Contacts from '../Shared/Contacts';
|
||||
import Chat from '../Shared/Chat';
|
||||
import SimpleStackScreen from './SimpleStack';
|
||||
|
||||
const getTabBarIcon = (name: string) => ({
|
||||
tintColor,
|
||||
color,
|
||||
horizontal,
|
||||
}: {
|
||||
tintColor: string;
|
||||
color: string;
|
||||
horizontal: boolean;
|
||||
}) => (
|
||||
<MaterialIcons name={name} color={tintColor} size={horizontal ? 17 : 24} />
|
||||
<MaterialCommunityIcons
|
||||
name={name}
|
||||
color={color}
|
||||
size={horizontal ? 17 : 24}
|
||||
/>
|
||||
);
|
||||
|
||||
type BottomTabParams = {
|
||||
@@ -36,7 +37,7 @@ export default function BottomTabsScreen() {
|
||||
name="article"
|
||||
options={{
|
||||
title: 'Article',
|
||||
tabBarIcon: getTabBarIcon('chrome-reader-mode'),
|
||||
tabBarIcon: getTabBarIcon('file-document-box'),
|
||||
tabBarButtonComponent: TouchableBounce,
|
||||
}}
|
||||
>
|
||||
@@ -49,7 +50,7 @@ export default function BottomTabsScreen() {
|
||||
component={Chat}
|
||||
options={{
|
||||
title: 'Chat',
|
||||
tabBarIcon: getTabBarIcon('chat-bubble'),
|
||||
tabBarIcon: getTabBarIcon('message-reply'),
|
||||
tabBarButtonComponent: TouchableBounce,
|
||||
}}
|
||||
/>
|
||||
@@ -67,7 +68,7 @@ export default function BottomTabsScreen() {
|
||||
component={Albums}
|
||||
options={{
|
||||
title: 'Albums',
|
||||
tabBarIcon: getTabBarIcon('photo-album'),
|
||||
tabBarIcon: getTabBarIcon('image-album'),
|
||||
tabBarButtonComponent: TouchableBounce,
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -19,27 +19,29 @@ type CompatStackParams = {
|
||||
|
||||
const ArticleScreen: CompatScreenType<
|
||||
StackNavigationProp<CompatStackParams, 'Article'>
|
||||
> = ({ navigation }) => (
|
||||
<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: navigation.getParam('author') }} />
|
||||
</React.Fragment>
|
||||
);
|
||||
> = ({ navigation }) => {
|
||||
return (
|
||||
<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: navigation.getParam('author') }} />
|
||||
</React.Fragment>
|
||||
);
|
||||
};
|
||||
|
||||
ArticleScreen.navigationOptions = ({ navigation }) => ({
|
||||
title: `Article by ${navigation.getParam('author')}`,
|
||||
@@ -47,27 +49,29 @@ ArticleScreen.navigationOptions = ({ navigation }) => ({
|
||||
|
||||
const AlbumsScreen: CompatScreenType<
|
||||
StackNavigationProp<CompatStackParams>
|
||||
> = ({ navigation }) => (
|
||||
<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>
|
||||
);
|
||||
> = ({ navigation }) => {
|
||||
return (
|
||||
<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 CompatStack = createCompatNavigatorFactory(createStackNavigator)<
|
||||
StackNavigationProp<CompatStackParams>
|
||||
@@ -92,7 +96,7 @@ export default function CompatStackScreen({
|
||||
navigation: StackNavigationProp<{}>;
|
||||
}) {
|
||||
navigation.setOptions({
|
||||
header: null,
|
||||
headerShown: false,
|
||||
});
|
||||
|
||||
return <CompatStack />;
|
||||
|
||||
@@ -24,7 +24,7 @@ export default function MaterialBottomTabsScreen() {
|
||||
name="article"
|
||||
options={{
|
||||
tabBarLabel: 'Article',
|
||||
tabBarIcon: 'chrome-reader-mode',
|
||||
tabBarIcon: 'file-document-box',
|
||||
tabBarColor: '#C9E7F8',
|
||||
}}
|
||||
>
|
||||
@@ -37,7 +37,7 @@ export default function MaterialBottomTabsScreen() {
|
||||
component={Chat}
|
||||
options={{
|
||||
tabBarLabel: 'Chat',
|
||||
tabBarIcon: 'chat-bubble',
|
||||
tabBarIcon: 'message-reply',
|
||||
tabBarColor: '#9FD5C9',
|
||||
tabBarBadge: true,
|
||||
}}
|
||||
@@ -56,7 +56,7 @@ export default function MaterialBottomTabsScreen() {
|
||||
component={Albums}
|
||||
options={{
|
||||
tabBarLabel: 'Albums',
|
||||
tabBarIcon: 'photo-album',
|
||||
tabBarIcon: 'image-album',
|
||||
tabBarColor: '#FAD4D6',
|
||||
}}
|
||||
/>
|
||||
|
||||
131
packages/example/src/Screens/ModalPresentationStack.tsx
Normal file
131
packages/example/src/Screens/ModalPresentationStack.tsx
Normal file
@@ -0,0 +1,131 @@
|
||||
import * as React from 'react';
|
||||
import { View, StyleSheet } from 'react-native';
|
||||
import { Button } from 'react-native-paper';
|
||||
import { useSafeArea } from 'react-native-safe-area-context';
|
||||
import { RouteProp, ParamListBase } from '@react-navigation/core';
|
||||
import {
|
||||
createStackNavigator,
|
||||
StackNavigationProp,
|
||||
TransitionPresets,
|
||||
} from '@react-navigation/stack';
|
||||
import Article from '../Shared/Article';
|
||||
import Albums from '../Shared/Albums';
|
||||
|
||||
type SimpleStackParams = {
|
||||
article: { author: string };
|
||||
album: undefined;
|
||||
};
|
||||
|
||||
type SimpleStackNavigation = StackNavigationProp<SimpleStackParams>;
|
||||
|
||||
const ArticleScreen = ({
|
||||
navigation,
|
||||
route,
|
||||
}: {
|
||||
navigation: SimpleStackNavigation;
|
||||
route: RouteProp<SimpleStackParams, 'article'>;
|
||||
}) => {
|
||||
const insets = useSafeArea();
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<View style={[styles.buttons, { marginTop: insets.top }]}>
|
||||
<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: SimpleStackNavigation;
|
||||
}) => {
|
||||
const insets = useSafeArea();
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<View style={[styles.buttons, { marginTop: insets.top }]}>
|
||||
<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 ModalPresentationStack = createStackNavigator<SimpleStackParams>();
|
||||
|
||||
type Props = {
|
||||
options?: React.ComponentProps<typeof ModalPresentationStack.Navigator>;
|
||||
navigation: StackNavigationProp<ParamListBase>;
|
||||
};
|
||||
|
||||
export default function SimpleStackScreen({ navigation, options }: Props) {
|
||||
navigation.setOptions({
|
||||
headerShown: false,
|
||||
});
|
||||
|
||||
return (
|
||||
<ModalPresentationStack.Navigator
|
||||
mode="modal"
|
||||
headerMode="none"
|
||||
screenOptions={{
|
||||
...TransitionPresets.ModalPresentationIOS,
|
||||
cardOverlayEnabled: true,
|
||||
gestureEnabled: true,
|
||||
}}
|
||||
{...options}
|
||||
>
|
||||
<ModalPresentationStack.Screen
|
||||
name="article"
|
||||
component={ArticleScreen}
|
||||
options={({ route }) => ({
|
||||
title: `Article by ${route.params.author}`,
|
||||
})}
|
||||
initialParams={{ author: 'Gandalf' }}
|
||||
/>
|
||||
<ModalPresentationStack.Screen
|
||||
name="album"
|
||||
component={AlbumsScreen}
|
||||
options={{ title: 'Album' }}
|
||||
/>
|
||||
</ModalPresentationStack.Navigator>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
buttons: {
|
||||
flexDirection: 'row',
|
||||
padding: 8,
|
||||
},
|
||||
button: {
|
||||
margin: 8,
|
||||
},
|
||||
});
|
||||
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,
|
||||
},
|
||||
});
|
||||
@@ -5,6 +5,7 @@ import { RouteProp, ParamListBase } from '@react-navigation/core';
|
||||
import {
|
||||
createStackNavigator,
|
||||
StackNavigationProp,
|
||||
StackNavigationOptions,
|
||||
} from '@react-navigation/stack';
|
||||
import Article from '../Shared/Article';
|
||||
import Albums from '../Shared/Albums';
|
||||
@@ -22,64 +23,68 @@ const ArticleScreen = ({
|
||||
}: {
|
||||
navigation: SimpleStackNavigation;
|
||||
route: RouteProp<SimpleStackParams, '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>
|
||||
);
|
||||
}) => {
|
||||
return (
|
||||
<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: SimpleStackNavigation;
|
||||
}) => (
|
||||
<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>
|
||||
);
|
||||
}) => {
|
||||
return (
|
||||
<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 SimpleStack = createStackNavigator<SimpleStackParams>();
|
||||
|
||||
type Props = {
|
||||
options?: React.ComponentProps<typeof SimpleStack.Navigator>;
|
||||
options?: StackNavigationOptions;
|
||||
navigation: StackNavigationProp<ParamListBase>;
|
||||
};
|
||||
|
||||
export default function SimpleStackScreen({ navigation, options }: Props) {
|
||||
navigation.setOptions({
|
||||
header: null,
|
||||
headerShown: false,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -25,8 +25,13 @@ export default function Albums() {
|
||||
contentContainerStyle={styles.content}
|
||||
>
|
||||
{COVERS.map((source, i) => (
|
||||
// eslint-disable-next-line react/no-array-index-key
|
||||
<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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ export default function Chat() {
|
||||
|
||||
return (
|
||||
<View
|
||||
// eslint-disable-next-line react/no-array-index-key
|
||||
key={i}
|
||||
style={[odd ? styles.odd : styles.even, styles.inverted]}
|
||||
>
|
||||
|
||||
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 { ScrollView, AsyncStorage, YellowBox } from 'react-native';
|
||||
import LinkingPrefixes from './LinkingPrefixes';
|
||||
import { MaterialIcons } from '@expo/vector-icons';
|
||||
import { Appbar, List } from 'react-native-paper';
|
||||
import { Asset } from 'expo-asset';
|
||||
import {
|
||||
@@ -22,8 +22,11 @@ import {
|
||||
StackNavigationProp,
|
||||
} from '@react-navigation/stack';
|
||||
|
||||
import SimpleStackScreen from './Screens/SimpleStack';
|
||||
import BottomTabsScreen from './Screens/BottomTabs';
|
||||
import LinkingPrefixes from './LinkingPrefixes';
|
||||
import SimpleStack from './Screens/SimpleStack';
|
||||
import NativeStack from './Screens/NativeStack';
|
||||
import ModalPresentationStack from './Screens/ModalPresentationStack';
|
||||
import BottomTabs from './Screens/BottomTabs';
|
||||
import MaterialTopTabsScreen from './Screens/MaterialTopTabs';
|
||||
import MaterialBottomTabs from './Screens/MaterialBottomTabs';
|
||||
import AuthFlow from './Screens/AuthFlow';
|
||||
@@ -32,31 +35,37 @@ import CompatAPI from './Screens/CompatAPI';
|
||||
YellowBox.ignoreWarnings(['Require cycle:', 'Warning: Async Storage']);
|
||||
|
||||
type RootDrawerParamList = {
|
||||
root: undefined;
|
||||
Root: undefined;
|
||||
Another: undefined;
|
||||
};
|
||||
|
||||
type RootStackParamList = {
|
||||
home: undefined;
|
||||
Home: undefined;
|
||||
} & {
|
||||
[P in keyof typeof SCREENS]: undefined;
|
||||
};
|
||||
|
||||
const SCREENS = {
|
||||
'simple-stack': { title: 'Simple Stack', component: SimpleStackScreen },
|
||||
'bottom-tabs': { title: 'Bottom Tabs', component: BottomTabsScreen },
|
||||
'material-top-tabs': {
|
||||
SimpleStack: { title: 'Simple Stack', component: SimpleStack },
|
||||
NativeStack: { title: 'Native Stack', component: NativeStack },
|
||||
ModalPresentationStack: {
|
||||
title: 'Modal Presentation Stack',
|
||||
component: ModalPresentationStack,
|
||||
},
|
||||
BottomTabs: { title: 'Bottom Tabs', component: BottomTabs },
|
||||
MaterialTopTabs: {
|
||||
title: 'Material Top Tabs',
|
||||
component: MaterialTopTabsScreen,
|
||||
},
|
||||
'material-bottom-tabs': {
|
||||
MaterialBottomTabs: {
|
||||
title: 'Material Bottom Tabs',
|
||||
component: MaterialBottomTabs,
|
||||
},
|
||||
'auth-flow': {
|
||||
AuthFlow: {
|
||||
title: 'Auth Flow',
|
||||
component: AuthFlow,
|
||||
},
|
||||
'compat-api': {
|
||||
CompatAPI: {
|
||||
title: 'Compat Layer',
|
||||
component: CompatAPI,
|
||||
},
|
||||
@@ -134,7 +143,15 @@ export default function App() {
|
||||
}
|
||||
>
|
||||
<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,
|
||||
}: {
|
||||
@@ -142,7 +159,7 @@ export default function App() {
|
||||
}) => (
|
||||
<Stack.Navigator>
|
||||
<Stack.Screen
|
||||
name="home"
|
||||
name="Home"
|
||||
options={{
|
||||
title: 'Examples',
|
||||
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,62 @@
|
||||
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.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)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.11](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.10...@react-navigation/material-bottom-tabs@5.0.0-alpha.11) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.10](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.9...@react-navigation/material-bottom-tabs@5.0.0-alpha.10) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.9](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.8...@react-navigation/material-bottom-tabs@5.0.0-alpha.9) (2019-09-27)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.8](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-bottom-tabs@5.0.0-alpha.7...@react-navigation/material-bottom-tabs@5.0.0-alpha.8) (2019-09-16)
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ export default function App() {
|
||||
component={Article}
|
||||
options={{
|
||||
tabBarLabel: 'Article',
|
||||
tabBarIcon: 'chrome-reader-mode',
|
||||
tabBarIcon: 'file-document-box',
|
||||
}}
|
||||
/>
|
||||
<MaterialBottomTabs.Screen
|
||||
@@ -35,7 +35,7 @@ export default function App() {
|
||||
component={Chat}
|
||||
options={{
|
||||
tabBarLabel: 'Chat',
|
||||
tabBarIcon: 'chat-bubble',
|
||||
tabBarIcon: 'message-reply',
|
||||
}}
|
||||
/>
|
||||
<MaterialBottomTabs.Screen
|
||||
@@ -51,7 +51,7 @@ export default function App() {
|
||||
component={Albums}
|
||||
options={{
|
||||
tabBarLabel: 'Albums',
|
||||
tabBarIcon: 'photo-album',
|
||||
tabBarIcon: 'image-album',
|
||||
}}
|
||||
/>
|
||||
</MaterialBottomTabs.Navigator>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"material",
|
||||
"tab"
|
||||
],
|
||||
"version": "5.0.0-alpha.8",
|
||||
"version": "5.0.0-alpha.14",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -34,25 +34,25 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/routers": "^5.0.0-alpha.7"
|
||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-native-community/bob": "^0.7.0",
|
||||
"@types/react": "^16.8.24",
|
||||
"@types/react-native": "^0.60.2",
|
||||
"@types/react-native-vector-icons": "^6.4.1",
|
||||
"del-cli": "^2.0.0",
|
||||
"react": "16.8.3",
|
||||
"react-native": "0.59.10",
|
||||
"react-native-paper": "^3.0.0-alpha.3",
|
||||
"@types/react": "^16.9.4",
|
||||
"@types/react-native": "^0.60.17",
|
||||
"@types/react-native-vector-icons": "^6.4.4",
|
||||
"del-cli": "^3.0.0",
|
||||
"react": "~16.8.3",
|
||||
"react-native": "~0.59.10",
|
||||
"react-native-paper": "^3.0.0-alpha.7",
|
||||
"react-native-vector-icons": "^6.6.0",
|
||||
"typescript": "^3.5.3"
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||
"react": "*",
|
||||
"react-native": "*",
|
||||
"react-native-paper": "^3.0.0-alpha.3",
|
||||
"react-native-paper": "^3.0.0-alpha.0",
|
||||
"react-native-vector-icons": "^6.0.0"
|
||||
},
|
||||
"@react-native-community/bob": {
|
||||
|
||||
@@ -60,7 +60,7 @@ export type MaterialBottomTabNavigationOptions = {
|
||||
|
||||
/**
|
||||
* 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?:
|
||||
| string
|
||||
@@ -96,6 +96,16 @@ export type MaterialBottomTabDescriptorMap = {
|
||||
export type MaterialBottomTabNavigationConfig = Partial<
|
||||
Omit<
|
||||
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 { StyleSheet } from 'react-native';
|
||||
import { BottomNavigation } from 'react-native-paper';
|
||||
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialIcons';
|
||||
import { Route } from '@react-navigation/core';
|
||||
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||
import { TabNavigationState, TabActions } from '@react-navigation/routers';
|
||||
|
||||
import {
|
||||
@@ -17,7 +16,7 @@ type Props = MaterialBottomTabNavigationConfig & {
|
||||
descriptors: MaterialBottomTabDescriptorMap;
|
||||
};
|
||||
|
||||
type Scene = { route: Route<string> };
|
||||
type Scene = { route: { key: string } };
|
||||
|
||||
export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
||||
private getColor = ({ route }: Scene) => {
|
||||
@@ -35,7 +34,7 @@ export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
||||
? options.tabBarLabel
|
||||
: typeof options.title === 'string'
|
||||
? options.title
|
||||
: route.name;
|
||||
: ((route as any) as { name: string }).name;
|
||||
};
|
||||
|
||||
private getAccessibilityLabel = ({ route }: Scene) => {
|
||||
@@ -49,9 +48,9 @@ export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
||||
const label = this.getLabelText({ route });
|
||||
|
||||
if (typeof label === 'string') {
|
||||
return `${label}, tab, ${state.routes.indexOf(route) + 1} of ${
|
||||
state.routes.length
|
||||
}`;
|
||||
return `${label}, tab, ${state.routes.findIndex(
|
||||
r => r.key === route.key
|
||||
) + 1} of ${state.routes.length}`;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
@@ -75,7 +74,7 @@ export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
||||
focused,
|
||||
color,
|
||||
}: {
|
||||
route: Route<string>;
|
||||
route: { key: string };
|
||||
focused: boolean;
|
||||
color: string;
|
||||
}) => {
|
||||
@@ -114,7 +113,7 @@ export default class MaterialBottomTabView extends React.PureComponent<Props> {
|
||||
target: state.key,
|
||||
})
|
||||
}
|
||||
renderScene={({ route }: Scene) => descriptors[route.key].render()}
|
||||
renderScene={({ route }) => descriptors[route.key].render()}
|
||||
renderIcon={this.renderIcon}
|
||||
getLabelText={this.getLabelText}
|
||||
getColor={this.getColor}
|
||||
|
||||
@@ -3,6 +3,52 @@
|
||||
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.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)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.10](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.9...@react-navigation/material-top-tabs@5.0.0-alpha.10) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.9](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.8...@react-navigation/material-top-tabs@5.0.0-alpha.9) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.8](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.7...@react-navigation/material-top-tabs@5.0.0-alpha.8) (2019-09-27)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* export some more type aliases ([8b78d61](https://github.com/react-navigation/navigation-ex/commit/8b78d61))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.7](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/material-top-tabs@5.0.0-alpha.6...@react-navigation/material-top-tabs@5.0.0-alpha.7) (2019-08-31)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/material-top-tabs
|
||||
|
||||
@@ -10,7 +10,7 @@ Open a Terminal in your project's folder and run,
|
||||
yarn add @react-navigation/core @react-navigation/material-top-tabs react-native-tab-view
|
||||
```
|
||||
|
||||
Now we need to install [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler) and [`react-native-reanimated`](https://github.com/kmagiera/react-native-reanimated).
|
||||
Now we need to install [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler) and [`react-native-reanimated`](https://github.com/kmagiera/react-native-reanimated)..
|
||||
|
||||
If you are using Expo, to ensure that you get the compatible versions of the libraries, run:
|
||||
|
||||
@@ -26,28 +26,13 @@ yarn add react-native-reanimated react-native-gesture-handler
|
||||
|
||||
If you are using Expo, you are done. Otherwise, continue to the next steps.
|
||||
|
||||
Next, we need to link these libraries. The steps depends on your React Native version:
|
||||
To complete the linking on iOS, make sure you have [Cocoapods](https://cocoapods.org/) installed. Then run:
|
||||
|
||||
- **React Native 0.60 and higher**
|
||||
|
||||
On newer versions of React Native, [linking is automatic](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md).
|
||||
|
||||
To complete the linking on iOS, make sure you have [Cocoapods](https://cocoapods.org/) installed. Then run:
|
||||
|
||||
```sh
|
||||
cd ios
|
||||
pod install
|
||||
cd ..
|
||||
```
|
||||
|
||||
- **React Native 0.59**
|
||||
|
||||
If you're on an older React Native version, you need to manually link the dependencies. To do that, run:
|
||||
|
||||
```sh
|
||||
react-native link react-native-reanimated
|
||||
react-native link react-native-gesture-handler
|
||||
```
|
||||
```sh
|
||||
cd ios
|
||||
pod install
|
||||
cd ..
|
||||
```
|
||||
|
||||
**IMPORTANT:** There are additional steps required for `react-native-gesture-handler` on Android after linking (for all React Native versions). Check the [this guide](https://kmagiera.github.io/react-native-gesture-handler/docs/getting-started.html) to complete the installation.
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"material",
|
||||
"tab"
|
||||
],
|
||||
"version": "5.0.0-alpha.7",
|
||||
"version": "5.0.0-alpha.12",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -34,19 +34,19 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/routers": "^5.0.0-alpha.7"
|
||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-native-community/bob": "^0.7.0",
|
||||
"@types/react": "^16.8.24",
|
||||
"@types/react-native": "^0.60.2",
|
||||
"del-cli": "^2.0.0",
|
||||
"react": "16.8.3",
|
||||
"react-native": "^0.59.8",
|
||||
"@types/react": "^16.9.4",
|
||||
"@types/react-native": "^0.60.17",
|
||||
"del-cli": "^3.0.0",
|
||||
"react": "~16.8.3",
|
||||
"react-native": "~0.59.10",
|
||||
"react-native-gesture-handler": "^1.3.0",
|
||||
"react-native-reanimated": "^1.1.0",
|
||||
"react-native-reanimated": "^1.3.0",
|
||||
"react-native-tab-view": "^2.10.0",
|
||||
"typescript": "^3.5.3"
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||
|
||||
@@ -16,4 +16,6 @@ export { default as MaterialTopTabBar } from './views/MaterialTopTabBar';
|
||||
export {
|
||||
MaterialTopTabNavigationOptions,
|
||||
MaterialTopTabNavigationProp,
|
||||
MaterialTopTabBarProps,
|
||||
MaterialTopTabBarOptions,
|
||||
} from './types';
|
||||
|
||||
@@ -64,19 +64,19 @@ export type MaterialTopTabNavigationOptions = {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
tabBarLabel?:
|
||||
| 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?:
|
||||
| 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.
|
||||
@@ -196,7 +196,7 @@ export type MaterialTopTabBarProps = MaterialTopTabBarOptions &
|
||||
getLabelText: (props: {
|
||||
route: Route<string>;
|
||||
}) =>
|
||||
| ((scene: { focused: boolean; tintColor: string }) => React.ReactNode)
|
||||
| ((scene: { focused: boolean; color: string }) => React.ReactNode)
|
||||
| React.ReactNode;
|
||||
getAccessibilityLabel: (props: {
|
||||
route: Route<string>;
|
||||
|
||||
@@ -53,7 +53,7 @@ export default class TabBarTop extends React.PureComponent<
|
||||
}
|
||||
|
||||
if (typeof label === 'function') {
|
||||
return label({ focused, tintColor: color });
|
||||
return label({ focused, color });
|
||||
}
|
||||
|
||||
return label;
|
||||
@@ -79,7 +79,7 @@ export default class TabBarTop extends React.PureComponent<
|
||||
if (options.tabBarIcon !== undefined) {
|
||||
const icon =
|
||||
typeof options.tabBarIcon === 'function'
|
||||
? options.tabBarIcon({ focused, tintColor: color })
|
||||
? options.tabBarIcon({ focused, color })
|
||||
: options.tabBarIcon;
|
||||
|
||||
return <View style={[styles.icon, iconStyle]}>{icon}</View>;
|
||||
|
||||
28
packages/native-stack/CHANGELOG.md
Normal file
28
packages/native-stack/CHANGELOG.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# 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.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.2",
|
||||
"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.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-native-community/bob": "^0.7.0",
|
||||
"del-cli": "^2.0.0",
|
||||
"react-native-screens": "^2.0.0-alpha.3",
|
||||
"typescript": "^3.5.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@react-navigation/core": "^5.0.0-alpha.0",
|
||||
"react": "*",
|
||||
"react-native": "*",
|
||||
"react-native-screens": "^2.0.0-alpha.3"
|
||||
},
|
||||
"@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);
|
||||
178
packages/native-stack/src/types.tsx
Normal file
178
packages/native-stack/src/types.tsx
Normal file
@@ -0,0 +1,178 @@
|
||||
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 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;
|
||||
};
|
||||
68
packages/native-stack/src/views/HeaderConfig.tsx
Normal file
68
packages/native-stack/src/views/HeaderConfig.tsx
Normal file
@@ -0,0 +1,68 @@
|
||||
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 = {},
|
||||
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}
|
||||
backgroundColor={headerStyle.backgroundColor}
|
||||
>
|
||||
{headerRight !== undefined ? (
|
||||
<ScreenStackHeaderRightView>{headerRight()}</ScreenStackHeaderRightView>
|
||||
) : null}
|
||||
</ScreenStackHeaderConfig>
|
||||
);
|
||||
}
|
||||
63
packages/native-stack/src/views/StackView.tsx
Normal file
63
packages/native-stack/src/views/StackView.tsx
Normal file
@@ -0,0 +1,63 @@
|
||||
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, contentStyle]}>{renderScene()}</View>
|
||||
</Screen>
|
||||
);
|
||||
})}
|
||||
</ScreenStack>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
content: {
|
||||
flex: 1,
|
||||
backgroundColor: '#eee',
|
||||
marginTop: Platform.OS === 'android' ? 56 : 0,
|
||||
},
|
||||
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"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user