Compare commits

..

8 Commits

Author SHA1 Message Date
Satyajit Sahoo
7f015130df chore: publish
- @react-navigation/bottom-tabs@6.0.0-next.10
 - @react-navigation/core@6.0.0-next.7
 - @react-navigation/devtools@6.0.0-next.7
 - @react-navigation/drawer@6.0.0-next.9
 - @react-navigation/elements@1.0.0-next.9
 - @react-navigation/material-bottom-tabs@6.0.0-next.7
 - @react-navigation/material-top-tabs@6.0.0-next.8
 - @react-navigation/native@6.0.0-next.7
 - @react-navigation/stack@6.0.0-next.15
2021-05-10 13:36:34 +02:00
Satyajit Sahoo
7580efce89 refactor: rename animationPresentation to presentation 2021-05-10 12:42:02 +02:00
Satyajit Sahoo
1179d56c50 feat: return a NavigationContent component from useNavigationBuilder 2021-05-10 00:17:39 +02:00
Satyajit Sahoo
a6e498170f fix: add a deprecation warning for mode prop in stack 2021-05-09 23:42:12 +02:00
Satyajit Sahoo
4af9d10298 chore: publish
- @react-navigation/stack@6.0.0-next.14
2021-05-09 08:06:56 +02:00
Satyajit Sahoo
08e74af545 fix: fix modal animation not being set properly 2021-05-09 08:06:38 +02:00
Satyajit Sahoo
1e05895b24 chore: publish
- @react-navigation/bottom-tabs@6.0.0-next.9
 - @react-navigation/core@6.0.0-next.6
 - @react-navigation/devtools@6.0.0-next.6
 - @react-navigation/drawer@6.0.0-next.8
 - @react-navigation/elements@1.0.0-next.8
 - @react-navigation/material-bottom-tabs@6.0.0-next.6
 - @react-navigation/material-top-tabs@6.0.0-next.7
 - @react-navigation/native@6.0.0-next.6
 - @react-navigation/stack@6.0.0-next.13
2021-05-09 07:14:01 +02:00
Satyajit Sahoo
929c3e3a3b fix: fix type annotations for useNavigation (again) 2021-05-09 07:12:55 +02:00
40 changed files with 532 additions and 304 deletions

View File

