mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-01-14 17:42:29 +08:00
Compare commits
14 Commits
@react-nav
...
@react-nav
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5303e8ffb5 | ||
|
|
ba6b6ae025 | ||
|
|
16079d1050 | ||
|
|
b4a76814c6 | ||
|
|
8294efc8f4 | ||
|
|
a27ade8881 | ||
|
|
615b523d26 | ||
|
|
070c46ba64 | ||
|
|
d8394cf919 | ||
|
|
a7c4a4d7cd | ||
|
|
282b465ae1 | ||
|
|
6f5f4b7d35 | ||
|
|
d75915d1f3 | ||
|
|
832ed882bc |
@@ -42,8 +42,7 @@
|
||||
},
|
||||
"resolutions": {
|
||||
"react": "16.8.3",
|
||||
"react-native": "0.59.10",
|
||||
"react-native-safe-area-view": "0.14.7"
|
||||
"react-native": "0.59.10"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
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.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
|
||||
|
||||
@@ -10,6 +10,30 @@ 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
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"android",
|
||||
"tab"
|
||||
],
|
||||
"version": "5.0.0-alpha.11",
|
||||
"version": "5.0.0-alpha.13",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -33,8 +33,7 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/routers": "^5.0.0-alpha.9",
|
||||
"react-native-safe-area-view": "^0.14.7"
|
||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-native-community/bob": "^0.7.0",
|
||||
@@ -43,12 +42,14 @@
|
||||
"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",
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
TextStyle,
|
||||
ViewStyle,
|
||||
} from 'react-native';
|
||||
import SafeAreaView from 'react-native-safe-area-view';
|
||||
import {
|
||||
NavigationHelpers,
|
||||
NavigationProp,
|
||||
@@ -234,5 +233,4 @@ export type BottomTabBarProps = BottomTabBarOptions & {
|
||||
}) => React.ReactNode;
|
||||
activeTintColor: string;
|
||||
inactiveTintColor: string;
|
||||
safeAreaInset?: React.ComponentProps<typeof SafeAreaView>['forceInset'];
|
||||
};
|
||||
|
||||
@@ -8,8 +8,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,9 +22,7 @@ type State = {
|
||||
visible: Animated.Value;
|
||||
};
|
||||
|
||||
type Props = BottomTabBarProps & {
|
||||
safeAreaInset: React.ComponentProps<typeof SafeAreaView>['forceInset'];
|
||||
};
|
||||
type Props = BottomTabBarProps;
|
||||
|
||||
const majorVersion = parseInt(Platform.Version as string, 10);
|
||||
const isIos = Platform.OS === 'ios';
|
||||
@@ -43,9 +41,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 = {
|
||||
@@ -270,99 +265,101 @@ 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
|
||||
? {
|
||||
// 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,
|
||||
});
|
||||
<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,
|
||||
{
|
||||
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'
|
||||
}
|
||||
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,
|
||||
]}
|
||||
return (
|
||||
<NavigationContext.Provider
|
||||
key={route.key}
|
||||
value={descriptors[route.key].navigation}
|
||||
>
|
||||
{this.renderIcon(scene)}
|
||||
{this.renderLabel(scene)}
|
||||
</ButtonComponent>
|
||||
</NavigationContext.Provider>
|
||||
);
|
||||
})}
|
||||
</SafeAreaView>
|
||||
</Animated.View>
|
||||
<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>
|
||||
);
|
||||
})}
|
||||
</Animated.View>
|
||||
)}
|
||||
</SafeAreaConsumer>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -372,23 +369,15 @@ const COMPACT_HEIGHT = 29;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
tabBar: {
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
backgroundColor: '#fff',
|
||||
borderTopWidth: StyleSheet.hairlineWidth,
|
||||
borderTopColor: 'rgba(0, 0, 0, .3)',
|
||||
flexDirection: 'row',
|
||||
},
|
||||
container: {
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
elevation: 8,
|
||||
},
|
||||
tabBarCompact: {
|
||||
height: COMPACT_HEIGHT,
|
||||
},
|
||||
tabBarRegular: {
|
||||
height: DEFAULT_HEIGHT,
|
||||
},
|
||||
tab: {
|
||||
flex: 1,
|
||||
alignItems: isIos ? 'center' : 'stretch',
|
||||
|
||||
@@ -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 {
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
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.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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@react-navigation/compat",
|
||||
"description": "Compatibility layer to write navigator definitions in static configuration format",
|
||||
"version": "5.0.0-alpha.5",
|
||||
"version": "5.0.0-alpha.7",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
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/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)
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"react-native",
|
||||
"react-navigation"
|
||||
],
|
||||
"version": "5.0.0-alpha.12",
|
||||
"version": "5.0.0-alpha.14",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -273,7 +273,11 @@ it('fires blur event when a route is removed with a delay', async () => {
|
||||
|
||||
const [previous, dispatch] = React.useReducer(
|
||||
(state, action) => {
|
||||
return { ...state, ...action };
|
||||
if (state.routes !== action.routes) {
|
||||
return { ...state, ...action };
|
||||
}
|
||||
|
||||
return state;
|
||||
},
|
||||
{ routes: state.routes, descriptors }
|
||||
);
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
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.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
|
||||
|
||||
@@ -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.11",
|
||||
"version": "5.0.0-alpha.13",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -34,8 +34,7 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/routers": "^5.0.0-alpha.9",
|
||||
"react-native-safe-area-view": "^0.14.7"
|
||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-native-community/bob": "^0.7.0",
|
||||
@@ -46,6 +45,7 @@
|
||||
"react-native": "0.59.10",
|
||||
"react-native-gesture-handler": "^1.3.0",
|
||||
"react-native-reanimated": "^1.3.0",
|
||||
"react-native-safe-area-context": "^0.3.6",
|
||||
"react-native-screens": "^1.0.0-alpha.22",
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
@@ -55,6 +55,7 @@
|
||||
"react-native": "*",
|
||||
"react-native-gesture-handler": "^1.0.0",
|
||||
"react-native-reanimated": "^1.0.0",
|
||||
"react-native-safe-area-context": "^0.3.6",
|
||||
"react-native-screens": "^1.0.0-alpha.0"
|
||||
},
|
||||
"@react-native-community/bob": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import { View, Text, StyleSheet } from 'react-native';
|
||||
import SafeAreaView from 'react-native-safe-area-view';
|
||||
import { useSafeArea } from 'react-native-safe-area-context';
|
||||
|
||||
import TouchableItem from './TouchableItem';
|
||||
import { DrawerNavigationItemsProps } from '../types';
|
||||
@@ -25,63 +25,72 @@ const DrawerNavigatorItems = ({
|
||||
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',
|
||||
}: DrawerNavigationItemsProps) => {
|
||||
const insets = useSafeArea();
|
||||
|
||||
return (
|
||||
<View style={[styles.container, itemsContainerStyle]}>
|
||||
{items.map((route, index: number) => {
|
||||
const focused = activeItemKey === route.key;
|
||||
const color = focused ? activeTintColor : inactiveTintColor;
|
||||
const backgroundColor = focused
|
||||
? activeBackgroundColor
|
||||
: inactiveBackgroundColor;
|
||||
const scene = { route, index, focused, tintColor: color };
|
||||
const icon = renderIcon(scene);
|
||||
const label = getLabel(scene);
|
||||
const accessibilityLabel =
|
||||
typeof label === 'string' ? label : undefined;
|
||||
const extraLabelStyle = focused ? activeLabelStyle : inactiveLabelStyle;
|
||||
|
||||
return (
|
||||
<TouchableItem
|
||||
key={route.key}
|
||||
accessible
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
onPress={() => {
|
||||
onItemPress({ route, focused });
|
||||
}}
|
||||
delayPressIn={0}
|
||||
>
|
||||
{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>
|
||||
);
|
||||
<View
|
||||
style={[
|
||||
{
|
||||
backgroundColor,
|
||||
marginLeft: drawerPosition === 'left' ? insets.left : 0,
|
||||
marginRight: drawerPosition === 'right' ? insets.right : 0,
|
||||
},
|
||||
styles.item,
|
||||
itemStyle,
|
||||
]}
|
||||
>
|
||||
{icon ? (
|
||||
<View
|
||||
style={[
|
||||
styles.icon,
|
||||
focused ? null : styles.inactiveIcon,
|
||||
iconContainerStyle,
|
||||
]}
|
||||
>
|
||||
{icon}
|
||||
</View>
|
||||
) : null}
|
||||
{typeof label === 'string' ? (
|
||||
<Text
|
||||
style={[styles.label, { color }, labelStyle, extraLabelStyle]}
|
||||
>
|
||||
{label}
|
||||
</Text>
|
||||
) : (
|
||||
label
|
||||
)}
|
||||
</View>
|
||||
</TouchableItem>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
/* Material design specs - https://material.io/guidelines/patterns/navigation-drawer.html#navigation-drawer-specs */
|
||||
DrawerNavigatorItems.defaultProps = {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import * as React from 'react';
|
||||
import { Dimensions, StyleSheet, I18nManager, Platform } from 'react-native';
|
||||
import { SafeAreaProvider, useSafeArea } 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 {
|
||||
DrawerNavigationState,
|
||||
@@ -32,13 +32,18 @@ type State = {
|
||||
drawerWidth: number;
|
||||
};
|
||||
|
||||
const DefaultContentComponent = (props: ContentComponentProps) => (
|
||||
<ScrollView alwaysBounceVertical={false}>
|
||||
<SafeAreaView forceInset={{ top: 'always', horizontal: 'never' }}>
|
||||
const DefaultContentComponent = (props: ContentComponentProps) => {
|
||||
const insets = useSafeArea();
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
alwaysBounceVertical={false}
|
||||
contentContainerStyle={{ marginTop: insets.top }}
|
||||
>
|
||||
<DrawerNavigatorItems {...props} />
|
||||
</SafeAreaView>
|
||||
</ScrollView>
|
||||
);
|
||||
</ScrollView>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Component that renders the drawer.
|
||||
@@ -208,35 +213,37 @@ 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={{
|
||||
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>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,33 @@
|
||||
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/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
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.9",
|
||||
"version": "5.0.0-alpha.12",
|
||||
"private": true,
|
||||
"workspaces": {
|
||||
"nohoist": [
|
||||
@@ -21,12 +21,13 @@
|
||||
"expo": "^35.0.0",
|
||||
"expo-asset": "~7.0.0",
|
||||
"query-string": "^6.8.3",
|
||||
"react": "^16.10.1",
|
||||
"react": "^16.8.3",
|
||||
"react-dom": "^16.8.3",
|
||||
"react-native": "^0.61.2",
|
||||
"react-native": "^0.59.10",
|
||||
"react-native-gesture-handler": "~1.3.0",
|
||||
"react-native-paper": "^3.0.0-alpha.3",
|
||||
"react-native-reanimated": "~1.2.0",
|
||||
"react-native-safe-area-context": "~0.3.6",
|
||||
"react-native-screens": "~1.0.0-alpha.23",
|
||||
"react-native-tab-view": "2.10.0",
|
||||
"react-native-unimodules": "^0.7.0-rc.1",
|
||||
@@ -41,8 +42,5 @@
|
||||
"babel-preset-expo": "^7.0.0",
|
||||
"expo-cli": "^3.1.2",
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
"resolutions": {
|
||||
"react-native-safe-area-view": "0.14.7"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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 />;
|
||||
|
||||
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,
|
||||
},
|
||||
});
|
||||
@@ -22,53 +22,57 @@ 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>();
|
||||
|
||||
@@ -79,7 +83,7 @@ type Props = {
|
||||
|
||||
export default function SimpleStackScreen({ navigation, options }: Props) {
|
||||
navigation.setOptions({
|
||||
header: null,
|
||||
headerShown: false,
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -22,8 +22,9 @@ import {
|
||||
StackNavigationProp,
|
||||
} from '@react-navigation/stack';
|
||||
|
||||
import SimpleStackScreen from './Screens/SimpleStack';
|
||||
import BottomTabsScreen from './Screens/BottomTabs';
|
||||
import SimpleStack from './Screens/SimpleStack';
|
||||
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';
|
||||
@@ -42,21 +43,25 @@ type RootStackParamList = {
|
||||
};
|
||||
|
||||
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 },
|
||||
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,
|
||||
},
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
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-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
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"material",
|
||||
"tab"
|
||||
],
|
||||
"version": "5.0.0-alpha.10",
|
||||
"version": "5.0.0-alpha.12",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
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.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
|
||||
|
||||
@@ -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.9",
|
||||
"version": "5.0.0-alpha.11",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -42,7 +42,7 @@
|
||||
"@types/react-native": "^0.60.17",
|
||||
"del-cli": "^3.0.0",
|
||||
"react": "16.8.3",
|
||||
"react-native": "^0.59.8",
|
||||
"react-native": "^0.59.10",
|
||||
"react-native-gesture-handler": "^1.3.0",
|
||||
"react-native-reanimated": "^1.3.0",
|
||||
"react-native-tab-view": "^2.10.0",
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
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.11](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native@5.0.0-alpha.10...@react-navigation/native@5.0.0-alpha.11) (2019-10-06)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/native
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.10](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native@5.0.0-alpha.9...@react-navigation/native@5.0.0-alpha.10) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/native
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.9](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/native@5.0.0-alpha.8...@react-navigation/native@5.0.0-alpha.9) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/native
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"ios",
|
||||
"android"
|
||||
],
|
||||
"version": "5.0.0-alpha.9",
|
||||
"version": "5.0.0-alpha.11",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -3,6 +3,46 @@
|
||||
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.24](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.23...@react-navigation/stack@5.0.0-alpha.24) (2019-10-06)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* actually expose gestureVelocityImpact in the public API ([16079d1](https://github.com/react-navigation/navigation-ex/commit/16079d1))
|
||||
* don't recompute if routes didn't change ([615b523](https://github.com/react-navigation/navigation-ex/commit/615b523))
|
||||
* handling vertical gesture in RTL ([#122](https://github.com/react-navigation/navigation-ex/issues/122)) ([a27ade8](https://github.com/react-navigation/navigation-ex/commit/a27ade8))
|
||||
* use next screen's animation when not focused. fixes [#87](https://github.com/react-navigation/navigation-ex/issues/87) ([b4a7681](https://github.com/react-navigation/navigation-ex/commit/b4a7681))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add gestureVelocityImpact as a prop for stack ([#123](https://github.com/react-navigation/navigation-ex/issues/123)) ([8294efc](https://github.com/react-navigation/navigation-ex/commit/8294efc))
|
||||
* drop header: null in favor of more explitit headerShown option ([ba6b6ae](https://github.com/react-navigation/navigation-ex/commit/ba6b6ae))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.23](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.22...@react-navigation/stack@5.0.0-alpha.23) (2019-10-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix passing insets to interpolator ([6f5f4b7](https://github.com/react-navigation/navigation-ex/commit/6f5f4b7))
|
||||
* fix vertical gesture ([a7c4a4d](https://github.com/react-navigation/navigation-ex/commit/a7c4a4d))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.22](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.21...@react-navigation/stack@5.0.0-alpha.22) (2019-10-03)
|
||||
|
||||
**Note:** Version bump only for package @react-navigation/stack
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [5.0.0-alpha.21](https://github.com/react-navigation/navigation-ex/compare/@react-navigation/stack@5.0.0-alpha.20...@react-navigation/stack@5.0.0-alpha.21) (2019-10-03)
|
||||
|
||||
|
||||
|
||||
@@ -10,44 +10,36 @@ Open a Terminal in your project's folder and run,
|
||||
yarn add @react-navigation/core @react-navigation/stack @react-native-community/masked-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), [`react-native-reanimated`](https://github.com/kmagiera/react-native-reanimated), [`react-native-screens`](https://github.com/kmagiera/react-native-screens) 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-screens 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-screens 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**
|
||||
```sh
|
||||
cd ios
|
||||
pod install
|
||||
cd ..
|
||||
```
|
||||
|
||||
On newer versions of React Native, [linking is automatic](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md).
|
||||
To finalize installation of `react-native-screens` for Android, add the following two lines to dependencies section in `android/app/build.gradle`:
|
||||
|
||||
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
|
||||
```
|
||||
```gradle
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
|
||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
|
||||
```
|
||||
|
||||
**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.
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"android",
|
||||
"stack"
|
||||
],
|
||||
"version": "5.0.0-alpha.21",
|
||||
"version": "5.0.0-alpha.24",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -33,8 +33,7 @@
|
||||
"clean": "del lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-navigation/routers": "^5.0.0-alpha.9",
|
||||
"react-native-safe-area-view": "^0.14.7"
|
||||
"@react-navigation/routers": "^5.0.0-alpha.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@react-native-community/bob": "^0.7.0",
|
||||
@@ -46,6 +45,7 @@
|
||||
"react-native": "0.59.10",
|
||||
"react-native-gesture-handler": "^1.3.0",
|
||||
"react-native-reanimated": "^1.3.0",
|
||||
"react-native-safe-area-context": "^0.3.6",
|
||||
"react-native-screens": "^1.0.0-alpha.22",
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
@@ -56,6 +56,7 @@
|
||||
"react-native": "*",
|
||||
"react-native-gesture-handler": "^1.0.0",
|
||||
"react-native-reanimated": "^1.0.0",
|
||||
"react-native-safe-area-context": "^0.3.6",
|
||||
"react-native-screens": "^1.0.0-alpha.0"
|
||||
},
|
||||
"@react-native-community/bob": {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { I18nManager } from 'react-native';
|
||||
import Animated from 'react-native-reanimated';
|
||||
import getStatusBarHeight from '../utils/getStatusBarHeight';
|
||||
import {
|
||||
StackCardInterpolationProps,
|
||||
StackCardInterpolatedStyle,
|
||||
@@ -84,9 +83,10 @@ export function forModalPresentationIOS({
|
||||
current,
|
||||
next,
|
||||
layouts: { screen },
|
||||
insets,
|
||||
}: StackCardInterpolationProps): StackCardInterpolatedStyle {
|
||||
const topOffset = 10;
|
||||
const statusBarHeight = getStatusBarHeight(screen.width > screen.height);
|
||||
const statusBarHeight = insets.top;
|
||||
const aspectRatio = screen.height / screen.width;
|
||||
|
||||
const progress = add(current.progress, next ? next.progress : 0);
|
||||
|
||||
@@ -184,10 +184,6 @@ export type StackHeaderOptions = {
|
||||
* Style object for the header. You can specify a custom background color here, for example.
|
||||
*/
|
||||
headerStyle?: StyleProp<ViewStyle>;
|
||||
/**
|
||||
* Custom status bar height to set as the top padding in the header.
|
||||
*/
|
||||
headerStatusBarHeight?: number;
|
||||
/**
|
||||
* Defaults to `false`. If `true`, the header will not have a background unless you explicitly provide it with `headerBackground`.
|
||||
* The header will also float over the screen so that it overlaps the content underneath.
|
||||
@@ -245,7 +241,12 @@ export type StackNavigationOptions = StackHeaderOptions &
|
||||
* Function that given `HeaderProps` returns a React Element to display as a header.
|
||||
* Setting to `null` hides header.
|
||||
*/
|
||||
header?: null | ((props: StackHeaderProps) => React.ReactNode);
|
||||
header?: (props: StackHeaderProps) => React.ReactNode;
|
||||
/**
|
||||
* Whether to show the header. The header is shown by default unless `headerMode` was set to `none`.
|
||||
* Setting this to `false` hides the header.
|
||||
*/
|
||||
headerShown?: boolean;
|
||||
/**
|
||||
* Whether a shadow is visible for the card during transitions. Defaults to `true`.
|
||||
*/
|
||||
@@ -291,6 +292,11 @@ export type StackNavigationOptions = StackHeaderOptions &
|
||||
*/
|
||||
horizontal?: number;
|
||||
};
|
||||
/**
|
||||
* Number which determines the relevance of velocity for the gesture.
|
||||
* Defaults to 0.3.
|
||||
*/
|
||||
gestureVelocityImpact?: number;
|
||||
};
|
||||
|
||||
export type StackNavigationConfig = {
|
||||
@@ -445,6 +451,15 @@ export type StackCardInterpolationProps = {
|
||||
*/
|
||||
screen: Layout;
|
||||
};
|
||||
/**
|
||||
* Safe area insets
|
||||
*/
|
||||
insets: {
|
||||
top: number;
|
||||
right: number;
|
||||
bottom: number;
|
||||
left: number;
|
||||
};
|
||||
};
|
||||
|
||||
export type StackCardInterpolatedStyle = {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { Platform } from 'react-native';
|
||||
import { getStatusBarHeight as getStatusBarHeightNative } from 'react-native-safe-area-view';
|
||||
|
||||
const getStatusBarHeight = Platform.select({
|
||||
default: getStatusBarHeightNative,
|
||||
web: () => 0,
|
||||
});
|
||||
|
||||
export default getStatusBarHeight;
|
||||
@@ -1,10 +1,14 @@
|
||||
import * as React from 'react';
|
||||
import { StackActions } from '@react-navigation/routers';
|
||||
import { useSafeArea } from 'react-native-safe-area-context';
|
||||
|
||||
import HeaderSegment from './HeaderSegment';
|
||||
import { StackHeaderProps, StackHeaderTitleProps } from '../../types';
|
||||
import HeaderTitle from './HeaderTitle';
|
||||
|
||||
export default React.memo(function Header(props: StackHeaderProps) {
|
||||
const insets = useSafeArea();
|
||||
|
||||
const { scene, previous, layout, navigation, styleInterpolator } = props;
|
||||
const { options } = scene.descriptor;
|
||||
const title =
|
||||
@@ -35,6 +39,7 @@ export default React.memo(function Header(props: StackHeaderProps) {
|
||||
return (
|
||||
<HeaderSegment
|
||||
{...options}
|
||||
insets={insets}
|
||||
layout={layout}
|
||||
scene={scene}
|
||||
title={title}
|
||||
|
||||
@@ -77,11 +77,11 @@ export default function HeaderContainer({
|
||||
const isHeaderStatic =
|
||||
mode === 'float'
|
||||
? (previousScene &&
|
||||
previousScene.descriptor.options.header === null &&
|
||||
previousScene.descriptor.options.headerShown === false &&
|
||||
// We still need to animate when coming back from next scene
|
||||
// A hacky way to check this is if the next scene exists
|
||||
!nextScene) ||
|
||||
(nextScene && nextScene.descriptor.options.header === null)
|
||||
(nextScene && nextScene.descriptor.options.headerShown === false)
|
||||
: false;
|
||||
|
||||
const props = {
|
||||
@@ -121,13 +121,13 @@ export default function HeaderContainer({
|
||||
: null
|
||||
}
|
||||
>
|
||||
{options.header !== undefined ? (
|
||||
options.header === null ? null : (
|
||||
{options.headerShown !== false ? (
|
||||
options.header !== undefined ? (
|
||||
options.header(props)
|
||||
) : (
|
||||
<Header {...props} />
|
||||
)
|
||||
) : (
|
||||
<Header {...props} />
|
||||
)}
|
||||
) : null}
|
||||
</View>
|
||||
</NavigationContext.Provider>
|
||||
);
|
||||
|
||||
@@ -7,10 +7,10 @@ import {
|
||||
ViewStyle,
|
||||
} from 'react-native';
|
||||
import Animated from 'react-native-reanimated';
|
||||
import { EdgeInsets } from 'react-native-safe-area-context';
|
||||
import { Route } from '@react-navigation/core';
|
||||
import HeaderBackButton from './HeaderBackButton';
|
||||
import HeaderBackground from './HeaderBackground';
|
||||
import getStatusBarHeight from '../../utils/getStatusBarHeight';
|
||||
import memoize from '../../utils/memoize';
|
||||
import {
|
||||
Layout,
|
||||
@@ -29,6 +29,7 @@ export type Scene<T> = {
|
||||
type Props = StackHeaderOptions & {
|
||||
headerTitle: (props: StackHeaderTitleProps) => React.ReactNode;
|
||||
layout: Layout;
|
||||
insets: EdgeInsets;
|
||||
onGoBack?: () => void;
|
||||
title?: string;
|
||||
leftLabel?: string;
|
||||
@@ -57,7 +58,7 @@ const warnIfHeaderStylesDefined = (styles: { [key: string]: any }) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const getDefaultHeaderHeight = (layout: Layout) => {
|
||||
export const getDefaultHeaderHeight = (layout: Layout, insets: EdgeInsets) => {
|
||||
const isLandscape = layout.width > layout.height;
|
||||
|
||||
let headerHeight;
|
||||
@@ -75,7 +76,7 @@ export const getDefaultHeaderHeight = (layout: Layout) => {
|
||||
headerHeight = 64;
|
||||
}
|
||||
|
||||
return headerHeight + getStatusBarHeight(isLandscape);
|
||||
return headerHeight + insets.top;
|
||||
};
|
||||
|
||||
export default class HeaderSegment extends React.Component<Props, State> {
|
||||
@@ -135,6 +136,7 @@ export default class HeaderSegment extends React.Component<Props, State> {
|
||||
const {
|
||||
scene,
|
||||
layout,
|
||||
insets,
|
||||
title: currentTitle,
|
||||
leftLabel: previousTitle,
|
||||
onGoBack,
|
||||
@@ -142,8 +144,6 @@ export default class HeaderSegment extends React.Component<Props, State> {
|
||||
headerLeft: left = onGoBack
|
||||
? (props: StackHeaderLeftButtonProps) => <HeaderBackButton {...props} />
|
||||
: undefined,
|
||||
// @ts-ignore
|
||||
headerStatusBarHeight = getStatusBarHeight(layout.width > layout.height),
|
||||
headerTransparent,
|
||||
headerTintColor,
|
||||
headerBackground,
|
||||
@@ -182,7 +182,7 @@ export default class HeaderSegment extends React.Component<Props, State> {
|
||||
);
|
||||
|
||||
const {
|
||||
height = getDefaultHeaderHeight(layout),
|
||||
height = getDefaultHeaderHeight(layout, insets),
|
||||
minHeight,
|
||||
maxHeight,
|
||||
backgroundColor,
|
||||
@@ -306,15 +306,17 @@ export default class HeaderSegment extends React.Component<Props, State> {
|
||||
pointerEvents="box-none"
|
||||
style={[{ height, minHeight, maxHeight, opacity }]}
|
||||
>
|
||||
<View
|
||||
pointerEvents="none"
|
||||
style={{ height: headerStatusBarHeight }}
|
||||
/>
|
||||
<View pointerEvents="none" style={{ height: insets.top }} />
|
||||
<View pointerEvents="box-none" style={styles.content}>
|
||||
{leftButton ? (
|
||||
<Animated.View
|
||||
pointerEvents="box-none"
|
||||
style={[styles.left, leftButtonStyle, leftContainerStyle]}
|
||||
style={[
|
||||
styles.left,
|
||||
{ left: insets.left },
|
||||
leftButtonStyle,
|
||||
leftContainerStyle,
|
||||
]}
|
||||
>
|
||||
{leftButton}
|
||||
</Animated.View>
|
||||
@@ -341,7 +343,12 @@ export default class HeaderSegment extends React.Component<Props, State> {
|
||||
{right ? (
|
||||
<Animated.View
|
||||
pointerEvents="box-none"
|
||||
style={[styles.right, rightButtonStyle, rightContainerStyle]}
|
||||
style={[
|
||||
styles.right,
|
||||
{ right: insets.right },
|
||||
rightButtonStyle,
|
||||
rightContainerStyle,
|
||||
]}
|
||||
>
|
||||
{right({ tintColor: headerTintColor })}
|
||||
</Animated.View>
|
||||
|
||||
@@ -14,6 +14,10 @@ import {
|
||||
PanGestureHandler,
|
||||
State as GestureState,
|
||||
} from 'react-native-gesture-handler';
|
||||
import { EdgeInsets } from 'react-native-safe-area-context';
|
||||
import PointerEventsView from './PointerEventsView';
|
||||
import memoize from '../../utils/memoize';
|
||||
import StackGestureContext from '../../utils/StackGestureContext';
|
||||
import {
|
||||
TransitionSpec,
|
||||
StackCardStyleInterpolator,
|
||||
@@ -21,9 +25,6 @@ import {
|
||||
SpringConfig,
|
||||
TimingConfig,
|
||||
} from '../../types';
|
||||
import memoize from '../../utils/memoize';
|
||||
import StackGestureContext from '../../utils/StackGestureContext';
|
||||
import PointerEventsView from './PointerEventsView';
|
||||
|
||||
type Props = ViewProps & {
|
||||
index: number;
|
||||
@@ -33,6 +34,7 @@ type Props = ViewProps & {
|
||||
next?: Animated.Node<number>;
|
||||
current: Animated.Value<number>;
|
||||
layout: Layout;
|
||||
insets: EdgeInsets;
|
||||
gestureDirection: 'horizontal' | 'vertical';
|
||||
onOpen: (isFinished: boolean) => void;
|
||||
onClose: (isFinished: boolean) => void;
|
||||
@@ -48,6 +50,7 @@ type Props = ViewProps & {
|
||||
vertical?: number;
|
||||
horizontal?: number;
|
||||
};
|
||||
gestureVelocityImpact: number;
|
||||
transitionSpec: {
|
||||
open: TransitionSpec;
|
||||
close: TransitionSpec;
|
||||
@@ -86,7 +89,7 @@ const MINUS_ONE_NODE = UNSET_NODE;
|
||||
const DIRECTION_VERTICAL = -1;
|
||||
const DIRECTION_HORIZONTAL = 1;
|
||||
|
||||
const SWIPE_VELOCITY_IMPACT = 0.3;
|
||||
const GESTURE_VELOCITY_IMPACT = 0.3;
|
||||
|
||||
/**
|
||||
* The distance of touch start from the edge of the screen where the gesture will be recognized
|
||||
@@ -228,10 +231,16 @@ export default class Card extends React.Component<Props> {
|
||||
overlayEnabled: Platform.OS !== 'ios',
|
||||
shadowEnabled: true,
|
||||
gestureEnabled: true,
|
||||
gestureVelocityImpact: GESTURE_VELOCITY_IMPACT,
|
||||
};
|
||||
|
||||
componentDidUpdate(prevProps: Props) {
|
||||
const { layout, gestureDirection, closing } = this.props;
|
||||
const {
|
||||
layout,
|
||||
gestureDirection,
|
||||
gestureVelocityImpact,
|
||||
closing,
|
||||
} = this.props;
|
||||
const { width, height } = layout;
|
||||
|
||||
if (width !== prevProps.layout.width) {
|
||||
@@ -242,6 +251,10 @@ export default class Card extends React.Component<Props> {
|
||||
this.layout.height.setValue(height);
|
||||
}
|
||||
|
||||
if (gestureVelocityImpact !== prevProps.gestureVelocityImpact) {
|
||||
this.gestureVelocityImpact.setValue(gestureVelocityImpact);
|
||||
}
|
||||
|
||||
if (gestureDirection !== prevProps.gestureDirection) {
|
||||
this.direction.setValue(
|
||||
gestureDirection === 'vertical'
|
||||
@@ -277,6 +290,9 @@ export default class Card extends React.Component<Props> {
|
||||
}
|
||||
|
||||
private isVisible = new Value<Binary>(TRUE);
|
||||
private gestureVelocityImpact = new Value<number>(
|
||||
this.props.gestureVelocityImpact
|
||||
);
|
||||
private isVisibleValue: Binary = TRUE;
|
||||
private nextIsVisible = new Value<Binary | -1>(UNSET);
|
||||
|
||||
@@ -368,7 +384,8 @@ export default class Card extends React.Component<Props> {
|
||||
this.props.index,
|
||||
this.props.current,
|
||||
this.props.next,
|
||||
this.props.layout
|
||||
this.props.layout,
|
||||
this.props.insets
|
||||
);
|
||||
};
|
||||
|
||||
@@ -471,18 +488,19 @@ export default class Card extends React.Component<Props> {
|
||||
|
||||
private extrapolatedPosition = add(
|
||||
this.gesture,
|
||||
multiply(this.velocity, SWIPE_VELOCITY_IMPACT)
|
||||
multiply(this.velocity, this.gestureVelocityImpact)
|
||||
);
|
||||
|
||||
private exec = [
|
||||
cond(
|
||||
eq(this.direction, DIRECTION_HORIZONTAL),
|
||||
set(
|
||||
this.gesture,
|
||||
set(
|
||||
this.gesture,
|
||||
cond(
|
||||
eq(this.direction, DIRECTION_HORIZONTAL),
|
||||
multiply(
|
||||
this.gestureUntraversed,
|
||||
I18nManager.isRTL ? MINUS_ONE_NODE : TRUE_NODE
|
||||
)
|
||||
),
|
||||
this.gestureUntraversed
|
||||
)
|
||||
),
|
||||
set(
|
||||
@@ -577,9 +595,13 @@ export default class Card extends React.Component<Props> {
|
||||
cond(
|
||||
this.distance,
|
||||
divide(
|
||||
multiply(
|
||||
this.gestureUntraversed,
|
||||
I18nManager.isRTL ? MINUS_ONE_NODE : TRUE_NODE
|
||||
cond(
|
||||
eq(this.direction, DIRECTION_HORIZONTAL),
|
||||
multiply(
|
||||
this.gestureUntraversed,
|
||||
I18nManager.isRTL ? MINUS_ONE_NODE : TRUE_NODE
|
||||
),
|
||||
this.gestureUntraversed
|
||||
),
|
||||
this.distance
|
||||
),
|
||||
@@ -645,8 +667,8 @@ export default class Card extends React.Component<Props> {
|
||||
private handleGestureEventVertical = Animated.event([
|
||||
{
|
||||
nativeEvent: {
|
||||
translationY: this.gesture,
|
||||
velocityY: this.velocity,
|
||||
translationY: this.gestureUntraversed,
|
||||
velocityY: this.velocityUntraversed,
|
||||
state: this.gestureState,
|
||||
},
|
||||
},
|
||||
@@ -661,7 +683,8 @@ export default class Card extends React.Component<Props> {
|
||||
index: number,
|
||||
current: Animated.Node<number>,
|
||||
next: Animated.Node<number> | undefined,
|
||||
layout: Layout
|
||||
layout: Layout,
|
||||
insets: EdgeInsets
|
||||
) =>
|
||||
styleInterpolator({
|
||||
index,
|
||||
@@ -671,6 +694,7 @@ export default class Card extends React.Component<Props> {
|
||||
layouts: {
|
||||
screen: layout,
|
||||
},
|
||||
insets,
|
||||
})
|
||||
);
|
||||
|
||||
@@ -683,7 +707,8 @@ export default class Card extends React.Component<Props> {
|
||||
this.props.index,
|
||||
this.props.current,
|
||||
this.props.next,
|
||||
this.props.layout
|
||||
this.props.layout,
|
||||
this.props.insets
|
||||
);
|
||||
|
||||
private gestureActivationCriteria() {
|
||||
@@ -733,6 +758,7 @@ export default class Card extends React.Component<Props> {
|
||||
current,
|
||||
next,
|
||||
layout,
|
||||
insets,
|
||||
overlayEnabled,
|
||||
shadowEnabled,
|
||||
gestureEnabled,
|
||||
@@ -749,7 +775,8 @@ export default class Card extends React.Component<Props> {
|
||||
index,
|
||||
current,
|
||||
next,
|
||||
layout
|
||||
layout,
|
||||
insets
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
ViewProps,
|
||||
} from 'react-native';
|
||||
import Animated from 'react-native-reanimated';
|
||||
import { EdgeInsets } from 'react-native-safe-area-context';
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import * as Screens from 'react-native-screens'; // Import with * as to prevent getters being called
|
||||
import { Route } from '@react-navigation/core';
|
||||
@@ -36,12 +37,13 @@ type ProgressValues = {
|
||||
|
||||
type Props = {
|
||||
mode: 'card' | 'modal';
|
||||
insets: EdgeInsets;
|
||||
state: StackNavigationState;
|
||||
navigation: StackNavigationHelpers;
|
||||
descriptors: StackDescriptorMap;
|
||||
routes: Route<string>[];
|
||||
openingRoutes: string[];
|
||||
closingRoutes: string[];
|
||||
openingRouteKeys: string[];
|
||||
closingRouteKeys: string[];
|
||||
onGoBack: (props: { route: Route<string> }) => void;
|
||||
onOpenRoute: (props: { route: Route<string> }) => void;
|
||||
onCloseRoute: (props: { route: Route<string> }) => void;
|
||||
@@ -114,10 +116,11 @@ const FALLBACK_DESCRIPTOR = Object.freeze({ options: {} });
|
||||
|
||||
const getFloatingHeaderHeights = (
|
||||
routes: Route<string>[],
|
||||
insets: EdgeInsets,
|
||||
layout: Layout,
|
||||
previous: { [key: string]: number }
|
||||
) => {
|
||||
const defaultHeaderHeight = getDefaultHeaderHeight(layout);
|
||||
const defaultHeaderHeight = getDefaultHeaderHeight(layout, insets);
|
||||
|
||||
return routes.reduce(
|
||||
(acc, curr) => {
|
||||
@@ -145,7 +148,7 @@ export default class Stack extends React.Component<Props, State> {
|
||||
acc[curr.key] =
|
||||
state.progress[curr.key] ||
|
||||
new Animated.Value(
|
||||
props.openingRoutes.includes(curr.key) &&
|
||||
props.openingRouteKeys.includes(curr.key) &&
|
||||
descriptor &&
|
||||
descriptor.options.animationEnabled !== false
|
||||
? 0
|
||||
@@ -201,6 +204,7 @@ export default class Stack extends React.Component<Props, State> {
|
||||
descriptors: props.descriptors,
|
||||
floatingHeaderHeights: getFloatingHeaderHeights(
|
||||
props.routes,
|
||||
props.insets,
|
||||
state.layout,
|
||||
state.floatingHeaderHeights
|
||||
),
|
||||
@@ -237,6 +241,7 @@ export default class Stack extends React.Component<Props, State> {
|
||||
layout,
|
||||
floatingHeaderHeights: getFloatingHeaderHeights(
|
||||
this.props.routes,
|
||||
this.props.insets,
|
||||
layout,
|
||||
{}
|
||||
),
|
||||
@@ -287,11 +292,12 @@ export default class Stack extends React.Component<Props, State> {
|
||||
render() {
|
||||
const {
|
||||
mode,
|
||||
insets,
|
||||
descriptors,
|
||||
state,
|
||||
navigation,
|
||||
routes,
|
||||
closingRoutes,
|
||||
closingRouteKeys,
|
||||
onOpenRoute,
|
||||
onCloseRoute,
|
||||
onGoBack,
|
||||
@@ -332,7 +338,6 @@ export default class Stack extends React.Component<Props, State> {
|
||||
const focused = focusedRoute.key === route.key;
|
||||
const current = progress[route.key];
|
||||
const scene = scenes[index];
|
||||
const descriptor = scene.descriptor;
|
||||
const next = self[index + 1]
|
||||
? progress[self[index + 1].key]
|
||||
: ANIMATED_ONE;
|
||||
@@ -348,21 +353,54 @@ export default class Stack extends React.Component<Props, State> {
|
||||
: 0;
|
||||
|
||||
const {
|
||||
header,
|
||||
headerShown,
|
||||
headerTransparent,
|
||||
cardTransparent,
|
||||
cardShadowEnabled,
|
||||
cardOverlayEnabled,
|
||||
cardStyle,
|
||||
gestureResponseDistance,
|
||||
gestureVelocityImpact,
|
||||
gestureDirection = defaultTransitionPreset.gestureDirection,
|
||||
transitionSpec = defaultTransitionPreset.transitionSpec,
|
||||
cardStyleInterpolator = defaultTransitionPreset.cardStyleInterpolator,
|
||||
headerStyleInterpolator = defaultTransitionPreset.headerStyleInterpolator,
|
||||
} = descriptor
|
||||
? descriptor.options
|
||||
} = scene.descriptor
|
||||
? scene.descriptor.options
|
||||
: ({} as StackNavigationOptions);
|
||||
|
||||
let transitionConfig = {
|
||||
transitionSpec,
|
||||
cardStyleInterpolator,
|
||||
headerStyleInterpolator,
|
||||
};
|
||||
|
||||
// When a screen is not the last, it should use next screen's transition config
|
||||
// Many transitions also animate the previous screen, so using 2 different transitions doesn't look right
|
||||
// For example combining a slide and a modal transition would look wrong otherwise
|
||||
// With this approach, combining different transition styles in the same navigator mostly looks right
|
||||
// This will still be broken when 2 transitions have different idle state (e.g. modal presentation),
|
||||
// but majority of the transitions look alright
|
||||
if (index !== self.length - 1) {
|
||||
const nextScene = scenes[index + 1];
|
||||
|
||||
if (nextScene) {
|
||||
const {
|
||||
transitionSpec = defaultTransitionPreset.transitionSpec,
|
||||
cardStyleInterpolator = defaultTransitionPreset.cardStyleInterpolator,
|
||||
headerStyleInterpolator = defaultTransitionPreset.headerStyleInterpolator,
|
||||
} = nextScene.descriptor
|
||||
? nextScene.descriptor.options
|
||||
: ({} as StackNavigationOptions);
|
||||
|
||||
transitionConfig = {
|
||||
transitionSpec,
|
||||
cardStyleInterpolator,
|
||||
headerStyleInterpolator,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<MaybeScreen
|
||||
key={route.key}
|
||||
@@ -375,8 +413,9 @@ export default class Stack extends React.Component<Props, State> {
|
||||
index={index}
|
||||
active={index === self.length - 1}
|
||||
focused={focused}
|
||||
closing={closingRoutes.includes(route.key)}
|
||||
closing={closingRouteKeys.includes(route.key)}
|
||||
layout={layout}
|
||||
insets={insets}
|
||||
current={current}
|
||||
scene={scene}
|
||||
previousScene={scenes[index - 1]}
|
||||
@@ -386,15 +425,14 @@ export default class Stack extends React.Component<Props, State> {
|
||||
cardOverlayEnabled={cardOverlayEnabled}
|
||||
cardShadowEnabled={cardShadowEnabled}
|
||||
cardStyle={cardStyle}
|
||||
gestureEnabled={index !== 0 && getGesturesEnabled({ route })}
|
||||
onPageChangeStart={onPageChangeStart}
|
||||
onPageChangeConfirm={onPageChangeConfirm}
|
||||
onPageChangeCancel={onPageChangeCancel}
|
||||
gestureResponseDistance={gestureResponseDistance}
|
||||
floatingHeaderHeight={floatingHeaderHeights[route.key]}
|
||||
hasCustomHeader={header === null}
|
||||
getPreviousRoute={getPreviousRoute}
|
||||
headerMode={headerMode}
|
||||
headerShown={headerShown}
|
||||
headerTransparent={headerTransparent}
|
||||
renderHeader={renderHeader}
|
||||
renderScene={renderScene}
|
||||
@@ -403,10 +441,10 @@ export default class Stack extends React.Component<Props, State> {
|
||||
onTransitionStart={this.handleTransitionStart}
|
||||
onTransitionEnd={this.handleTransitionEnd}
|
||||
onGoBack={onGoBack}
|
||||
gestureEnabled={index !== 0 && getGesturesEnabled({ route })}
|
||||
gestureVelocityImpact={gestureVelocityImpact}
|
||||
gestureDirection={gestureDirection}
|
||||
transitionSpec={transitionSpec}
|
||||
cardStyleInterpolator={cardStyleInterpolator}
|
||||
headerStyleInterpolator={headerStyleInterpolator}
|
||||
{...transitionConfig}
|
||||
/>
|
||||
</MaybeScreen>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as React from 'react';
|
||||
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';
|
||||
import Animated from 'react-native-reanimated';
|
||||
import { EdgeInsets } from 'react-native-safe-area-context';
|
||||
import { StackNavigationState } from '@react-navigation/routers';
|
||||
import { Route } from '@react-navigation/core';
|
||||
import { Props as HeaderContainerProps } from '../Header/HeaderContainer';
|
||||
@@ -19,6 +20,7 @@ type Props = TransitionPreset & {
|
||||
focused: boolean;
|
||||
closing: boolean;
|
||||
layout: Layout;
|
||||
insets: EdgeInsets;
|
||||
current: Animated.Value<number>;
|
||||
previousScene?: Scene<Route<string>>;
|
||||
scene: Scene<Route<string>>;
|
||||
@@ -28,7 +30,6 @@ type Props = TransitionPreset & {
|
||||
cardOverlayEnabled?: boolean;
|
||||
cardShadowEnabled?: boolean;
|
||||
cardStyle?: StyleProp<ViewStyle>;
|
||||
gestureEnabled?: boolean;
|
||||
getPreviousRoute: (props: {
|
||||
route: Route<string>;
|
||||
}) => Route<string> | undefined;
|
||||
@@ -45,14 +46,16 @@ type Props = TransitionPreset & {
|
||||
onPageChangeStart?: () => void;
|
||||
onPageChangeConfirm?: () => void;
|
||||
onPageChangeCancel?: () => void;
|
||||
gestureEnabled?: boolean;
|
||||
gestureResponseDistance?: {
|
||||
vertical?: number;
|
||||
horizontal?: number;
|
||||
};
|
||||
gestureVelocityImpact?: number;
|
||||
headerMode: StackHeaderMode;
|
||||
headerShown?: boolean;
|
||||
headerTransparent?: boolean;
|
||||
floatingHeaderHeight: number;
|
||||
hasCustomHeader: boolean;
|
||||
};
|
||||
|
||||
export default class StackItem extends React.PureComponent<Props> {
|
||||
@@ -93,6 +96,7 @@ export default class StackItem extends React.PureComponent<Props> {
|
||||
const {
|
||||
index,
|
||||
layout,
|
||||
insets,
|
||||
active,
|
||||
focused,
|
||||
closing,
|
||||
@@ -104,12 +108,13 @@ export default class StackItem extends React.PureComponent<Props> {
|
||||
cardOverlayEnabled,
|
||||
cardShadowEnabled,
|
||||
cardStyle,
|
||||
gestureEnabled,
|
||||
onPageChangeStart,
|
||||
onPageChangeCancel,
|
||||
gestureEnabled,
|
||||
gestureResponseDistance,
|
||||
gestureVelocityImpact,
|
||||
floatingHeaderHeight,
|
||||
hasCustomHeader,
|
||||
headerShown,
|
||||
getPreviousRoute,
|
||||
headerMode,
|
||||
headerTransparent,
|
||||
@@ -128,6 +133,7 @@ export default class StackItem extends React.PureComponent<Props> {
|
||||
transparent={cardTransparent}
|
||||
gestureDirection={gestureDirection}
|
||||
layout={layout}
|
||||
insets={insets}
|
||||
current={current}
|
||||
next={scene.progress.next}
|
||||
closing={closing}
|
||||
@@ -135,18 +141,19 @@ export default class StackItem extends React.PureComponent<Props> {
|
||||
onClose={this.handleClose}
|
||||
overlayEnabled={cardOverlayEnabled}
|
||||
shadowEnabled={cardShadowEnabled}
|
||||
gestureEnabled={gestureEnabled}
|
||||
onTransitionStart={this.handleTransitionStart}
|
||||
onGestureBegin={onPageChangeStart}
|
||||
onGestureCanceled={onPageChangeCancel}
|
||||
gestureEnabled={gestureEnabled}
|
||||
gestureResponseDistance={gestureResponseDistance}
|
||||
gestureVelocityImpact={gestureVelocityImpact}
|
||||
transitionSpec={transitionSpec}
|
||||
styleInterpolator={cardStyleInterpolator}
|
||||
accessibilityElementsHidden={!focused}
|
||||
importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}
|
||||
pointerEvents="box-none"
|
||||
containerStyle={
|
||||
headerMode === 'float' && !headerTransparent && !hasCustomHeader
|
||||
headerMode === 'float' && !headerTransparent && headerShown !== false
|
||||
? { marginTop: floatingHeaderHeight }
|
||||
: null
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import * as React from 'react';
|
||||
import { Platform } from 'react-native';
|
||||
import {
|
||||
SafeAreaProvider,
|
||||
SafeAreaConsumer,
|
||||
EdgeInsets,
|
||||
} from 'react-native-safe-area-context';
|
||||
import { Route } from '@react-navigation/core';
|
||||
import { StackActions, StackNavigationState } from '@react-navigation/routers';
|
||||
|
||||
@@ -25,12 +30,14 @@ type Props = StackNavigationConfig & {
|
||||
type State = {
|
||||
// Local copy of the routes which are actually rendered
|
||||
routes: Route<string>[];
|
||||
// Previous routes, to compare whether routes have changed or not
|
||||
previousRoutes: Route<string>[];
|
||||
// List of routes being opened, we need to animate pushing of these new routes
|
||||
opening: string[];
|
||||
openingRouteKeys: string[];
|
||||
// List of routes being closed, we need to animate popping of these routes
|
||||
closing: string[];
|
||||
closingRouteKeys: string[];
|
||||
// List of routes being replaced, we need to keep a copy until the new route animates in
|
||||
replacing: string[];
|
||||
replacingRouteKeys: string[];
|
||||
// Since the local routes can vary from the routes from props, we need to keep the descriptors for old routes
|
||||
// Otherwise we won't be able to access the options for routes that were removed
|
||||
descriptors: StackDescriptorMap;
|
||||
@@ -41,6 +48,11 @@ class StackView extends React.Component<Props, State> {
|
||||
props: Readonly<Props>,
|
||||
state: Readonly<State>
|
||||
) {
|
||||
// If there was no change in routes, we don't need to compute anything
|
||||
if (props.state.routes === state.previousRoutes && state.routes.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Here we determine which routes were added or removed to animate them
|
||||
// We keep a copy of the route being removed in local state to be able to animate it
|
||||
|
||||
@@ -51,31 +63,23 @@ class StackView extends React.Component<Props, State> {
|
||||
props.state.routes.slice(0, props.state.index + 1)
|
||||
: props.state.routes;
|
||||
|
||||
if (props.state.index < props.state.routes.length - 1) {
|
||||
console.warn(
|
||||
'StackRouter provided invalid state, index should always be the last route in the stack.'
|
||||
);
|
||||
}
|
||||
|
||||
// If there was no change in routes, we don't need to compute anything
|
||||
if (routes === state.routes || !state.routes.length) {
|
||||
return {
|
||||
routes,
|
||||
descriptors: props.descriptors,
|
||||
};
|
||||
}
|
||||
|
||||
// Now we need to determine which routes were added and removed
|
||||
let { opening, closing, replacing } = state;
|
||||
let {
|
||||
openingRouteKeys,
|
||||
closingRouteKeys,
|
||||
replacingRouteKeys,
|
||||
previousRoutes,
|
||||
} = state;
|
||||
|
||||
const previousRoutes = state.routes.filter(
|
||||
route => !closing.includes(route.key) && !replacing.includes(route.key)
|
||||
);
|
||||
|
||||
const previousFocusedRoute = previousRoutes[previousRoutes.length - 1];
|
||||
const previousFocusedRoute = previousRoutes[previousRoutes.length - 1] as
|
||||
| Route<string>
|
||||
| undefined;
|
||||
const nextFocusedRoute = routes[routes.length - 1];
|
||||
|
||||
if (previousFocusedRoute.key !== nextFocusedRoute.key) {
|
||||
if (
|
||||
previousFocusedRoute &&
|
||||
previousFocusedRoute.key !== nextFocusedRoute.key
|
||||
) {
|
||||
// We only need to animate routes if the focused route changed
|
||||
// Animating previous routes won't be visible coz the focused route is on top of everything
|
||||
|
||||
@@ -94,22 +98,33 @@ class StackView extends React.Component<Props, State> {
|
||||
|
||||
if (
|
||||
isAnimationEnabled(nextFocusedRoute) &&
|
||||
!opening.includes(nextFocusedRoute.key)
|
||||
!openingRouteKeys.includes(nextFocusedRoute.key)
|
||||
) {
|
||||
// In this case, we need to animate pushing the focused route
|
||||
// We don't care about animating any other added routes because they won't be visible
|
||||
opening = [...opening, nextFocusedRoute.key];
|
||||
openingRouteKeys = [...openingRouteKeys, nextFocusedRoute.key];
|
||||
|
||||
closing = closing.filter(key => key !== nextFocusedRoute.key);
|
||||
replacing = replacing.filter(key => key !== nextFocusedRoute.key);
|
||||
closingRouteKeys = closingRouteKeys.filter(
|
||||
key => key !== nextFocusedRoute.key
|
||||
);
|
||||
replacingRouteKeys = replacingRouteKeys.filter(
|
||||
key => key !== nextFocusedRoute.key
|
||||
);
|
||||
|
||||
if (!routes.find(r => r.key === previousFocusedRoute.key)) {
|
||||
// The previous focused route isn't present in state, we treat this as a replace
|
||||
|
||||
replacing = [...replacing, previousFocusedRoute.key];
|
||||
replacingRouteKeys = [
|
||||
...replacingRouteKeys,
|
||||
previousFocusedRoute.key,
|
||||
];
|
||||
|
||||
opening = opening.filter(key => key !== previousFocusedRoute.key);
|
||||
closing = closing.filter(key => key !== previousFocusedRoute.key);
|
||||
openingRouteKeys = openingRouteKeys.filter(
|
||||
key => key !== previousFocusedRoute.key
|
||||
);
|
||||
closingRouteKeys = closingRouteKeys.filter(
|
||||
key => key !== previousFocusedRoute.key
|
||||
);
|
||||
|
||||
// Keep the old route in state because it's visible under the new route, and removing it will feel abrupt
|
||||
// We need to insert it just before the focused one (the route being pushed)
|
||||
@@ -123,14 +138,18 @@ class StackView extends React.Component<Props, State> {
|
||||
|
||||
if (
|
||||
isAnimationEnabled(previousFocusedRoute) &&
|
||||
!closing.includes(previousFocusedRoute.key)
|
||||
!closingRouteKeys.includes(previousFocusedRoute.key)
|
||||
) {
|
||||
// Sometimes a route can be closed before the opening animation finishes
|
||||
// So we also need to remove it from the opening list
|
||||
closing = [...closing, previousFocusedRoute.key];
|
||||
closingRouteKeys = [...closingRouteKeys, previousFocusedRoute.key];
|
||||
|
||||
opening = opening.filter(key => key !== previousFocusedRoute.key);
|
||||
replacing = replacing.filter(key => key !== previousFocusedRoute.key);
|
||||
openingRouteKeys = openingRouteKeys.filter(
|
||||
key => key !== previousFocusedRoute.key
|
||||
);
|
||||
replacingRouteKeys = replacingRouteKeys.filter(
|
||||
key => key !== previousFocusedRoute.key
|
||||
);
|
||||
|
||||
// Keep a copy of route being removed in the state to be able to animate it
|
||||
routes = [...routes, previousFocusedRoute];
|
||||
@@ -140,14 +159,15 @@ class StackView extends React.Component<Props, State> {
|
||||
// i.e. the currently focused route already existed and the previously focused route still exists
|
||||
// We don't know how to animate this
|
||||
}
|
||||
} else {
|
||||
} else if (replacingRouteKeys.length || closingRouteKeys.length) {
|
||||
// Keep the routes we are closing or replacing
|
||||
routes = routes.slice();
|
||||
routes.splice(
|
||||
routes.length - 1,
|
||||
0,
|
||||
...state.routes.filter(
|
||||
({ key }) => replacing.includes(key) || closing.includes(key)
|
||||
({ key }) =>
|
||||
replacingRouteKeys.includes(key) || closingRouteKeys.includes(key)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -168,18 +188,20 @@ class StackView extends React.Component<Props, State> {
|
||||
|
||||
return {
|
||||
routes,
|
||||
opening,
|
||||
closing,
|
||||
replacing,
|
||||
previousRoutes: props.state.routes,
|
||||
openingRouteKeys,
|
||||
closingRouteKeys,
|
||||
replacingRouteKeys,
|
||||
descriptors,
|
||||
};
|
||||
}
|
||||
|
||||
state: State = {
|
||||
routes: [],
|
||||
opening: [],
|
||||
closing: [],
|
||||
replacing: [],
|
||||
previousRoutes: [],
|
||||
openingRouteKeys: [],
|
||||
closingRouteKeys: [],
|
||||
replacingRouteKeys: [],
|
||||
descriptors: {},
|
||||
};
|
||||
|
||||
@@ -204,11 +226,12 @@ class StackView extends React.Component<Props, State> {
|
||||
};
|
||||
|
||||
private getPreviousRoute = ({ route }: { route: Route<string> }) => {
|
||||
const { closing, replacing } = this.state;
|
||||
const { closingRouteKeys, replacingRouteKeys } = this.state;
|
||||
const routes = this.state.routes.filter(
|
||||
r =>
|
||||
r.key === route.key ||
|
||||
(!closing.includes(r.key) && !replacing.includes(r.key))
|
||||
(!closingRouteKeys.includes(r.key) &&
|
||||
!replacingRouteKeys.includes(r.key))
|
||||
);
|
||||
const index = routes.findIndex(r => r.key === route.key);
|
||||
|
||||
@@ -244,12 +267,12 @@ class StackView extends React.Component<Props, State> {
|
||||
|
||||
private handleOpenRoute = ({ route }: { route: Route<string> }) => {
|
||||
this.setState(state => ({
|
||||
routes: state.replacing.length
|
||||
? state.routes.filter(r => !state.replacing.includes(r.key))
|
||||
routes: state.replacingRouteKeys.length
|
||||
? state.routes.filter(r => !state.replacingRouteKeys.includes(r.key))
|
||||
: state.routes,
|
||||
opening: state.opening.filter(key => key !== route.key),
|
||||
closing: state.closing.filter(key => key !== route.key),
|
||||
replacing: [],
|
||||
openingRouteKeys: state.openingRouteKeys.filter(key => key !== route.key),
|
||||
closingRouteKeys: state.closingRouteKeys.filter(key => key !== route.key),
|
||||
replacingRouteKeys: [],
|
||||
}));
|
||||
};
|
||||
|
||||
@@ -260,8 +283,8 @@ class StackView extends React.Component<Props, State> {
|
||||
// @ts-ignore
|
||||
this.setState(state => ({
|
||||
routes: state.routes.filter(r => r.key !== route.key),
|
||||
opening: state.opening.filter(key => key !== route.key),
|
||||
closing: state.closing.filter(key => key !== route.key),
|
||||
openingRouteKeys: state.openingRouteKeys.filter(key => key !== route.key),
|
||||
closingRouteKeys: state.closingRouteKeys.filter(key => key !== route.key),
|
||||
}));
|
||||
};
|
||||
|
||||
@@ -276,33 +299,45 @@ class StackView extends React.Component<Props, State> {
|
||||
...rest
|
||||
} = this.props;
|
||||
|
||||
const { routes, descriptors, opening, closing } = this.state;
|
||||
const {
|
||||
routes,
|
||||
descriptors,
|
||||
openingRouteKeys,
|
||||
closingRouteKeys,
|
||||
} = this.state;
|
||||
|
||||
const headerMode =
|
||||
mode !== 'modal' && Platform.OS === 'ios' ? 'float' : 'screen';
|
||||
|
||||
return (
|
||||
<Stack
|
||||
mode={mode}
|
||||
getPreviousRoute={this.getPreviousRoute}
|
||||
getGesturesEnabled={this.getGesturesEnabled}
|
||||
routes={routes}
|
||||
openingRoutes={opening}
|
||||
closingRoutes={closing}
|
||||
onGoBack={this.handleGoBack}
|
||||
onOpenRoute={this.handleOpenRoute}
|
||||
onCloseRoute={this.handleCloseRoute}
|
||||
onPageChangeStart={onPageChangeStart}
|
||||
onPageChangeConfirm={onPageChangeConfirm}
|
||||
onPageChangeCancel={onPageChangeCancel}
|
||||
renderHeader={this.renderHeader}
|
||||
renderScene={this.renderScene}
|
||||
headerMode={headerMode}
|
||||
state={state}
|
||||
navigation={navigation}
|
||||
descriptors={descriptors}
|
||||
{...rest}
|
||||
/>
|
||||
<SafeAreaProvider>
|
||||
<SafeAreaConsumer>
|
||||
{insets => (
|
||||
<Stack
|
||||
mode={mode}
|
||||
insets={insets as EdgeInsets}
|
||||
getPreviousRoute={this.getPreviousRoute}
|
||||
getGesturesEnabled={this.getGesturesEnabled}
|
||||
routes={routes}
|
||||
openingRouteKeys={openingRouteKeys}
|
||||
closingRouteKeys={closingRouteKeys}
|
||||
onGoBack={this.handleGoBack}
|
||||
onOpenRoute={this.handleOpenRoute}
|
||||
onCloseRoute={this.handleCloseRoute}
|
||||
onPageChangeStart={onPageChangeStart}
|
||||
onPageChangeConfirm={onPageChangeConfirm}
|
||||
onPageChangeCancel={onPageChangeCancel}
|
||||
renderHeader={this.renderHeader}
|
||||
renderScene={this.renderScene}
|
||||
headerMode={headerMode}
|
||||
state={state}
|
||||
navigation={navigation}
|
||||
descriptors={descriptors}
|
||||
{...rest}
|
||||
/>
|
||||
)}
|
||||
</SafeAreaConsumer>
|
||||
</SafeAreaProvider>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user