feat: add native-stack to repo (#9596)

This commit is contained in:
Wojciech Lewicki
2021-05-19 09:28:26 +02:00
committed by GitHub
parent 4738554560
commit a55d6a8d79
14 changed files with 965 additions and 0 deletions

View File

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 React Navigation Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,5 @@
# `@react-navigation/material-bottom-tabs`
React Navigation integration for [native-stack](https://github.com/software-mansion/react-native-screens/tree/master/native-stack) component from [`react-native-screens`](https://github.com/software-mansion/react-native-screens).
Installation instructions and documentation can be found on the [React Navigation website](https://reactnavigation.org/docs/6.x/native-stack-navigator/).

View File

@@ -0,0 +1,74 @@
{
"name": "@react-navigation/native-stack",
"description": "Integration for native stack component from react-native-screens",
"version": "6.0.0",
"keywords": [
"react-native-component",
"react-component",
"react-native",
"react-navigation",
"ios",
"android",
"native",
"stack"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/react-navigation/react-navigation.git",
"directory": "packages/native-stack"
},
"bugs": {
"url": "https://github.com/software-mansion/react-native-screens/issues"
},
"homepage": "https://github.com/software-mansion/react-native-screens#readme",
"main": "lib/commonjs/index.js",
"react-native": "src/index.tsx",
"source": "src/index.tsx",
"module": "lib/module/index.js",
"types": "lib/typescript/src/index.d.ts",
"files": [
"src",
"lib",
"!**/__tests__"
],
"sideEffects": false,
"publishConfig": {
"access": "public"
},
"scripts": {
"prepare": "bob build",
"clean": "del lib"
},
"devDependencies": {
"@react-navigation/native": "^6.0.0-next.8",
"@testing-library/react-native": "^7.2.0",
"@types/react": "^16.9.53",
"@types/react-native": "~0.64.4",
"react": "~16.13.1",
"react-native": "~0.63.4",
"react-native-builder-bob": "^0.18.1",
"react-native-screens": "^3.0.0",
"typescript": "^4.2.3"
},
"peerDependencies": {
"@react-navigation/native": "^6.0.0",
"react": "*",
"react-native": "*",
"react-native-screens": ">= 3.0.0"
},
"react-native-builder-bob": {
"source": "src",
"output": "lib",
"targets": [
"commonjs",
"module",
[
"typescript",
{
"project": "tsconfig.build.json"
}
]
]
}
}

View File

@@ -0,0 +1,36 @@
import * as React from 'react';
import { View, Text, Button } from 'react-native';
import { render, fireEvent } from '@testing-library/react-native';
import { NavigationContainer, ParamListBase } from '@react-navigation/native';
import { createNativeStackNavigator, NativeStackScreenProps } from '../index';
it('renders a native-stack navigator with screens', async () => {
const Test = ({
route,
navigation,
}: NativeStackScreenProps<ParamListBase>) => (
<View>
<Text>Screen {route.name}</Text>
<Button onPress={() => navigation.navigate('A')} title="Go to A" />
<Button onPress={() => navigation.navigate('B')} title="Go to B" />
</View>
);
const Stack = createNativeStackNavigator();
const { findByText, queryByText } = render(
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="A" component={Test} />
<Stack.Screen name="B" component={Test} />
</Stack.Navigator>
</NavigationContainer>
);
expect(queryByText('Screen A')).not.toBeNull();
expect(queryByText('Screen B')).toBeNull();
fireEvent.press(await findByText('Go to B'));
expect(queryByText('Screen B')).not.toBeNull();
});

View File

@@ -0,0 +1,13 @@
/**
* Navigators
*/
export { default as createNativeStackNavigator } from './navigators/createNativeStackNavigator';
/**
* Types
*/
export type {
NativeStackNavigationOptions,
NativeStackNavigationProp,
NativeStackScreenProps,
} from './types';

View File

@@ -0,0 +1,104 @@
import {
createNavigatorFactory,
DefaultNavigatorOptions,
EventArg,
StackActions,
StackActionHelpers,
StackNavigationState,
StackRouter,
StackRouterOptions,
ParamListBase,
useNavigationBuilder,
} from '@react-navigation/native';
import * as React from 'react';
import {
NativeStackView,
NativeStackNavigationOptions,
} from 'react-native-screens/native-stack';
// We want it to be an empty object beacuse navigator does not have any additional config
export type NativeStackNavigationConfig = {};
export type NativeStackNavigationEventMap = {
/**
* Event which fires when the screen appears.
*/
appear: { data: undefined };
/**
* Event which fires when the current screen is dismissed by hardware back (on Android) or dismiss gesture (swipe back or down).
*/
dismiss: { data: undefined };
/**
* Event which fires when a transition animation starts.
*/
transitionStart: { data: { closing: boolean } };
/**
* Event which fires when a transition animation ends.
*/
transitionEnd: { data: { closing: boolean } };
};
export type NativeStackNavigatorProps = DefaultNavigatorOptions<NativeStackNavigationOptions> &
StackRouterOptions &
NativeStackNavigationConfig;
function NativeStackNavigator({
initialRouteName,
children,
screenOptions,
...rest
}: NativeStackNavigatorProps) {
const { state, descriptors, navigation } = useNavigationBuilder<
StackNavigationState<ParamListBase>,
StackRouterOptions,
StackActionHelpers<ParamListBase>,
NativeStackNavigationOptions,
NativeStackNavigationEventMap
>(StackRouter, {
initialRouteName,
children,
screenOptions,
});
React.useEffect(
() =>
navigation?.addListener?.('tabPress', (e: any) => {
const isFocused = navigation.isFocused();
// Run the operation in the next frame so we're sure all listeners have been run
// This is necessary to know if preventDefault() has been called
requestAnimationFrame(() => {
if (
state.index > 0 &&
isFocused &&
!(e as EventArg<'tabPress', true>).defaultPrevented
) {
// When user taps on already focused tab and we're inside the tab,
// reset the stack to replicate native behaviour
navigation.dispatch({
...StackActions.popToTop(),
target: state.key,
});
}
});
}),
[navigation, state.index, state.key]
);
return (
<NativeStackView
{...rest}
state={state}
navigation={navigation}
descriptors={descriptors}
/>
);
}
export default createNavigatorFactory<
StackNavigationState<ParamListBase>,
NativeStackNavigationOptions,
NativeStackNavigationEventMap,
typeof NativeStackNavigator
>(NativeStackNavigator);

View File

@@ -0,0 +1,307 @@
import type { ImageSourcePropType, StyleProp, ViewStyle } from 'react-native';
import type {
DefaultNavigatorOptions,
Descriptor,
NavigationHelpers,
NavigationProp,
ParamListBase,
StackNavigationState,
StackRouterOptions,
StackActionHelpers,
RouteProp,
} from '@react-navigation/native';
import type {
ScreenProps,
ScreenStackHeaderConfigProps,
SearchBarProps,
} from 'react-native-screens';
export type NativeStackNavigationEventMap = {
/**
* Event which fires when the screen appears.
*/
appear: { data: undefined };
/**
* Event which fires when the current screen is dismissed by hardware back (on Android) or dismiss gesture (swipe back or down).
*/
dismiss: { data: undefined };
/**
* Event which fires when a transition animation starts.
*/
transitionStart: { data: { closing: boolean } };
/**
* Event which fires when a transition animation ends.
*/
transitionEnd: { data: { closing: boolean } };
};
export type NativeStackNavigationProp<
ParamList extends ParamListBase,
RouteName extends keyof ParamList = string
> = NavigationProp<
ParamList,
RouteName,
StackNavigationState<ParamList>,
NativeStackNavigationOptions,
NativeStackNavigationEventMap
> &
StackActionHelpers<ParamList>;
export type NativeStackScreenProps<
ParamList extends ParamListBase,
RouteName extends keyof ParamList = string
> = {
navigation: NativeStackNavigationProp<ParamList, RouteName>;
route: RouteProp<ParamList, RouteName>;
};
export type NativeStackNavigationHelpers = NavigationHelpers<
ParamListBase,
NativeStackNavigationEventMap
>;
// We want it to be an empty object beacuse navigator does not have any additional config
export type NativeStackNavigationConfig = {};
export type NativeStackNavigationOptions = {
/**
* Image to display in the header as the back button.
* Defaults to back icon image for the platform (a chevron on iOS and an arrow on Android).
*/
backButtonImage?: ImageSourcePropType;
/**
* Whether to show the back button with custom left side of the header.
*/
backButtonInCustomView?: boolean;
/**
* Style object for the scene content.
*/
contentStyle?: StyleProp<ViewStyle>;
/**
* Whether the stack should be in rtl or ltr form.
*/
direction?: 'rtl' | 'ltr';
/**
* Whether you can use gestures to dismiss this screen. Defaults to `true`.
* Only supported on iOS.
*
* @platform ios
*/
gestureEnabled?: boolean;
/**
* Title to display in the back button.
* Only supported on iOS.
*
* @platform ios
*/
headerBackTitle?: string;
/**
* Style object for header back title. Supported properties:
* - fontFamily
* - fontSize
*
* Only supported on iOS.
*
* @platform ios
*/
headerBackTitleStyle?: {
fontFamily?: string;
fontSize?: number;
};
/**
* Whether the back button title should be visible or not. Defaults to `true`.
* Only supported on iOS.
*
* @platform ios
*/
headerBackTitleVisible?: boolean;
/**
* Function which returns a React Element to display in the center of the header.
*/
headerCenter?: (props: { tintColor?: string }) => React.ReactNode;
/**
* Boolean indicating whether to hide the back button in header.
*/
headerHideBackButton?: boolean;
/**
* Boolean indicating whether to hide the elevation shadow or the bottom border on the header.
*/
headerHideShadow?: boolean;
/**
* Controls the style of the navigation header when the edge of any scrollable content reaches the matching edge of the navigation bar. Supported properties:
* - backgroundColor
*
* @platform ios
*/
headerLargeStyle?: {
backgroundColor?: string;
};
/**
* Boolean to set native property to prefer large title header (like in iOS setting).
* For large title to collapse on scroll, the content of the screen should be wrapped in a scrollable view such as `ScrollView` or `FlatList`.
* If the scrollable area doesn't fill the screen, the large title won't collapse on scroll.
* Only supported on iOS.
*
* @platform ios
*/
headerLargeTitle?: boolean;
/**
* Boolean that allows for disabling drop shadow under navigation header when the edge of any scrollable content reaches the matching edge of the navigation bar.
*/
headerLargeTitleHideShadow?: boolean;
/**
* Style object for header large title. Supported properties:
* - fontFamily
* - fontSize
* - color
*
* Only supported on iOS.
*
* @platform ios
*/
headerLargeTitleStyle?: {
fontFamily?: string;
fontSize?: number;
fontWeight?: string;
color?: string;
};
/**
* Function which returns a React Element to display on the left side of the header.
*/
headerLeft?: (props: { tintColor?: string }) => React.ReactNode;
/**
* Function which returns a React Element to display on the right side of the header.
*/
headerRight?: (props: { tintColor?: string }) => React.ReactNode;
/**
* Whether to show the header.
*/
headerShown?: boolean;
/**
* Style object for header title. Supported properties:
* - backgroundColor
* - blurEffect
*/
headerStyle?: {
backgroundColor?: string;
blurEffect?: ScreenStackHeaderConfigProps['blurEffect'];
};
/**
* Tint color for the header. Changes the color of back button and title.
*/
headerTintColor?: string;
/**
* String to display in the header as title. Defaults to scene `title`.
*/
headerTitle?: string;
/**
* Style object for header title. Supported properties:
* - fontFamily
* - fontSize
* - fontWeight
* - color
*/
headerTitleStyle?: {
fontFamily?: string;
fontSize?: number;
fontWeight?: string;
color?: string;
};
/**
* A flag to that lets you opt out of insetting the header. You may want to
* set this to `false` if you use an opaque status bar. Defaults to `true`.
* Only supported on Android. Insets are always applied on iOS because the
* header cannot be opaque.
*
* @platform android
*/
headerTopInsetEnabled?: boolean;
/**
* Boolean indicating whether the navigation bar is translucent.
*/
headerTranslucent?: boolean;
/**
* How should the screen replacing another screen animate. Defaults to `pop`.
* The following values are currently supported:
* - "push" the new screen will perform push animation.
* - "pop" the new screen will perform pop animation.
*/
replaceAnimation?: ScreenProps['replaceAnimation'];
/**
* In which orientation should the screen appear.
* The following values are currently supported:
* - "default" - resolves to "all" without "portrait_down" on iOS. On Android, this lets the system decide the best orientation.
* - "all" all orientations are permitted
* - "portrait" portrait orientations are permitted
* - "portrait_up" right-side portrait orientation is permitted
* - "portrait_down" upside-down portrait orientation is permitted
* - "landscape" landscape orientations are permitted
* - "landscape_left" landscape-left orientation is permitted
* - "landscape_right" landscape-right orientation is permitted
*/
screenOrientation?: ScreenStackHeaderConfigProps['screenOrientation'];
/**
* Object in which you should pass props in order to render native iOS searchBar.
*
* @platform ios
*/
searchBar?: SearchBarProps;
/**
* How the screen should appear/disappear when pushed or popped at the top of the stack.
* The following values are currently supported:
* - "default" uses a platform default animation
* - "fade" fades screen in or out
* - "flip" flips the screen, requires stackPresentation: "modal" (iOS only)
* - "slide_from_right" - slide in the new screen from right to left (Android only, resolves to default transition on iOS)
* - "slide_from_left" - slide in the new screen from left to right (Android only, resolves to default transition on iOS)
* - "none" the screen appears/dissapears without an animation
*/
stackAnimation?: ScreenProps['stackAnimation'];
/**
* How should the screen be presented.
* The following values are currently supported:
* - "push" the new screen will be pushed onto a stack which on iOS means that the default animation will be slide from the side, the animation on Android may vary depending on the OS version and theme.
* - "modal" the new screen will be presented modally. In addition this allow for a nested stack to be rendered inside such screens.
* - "transparentModal" the new screen will be presented modally but in addition the second to last screen will remain attached to the stack container such that if the top screen is non opaque the content below can still be seen. If "modal" is used instead the below screen will get unmounted as soon as the transition ends.
* - "containedModal" will use "UIModalPresentationCurrentContext" modal style on iOS and will fallback to "modal" on Android.
* - "containedTransparentModal" will use "UIModalPresentationOverCurrentContext" modal style on iOS and will fallback to "transparentModal" on Android.
* - "fullScreenModal" will use "UIModalPresentationFullScreen" modal style on iOS and will fallback to "modal" on Android.
* - "formSheet" will use "UIModalPresentationFormSheet" modal style on iOS and will fallback to "modal" on Android.
*/
stackPresentation?: ScreenProps['stackPresentation'];
/**
* Sets the status bar animation (similar to the `StatusBar` component). Requires enabling (or deleting) `View controller-based status bar appearance` in your Info.plist file.
*
* @platform ios
*/
statusBarAnimation?: ScreenStackHeaderConfigProps['statusBarAnimation'];
/**
* Whether the status bar should be hidden on this screen. Requires enabling (or deleting) `View controller-based status bar appearance` in your Info.plist file.
*
* @platform ios
*/
statusBarHidden?: boolean;
/** Sets the status bar color (similar to the `StatusBar` component). Requires enabling (or deleting) `View controller-based status bar appearance` in your Info.plist file.
*
* @platform ios
*/
statusBarStyle?: ScreenStackHeaderConfigProps['statusBarStyle'];
/**
* String that can be displayed in the header as a fallback for `headerTitle`.
*/
title?: string;
};
export type NativeStackNavigatorProps = DefaultNavigatorOptions<NativeStackNavigationOptions> &
StackRouterOptions &
NativeStackNavigationConfig;
export type NativeStackDescriptor = Descriptor<
NativeStackNavigationOptions,
NativeStackNavigationProp<ParamListBase>,
RouteProp<ParamListBase>
>;
export type NativeStackDescriptorMap = {
[key: string]: NativeStackDescriptor;
};

View File

@@ -0,0 +1,13 @@
// @ts-ignore: No declaration available
import ReactNativeStyleAttributes from 'react-native/Libraries/Components/View/ReactNativeStyleAttributes';
export function processFonts(
fontFamilies: (string | undefined)[]
): (string | undefined)[] {
// @ts-ignore: React Native types are incorrect here and don't consider fontFamily a style value
const fontFamilyProcessor = ReactNativeStyleAttributes.fontFamily?.process;
if (typeof fontFamilyProcessor === 'function') {
return fontFamilies.map(fontFamilyProcessor);
}
return fontFamilies;
}

View File

@@ -0,0 +1,138 @@
import { Route, useTheme } from '@react-navigation/native';
import * as React from 'react';
import { Platform } from 'react-native';
import {
ScreenStackHeaderBackButtonImage,
ScreenStackHeaderCenterView,
ScreenStackHeaderConfig,
ScreenStackHeaderLeftView,
ScreenStackHeaderRightView,
ScreenStackHeaderSearchBarView,
SearchBar,
} from 'react-native-screens';
import type { NativeStackNavigationOptions } from '../types';
import { processFonts } from './FontProcessor';
type Props = NativeStackNavigationOptions & {
route: Route<string>;
};
export default function HeaderConfig({
backButtonImage,
backButtonInCustomView,
direction,
headerBackTitle,
headerBackTitleStyle = {},
headerBackTitleVisible = true,
headerCenter,
headerHideBackButton,
headerHideShadow,
headerLargeStyle = {},
headerLargeTitle,
headerLargeTitleHideShadow,
headerLargeTitleStyle = {},
headerLeft,
headerRight,
headerShown,
headerStyle = {},
headerTintColor,
headerTitle,
headerTitleStyle = {},
headerTopInsetEnabled = true,
headerTranslucent,
route,
screenOrientation,
searchBar,
statusBarAnimation,
statusBarHidden,
statusBarStyle,
title,
}: Props): JSX.Element {
const { colors } = useTheme();
const tintColor = headerTintColor ?? colors.primary;
const [
backTitleFontFamily,
largeTitleFontFamily,
titleFontFamily,
] = processFonts([
headerBackTitleStyle.fontFamily,
headerLargeTitleStyle.fontFamily,
headerTitleStyle.fontFamily,
]);
return (
<ScreenStackHeaderConfig
backButtonInCustomView={backButtonInCustomView}
backgroundColor={
headerStyle.backgroundColor ? headerStyle.backgroundColor : colors.card
}
backTitle={headerBackTitleVisible ? headerBackTitle : ' '}
backTitleFontFamily={backTitleFontFamily}
backTitleFontSize={headerBackTitleStyle.fontSize}
blurEffect={headerStyle.blurEffect}
color={tintColor}
direction={direction}
hidden={headerShown === false}
hideBackButton={headerHideBackButton}
hideShadow={headerHideShadow}
largeTitle={headerLargeTitle}
largeTitleBackgroundColor={headerLargeStyle.backgroundColor}
largeTitleColor={headerLargeTitleStyle.color}
largeTitleFontFamily={largeTitleFontFamily}
largeTitleFontSize={headerLargeTitleStyle.fontSize}
largeTitleFontWeight={headerLargeTitleStyle.fontWeight}
largeTitleHideShadow={headerLargeTitleHideShadow}
screenOrientation={screenOrientation}
statusBarAnimation={statusBarAnimation}
statusBarHidden={statusBarHidden}
statusBarStyle={statusBarStyle}
title={
headerTitle !== undefined
? headerTitle
: title !== undefined
? title
: route.name
}
titleColor={
headerTitleStyle.color !== undefined
? headerTitleStyle.color
: headerTintColor !== undefined
? headerTintColor
: colors.text
}
titleFontFamily={titleFontFamily}
titleFontSize={headerTitleStyle.fontSize}
titleFontWeight={headerTitleStyle.fontWeight}
topInsetEnabled={headerTopInsetEnabled}
translucent={headerTranslucent === true}
>
{headerRight !== undefined ? (
<ScreenStackHeaderRightView>
{headerRight({ tintColor })}
</ScreenStackHeaderRightView>
) : null}
{backButtonImage !== undefined ? (
<ScreenStackHeaderBackButtonImage
key="backImage"
source={backButtonImage}
/>
) : null}
{headerLeft !== undefined ? (
<ScreenStackHeaderLeftView>
{headerLeft({ tintColor })}
</ScreenStackHeaderLeftView>
) : null}
{headerCenter !== undefined ? (
<ScreenStackHeaderCenterView>
{headerCenter({ tintColor })}
</ScreenStackHeaderCenterView>
) : null}
{Platform.OS === 'ios' && searchBar !== undefined ? (
<ScreenStackHeaderSearchBarView>
<SearchBar {...searchBar} />
</ScreenStackHeaderSearchBarView>
) : null}
</ScreenStackHeaderConfig>
);
}

View File

@@ -0,0 +1,232 @@
import * as React from 'react';
import {
Platform,
StyleProp,
StyleSheet,
View,
ViewProps,
ViewStyle,
} from 'react-native';
// @ts-ignore Getting private component
import AppContainer from 'react-native/Libraries/ReactNative/AppContainer';
import {
ParamListBase,
StackActions,
StackNavigationState,
useTheme,
Route,
} from '@react-navigation/native';
import {
Screen as ScreenComponent,
ScreenProps,
ScreenStack,
StackPresentationTypes,
} from 'react-native-screens';
import type {
NativeStackDescriptorMap,
NativeStackNavigationHelpers,
NativeStackNavigationOptions,
} from '../types';
import HeaderConfig from './HeaderConfig';
const Screen = (ScreenComponent as unknown) as React.ComponentType<ScreenProps>;
const isAndroid = Platform.OS === 'android';
let didWarn = isAndroid;
let Container = View;
if (__DEV__) {
const DebugContainer = (
props: ViewProps & { stackPresentation: StackPresentationTypes }
) => {
const { stackPresentation, ...rest } = props;
if (Platform.OS === 'ios' && stackPresentation !== 'push') {
return (
<AppContainer>
<View {...rest} />
</AppContainer>
);
}
return <View {...rest} />;
};
// @ts-ignore Wrong props
Container = DebugContainer;
}
const maybeRenderNestedStack = (
options: NativeStackNavigationOptions,
route: Route<string>,
renderScene: () => JSX.Element,
stackPresentation: StackPresentationTypes,
isHeaderInModal: boolean,
viewStyles: StyleProp<ViewStyle>
): JSX.Element => {
if (isHeaderInModal) {
return (
<ScreenStack style={styles.container}>
<Screen enabled style={StyleSheet.absoluteFill}>
<HeaderConfig {...options} route={route} />
<Container
style={viewStyles}
// @ts-ignore Wrong props passed to View
stackPresentation={stackPresentation}
>
{renderScene()}
</Container>
</Screen>
</ScreenStack>
);
}
return (
<Container
style={viewStyles}
// @ts-ignore Wrong props passed to View
stackPresentation={stackPresentation}
>
{renderScene()}
</Container>
);
};
type Props = {
state: StackNavigationState<ParamListBase>;
navigation: NativeStackNavigationHelpers;
descriptors: NativeStackDescriptorMap;
};
export default function NativeStackView({
state,
navigation,
descriptors,
}: Props): JSX.Element {
const { key, routes } = state;
const { colors } = useTheme();
return (
<ScreenStack style={styles.container}>
{routes.map((route, index) => {
const { options, render: renderScene } = descriptors[route.key];
const {
contentStyle,
gestureEnabled,
headerShown,
replaceAnimation = 'pop',
stackAnimation,
} = options;
let { stackPresentation = 'push' } = options;
if (index === 0) {
// first screen should always be treated as `push`, it resolves problems with no header animation
// for navigator with first screen as `modal` and the next as `push`
stackPresentation = 'push';
}
const viewStyles = [
styles.container,
stackPresentation !== 'transparentModal' &&
stackPresentation !== 'containedTransparentModal' && {
backgroundColor: colors.background,
},
contentStyle,
];
if (
!didWarn &&
stackPresentation !== 'push' &&
headerShown !== undefined
) {
didWarn = true;
console.warn(
'Be aware that changing the visibility of header in modal on iOS will result in resetting the state of the screen.'
);
}
const isHeaderInModal = isAndroid
? false
: stackPresentation !== 'push' && headerShown === true;
const isHeaderInPush = isAndroid
? headerShown
: stackPresentation === 'push' && headerShown !== false;
return (
<Screen
key={route.key}
enabled
style={StyleSheet.absoluteFill}
gestureEnabled={isAndroid ? false : gestureEnabled}
replaceAnimation={replaceAnimation}
stackPresentation={stackPresentation}
stackAnimation={stackAnimation}
onWillAppear={() => {
navigation.emit({
type: 'transitionStart',
data: { closing: false },
target: route.key,
});
}}
onWillDisappear={() => {
navigation.emit({
type: 'transitionStart',
data: { closing: true },
target: route.key,
});
}}
onAppear={() => {
navigation.emit({
type: 'appear',
target: route.key,
});
navigation.emit({
type: 'transitionEnd',
data: { closing: false },
target: route.key,
});
}}
onDisappear={() => {
navigation.emit({
type: 'transitionEnd',
data: { closing: true },
target: route.key,
});
}}
onDismissed={() => {
navigation.emit({
type: 'dismiss',
target: route.key,
});
navigation.dispatch({
...StackActions.pop(),
source: route.key,
target: key,
});
}}
>
<HeaderConfig
{...options}
route={route}
headerShown={isHeaderInPush}
/>
{maybeRenderNestedStack(
options,
route,
renderScene,
stackPresentation,
isHeaderInModal,
viewStyles
)}
</Screen>
);
})}
</ScreenStack>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});

View File

@@ -0,0 +1,6 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"paths": {}
}
}

View File

@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig",
"references": [
{ "path": "../core" },
{ "path": "../routers" },
{ "path": "../native" }
],
"compilerOptions": {
"outDir": "./lib/typescript"
}
}

View File

@@ -18389,6 +18389,11 @@ react-native-safe-area-context@3.2.0, react-native-safe-area-context@~3.2.0:
resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-3.2.0.tgz#06113c6b208f982d68ab5c3cebd199ca93db6941"
integrity sha512-k2Nty4PwSnrg9HwrYeeE+EYqViYJoOFwEy9LxL5RIRfoqxAq/uQXNGwpUg2/u4gnKpBbEPa9eRh15KKMe/VHkA==
react-native-screens@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/react-native-screens/-/react-native-screens-3.2.0.tgz#e2c8a4879c72f49af5b49e8859c84978a95d112b"
integrity sha512-pV4a32neQA69xhVsL9k1J/rM/SiP5zgGHjJsnNVEcuhBu+dlsutT2YFszQN4MgpP2dhHHu1O7DyRSHti+wh7Wg==
react-native-screens@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/react-native-screens/-/react-native-screens-3.0.0.tgz#ee4c2d69abf7411603868b57214feec5e8f637fa"