@@ -5,7 +5,6 @@ import type { ParamListBase } from '@react-navigation/native';
import {
createStackNavigator,
StackScreenProps,
TransitionPresets,
} from '@react-navigation/stack';
import Article from '../Shared/Article';
import Albums from '../Shared/Albums';
@@ -119,7 +118,7 @@ export default function MixedStackScreen({ navigation }: Props) {
component={AlbumsScreen}
options={{
title: 'Albums',
...TransitionPresets.ModalPresentationIOS,
presentation: 'modal',
}}
/>
</MixedStack.Navigator>

View File

@@ -82,7 +82,7 @@ export default function ModalStackScreen({ navigation }: Props) {
}, [navigation]);
return (
<ModalStack.Navigator screenOptions={{ animationPresentation: 'modal' }}>
<ModalStack.Navigator screenOptions={{ presentation: 'modal' }}>
<ModalStack.Screen
name="Article"
component={ArticleScreen}

View File

@@ -84,9 +84,7 @@ export default function TransparentStackScreen({ navigation }: Props) {
}, [navigation]);
return (
<TransparentStack.Navigator
screenOptions={{ animationPresentation: 'modal' }}
>
<TransparentStack.Navigator screenOptions={{ presentation: 'modal' }}>
<TransparentStack.Screen
name="Article"
component={ArticleScreen}

View File

@@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.10](https://github.com/react-navigation/react-navigation/compare/@react-navigation/bottom-tabs@6.0.0-next.9...@react-navigation/bottom-tabs@6.0.0-next.10) (2021-05-10)
### Bug Fixes
* add a deprecation warning for mode prop in stack ([a6e4981](https://github.com/react-navigation/react-navigation/commit/a6e498170f59648190fa5513e273ca523e56c5d5))
### Features
* return a NavigationContent component from useNavigationBuilder ([1179d56](https://github.com/react-navigation/react-navigation/commit/1179d56c5008270753feef41acdc1dbd2191efcf))
# [6.0.0-next.9](https://github.com/react-navigation/react-navigation/compare/@react-navigation/bottom-tabs@6.0.0-next.8...@react-navigation/bottom-tabs@6.0.0-next.9) (2021-05-09)
**Note:** Version bump only for package @react-navigation/bottom-tabs
# [6.0.0-next.8](https://github.com/react-navigation/react-navigation/compare/@react-navigation/bottom-tabs@6.0.0-next.7...@react-navigation/bottom-tabs@6.0.0-next.8) (2021-05-09)
**Note:** Version bump only for package @react-navigation/bottom-tabs

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/bottom-tabs",
"description": "Bottom tab navigator following iOS design guidelines",
"version": "6.0.0-next.8",
"version": "6.0.0-next.10",
"keywords": [
"react-native-component",
"react-component",
@@ -36,12 +36,12 @@
"clean": "del lib"
},
"dependencies": {
"@react-navigation/elements": "^1.0.0-next.7",
"@react-navigation/elements": "^1.0.0-next.9",
"color": "^3.1.3",
"warn-once": "^0.0.1"
"warn-once": "^0.1.0"
},
"devDependencies": {
"@react-navigation/native": "^6.0.0-next.5",
"@react-navigation/native": "^6.0.0-next.7",
"@testing-library/react-native": "^7.2.0",
"@types/color": "^3.0.1",
"@types/react": "^16.9.53",

View File

@@ -70,7 +70,12 @@ function BottomTabNavigator({
);
}
const { state, descriptors, navigation } = useNavigationBuilder<
const {
state,
descriptors,
navigation,
NavigationContent,
} = useNavigationBuilder<
TabNavigationState<ParamListBase>,
TabRouterOptions,
TabActionHelpers<ParamListBase>,
@@ -85,13 +90,15 @@ function BottomTabNavigator({
});
return (
<BottomTabView
{...rest}
state={state}
navigation={navigation}
descriptors={descriptors}
sceneContainerStyle={sceneContainerStyle}
/>
<NavigationContent>
<BottomTabView
{...rest}
state={state}
navigation={navigation}
descriptors={descriptors}
sceneContainerStyle={sceneContainerStyle}
/>
</NavigationContent>
);
}

View File

@@ -1,8 +1,7 @@
import * as React from 'react';
import { StyleSheet, Platform } from 'react-native';
import { SafeAreaInsetsContext } from 'react-native-safe-area-context';
import {
NavigationHelpersContext,
import type {
ParamListBase,
TabNavigationState,
} from '@react-navigation/native';
@@ -89,72 +88,70 @@ export default function BottomTabView(props: Props) {
const { routes } = state;
return (
<NavigationHelpersContext.Provider value={navigation}>
<SafeAreaProviderCompat>
<MaybeScreenContainer
enabled={detachInactiveScreens}
style={styles.container}
>
{routes.map((route, index) => {
const descriptor = descriptors[route.key];
const { lazy = true, unmountOnBlur } = descriptor.options;
const isFocused = state.index === index;
<SafeAreaProviderCompat>
<MaybeScreenContainer
enabled={detachInactiveScreens}
style={styles.container}
>
{routes.map((route, index) => {
const descriptor = descriptors[route.key];
const { lazy = true, unmountOnBlur } = descriptor.options;
const isFocused = state.index === index;
if (unmountOnBlur && !isFocused) {
return null;
}
if (unmountOnBlur && !isFocused) {
return null;
}
if (lazy && !loaded.includes(route.key) && !isFocused) {
// Don't render a lazy screen if we've never navigated to it
return null;
}
if (lazy && !loaded.includes(route.key) && !isFocused) {
// Don't render a lazy screen if we've never navigated to it
return null;
}
const {
header = ({ layout, options }: BottomTabHeaderProps) => (
<Header
{...options}
layout={layout}
title={getHeaderTitle(options, route.name)}
/>
),
} = descriptor.options;
const {
header = ({ layout, options }: BottomTabHeaderProps) => (
<Header
{...options}
layout={layout}
title={getHeaderTitle(options, route.name)}
/>
),
} = descriptor.options;
return (
<MaybeScreen
key={route.key}
style={StyleSheet.absoluteFill}
visible={isFocused}
enabled={detachInactiveScreens}
>
<BottomTabBarHeightContext.Provider value={tabBarHeight}>
<Screen
focused={isFocused}
route={descriptor.route}
navigation={descriptor.navigation}
headerShown={descriptor.options.headerShown}
headerStatusBarHeight={
descriptor.options.headerStatusBarHeight
}
header={header({
layout: dimensions,
route: descriptor.route,
navigation: descriptor.navigation as BottomTabNavigationProp<ParamListBase>,
options: descriptor.options,
})}
style={sceneContainerStyle}
>
{descriptor.render()}
</Screen>
</BottomTabBarHeightContext.Provider>
</MaybeScreen>
);
})}
</MaybeScreenContainer>
<BottomTabBarHeightCallbackContext.Provider value={setTabBarHeight}>
{renderTabBar()}
</BottomTabBarHeightCallbackContext.Provider>
</SafeAreaProviderCompat>
</NavigationHelpersContext.Provider>
return (
<MaybeScreen
key={route.key}
style={StyleSheet.absoluteFill}
visible={isFocused}
enabled={detachInactiveScreens}
>
<BottomTabBarHeightContext.Provider value={tabBarHeight}>
<Screen
focused={isFocused}
route={descriptor.route}
navigation={descriptor.navigation}
headerShown={descriptor.options.headerShown}
headerStatusBarHeight={
descriptor.options.headerStatusBarHeight
}
header={header({
layout: dimensions,
route: descriptor.route,
navigation: descriptor.navigation as BottomTabNavigationProp<ParamListBase>,
options: descriptor.options,
})}
style={sceneContainerStyle}
>
{descriptor.render()}
</Screen>
</BottomTabBarHeightContext.Provider>
</MaybeScreen>
);
})}
</MaybeScreenContainer>
<BottomTabBarHeightCallbackContext.Provider value={setTabBarHeight}>
{renderTabBar()}
</BottomTabBarHeightCallbackContext.Provider>
</SafeAreaProviderCompat>
);
}

View File

@@ -3,6 +3,28 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.7](https://github.com/react-navigation/react-navigation/compare/@react-navigation/core@6.0.0-next.6...@react-navigation/core@6.0.0-next.7) (2021-05-10)
### Features
* return a NavigationContent component from useNavigationBuilder ([1179d56](https://github.com/react-navigation/react-navigation/commit/1179d56c5008270753feef41acdc1dbd2191efcf))
# [6.0.0-next.6](https://github.com/react-navigation/react-navigation/compare/@react-navigation/core@6.0.0-next.5...@react-navigation/core@6.0.0-next.6) (2021-05-09)
### Bug Fixes
* fix type annotations for useNavigation (again) ([929c3e3](https://github.com/react-navigation/react-navigation/commit/929c3e3a3b3eb32d197ef1f887dc4cbdce48eaff))
# [6.0.0-next.5](https://github.com/react-navigation/react-navigation/compare/@react-navigation/core@6.0.0-next.4...@react-navigation/core@6.0.0-next.5) (2021-05-09)

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/core",
"description": "Core utilities for building navigators",
"version": "6.0.0-next.5",
"version": "6.0.0-next.7",
"keywords": [
"react",
"react-native",

View File

@@ -0,0 +1,30 @@
import * as React from 'react';
export default function useComponent<
T extends React.ComponentType<any>,
P extends {}
>(Component: T, props: P) {
const propsRef = React.useRef<P | null>(props);
// Normally refs shouldn't be mutated in render
// But we return a component which will be rendered
// So it's just for immediate consumption
propsRef.current = props;
React.useEffect(() => {
propsRef.current = null;
});
return React.useRef((rest: Omit<React.ComponentProps<T>, keyof P>) => {
const props = propsRef.current;
if (props === null) {
throw new Error(
'The returned component must be rendered in the same render phase as the hook.'
);
}
// @ts-expect-error: the props should be fine here
return <Component {...props} {...rest} />;
}).current;
}

View File

@@ -8,9 +8,7 @@ import type { NavigationProp } from './types';
* @returns Navigation prop of the parent screen.
*/
export default function useNavigation<
T extends
| NavigationProp<{}>
| NavigationProp<any> = NavigationProp<ReactNavigation.RootParamList>
T = NavigationProp<ReactNavigation.RootParamList>
>(): T {
const navigation = React.useContext(NavigationContext);
@@ -20,5 +18,6 @@ export default function useNavigation<
);
}
return navigation as T;
// FIXME: Figure out a better way to do this
return (navigation as unknown) as T;
}

View File

@@ -14,6 +14,7 @@ import {
} from '@react-navigation/routers';
import NavigationStateContext from './NavigationStateContext';
import NavigationRouteContext from './NavigationRouteContext';
import NavigationHelpersContext from './NavigationHelpersContext';
import Group from './Group';
import Screen from './Screen';
import useEventEmitter from './useEventEmitter';
@@ -29,6 +30,7 @@ import useKeyedChildListeners from './useKeyedChildListeners';
import useOnGetState from './useOnGetState';
import useScheduleUpdate from './useScheduleUpdate';
import useCurrentRender from './useCurrentRender';
import useComponent from './useComponent';
import isArrayEqual from './isArrayEqual';
import {
DefaultNavigatorOptions,
@@ -586,9 +588,14 @@ export default function useNavigationBuilder<
descriptors,
});
const NavigationContent = useComponent(NavigationHelpersContext.Provider, {
value: navigation,
});
return {
state,
navigation,
descriptors,
NavigationContent,
};
}

View File

@@ -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.
# [6.0.0-next.7](https://github.com/react-navigation/react-navigation/compare/@react-navigation/devtools@6.0.0-next.6...@react-navigation/devtools@6.0.0-next.7) (2021-05-10)
**Note:** Version bump only for package @react-navigation/devtools
# [6.0.0-next.6](https://github.com/react-navigation/react-navigation/compare/@react-navigation/devtools@6.0.0-next.5...@react-navigation/devtools@6.0.0-next.6) (2021-05-09)
**Note:** Version bump only for package @react-navigation/devtools
# [6.0.0-next.5](https://github.com/react-navigation/react-navigation/compare/@react-navigation/devtools@6.0.0-next.4...@react-navigation/devtools@6.0.0-next.5) (2021-05-09)
**Note:** Version bump only for package @react-navigation/devtools

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/devtools",
"description": "Developer tools for React Navigation",
"version": "6.0.0-next.5",
"version": "6.0.0-next.7",
"keywords": [
"react",
"react-native",
@@ -36,7 +36,7 @@
"clean": "del lib"
},
"dependencies": {
"@react-navigation/core": "^6.0.0-next.5",
"@react-navigation/core": "^6.0.0-next.7",
"deep-equal": "^2.0.5"
},
"devDependencies": {

View File

@@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.9](https://github.com/react-navigation/react-navigation/compare/@react-navigation/drawer@6.0.0-next.8...@react-navigation/drawer@6.0.0-next.9) (2021-05-10)
### Bug Fixes
* add a deprecation warning for mode prop in stack ([a6e4981](https://github.com/react-navigation/react-navigation/commit/a6e498170f59648190fa5513e273ca523e56c5d5))
### Features
* return a NavigationContent component from useNavigationBuilder ([1179d56](https://github.com/react-navigation/react-navigation/commit/1179d56c5008270753feef41acdc1dbd2191efcf))
# [6.0.0-next.8](https://github.com/react-navigation/react-navigation/compare/@react-navigation/drawer@6.0.0-next.7...@react-navigation/drawer@6.0.0-next.8) (2021-05-09)
**Note:** Version bump only for package @react-navigation/drawer
# [6.0.0-next.7](https://github.com/react-navigation/react-navigation/compare/@react-navigation/drawer@6.0.0-next.6...@react-navigation/drawer@6.0.0-next.7) (2021-05-09)
**Note:** Version bump only for package @react-navigation/drawer

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/drawer",
"description": "Drawer navigator component with animated transitions and gesturess",
"version": "6.0.0-next.7",
"version": "6.0.0-next.9",
"keywords": [
"react-native-component",
"react-component",
@@ -41,12 +41,12 @@
"clean": "del lib"
},
"dependencies": {
"@react-navigation/elements": "^1.0.0-next.7",
"@react-navigation/elements": "^1.0.0-next.9",
"color": "^3.1.3",
"warn-once": "^0.0.1"
"warn-once": "^0.1.0"
},
"devDependencies": {
"@react-navigation/native": "^6.0.0-next.5",
"@react-navigation/native": "^6.0.0-next.7",
"@testing-library/react-native": "^7.2.0",
"@types/react": "^16.9.53",
"@types/react-native": "~0.64.4",

View File

@@ -67,7 +67,12 @@ function DrawerNavigator({
);
}
const { state, descriptors, navigation } = useNavigationBuilder<
const {
state,
descriptors,
navigation,
NavigationContent,
} = useNavigationBuilder<
DrawerNavigationState<ParamListBase>,
DrawerRouterOptions,
DrawerActionHelpers<ParamListBase>,
@@ -83,12 +88,14 @@ function DrawerNavigator({
});
return (
<DrawerView
{...rest}
state={state}
descriptors={descriptors}
navigation={navigation}
/>
<NavigationContent>
<DrawerView
{...rest}
state={state}
descriptors={descriptors}
navigation={navigation}
/>
</NavigationContent>
);
}

View File

@@ -9,7 +9,6 @@ import {
import { useSafeAreaFrame } from 'react-native-safe-area-context';
import Animated from 'react-native-reanimated';
import {
NavigationHelpersContext,
DrawerNavigationState,
DrawerActions,
useTheme,
@@ -296,13 +295,11 @@ function DrawerViewBase({
export default function DrawerView({ navigation, ...rest }: Props) {
return (
<NavigationHelpersContext.Provider value={navigation}>
<SafeAreaProviderCompat>
<GestureHandlerWrapper style={styles.content}>
<DrawerViewBase navigation={navigation} {...rest} />
</GestureHandlerWrapper>
</SafeAreaProviderCompat>
</NavigationHelpersContext.Provider>
<SafeAreaProviderCompat>
<GestureHandlerWrapper style={styles.content}>
<DrawerViewBase navigation={navigation} {...rest} />
</GestureHandlerWrapper>
</SafeAreaProviderCompat>
);
}

View File

@@ -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.
# [1.0.0-next.9](https://github.com/react-navigation/react-navigation/compare/@react-navigation/elements@1.0.0-next.8...@react-navigation/elements@1.0.0-next.9) (2021-05-10)
**Note:** Version bump only for package @react-navigation/elements
# [1.0.0-next.8](https://github.com/react-navigation/react-navigation/compare/@react-navigation/elements@1.0.0-next.7...@react-navigation/elements@1.0.0-next.8) (2021-05-09)
**Note:** Version bump only for package @react-navigation/elements
# [1.0.0-next.7](https://github.com/react-navigation/react-navigation/compare/@react-navigation/elements@1.0.0-next.6...@react-navigation/elements@1.0.0-next.7) (2021-05-09)
**Note:** Version bump only for package @react-navigation/elements

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/elements",
"description": "UI Components for React Navigation",
"version": "1.0.0-next.7",
"version": "1.0.0-next.9",
"keywords": [
"react-native",
"react-navigation",
@@ -38,7 +38,7 @@
},
"devDependencies": {
"@react-native-masked-view/masked-view": "^0.2.3",
"@react-navigation/native": "^6.0.0-next.5",
"@react-navigation/native": "^6.0.0-next.7",
"@testing-library/react-native": "^7.2.0",
"@types/react": "^16.9.53",
"@types/react-native": "~0.64.4",

View File

@@ -3,6 +3,25 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.7](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-bottom-tabs@6.0.0-next.6...@react-navigation/material-bottom-tabs@6.0.0-next.7) (2021-05-10)
### Features
* return a NavigationContent component from useNavigationBuilder ([1179d56](https://github.com/react-navigation/react-navigation/commit/1179d56c5008270753feef41acdc1dbd2191efcf))
# [6.0.0-next.6](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-bottom-tabs@6.0.0-next.5...@react-navigation/material-bottom-tabs@6.0.0-next.6) (2021-05-09)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
# [6.0.0-next.5](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-bottom-tabs@6.0.0-next.4...@react-navigation/material-bottom-tabs@6.0.0-next.5) (2021-05-09)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/material-bottom-tabs",
"description": "Integration for bottom navigation component from react-native-paper",
"version": "6.0.0-next.5",
"version": "6.0.0-next.7",
"keywords": [
"react-native-component",
"react-component",
@@ -41,7 +41,7 @@
"clean": "del lib"
},
"devDependencies": {
"@react-navigation/native": "^6.0.0-next.5",
"@react-navigation/native": "^6.0.0-next.7",
"@testing-library/react-native": "^7.2.0",
"@types/react": "^16.9.53",
"@types/react-native": "~0.64.4",

View File

@@ -28,7 +28,12 @@ function MaterialBottomTabNavigator({
screenOptions,
...rest
}: Props) {
const { state, descriptors, navigation } = useNavigationBuilder<
const {
state,
descriptors,
navigation,
NavigationContent,
} = useNavigationBuilder<
TabNavigationState<ParamListBase>,
TabRouterOptions,
TabActionHelpers<ParamListBase>,
@@ -42,12 +47,14 @@ function MaterialBottomTabNavigator({
});
return (
<MaterialBottomTabView
{...rest}
state={state}
navigation={navigation}
descriptors={descriptors}
/>
<NavigationContent>
<MaterialBottomTabView
{...rest}
state={state}
navigation={navigation}
descriptors={descriptors}
/>
</NavigationContent>
);
}

View File

@@ -2,7 +2,6 @@ import * as React from 'react';
import { Text, StyleSheet, Platform } from 'react-native';
import { BottomNavigation, DefaultTheme, DarkTheme } from 'react-native-paper';
import {
NavigationHelpersContext,
Route,
TabNavigationState,
TabActions,
@@ -75,7 +74,7 @@ try {
};
}
function MaterialBottomTabViewInner({
export default function MaterialBottomTabView({
state,
navigation,
descriptors,
@@ -192,14 +191,6 @@ function MaterialBottomTabViewInner({
);
}
export default function MaterialBottomTabView(props: Props) {
return (
<NavigationHelpersContext.Provider value={props.navigation}>
<MaterialBottomTabViewInner {...props} />
</NavigationHelpersContext.Provider>
);
}
const styles = StyleSheet.create({
icon: {
backgroundColor: 'transparent',

View File

@@ -3,6 +3,30 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.8](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-top-tabs@6.0.0-next.7...@react-navigation/material-top-tabs@6.0.0-next.8) (2021-05-10)
### Bug Fixes
* add a deprecation warning for mode prop in stack ([a6e4981](https://github.com/react-navigation/react-navigation/commit/a6e498170f59648190fa5513e273ca523e56c5d5))
### Features
* return a NavigationContent component from useNavigationBuilder ([1179d56](https://github.com/react-navigation/react-navigation/commit/1179d56c5008270753feef41acdc1dbd2191efcf))
# [6.0.0-next.7](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-top-tabs@6.0.0-next.6...@react-navigation/material-top-tabs@6.0.0-next.7) (2021-05-09)
**Note:** Version bump only for package @react-navigation/material-top-tabs
# [6.0.0-next.6](https://github.com/react-navigation/react-navigation/compare/@react-navigation/material-top-tabs@6.0.0-next.5...@react-navigation/material-top-tabs@6.0.0-next.6) (2021-05-09)
**Note:** Version bump only for package @react-navigation/material-top-tabs

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/material-top-tabs",
"description": "Integration for the animated tab view component from react-native-tab-view",
"version": "6.0.0-next.6",
"version": "6.0.0-next.8",
"keywords": [
"react-native-component",
"react-component",
@@ -42,10 +42,10 @@
},
"dependencies": {
"color": "^3.1.3",
"warn-once": "^0.0.1"
"warn-once": "^0.1.0"
},
"devDependencies": {
"@react-navigation/native": "^6.0.0-next.5",
"@react-navigation/native": "^6.0.0-next.7",
"@testing-library/react-native": "^7.2.0",
"@types/react": "^16.9.53",
"@types/react-native": "~0.64.4",

View File

@@ -71,7 +71,12 @@ function MaterialTopTabNavigator({
);
}
const { state, descriptors, navigation } = useNavigationBuilder<
const {
state,
descriptors,
navigation,
NavigationContent,
} = useNavigationBuilder<
TabNavigationState<ParamListBase>,
TabRouterOptions,
TabActionHelpers<ParamListBase>,
@@ -85,12 +90,14 @@ function MaterialTopTabNavigator({
});
return (
<MaterialTopTabView
{...rest}
state={state}
navigation={navigation}
descriptors={descriptors}
/>
<NavigationContent>
<MaterialTopTabView
{...rest}
state={state}
navigation={navigation}
descriptors={descriptors}
/>
</NavigationContent>
);
}

View File

@@ -1,7 +1,6 @@
import * as React from 'react';
import { TabView, SceneRendererProps } from 'react-native-tab-view';
import {
NavigationHelpersContext,
TabNavigationState,
TabActions,
ParamListBase,
@@ -43,29 +42,27 @@ export default function MaterialTopTabView({
};
return (
<NavigationHelpersContext.Provider value={navigation}>
<TabView<Route<string>>
{...rest}
onIndexChange={(index) =>
navigation.dispatch({
...TabActions.jumpTo(state.routes[index].name),
target: state.key,
})
}
renderScene={({ route }) => descriptors[route.key].render()}
navigationState={state}
renderTabBar={renderTabBar}
renderLazyPlaceholder={({ route }) =>
descriptors[route.key].options.lazyPlaceholder?.() ?? null
}
lazy={({ route }) => descriptors[route.key].options.lazy === true}
onSwipeStart={() => navigation.emit({ type: 'swipeStart' })}
onSwipeEnd={() => navigation.emit({ type: 'swipeEnd' })}
sceneContainerStyle={[
{ backgroundColor: colors.background },
sceneContainerStyle,
]}
/>
</NavigationHelpersContext.Provider>
<TabView<Route<string>>
{...rest}
onIndexChange={(index) =>
navigation.dispatch({
...TabActions.jumpTo(state.routes[index].name),
target: state.key,
})
}
renderScene={({ route }) => descriptors[route.key].render()}
navigationState={state}
renderTabBar={renderTabBar}
renderLazyPlaceholder={({ route }) =>
descriptors[route.key].options.lazyPlaceholder?.() ?? null
}
lazy={({ route }) => descriptors[route.key].options.lazy === true}
onSwipeStart={() => navigation.emit({ type: 'swipeStart' })}
onSwipeEnd={() => navigation.emit({ type: 'swipeEnd' })}
sceneContainerStyle={[
{ backgroundColor: colors.background },
sceneContainerStyle,
]}
/>
);
}

View File

@@ -3,6 +3,25 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.7](https://github.com/react-navigation/react-navigation/compare/@react-navigation/native@6.0.0-next.6...@react-navigation/native@6.0.0-next.7) (2021-05-10)
### Features
* return a NavigationContent component from useNavigationBuilder ([1179d56](https://github.com/react-navigation/react-navigation/commit/1179d56c5008270753feef41acdc1dbd2191efcf))
# [6.0.0-next.6](https://github.com/react-navigation/react-navigation/compare/@react-navigation/native@6.0.0-next.5...@react-navigation/native@6.0.0-next.6) (2021-05-09)
**Note:** Version bump only for package @react-navigation/native
# [6.0.0-next.5](https://github.com/react-navigation/react-navigation/compare/@react-navigation/native@6.0.0-next.4...@react-navigation/native@6.0.0-next.5) (2021-05-09)
**Note:** Version bump only for package @react-navigation/native

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/native",
"description": "React Native integration for React Navigation",
"version": "6.0.0-next.5",
"version": "6.0.0-next.7",
"keywords": [
"react-native",
"react-navigation",
@@ -37,7 +37,7 @@
"clean": "del lib"
},
"dependencies": {
"@react-navigation/core": "^6.0.0-next.5",
"@react-navigation/core": "^6.0.0-next.7",
"escape-string-regexp": "^4.0.0",
"nanoid": "^3.1.22"
},

View File

@@ -4,7 +4,6 @@ import {
createNavigatorFactory,
StackRouter,
TabRouter,
NavigationHelpersContext,
createNavigationContainerRef,
ParamListBase,
} from '@react-navigation/core';
@@ -22,36 +21,36 @@ it('integrates with the history API', () => {
jest.useFakeTimers();
const createStackNavigator = createNavigatorFactory((props: any) => {
const { navigation, state, descriptors } = useNavigationBuilder(
const { state, descriptors, NavigationContent } = useNavigationBuilder(
StackRouter,
props
);
return (
<NavigationHelpersContext.Provider value={navigation}>
<NavigationContent>
{state.routes.map((route, i) => (
<div key={route.key} aria-current={state.index === i || undefined}>
{descriptors[route.key].render()}
</div>
))}
</NavigationHelpersContext.Provider>
</NavigationContent>
);
});
const createTabNavigator = createNavigatorFactory((props: any) => {
const { navigation, state, descriptors } = useNavigationBuilder(
const { state, descriptors, NavigationContent } = useNavigationBuilder(
TabRouter,
props
);
return (
<NavigationHelpersContext.Provider value={navigation}>
<NavigationContent>
{state.routes.map((route, i) => (
<div key={route.key} aria-current={state.index === i || undefined}>
{descriptors[route.key].render()}
</div>
))}
</NavigationHelpersContext.Provider>
</NavigationContent>
);
});

View File

@@ -4,7 +4,6 @@ import {
createNavigatorFactory,
StackRouter,
TabRouter,
NavigationHelpersContext,
NavigatorScreenParams,
} from '@react-navigation/core';
import { renderToString } from 'react-dom/server';
@@ -23,17 +22,17 @@ jest.mock('../useLinking', () => require('../useLinking.tsx').default);
it('renders correct state with location', () => {
const createStackNavigator = createNavigatorFactory((props: any) => {
const { navigation, state, descriptors } = useNavigationBuilder(
const { state, descriptors, NavigationContent } = useNavigationBuilder(
StackRouter,
props
);
return (
<NavigationHelpersContext.Provider value={navigation}>
<NavigationContent>
{state.routes.map((route) => (
<div key={route.key}>{descriptors[route.key].render()}</div>
))}
</NavigationHelpersContext.Provider>
</NavigationContent>
);
});
@@ -116,17 +115,17 @@ it('renders correct state with location', () => {
it('gets the current options', () => {
const createTabNavigator = createNavigatorFactory((props: any) => {
const { navigation, state, descriptors } = useNavigationBuilder(
const { state, descriptors, NavigationContent } = useNavigationBuilder(
TabRouter,
props
);
return (
<NavigationHelpersContext.Provider value={navigation}>
<NavigationContent>
{state.routes.map((route) => (
<div key={route.key}>{descriptors[route.key].render()}</div>
))}
</NavigationHelpersContext.Provider>
</NavigationContent>
);
});

View File

@@ -3,6 +3,41 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [6.0.0-next.15](https://github.com/react-navigation/react-navigation/compare/@react-navigation/stack@6.0.0-next.14...@react-navigation/stack@6.0.0-next.15) (2021-05-10)
### Bug Fixes
* add a deprecation warning for mode prop in stack ([a6e4981](https://github.com/react-navigation/react-navigation/commit/a6e498170f59648190fa5513e273ca523e56c5d5))
### Features
* return a NavigationContent component from useNavigationBuilder ([1179d56](https://github.com/react-navigation/react-navigation/commit/1179d56c5008270753feef41acdc1dbd2191efcf))
# [6.0.0-next.14](https://github.com/react-navigation/react-navigation/compare/@react-navigation/stack@6.0.0-next.13...@react-navigation/stack@6.0.0-next.14) (2021-05-09)
### Bug Fixes
* fix modal animation not being set properly ([08e74af](https://github.com/react-navigation/react-navigation/commit/08e74af54529582dcbc8d91e77bfed70f006f00d))
# [6.0.0-next.13](https://github.com/react-navigation/react-navigation/compare/@react-navigation/stack@6.0.0-next.12...@react-navigation/stack@6.0.0-next.13) (2021-05-09)
**Note:** Version bump only for package @react-navigation/stack
# [6.0.0-next.12](https://github.com/react-navigation/react-navigation/compare/@react-navigation/stack@6.0.0-next.11...@react-navigation/stack@6.0.0-next.12) (2021-05-09)
**Note:** Version bump only for package @react-navigation/stack

View File

@@ -1,7 +1,7 @@
{
"name": "@react-navigation/stack",
"description": "Stack navigator component for iOS and Android with animated transitions and gestures",
"version": "6.0.0-next.12",
"version": "6.0.0-next.15",
"keywords": [
"react-native-component",
"react-component",
@@ -40,13 +40,13 @@
"clean": "del lib"
},
"dependencies": {
"@react-navigation/elements": "^1.0.0-next.7",
"@react-navigation/elements": "^1.0.0-next.9",
"color": "^3.1.3",
"react-native-iphone-x-helper": "^1.3.0",
"warn-once": "^0.0.1"
"warn-once": "^0.1.0"
},
"devDependencies": {
"@react-navigation/native": "^6.0.0-next.5",
"@react-navigation/native": "^6.0.0-next.7",
"@testing-library/react-native": "^7.2.0",
"@types/color": "^3.0.1",
"@types/react": "^16.9.53",

View File

@@ -30,20 +30,33 @@ function StackNavigator({
screenOptions,
...rest
}: Props) {
// @ts-expect-error: mode is deprecated
const mode = rest.mode as 'card' | 'modal' | undefined;
// @ts-expect-error: headerMode='none' is deprecated
const headerMode = rest.headerMode as StackHeaderMode | 'none' | undefined;
warnOnce(
mode != null,
`Stack Navigator: 'mode="${mode}"' is deprecated. Use 'presentation: "${mode}"' in 'screenOptions' instead.`
);
warnOnce(
headerMode === 'none',
`Stack Navigator: 'headerMode="none"' is deprecated. Use 'headerShown: false' in 'screenOptions' instead.`
);
warnOnce(
headerMode && headerMode !== 'none',
headerMode != null && headerMode !== 'none',
`Stack Navigator: 'headerMode' is moved to 'options'. Moved it to 'screenOptions' to keep current behavior.`
);
const { state, descriptors, navigation } = useNavigationBuilder<
const {
state,
descriptors,
navigation,
NavigationContent,
} = useNavigationBuilder<
StackNavigationState<ParamListBase>,
StackRouterOptions,
StackActionHelpers<ParamListBase>,
@@ -54,6 +67,7 @@ function StackNavigator({
children,
screenOptions,
defaultScreenOptions: () => ({
presentation: mode,
headerShown: headerMode ? headerMode !== 'none' : true,
headerMode: headerMode && headerMode !== 'none' ? headerMode : undefined,
}),
@@ -85,12 +99,14 @@ function StackNavigator({
);
return (
<StackView
{...rest}
state={state}
descriptors={descriptors}
navigation={navigation}
/>
<NavigationContent>
<StackView
{...rest}
state={state}
descriptors={descriptors}
navigation={navigation}
/>
</NavigationContent>
);
}

View File

@@ -246,22 +246,25 @@ export type StackNavigationOptions = StackHeaderOptions &
* so that the previous screen isn't transformed or invisible.
*/
cardStyle?: StyleProp<ViewStyle>;
/**
* Whether this screen should be presented as a modal or a regular card.
*
* Specifying this will configure several options:
* - `card`: Use the default OS animations for iOS and Android screen transitions.
* - `modal`: Use Modal animations. This changes a few things:
* - Sets `headerMode` to `screen` for the screen unless specified otherwise.
* - Changes the screen animation to match the platform behavior for modals.
* - Adjusts the `detachPreviousScreen` option so that the previous screen stays rendered.
*
* Defaults to 'card'.
*/
presentation?: 'card' | 'modal';
/**
* Whether transition animation should be enabled the screen.
* If you set it to `false`, the screen won't animate when pushing or popping.
* Defaults to `true` on Android and iOS, `false` on Web.
*/
animationEnabled?: boolean;
/**
* Whether this screen should be presented as a modal or a regular card.
*
* If you haven't customized the animations separately, the animation will change based on the value:
* - 'modal' - modal animation on iOS and Android. It'll also default `headerMode` to `screen`.
* - 'card' - horizontal slide animation on iOS, OS-default animation on Android.
*
* Defaults to 'card'.
*/
animationPresentation?: 'card' | 'modal';
/**
* The type of animation to use when this screen replaces another screen. Defaults to `push`.
* When `pop` is used, the `pop` animation is applied to the screen being replaced.

View File

@@ -170,7 +170,7 @@ function CardContainer({
}, [pointerEvents, scene.progress.next]);
const {
animationPresentation,
presentation,
cardOverlay,
cardOverlayEnabled,
cardShadowEnabled,
@@ -228,9 +228,7 @@ function CardContainer({
accessibilityElementsHidden={!focused}
importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}
pointerEvents={active ? 'box-none' : pointerEvents}
pageOverflowEnabled={
headerMode !== 'float' && animationPresentation !== 'modal'
}
pageOverflowEnabled={headerMode !== 'float' && presentation !== 'modal'}
headerDarkContent={headerDarkContent}
containerStyle={
hasAbsoluteFloatHeader && headerMode !== 'screen'

View File

@@ -122,8 +122,8 @@ const getDistanceFromOptions = (
descriptor?: StackDescriptor
) => {
const {
animationPresentation,
gestureDirection = animationPresentation === 'modal'
presentation,
gestureDirection = presentation === 'modal'
? ModalTransition.gestureDirection
: DefaultTransition.gestureDirection,
} = (descriptor?.options || {}) as StackNavigationOptions;
@@ -214,10 +214,19 @@ export default class CardStack extends React.Component<Props, State> {
props.descriptors[previousRoute?.key] ||
state.descriptors[previousRoute?.key];
const { options } = descriptor;
// 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
const optionsForTransitionConfig =
index !== self.length - 1 && nextDescriptor
? nextDescriptor.options
: descriptor.options;
let defaultTransitionPreset =
options.animationPresentation === 'modal'
optionsForTransitionConfig.presentation === 'modal'
? ModalTransition
: DefaultTransition;
@@ -225,9 +234,7 @@ export default class CardStack extends React.Component<Props, State> {
animationEnabled = Platform.OS !== 'web' &&
Platform.OS !== 'windows' &&
Platform.OS !== 'macos',
gestureEnabled = Platform.OS === 'ios' &&
animationEnabled &&
index !== 0,
gestureEnabled = Platform.OS === 'ios' && animationEnabled,
gestureDirection = defaultTransitionPreset.gestureDirection,
transitionSpec = defaultTransitionPreset.transitionSpec,
cardStyleInterpolator = animationEnabled === false
@@ -236,52 +243,16 @@ export default class CardStack extends React.Component<Props, State> {
headerStyleInterpolator = defaultTransitionPreset.headerStyleInterpolator,
cardOverlayEnabled = Platform.OS !== 'ios' ||
cardStyleInterpolator === forModalPresentationIOS,
} = options;
let transitionConfig = {
gestureDirection,
transitionSpec,
cardStyleInterpolator,
headerStyleInterpolator,
cardOverlayEnabled,
};
// 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) {
if (nextDescriptor) {
const {
animationEnabled,
gestureDirection = defaultTransitionPreset.gestureDirection,
transitionSpec = defaultTransitionPreset.transitionSpec,
cardStyleInterpolator = animationEnabled === false
? forNoAnimationCard
: defaultTransitionPreset.cardStyleInterpolator,
headerStyleInterpolator = defaultTransitionPreset.headerStyleInterpolator,
cardOverlayEnabled = descriptor.options.cardOverlayEnabled ??
cardStyleInterpolator === forModalPresentationIOS,
} = nextDescriptor.options;
transitionConfig = {
gestureDirection,
transitionSpec,
cardStyleInterpolator,
headerStyleInterpolator,
cardOverlayEnabled,
};
}
}
} = optionsForTransitionConfig;
const headerMode: StackHeaderMode =
options.headerMode ??
(options.animationPresentation !== 'modal' &&
transitionConfig.cardStyleInterpolator !== forModalPresentationIOS &&
descriptor.options.headerMode ??
(!(
optionsForTransitionConfig.presentation === 'modal' ||
cardStyleInterpolator === forModalPresentationIOS
) &&
Platform.OS === 'ios' &&
options.header === undefined
descriptor.options.header === undefined
? 'float'
: 'screen');
@@ -290,10 +261,14 @@ export default class CardStack extends React.Component<Props, State> {
descriptor: {
...descriptor,
options: {
...options,
...transitionConfig,
...descriptor.options,
animationEnabled,
cardOverlayEnabled,
cardStyleInterpolator,
gestureDirection,
gestureEnabled,
headerStyleInterpolator,
transitionSpec,
headerMode,
},
},
@@ -492,7 +467,7 @@ export default class CardStack extends React.Component<Props, State> {
const { options } = scenes[i].descriptor;
const {
// By default, we don't want to detach the previous screen of the active one for modals
detachPreviousScreen = options.animationPresentation === 'modal' ||
detachPreviousScreen = options.presentation === 'modal' ||
options.cardStyleInterpolator === forModalPresentationIOS
? i !== scenes.length - 1
: true,

View File

@@ -5,7 +5,6 @@ import {
EdgeInsets,
} from 'react-native-safe-area-context';
import {
NavigationHelpersContext,
StackActions,
StackNavigationState,
Route,
@@ -418,7 +417,6 @@ export default class StackView extends React.Component<Props, State> {
render() {
const {
state,
navigation,
keyboardHandlingEnabled,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
descriptors: _,
@@ -433,45 +431,43 @@ export default class StackView extends React.Component<Props, State> {
} = this.state;
return (
<NavigationHelpersContext.Provider value={navigation}>
<GestureHandlerWrapper style={styles.container}>
<SafeAreaProviderCompat>
<SafeAreaInsetsContext.Consumer>
{(insets) => (
<KeyboardManager enabled={keyboardHandlingEnabled !== false}>
{(props) => (
<HeaderShownContext.Consumer>
{(isParentHeaderShown) => (
<CardStack
insets={insets as EdgeInsets}
isParentHeaderShown={isParentHeaderShown}
getPreviousRoute={this.getPreviousRoute}
routes={routes}
openingRouteKeys={openingRouteKeys}
closingRouteKeys={closingRouteKeys}
onOpenRoute={this.handleOpenRoute}
onCloseRoute={this.handleCloseRoute}
onTransitionStart={this.handleTransitionStart}
onTransitionEnd={this.handleTransitionEnd}
renderHeader={this.renderHeader}
renderScene={this.renderScene}
state={state}
descriptors={descriptors}
onGestureStart={this.handleGestureStart}
onGestureEnd={this.handleGestureEnd}
onGestureCancel={this.handleGestureCancel}
{...rest}
{...props}
/>
)}
</HeaderShownContext.Consumer>
)}
</KeyboardManager>
)}
</SafeAreaInsetsContext.Consumer>
</SafeAreaProviderCompat>
</GestureHandlerWrapper>
</NavigationHelpersContext.Provider>
<GestureHandlerWrapper style={styles.container}>
<SafeAreaProviderCompat>
<SafeAreaInsetsContext.Consumer>
{(insets) => (
<KeyboardManager enabled={keyboardHandlingEnabled !== false}>
{(props) => (
<HeaderShownContext.Consumer>
{(isParentHeaderShown) => (
<CardStack
insets={insets as EdgeInsets}
isParentHeaderShown={isParentHeaderShown}
getPreviousRoute={this.getPreviousRoute}
routes={routes}
openingRouteKeys={openingRouteKeys}
closingRouteKeys={closingRouteKeys}
onOpenRoute={this.handleOpenRoute}
onCloseRoute={this.handleCloseRoute}
onTransitionStart={this.handleTransitionStart}
onTransitionEnd={this.handleTransitionEnd}
renderHeader={this.renderHeader}
renderScene={this.renderScene}
state={state}
descriptors={descriptors}
onGestureStart={this.handleGestureStart}
onGestureEnd={this.handleGestureEnd}
onGestureCancel={this.handleGestureCancel}
{...rest}
{...props}
/>
)}
</HeaderShownContext.Consumer>
)}
</KeyboardManager>
)}
</SafeAreaInsetsContext.Consumer>
</SafeAreaProviderCompat>
</GestureHandlerWrapper>
);
}
}

View File

@@ -18225,10 +18225,10 @@ walker@^1.0.7, walker@~1.0.5:
dependencies:
makeerror "1.0.x"
warn-once@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/warn-once/-/warn-once-0.0.1.tgz#71eda54c88f240c4461e5c7a84cac2263caf3a4e"
integrity sha512-Sh/kR0dQ9Tlr70E2zuR8mZ0yxmN9kGMNfvlwWWRi7frSox2uRC7U659Le8jBIqvjykSbvo9JX9ttsqw4vZPLmA==
warn-once@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/warn-once/-/warn-once-0.1.0.tgz#4f58d89b84f968d0389176aa99e0cf0f14ffd4c8"
integrity sha512-recZTSvuaH/On5ZU5ywq66y99lImWqzP93+AiUo9LUwG8gXHW+LJjhOd6REJHm7qb0niYqrEQJvbHSQfuJtTqA==
watchpack-chokidar2@^2.0.1:
version "2.0.1"