@react-navigation/native-stack 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/lib/commonjs/index.js +16 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/navigators/createNativeStackNavigator.js +67 -0
- package/lib/commonjs/navigators/createNativeStackNavigator.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/views/DebugContainer.js +24 -0
- package/lib/commonjs/views/DebugContainer.js.map +1 -0
- package/lib/commonjs/views/DebugContainer.native.js +43 -0
- package/lib/commonjs/views/DebugContainer.native.js.map +1 -0
- package/lib/commonjs/views/FontProcessor.js +11 -0
- package/lib/commonjs/views/FontProcessor.js.map +1 -0
- package/lib/commonjs/views/FontProcessor.native.js +25 -0
- package/lib/commonjs/views/FontProcessor.native.js.map +1 -0
- package/lib/commonjs/views/HeaderConfig.js +157 -0
- package/lib/commonjs/views/HeaderConfig.js.map +1 -0
- package/lib/commonjs/views/NativeStackView.js +133 -0
- package/lib/commonjs/views/NativeStackView.js.map +1 -0
- package/lib/commonjs/views/NativeStackView.native.js +247 -0
- package/lib/commonjs/views/NativeStackView.native.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/navigators/createNativeStackNavigator.js +50 -0
- package/lib/module/navigators/createNativeStackNavigator.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/views/DebugContainer.js +11 -0
- package/lib/module/views/DebugContainer.js.map +1 -0
- package/lib/module/views/DebugContainer.native.js +26 -0
- package/lib/module/views/DebugContainer.native.js.map +1 -0
- package/lib/module/views/FontProcessor.js +4 -0
- package/lib/module/views/FontProcessor.js.map +1 -0
- package/lib/module/views/FontProcessor.native.js +15 -0
- package/lib/module/views/FontProcessor.native.js.map +1 -0
- package/lib/module/views/HeaderConfig.js +138 -0
- package/lib/module/views/HeaderConfig.js.map +1 -0
- package/lib/module/views/NativeStackView.js +118 -0
- package/lib/module/views/NativeStackView.js.map +1 -0
- package/lib/module/views/NativeStackView.native.js +224 -0
- package/lib/module/views/NativeStackView.native.js.map +1 -0
- package/lib/typescript/src/index.d.ts +8 -0
- package/lib/typescript/src/navigators/createNativeStackNavigator.d.ts +6 -0
- package/lib/typescript/src/types.d.ts +373 -0
- package/lib/typescript/src/views/DebugContainer.d.ts +9 -0
- package/lib/typescript/src/views/DebugContainer.native.d.ts +9 -0
- package/lib/typescript/src/views/FontProcessor.d.ts +1 -0
- package/lib/typescript/src/views/FontProcessor.native.d.ts +1 -0
- package/lib/typescript/src/views/HeaderConfig.d.ts +9 -0
- package/lib/typescript/src/views/NativeStackView.d.ts +10 -0
- package/lib/typescript/src/views/NativeStackView.native.d.ts +10 -0
- package/package.json +80 -0
- package/src/index.tsx +14 -0
- package/src/navigators/createNativeStackNavigator.tsx +81 -0
- package/src/types.tsx +425 -0
- package/src/views/DebugContainer.native.tsx +33 -0
- package/src/views/DebugContainer.tsx +14 -0
- package/src/views/FontProcessor.native.tsx +13 -0
- package/src/views/FontProcessor.tsx +5 -0
- package/src/views/HeaderConfig.tsx +234 -0
- package/src/views/NativeStackView.native.tsx +331 -0
- package/src/views/NativeStackView.tsx +173 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { getHeaderTitle, Header, HeaderBackButton, SafeAreaProviderCompat, Screen } from '@react-navigation/elements';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Image, StyleSheet, View } from 'react-native';
|
|
4
|
+
export default function NativeStackView({
|
|
5
|
+
state,
|
|
6
|
+
descriptors
|
|
7
|
+
}) {
|
|
8
|
+
return /*#__PURE__*/React.createElement(SafeAreaProviderCompat, null, /*#__PURE__*/React.createElement(View, {
|
|
9
|
+
style: styles.container
|
|
10
|
+
}, state.routes.map((route, i) => {
|
|
11
|
+
var _state$routes;
|
|
12
|
+
|
|
13
|
+
const isFocused = state.index === i;
|
|
14
|
+
const canGoBack = i !== 0;
|
|
15
|
+
const previousKey = (_state$routes = state.routes[i - 1]) === null || _state$routes === void 0 ? void 0 : _state$routes.key;
|
|
16
|
+
const previousDescriptor = previousKey ? descriptors[previousKey] : undefined;
|
|
17
|
+
const {
|
|
18
|
+
options,
|
|
19
|
+
navigation,
|
|
20
|
+
render
|
|
21
|
+
} = descriptors[route.key];
|
|
22
|
+
const {
|
|
23
|
+
header,
|
|
24
|
+
headerShown,
|
|
25
|
+
headerTintColor,
|
|
26
|
+
headerBackImageSource,
|
|
27
|
+
headerLeft,
|
|
28
|
+
headerRight,
|
|
29
|
+
headerTitle,
|
|
30
|
+
headerTitleAlign,
|
|
31
|
+
headerTitleStyle,
|
|
32
|
+
headerStyle,
|
|
33
|
+
headerShadowVisible,
|
|
34
|
+
headerTransparent,
|
|
35
|
+
contentStyle,
|
|
36
|
+
headerBackTitle
|
|
37
|
+
} = options;
|
|
38
|
+
return /*#__PURE__*/React.createElement(Screen, {
|
|
39
|
+
key: route.key,
|
|
40
|
+
focused: isFocused,
|
|
41
|
+
route: route,
|
|
42
|
+
navigation: navigation,
|
|
43
|
+
headerShown: headerShown,
|
|
44
|
+
headerTransparent: headerTransparent,
|
|
45
|
+
header: header !== undefined ? header({
|
|
46
|
+
back: previousDescriptor ? {
|
|
47
|
+
title: getHeaderTitle(previousDescriptor.options, previousDescriptor.route.name)
|
|
48
|
+
} : undefined,
|
|
49
|
+
options,
|
|
50
|
+
route,
|
|
51
|
+
navigation
|
|
52
|
+
}) : /*#__PURE__*/React.createElement(Header, {
|
|
53
|
+
title: getHeaderTitle(options, route.name),
|
|
54
|
+
headerTintColor: headerTintColor,
|
|
55
|
+
headerLeft: typeof headerLeft === 'function' ? ({
|
|
56
|
+
tintColor
|
|
57
|
+
}) => headerLeft({
|
|
58
|
+
tintColor,
|
|
59
|
+
canGoBack,
|
|
60
|
+
label: headerBackTitle
|
|
61
|
+
}) : headerLeft === undefined && canGoBack ? ({
|
|
62
|
+
tintColor
|
|
63
|
+
}) => /*#__PURE__*/React.createElement(HeaderBackButton, {
|
|
64
|
+
tintColor: tintColor,
|
|
65
|
+
backImage: headerBackImageSource !== undefined ? () => /*#__PURE__*/React.createElement(Image, {
|
|
66
|
+
source: headerBackImageSource,
|
|
67
|
+
style: [styles.backImage, {
|
|
68
|
+
tintColor
|
|
69
|
+
}]
|
|
70
|
+
}) : undefined,
|
|
71
|
+
onPress: navigation.goBack,
|
|
72
|
+
canGoBack: canGoBack
|
|
73
|
+
}) : headerLeft,
|
|
74
|
+
headerRight: typeof headerRight === 'function' ? ({
|
|
75
|
+
tintColor
|
|
76
|
+
}) => headerRight({
|
|
77
|
+
tintColor
|
|
78
|
+
}) : headerRight,
|
|
79
|
+
headerTitle: typeof headerTitle === 'function' ? ({
|
|
80
|
+
children,
|
|
81
|
+
tintColor
|
|
82
|
+
}) => headerTitle({
|
|
83
|
+
children,
|
|
84
|
+
tintColor
|
|
85
|
+
}) : headerTitle,
|
|
86
|
+
headerTitleAlign: headerTitleAlign,
|
|
87
|
+
headerTitleStyle: headerTitleStyle,
|
|
88
|
+
headerStyle: [headerTransparent ? {
|
|
89
|
+
position: 'absolute',
|
|
90
|
+
backgroundColor: 'transparent'
|
|
91
|
+
} : null, headerStyle, headerShadowVisible === false ? {
|
|
92
|
+
shadowOpacity: 0,
|
|
93
|
+
borderBottomWidth: 0
|
|
94
|
+
} : null]
|
|
95
|
+
}),
|
|
96
|
+
style: [StyleSheet.absoluteFill, {
|
|
97
|
+
display: isFocused ? 'flex' : 'none'
|
|
98
|
+
}]
|
|
99
|
+
}, /*#__PURE__*/React.createElement(View, {
|
|
100
|
+
style: [styles.contentContainer, contentStyle]
|
|
101
|
+
}, render()));
|
|
102
|
+
})));
|
|
103
|
+
}
|
|
104
|
+
const styles = StyleSheet.create({
|
|
105
|
+
container: {
|
|
106
|
+
flex: 1
|
|
107
|
+
},
|
|
108
|
+
contentContainer: {
|
|
109
|
+
flex: 1
|
|
110
|
+
},
|
|
111
|
+
backImage: {
|
|
112
|
+
height: 24,
|
|
113
|
+
width: 24,
|
|
114
|
+
margin: 3,
|
|
115
|
+
resizeMode: 'contain'
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
//# sourceMappingURL=NativeStackView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["NativeStackView.tsx"],"names":["getHeaderTitle","Header","HeaderBackButton","SafeAreaProviderCompat","Screen","React","Image","StyleSheet","View","NativeStackView","state","descriptors","styles","container","routes","map","route","i","isFocused","index","canGoBack","previousKey","key","previousDescriptor","undefined","options","navigation","render","header","headerShown","headerTintColor","headerBackImageSource","headerLeft","headerRight","headerTitle","headerTitleAlign","headerTitleStyle","headerStyle","headerShadowVisible","headerTransparent","contentStyle","headerBackTitle","back","title","name","tintColor","label","backImage","goBack","children","position","backgroundColor","shadowOpacity","borderBottomWidth","absoluteFill","display","contentContainer","create","flex","height","width","margin","resizeMode"],"mappings":"AAAA,SACEA,cADF,EAEEC,MAFF,EAGEC,gBAHF,EAIEC,sBAJF,EAKEC,MALF,QAMO,4BANP;AAWA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SAASC,KAAT,EAAgBC,UAAhB,EAA4BC,IAA5B,QAAwC,cAAxC;AAeA,eAAe,SAASC,eAAT,CAAyB;AAAEC,EAAAA,KAAF;AAASC,EAAAA;AAAT,CAAzB,EAAwD;AACrE,sBACE,oBAAC,sBAAD,qBACE,oBAAC,IAAD;AAAM,IAAA,KAAK,EAAEC,MAAM,CAACC;AAApB,KACGH,KAAK,CAACI,MAAN,CAAaC,GAAb,CAAiB,CAACC,KAAD,EAAQC,CAAR,KAAc;AAAA;;AAC9B,UAAMC,SAAS,GAAGR,KAAK,CAACS,KAAN,KAAgBF,CAAlC;AACA,UAAMG,SAAS,GAAGH,CAAC,KAAK,CAAxB;AACA,UAAMI,WAAW,oBAAGX,KAAK,CAACI,MAAN,CA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AxB,GACI;AAAEc,UAAAA,aAAa,EAAE,CAAjB;AAAoBC,UAAAA,iBAAiB,EAAE;AAAvC,SADJ,GAEI,IAVO;AA/Cf,QAvBN;AAqFE,MAAA,KAAK,EAAE,CACL9C,UAAU,CAAC+C,YADN,EAEL;AAAEC,QAAAA,OAAO,EAAErC,SAAS,GAAG,MAAH,GAAY;AAAhC,OAFK;AArFT,oBA0FE,oBAAC,IAAD;AAAM,MAAA,KAAK,EAAE,CAACN,MAAM,CAAC4C,gBAAR,EAA0BhB,YAA1B;AAAb,OACGb,MAAM,EADT,CA1FF,CADF;AAgGD,GA1HA,CADH,CADF,CADF;AAiID;AAED,MAAMf,MAAM,GAAGL,UAAU,CAACkD,MAAX,CAAkB;AAC/B5C,EAAAA,SAAS,EAAE;AACT6C,IAAAA,IAAI,EAAE;AADG,GADoB;AAI/BF,EAAAA,gBAAgB,EAAE;AAChBE,IAAAA,IAAI,EAAE;AADU,GAJa;AAO/BX,EAAAA,SAAS,EAAE;AACTY,IAAAA,MAAM,EAAE,EADC;AAETC,IAAAA,KAAK,EAAE,EAFE;AAGTC,IAAAA,MAAM,EAAE,CAHC;AAITC,IAAAA,UAAU,EAAE;AAJH;AAPoB,CAAlB,CAAf","sourcesContent":["import {\n getHeaderTitle,\n Header,\n HeaderBackButton,\n SafeAreaProviderCompat,\n Screen,\n} from '@react-navigation/elements';\nimport type {\n ParamListBase,\n StackNavigationState,\n} from '@react-navigation/native';\nimport * as React from 'react';\nimport { Image, StyleSheet, View } from 'react-native';\n\nimport type {\n NativeStackDescriptorMap,\n NativeStackNavigationHelpers,\n} from '../types';\n\ntype Props = {\n state: StackNavigationState<ParamListBase>;\n // This is used for the native implementation of the stack.\n // eslint-disable-next-line react/no-unused-prop-types\n navigation: NativeStackNavigationHelpers;\n descriptors: NativeStackDescriptorMap;\n};\n\nexport default function NativeStackView({ state, descriptors }: Props) {\n return (\n <SafeAreaProviderCompat>\n <View style={styles.container}>\n {state.routes.map((route, i) => {\n const isFocused = state.index === i;\n const canGoBack = i !== 0;\n const previousKey = state.routes[i - 1]?.key;\n const previousDescriptor = previousKey\n ? descriptors[previousKey]\n : undefined;\n const { options, navigation, render } = descriptors[route.key];\n\n const {\n header,\n headerShown,\n headerTintColor,\n headerBackImageSource,\n headerLeft,\n headerRight,\n headerTitle,\n headerTitleAlign,\n headerTitleStyle,\n headerStyle,\n headerShadowVisible,\n headerTransparent,\n contentStyle,\n headerBackTitle,\n } = options;\n\n return (\n <Screen\n key={route.key}\n focused={isFocused}\n route={route}\n navigation={navigation}\n headerShown={headerShown}\n headerTransparent={headerTransparent}\n header={\n header !== undefined ? (\n header({\n back: previousDescriptor\n ? {\n title: getHeaderTitle(\n previousDescriptor.options,\n previousDescriptor.route.name\n ),\n }\n : undefined,\n options,\n route,\n navigation,\n })\n ) : (\n <Header\n title={getHeaderTitle(options, route.name)}\n headerTintColor={headerTintColor}\n headerLeft={\n typeof headerLeft === 'function'\n ? ({ tintColor }) =>\n headerLeft({\n tintColor,\n canGoBack,\n label: headerBackTitle,\n })\n : headerLeft === undefined && canGoBack\n ? ({ tintColor }) => (\n <HeaderBackButton\n tintColor={tintColor}\n backImage={\n headerBackImageSource !== undefined\n ? () => (\n <Image\n source={headerBackImageSource}\n style={[\n styles.backImage,\n { tintColor },\n ]}\n />\n )\n : undefined\n }\n onPress={navigation.goBack}\n canGoBack={canGoBack}\n />\n )\n : headerLeft\n }\n headerRight={\n typeof headerRight === 'function'\n ? ({ tintColor }) => headerRight({ tintColor })\n : headerRight\n }\n headerTitle={\n typeof headerTitle === 'function'\n ? ({ children, tintColor }) =>\n headerTitle({ children, tintColor })\n : headerTitle\n }\n headerTitleAlign={headerTitleAlign}\n headerTitleStyle={headerTitleStyle}\n headerStyle={[\n headerTransparent\n ? {\n position: 'absolute',\n backgroundColor: 'transparent',\n }\n : null,\n headerStyle,\n headerShadowVisible === false\n ? { shadowOpacity: 0, borderBottomWidth: 0 }\n : null,\n ]}\n />\n )\n }\n style={[\n StyleSheet.absoluteFill,\n { display: isFocused ? 'flex' : 'none' },\n ]}\n >\n <View style={[styles.contentContainer, contentStyle]}>\n {render()}\n </View>\n </Screen>\n );\n })}\n </View>\n </SafeAreaProviderCompat>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n },\n contentContainer: {\n flex: 1,\n },\n backImage: {\n height: 24,\n width: 24,\n margin: 3,\n resizeMode: 'contain',\n },\n});\n"]}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import { getDefaultHeaderHeight, getHeaderTitle, HeaderHeightContext, HeaderShownContext, SafeAreaProviderCompat } from '@react-navigation/elements';
|
|
4
|
+
import { StackActions, useTheme } from '@react-navigation/native';
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { Platform, StyleSheet } from 'react-native';
|
|
7
|
+
import { useSafeAreaFrame, useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
8
|
+
import { Screen, ScreenStack } from 'react-native-screens';
|
|
9
|
+
import warnOnce from 'warn-once';
|
|
10
|
+
import DebugContainer from './DebugContainer';
|
|
11
|
+
import HeaderConfig from './HeaderConfig';
|
|
12
|
+
const isAndroid = Platform.OS === 'android';
|
|
13
|
+
|
|
14
|
+
const MaybeNestedStack = ({
|
|
15
|
+
options,
|
|
16
|
+
route,
|
|
17
|
+
presentation,
|
|
18
|
+
children
|
|
19
|
+
}) => {
|
|
20
|
+
const {
|
|
21
|
+
colors
|
|
22
|
+
} = useTheme();
|
|
23
|
+
const {
|
|
24
|
+
header,
|
|
25
|
+
headerShown = true,
|
|
26
|
+
contentStyle
|
|
27
|
+
} = options;
|
|
28
|
+
const isHeaderInModal = isAndroid ? false : presentation !== 'card' && headerShown === true && header === undefined;
|
|
29
|
+
const headerShownPreviousRef = React.useRef(headerShown);
|
|
30
|
+
React.useEffect(() => {
|
|
31
|
+
warnOnce(!isAndroid && presentation !== 'card' && headerShownPreviousRef.current !== headerShown, `Dynamically changing 'headerShown' in modals will result in remounting the screen and losing all local state. See options for the screen '${route.name}'.`);
|
|
32
|
+
headerShownPreviousRef.current = headerShown;
|
|
33
|
+
}, [headerShown, presentation, route.name]);
|
|
34
|
+
const content = /*#__PURE__*/React.createElement(DebugContainer, {
|
|
35
|
+
style: [styles.container, presentation !== 'transparentModal' && presentation !== 'containedTransparentModal' && {
|
|
36
|
+
backgroundColor: colors.background
|
|
37
|
+
}, contentStyle],
|
|
38
|
+
stackPresentation: presentation === 'card' ? 'push' : presentation
|
|
39
|
+
}, children);
|
|
40
|
+
const insets = useSafeAreaInsets();
|
|
41
|
+
const dimensions = useSafeAreaFrame(); // landscape is meaningful only for iPhone
|
|
42
|
+
|
|
43
|
+
const isLandscape = dimensions.width > dimensions.height && !Platform.isPad && !Platform.isTVOS; // `modal` and `formSheet` presentations do not take whole screen, so should not take the inset.
|
|
44
|
+
|
|
45
|
+
const isFullScreenModal = presentation !== 'modal' && presentation !== 'formSheet';
|
|
46
|
+
const topInset = isFullScreenModal && !isLandscape ? insets.top : 0;
|
|
47
|
+
const headerHeight = getDefaultHeaderHeight(dimensions, !isFullScreenModal, topInset);
|
|
48
|
+
|
|
49
|
+
if (isHeaderInModal) {
|
|
50
|
+
return /*#__PURE__*/React.createElement(ScreenStack, {
|
|
51
|
+
style: styles.container
|
|
52
|
+
}, /*#__PURE__*/React.createElement(Screen, {
|
|
53
|
+
enabled: true,
|
|
54
|
+
style: StyleSheet.absoluteFill
|
|
55
|
+
}, /*#__PURE__*/React.createElement(HeaderShownContext.Provider, {
|
|
56
|
+
value: true
|
|
57
|
+
}, /*#__PURE__*/React.createElement(HeaderHeightContext.Provider, {
|
|
58
|
+
value: headerHeight
|
|
59
|
+
}, /*#__PURE__*/React.createElement(HeaderConfig, _extends({}, options, {
|
|
60
|
+
route: route,
|
|
61
|
+
canGoBack: true
|
|
62
|
+
})), content))));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return content;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const SceneView = ({
|
|
69
|
+
descriptor,
|
|
70
|
+
previousDescriptor,
|
|
71
|
+
index,
|
|
72
|
+
onWillDisappear,
|
|
73
|
+
onAppear,
|
|
74
|
+
onDisappear,
|
|
75
|
+
onDismissed
|
|
76
|
+
}) => {
|
|
77
|
+
const {
|
|
78
|
+
route,
|
|
79
|
+
navigation,
|
|
80
|
+
options,
|
|
81
|
+
render
|
|
82
|
+
} = descriptor;
|
|
83
|
+
const {
|
|
84
|
+
gestureEnabled,
|
|
85
|
+
header,
|
|
86
|
+
headerShown,
|
|
87
|
+
animationTypeForReplace = 'pop',
|
|
88
|
+
animation,
|
|
89
|
+
orientation,
|
|
90
|
+
statusBarAnimation,
|
|
91
|
+
statusBarHidden,
|
|
92
|
+
statusBarStyle
|
|
93
|
+
} = options;
|
|
94
|
+
let {
|
|
95
|
+
presentation = 'card'
|
|
96
|
+
} = options;
|
|
97
|
+
|
|
98
|
+
if (index === 0) {
|
|
99
|
+
// first screen should always be treated as `card`, it resolves problems with no header animation
|
|
100
|
+
// for navigator with first screen as `modal` and the next as `card`
|
|
101
|
+
presentation = 'card';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const isHeaderInPush = isAndroid ? headerShown : presentation === 'card' && headerShown !== false;
|
|
105
|
+
const isParentHeaderShown = React.useContext(HeaderShownContext);
|
|
106
|
+
const insets = useSafeAreaInsets();
|
|
107
|
+
const parentHeaderHeight = React.useContext(HeaderHeightContext);
|
|
108
|
+
const headerHeight = getDefaultHeaderHeight(useSafeAreaFrame(), false, insets.top);
|
|
109
|
+
return /*#__PURE__*/React.createElement(Screen, {
|
|
110
|
+
key: route.key,
|
|
111
|
+
enabled: true,
|
|
112
|
+
style: StyleSheet.absoluteFill,
|
|
113
|
+
gestureEnabled: isAndroid ? // This prop enables handling of system back gestures on Android
|
|
114
|
+
// Since we handle them in JS side, we disable this
|
|
115
|
+
false : gestureEnabled,
|
|
116
|
+
replaceAnimation: animationTypeForReplace,
|
|
117
|
+
stackPresentation: presentation === 'card' ? 'push' : presentation,
|
|
118
|
+
stackAnimation: animation,
|
|
119
|
+
screenOrientation: orientation,
|
|
120
|
+
statusBarAnimation: statusBarAnimation,
|
|
121
|
+
statusBarHidden: statusBarHidden,
|
|
122
|
+
statusBarStyle: statusBarStyle,
|
|
123
|
+
onWillDisappear: onWillDisappear,
|
|
124
|
+
onAppear: onAppear,
|
|
125
|
+
onDisappear: onDisappear,
|
|
126
|
+
onDismissed: onDismissed
|
|
127
|
+
}, /*#__PURE__*/React.createElement(HeaderShownContext.Provider, {
|
|
128
|
+
value: isParentHeaderShown || isHeaderInPush !== false
|
|
129
|
+
}, /*#__PURE__*/React.createElement(HeaderHeightContext.Provider, {
|
|
130
|
+
value: isHeaderInPush !== false ? headerHeight : parentHeaderHeight !== null && parentHeaderHeight !== void 0 ? parentHeaderHeight : 0
|
|
131
|
+
}, header !== undefined && headerShown !== false ? // TODO: expose custom header height
|
|
132
|
+
header({
|
|
133
|
+
back: previousDescriptor ? {
|
|
134
|
+
title: getHeaderTitle(previousDescriptor.options, previousDescriptor.route.name)
|
|
135
|
+
} : undefined,
|
|
136
|
+
options,
|
|
137
|
+
route,
|
|
138
|
+
navigation
|
|
139
|
+
}) : /*#__PURE__*/React.createElement(HeaderConfig, _extends({}, options, {
|
|
140
|
+
route: route,
|
|
141
|
+
headerShown: isHeaderInPush,
|
|
142
|
+
canGoBack: index !== 0
|
|
143
|
+
})), /*#__PURE__*/React.createElement(MaybeNestedStack, {
|
|
144
|
+
options: options,
|
|
145
|
+
route: route,
|
|
146
|
+
presentation: presentation
|
|
147
|
+
}, render()))));
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
function NativeStackViewInner({
|
|
151
|
+
state,
|
|
152
|
+
navigation,
|
|
153
|
+
descriptors
|
|
154
|
+
}) {
|
|
155
|
+
var _state$routes$find;
|
|
156
|
+
|
|
157
|
+
const [nextDismissedKey, setNextDismissedKey] = React.useState(null);
|
|
158
|
+
const dismissedRouteName = nextDismissedKey ? (_state$routes$find = state.routes.find(route => route.key === nextDismissedKey)) === null || _state$routes$find === void 0 ? void 0 : _state$routes$find.name : null;
|
|
159
|
+
React.useEffect(() => {
|
|
160
|
+
if (dismissedRouteName) {
|
|
161
|
+
const message = `The screen '${dismissedRouteName}' was removed natively but didn't get removed from JS state. ` + `This can happen if the action was prevented in a 'beforeRemove' listener, which is not fully supported in native-stack.\n\n` + `Consider using 'gestureEnabled: false' to prevent back gesture and use a custom back button with 'headerLeft' option to override the native behavior.`;
|
|
162
|
+
console.error(message);
|
|
163
|
+
}
|
|
164
|
+
}, [dismissedRouteName]);
|
|
165
|
+
return /*#__PURE__*/React.createElement(ScreenStack, {
|
|
166
|
+
style: styles.container
|
|
167
|
+
}, state.routes.map((route, index) => {
|
|
168
|
+
var _state$routes;
|
|
169
|
+
|
|
170
|
+
const descriptor = descriptors[route.key];
|
|
171
|
+
const previousKey = (_state$routes = state.routes[index - 1]) === null || _state$routes === void 0 ? void 0 : _state$routes.key;
|
|
172
|
+
const previousDescriptor = previousKey ? descriptors[previousKey] : undefined;
|
|
173
|
+
return /*#__PURE__*/React.createElement(SceneView, {
|
|
174
|
+
key: route.key,
|
|
175
|
+
index: index,
|
|
176
|
+
descriptor: descriptor,
|
|
177
|
+
previousDescriptor: previousDescriptor,
|
|
178
|
+
onWillDisappear: () => {
|
|
179
|
+
navigation.emit({
|
|
180
|
+
type: 'transitionStart',
|
|
181
|
+
data: {
|
|
182
|
+
closing: true
|
|
183
|
+
},
|
|
184
|
+
target: route.key
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
onAppear: () => {
|
|
188
|
+
navigation.emit({
|
|
189
|
+
type: 'transitionEnd',
|
|
190
|
+
data: {
|
|
191
|
+
closing: false
|
|
192
|
+
},
|
|
193
|
+
target: route.key
|
|
194
|
+
});
|
|
195
|
+
},
|
|
196
|
+
onDisappear: () => {
|
|
197
|
+
navigation.emit({
|
|
198
|
+
type: 'transitionEnd',
|
|
199
|
+
data: {
|
|
200
|
+
closing: true
|
|
201
|
+
},
|
|
202
|
+
target: route.key
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
onDismissed: () => {
|
|
206
|
+
navigation.dispatch({ ...StackActions.pop(),
|
|
207
|
+
source: route.key,
|
|
208
|
+
target: state.key
|
|
209
|
+
});
|
|
210
|
+
setNextDismissedKey(route.key);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export default function NativeStackView(props) {
|
|
217
|
+
return /*#__PURE__*/React.createElement(SafeAreaProviderCompat, null, /*#__PURE__*/React.createElement(NativeStackViewInner, props));
|
|
218
|
+
}
|
|
219
|
+
const styles = StyleSheet.create({
|
|
220
|
+
container: {
|
|
221
|
+
flex: 1
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
//# sourceMappingURL=NativeStackView.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["NativeStackView.native.tsx"],"names":["getDefaultHeaderHeight","getHeaderTitle","HeaderHeightContext","HeaderShownContext","SafeAreaProviderCompat","StackActions","useTheme","React","Platform","StyleSheet","useSafeAreaFrame","useSafeAreaInsets","Screen","ScreenStack","warnOnce","DebugContainer","HeaderConfig","isAndroid","OS","MaybeNestedStack","options","route","presentation","children","colors","header","headerShown","contentStyle","isHeaderInModal","undefined","headerShownPreviousRef","useRef","useEffect","current","name","content","styles","container","backgroundColor","background","insets","dimensions","isLandscape","width","height","isPad","isTVOS","isFullScreenModal","topInset","top","headerHeight","absoluteFill","SceneView","descriptor","previousDescriptor","index","onWillDisappear","onAppear","onDisappear","onDismissed","navigation","render","gestureEnabled","animationTypeForReplace","animation","orientation","statusBarAnimation","statusBarHidden","statusBarStyle","isHeaderInPush","isParentHeaderShown","useContext","parentHeaderHeight","key","back","title","NativeStackViewInner","state","descriptors","nextDismissedKey","setNextDismissedKey","useState","dismissedRouteName","routes","find","message","console","error","map","previousKey","emit","type","data","closing","target","dispatch","pop","source","NativeStackView","props","create","flex"],"mappings":";;AAAA,SACEA,sBADF,EAEEC,cAFF,EAGEC,mBAHF,EAIEC,kBAJF,EAKEC,sBALF,QAMO,4BANP;AAOA,SAGEC,YAHF,EAKEC,QALF,QAMO,0BANP;AAOA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SAASC,QAAT,EAAsCC,UAAtC,QAAwD,cAAxD;AACA,SACEC,gBADF,EAEEC,iBAFF,QAGO,gCAHP;AAIA,SACEC,MADF,EAEEC,WAFF,QAIO,sBAJP;AAKA,OAAOC,QAAP,MAAqB,WAArB;AAQA,OAAOC,cAAP,MAA2B,kBAA3B;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AAEA,MAAMC,SAAS,GAAGT,QAAQ,CAACU,EAAT,KAAgB,SAAlC;;AAEA,MAAMC,gBAAgB,GAAG,CAAC;AACxBC,EAAAA,OADwB;AAExBC,EAAAA,KAFwB;AAGxBC,EAAAA,YAHwB;AAIxBC,EAAAA;AAJwB,CAAD,KAUnB;AACJ,QAAM;AAAEC,IAAAA;AAAF,MAAalB,QAAQ,EAA3B;AACA,QAAM;AAAEmB,IAAAA,MAAF;AAAUC,IAAAA,WAAW,GAAG,IAAxB;AAA8BC,IAAAA;AAA9B,MAA+CP,OAArD;AAEA,QAAMQ,eAAe,GAAGX,SAAS,GAC7B,KAD6B,GAE7BK,YAAY,KAAK,MAAjB,IAA2BI,WAAW,KAAK,IAA3C,IAAmDD,MAAM,KAAKI,SAFlE;AAIA,QAAMC,sBAAsB,GAAGvB,KAAK,CAACwB,MAAN,CAAaL,WAAb,CAA/B;AAEAnB,EAAAA,KAAK,CAACyB,SAAN,CAAgB,MAAM;AACpBlB,IAAAA,QAAQ,CACN,CAACG,SA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ACjBb,QAAAA,UAAU,CAACmC,QAAX,CAAoB,EAClB,GAAG1F,YAAY,CAAC2F,GAAb,EADe;AAElBC,UAAAA,MAAM,EAAE5E,KAAK,CAACoD,GAFI;AAGlBqB,UAAAA,MAAM,EAAEjB,KAAK,CAACJ;AAHI,SAApB;AAMAO,QAAAA,mBAAmB,CAAC3D,KAAK,CAACoD,GAAP,CAAnB;AACD;AAlCH,MADF;AAsCD,GA7CA,CADH,CADF;AAkDD;;AAED,eAAe,SAASyB,eAAT,CAAyBC,KAAzB,EAAuC;AACpD,sBACE,oBAAC,sBAAD,qBACE,oBAAC,oBAAD,EAA0BA,KAA1B,CADF,CADF;AAKD;AAED,MAAM/D,MAAM,GAAG3B,UAAU,CAAC2F,MAAX,CAAkB;AAC/B/D,EAAAA,SAAS,EAAE;AACTgE,IAAAA,IAAI,EAAE;AADG;AADoB,CAAlB,CAAf","sourcesContent":["import {\n getDefaultHeaderHeight,\n getHeaderTitle,\n HeaderHeightContext,\n HeaderShownContext,\n SafeAreaProviderCompat,\n} from '@react-navigation/elements';\nimport {\n ParamListBase,\n Route,\n StackActions,\n StackNavigationState,\n useTheme,\n} from '@react-navigation/native';\nimport * as React from 'react';\nimport { Platform, PlatformIOSStatic, StyleSheet } from 'react-native';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\nimport {\n Screen,\n ScreenStack,\n StackPresentationTypes,\n} from 'react-native-screens';\nimport warnOnce from 'warn-once';\n\nimport type {\n NativeStackDescriptor,\n NativeStackDescriptorMap,\n NativeStackNavigationHelpers,\n NativeStackNavigationOptions,\n} from '../types';\nimport DebugContainer from './DebugContainer';\nimport HeaderConfig from './HeaderConfig';\n\nconst isAndroid = Platform.OS === 'android';\n\nconst MaybeNestedStack = ({\n options,\n route,\n presentation,\n children,\n}: {\n options: NativeStackNavigationOptions;\n route: Route<string>;\n presentation: Exclude<StackPresentationTypes, 'push'> | 'card';\n children: React.ReactNode;\n}) => {\n const { colors } = useTheme();\n const { header, headerShown = true, contentStyle } = options;\n\n const isHeaderInModal = isAndroid\n ? false\n : presentation !== 'card' && headerShown === true && header === undefined;\n\n const headerShownPreviousRef = React.useRef(headerShown);\n\n React.useEffect(() => {\n warnOnce(\n !isAndroid &&\n presentation !== 'card' &&\n headerShownPreviousRef.current !== headerShown,\n `Dynamically changing 'headerShown' in modals will result in remounting the screen and losing all local state. See options for the screen '${route.name}'.`\n );\n\n headerShownPreviousRef.current = headerShown;\n }, [headerShown, presentation, route.name]);\n\n const content = (\n <DebugContainer\n style={[\n styles.container,\n presentation !== 'transparentModal' &&\n presentation !== 'containedTransparentModal' && {\n backgroundColor: colors.background,\n },\n contentStyle,\n ]}\n stackPresentation={presentation === 'card' ? 'push' : presentation}\n >\n {children}\n </DebugContainer>\n );\n\n const insets = useSafeAreaInsets();\n const dimensions = useSafeAreaFrame();\n // landscape is meaningful only for iPhone\n const isLandscape =\n dimensions.width > dimensions.height &&\n !(Platform as PlatformIOSStatic).isPad &&\n !(Platform as PlatformIOSStatic).isTVOS;\n // `modal` and `formSheet` presentations do not take whole screen, so should not take the inset.\n const isFullScreenModal =\n presentation !== 'modal' && presentation !== 'formSheet';\n const topInset = isFullScreenModal && !isLandscape ? insets.top : 0;\n const headerHeight = getDefaultHeaderHeight(\n dimensions,\n !isFullScreenModal,\n topInset\n );\n\n if (isHeaderInModal) {\n return (\n <ScreenStack style={styles.container}>\n <Screen enabled style={StyleSheet.absoluteFill}>\n <HeaderShownContext.Provider value>\n <HeaderHeightContext.Provider value={headerHeight}>\n <HeaderConfig {...options} route={route} canGoBack />\n {content}\n </HeaderHeightContext.Provider>\n </HeaderShownContext.Provider>\n </Screen>\n </ScreenStack>\n );\n }\n\n return content;\n};\n\ntype SceneViewProps = {\n index: number;\n descriptor: NativeStackDescriptor;\n previousDescriptor?: NativeStackDescriptor;\n onWillDisappear: () => void;\n onAppear: () => void;\n onDisappear: () => void;\n onDismissed: () => void;\n};\n\nconst SceneView = ({\n descriptor,\n previousDescriptor,\n index,\n onWillDisappear,\n onAppear,\n onDisappear,\n onDismissed,\n}: SceneViewProps) => {\n const { route, navigation, options, render } = descriptor;\n const {\n gestureEnabled,\n header,\n headerShown,\n animationTypeForReplace = 'pop',\n animation,\n orientation,\n statusBarAnimation,\n statusBarHidden,\n statusBarStyle,\n } = options;\n\n let { presentation = 'card' } = options;\n\n if (index === 0) {\n // first screen should always be treated as `card`, it resolves problems with no header animation\n // for navigator with first screen as `modal` and the next as `card`\n presentation = 'card';\n }\n\n const isHeaderInPush = isAndroid\n ? headerShown\n : presentation === 'card' && headerShown !== false;\n\n const isParentHeaderShown = React.useContext(HeaderShownContext);\n const insets = useSafeAreaInsets();\n const parentHeaderHeight = React.useContext(HeaderHeightContext);\n const headerHeight = getDefaultHeaderHeight(\n useSafeAreaFrame(),\n false,\n insets.top\n );\n\n return (\n <Screen\n key={route.key}\n enabled\n style={StyleSheet.absoluteFill}\n gestureEnabled={\n isAndroid\n ? // This prop enables handling of system back gestures on Android\n // Since we handle them in JS side, we disable this\n false\n : gestureEnabled\n }\n replaceAnimation={animationTypeForReplace}\n stackPresentation={presentation === 'card' ? 'push' : presentation}\n stackAnimation={animation}\n screenOrientation={orientation}\n statusBarAnimation={statusBarAnimation}\n statusBarHidden={statusBarHidden}\n statusBarStyle={statusBarStyle}\n onWillDisappear={onWillDisappear}\n onAppear={onAppear}\n onDisappear={onDisappear}\n onDismissed={onDismissed}\n >\n <HeaderShownContext.Provider\n value={isParentHeaderShown || isHeaderInPush !== false}\n >\n <HeaderHeightContext.Provider\n value={\n isHeaderInPush !== false ? headerHeight : parentHeaderHeight ?? 0\n }\n >\n {header !== undefined && headerShown !== false ? (\n // TODO: expose custom header height\n header({\n back: previousDescriptor\n ? {\n title: getHeaderTitle(\n previousDescriptor.options,\n previousDescriptor.route.name\n ),\n }\n : undefined,\n options,\n route,\n navigation,\n })\n ) : (\n <HeaderConfig\n {...options}\n route={route}\n headerShown={isHeaderInPush}\n canGoBack={index !== 0}\n />\n )}\n <MaybeNestedStack\n options={options}\n route={route}\n presentation={presentation}\n >\n {render()}\n </MaybeNestedStack>\n </HeaderHeightContext.Provider>\n </HeaderShownContext.Provider>\n </Screen>\n );\n};\n\ntype Props = {\n state: StackNavigationState<ParamListBase>;\n navigation: NativeStackNavigationHelpers;\n descriptors: NativeStackDescriptorMap;\n};\n\nfunction NativeStackViewInner({ state, navigation, descriptors }: Props) {\n const [nextDismissedKey, setNextDismissedKey] =\n React.useState<string | null>(null);\n\n const dismissedRouteName = nextDismissedKey\n ? state.routes.find((route) => route.key === nextDismissedKey)?.name\n : null;\n\n React.useEffect(() => {\n if (dismissedRouteName) {\n const message =\n `The screen '${dismissedRouteName}' was removed natively but didn't get removed from JS state. ` +\n `This can happen if the action was prevented in a 'beforeRemove' listener, which is not fully supported in native-stack.\\n\\n` +\n `Consider using 'gestureEnabled: false' to prevent back gesture and use a custom back button with 'headerLeft' option to override the native behavior.`;\n\n console.error(message);\n }\n }, [dismissedRouteName]);\n\n return (\n <ScreenStack style={styles.container}>\n {state.routes.map((route, index) => {\n const descriptor = descriptors[route.key];\n const previousKey = state.routes[index - 1]?.key;\n const previousDescriptor = previousKey\n ? descriptors[previousKey]\n : undefined;\n\n return (\n <SceneView\n key={route.key}\n index={index}\n descriptor={descriptor}\n previousDescriptor={previousDescriptor}\n onWillDisappear={() => {\n navigation.emit({\n type: 'transitionStart',\n data: { closing: true },\n target: route.key,\n });\n }}\n onAppear={() => {\n navigation.emit({\n type: 'transitionEnd',\n data: { closing: false },\n target: route.key,\n });\n }}\n onDisappear={() => {\n navigation.emit({\n type: 'transitionEnd',\n data: { closing: true },\n target: route.key,\n });\n }}\n onDismissed={() => {\n navigation.dispatch({\n ...StackActions.pop(),\n source: route.key,\n target: state.key,\n });\n\n setNextDismissedKey(route.key);\n }}\n />\n );\n })}\n </ScreenStack>\n );\n}\n\nexport default function NativeStackView(props: Props) {\n return (\n <SafeAreaProviderCompat>\n <NativeStackViewInner {...props} />\n </SafeAreaProviderCompat>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n },\n});\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigators
|
|
3
|
+
*/
|
|
4
|
+
export { default as createNativeStackNavigator } from './navigators/createNativeStackNavigator';
|
|
5
|
+
/**
|
|
6
|
+
* Types
|
|
7
|
+
*/
|
|
8
|
+
export type { NativeStackHeaderProps, NativeStackNavigationOptions, NativeStackNavigationProp, NativeStackScreenProps, } from './types';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ParamListBase, StackNavigationState } from '@react-navigation/native';
|
|
3
|
+
import type { NativeStackNavigationEventMap, NativeStackNavigationOptions, NativeStackNavigatorProps } from '../types';
|
|
4
|
+
declare function NativeStackNavigator({ initialRouteName, children, screenListeners, screenOptions, ...rest }: NativeStackNavigatorProps): JSX.Element;
|
|
5
|
+
declare const _default: <ParamList extends ParamListBase>() => import("@react-navigation/native").TypedNavigator<ParamList, StackNavigationState<ParamListBase>, NativeStackNavigationOptions, NativeStackNavigationEventMap, typeof NativeStackNavigator>;
|
|
6
|
+
export default _default;
|