@react-navigation/native-stack 6.2.5 → 6.5.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/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/navigators/createNativeStackNavigator.js +12 -10
- package/lib/commonjs/navigators/createNativeStackNavigator.js.map +1 -1
- package/lib/commonjs/views/HeaderConfig.js +62 -39
- package/lib/commonjs/views/HeaderConfig.js.map +1 -1
- package/lib/commonjs/views/NativeStackView.js +62 -40
- package/lib/commonjs/views/NativeStackView.js.map +1 -1
- package/lib/commonjs/views/NativeStackView.native.js +57 -41
- package/lib/commonjs/views/NativeStackView.native.js.map +1 -1
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/navigators/createNativeStackNavigator.js +12 -10
- package/lib/module/navigators/createNativeStackNavigator.js.map +1 -1
- package/lib/module/views/HeaderConfig.js +62 -39
- package/lib/module/views/HeaderConfig.js.map +1 -1
- package/lib/module/views/NativeStackView.js +61 -40
- package/lib/module/views/NativeStackView.js.map +1 -1
- package/lib/module/views/NativeStackView.native.js +59 -43
- package/lib/module/views/NativeStackView.native.js.map +1 -1
- package/lib/typescript/src/index.d.ts +5 -1
- package/lib/typescript/src/types.d.ts +40 -11
- package/lib/typescript/src/views/HeaderConfig.d.ts +2 -1
- package/package.json +6 -6
- package/src/index.tsx +6 -0
- package/src/navigators/createNativeStackNavigator.tsx +21 -18
- package/src/types.tsx +41 -9
- package/src/views/HeaderConfig.tsx +153 -103
- package/src/views/NativeStackView.native.tsx +65 -47
- package/src/views/NativeStackView.tsx +25 -3
|
@@ -33,12 +33,14 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
|
33
33
|
|
|
34
34
|
const isAndroid = _reactNative.Platform.OS === 'android';
|
|
35
35
|
|
|
36
|
-
const MaybeNestedStack =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
const MaybeNestedStack = _ref => {
|
|
37
|
+
let {
|
|
38
|
+
options,
|
|
39
|
+
route,
|
|
40
|
+
presentation,
|
|
41
|
+
headerHeight,
|
|
42
|
+
children
|
|
43
|
+
} = _ref;
|
|
42
44
|
const {
|
|
43
45
|
colors
|
|
44
46
|
} = (0, _native.useTheme)();
|
|
@@ -59,14 +61,6 @@ const MaybeNestedStack = ({
|
|
|
59
61
|
}, contentStyle],
|
|
60
62
|
stackPresentation: presentation === 'card' ? 'push' : presentation
|
|
61
63
|
}, children);
|
|
62
|
-
const insets = (0, _reactNativeSafeAreaContext.useSafeAreaInsets)();
|
|
63
|
-
const dimensions = (0, _reactNativeSafeAreaContext.useSafeAreaFrame)(); // landscape is meaningful only for iPhone
|
|
64
|
-
|
|
65
|
-
const isLandscape = dimensions.width > dimensions.height && !_reactNative.Platform.isPad && !_reactNative.Platform.isTVOS; // `modal` and `formSheet` presentations do not take whole screen, so should not take the inset.
|
|
66
|
-
|
|
67
|
-
const isFullScreenModal = presentation !== 'modal' && presentation !== 'formSheet';
|
|
68
|
-
const topInset = isFullScreenModal && !isLandscape ? insets.top : 0;
|
|
69
|
-
const headerHeight = (0, _elements.getDefaultHeaderHeight)(dimensions, !isFullScreenModal, topInset);
|
|
70
64
|
|
|
71
65
|
if (isHeaderInModal) {
|
|
72
66
|
return /*#__PURE__*/React.createElement(_reactNativeScreens.ScreenStack, {
|
|
@@ -74,28 +68,26 @@ const MaybeNestedStack = ({
|
|
|
74
68
|
}, /*#__PURE__*/React.createElement(_reactNativeScreens.Screen, {
|
|
75
69
|
enabled: true,
|
|
76
70
|
style: _reactNative.StyleSheet.absoluteFill
|
|
77
|
-
}, /*#__PURE__*/React.createElement(_elements.HeaderShownContext.Provider, {
|
|
78
|
-
value: true
|
|
79
|
-
}, /*#__PURE__*/React.createElement(_elements.HeaderHeightContext.Provider, {
|
|
80
|
-
value: headerHeight
|
|
81
71
|
}, /*#__PURE__*/React.createElement(_HeaderConfig.default, _extends({}, options, {
|
|
82
72
|
route: route,
|
|
73
|
+
headerHeight: headerHeight,
|
|
83
74
|
canGoBack: true
|
|
84
|
-
})), content))
|
|
75
|
+
})), content));
|
|
85
76
|
}
|
|
86
77
|
|
|
87
78
|
return content;
|
|
88
79
|
};
|
|
89
80
|
|
|
90
|
-
const SceneView =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
81
|
+
const SceneView = _ref2 => {
|
|
82
|
+
let {
|
|
83
|
+
descriptor,
|
|
84
|
+
previousDescriptor,
|
|
85
|
+
index,
|
|
86
|
+
onWillDisappear,
|
|
87
|
+
onAppear,
|
|
88
|
+
onDisappear,
|
|
89
|
+
onDismissed
|
|
90
|
+
} = _ref2;
|
|
99
91
|
const {
|
|
100
92
|
route,
|
|
101
93
|
navigation,
|
|
@@ -103,11 +95,13 @@ const SceneView = ({
|
|
|
103
95
|
render
|
|
104
96
|
} = descriptor;
|
|
105
97
|
const {
|
|
98
|
+
animation,
|
|
99
|
+
animationTypeForReplace = 'push',
|
|
100
|
+
customAnimationOnGesture,
|
|
101
|
+
fullScreenGestureEnabled,
|
|
106
102
|
gestureEnabled,
|
|
107
103
|
header,
|
|
108
104
|
headerShown,
|
|
109
|
-
animationTypeForReplace = 'push',
|
|
110
|
-
animation,
|
|
111
105
|
orientation,
|
|
112
106
|
statusBarAnimation,
|
|
113
107
|
statusBarHidden,
|
|
@@ -125,13 +119,24 @@ const SceneView = ({
|
|
|
125
119
|
|
|
126
120
|
const isHeaderInPush = isAndroid ? headerShown : presentation === 'card' && headerShown !== false;
|
|
127
121
|
const insets = (0, _reactNativeSafeAreaContext.useSafeAreaInsets)();
|
|
122
|
+
const frame = (0, _reactNativeSafeAreaContext.useSafeAreaFrame)(); // `modal` and `formSheet` presentations do not take whole screen, so should not take the inset.
|
|
123
|
+
|
|
124
|
+
const isModal = presentation === 'modal' || presentation === 'formSheet'; // Modals are fullscreen in landscape only on iPhone
|
|
125
|
+
|
|
126
|
+
const isIPhone = _reactNative.Platform.OS === 'ios' && !(_reactNative.Platform.isPad && _reactNative.Platform.isTVOS);
|
|
127
|
+
const isLandscape = frame.width > frame.height;
|
|
128
|
+
const topInset = isModal || isIPhone && isLandscape ? 0 : insets.top;
|
|
128
129
|
const isParentHeaderShown = React.useContext(_elements.HeaderShownContext);
|
|
129
130
|
const parentHeaderHeight = React.useContext(_elements.HeaderHeightContext);
|
|
130
|
-
const
|
|
131
|
+
const defaultHeaderHeight = (0, _elements.getDefaultHeaderHeight)(frame, isModal, topInset);
|
|
132
|
+
const [customHeaderHeight, setCustomHeaderHeight] = React.useState(defaultHeaderHeight);
|
|
133
|
+
const headerHeight = header ? customHeaderHeight : defaultHeaderHeight;
|
|
131
134
|
return /*#__PURE__*/React.createElement(_reactNativeScreens.Screen, {
|
|
132
135
|
key: route.key,
|
|
133
136
|
enabled: true,
|
|
134
137
|
style: _reactNative.StyleSheet.absoluteFill,
|
|
138
|
+
customAnimationOnSwipe: customAnimationOnGesture,
|
|
139
|
+
fullScreenSwipeEnabled: fullScreenGestureEnabled,
|
|
135
140
|
gestureEnabled: isAndroid ? // This prop enables handling of system back gestures on Android
|
|
136
141
|
// Since we handle them in JS side, we disable this
|
|
137
142
|
false : gestureEnabled,
|
|
@@ -145,37 +150,48 @@ const SceneView = ({
|
|
|
145
150
|
onWillDisappear: onWillDisappear,
|
|
146
151
|
onAppear: onAppear,
|
|
147
152
|
onDisappear: onDisappear,
|
|
148
|
-
onDismissed: onDismissed
|
|
153
|
+
onDismissed: onDismissed,
|
|
154
|
+
isNativeStack: true
|
|
149
155
|
}, /*#__PURE__*/React.createElement(_elements.HeaderShownContext.Provider, {
|
|
150
156
|
value: isParentHeaderShown || isHeaderInPush !== false
|
|
151
157
|
}, /*#__PURE__*/React.createElement(_elements.HeaderHeightContext.Provider, {
|
|
152
158
|
value: isHeaderInPush !== false ? headerHeight : parentHeaderHeight !== null && parentHeaderHeight !== void 0 ? parentHeaderHeight : 0
|
|
153
|
-
}, header !== undefined && headerShown !== false ?
|
|
154
|
-
|
|
159
|
+
}, header !== undefined && headerShown !== false ? /*#__PURE__*/React.createElement(_native.NavigationContext.Provider, {
|
|
160
|
+
value: navigation
|
|
161
|
+
}, /*#__PURE__*/React.createElement(_native.NavigationRouteContext.Provider, {
|
|
162
|
+
value: route
|
|
163
|
+
}, /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
164
|
+
onLayout: e => {
|
|
165
|
+
setCustomHeaderHeight(e.nativeEvent.layout.height);
|
|
166
|
+
}
|
|
167
|
+
}, header({
|
|
155
168
|
back: previousDescriptor ? {
|
|
156
169
|
title: (0, _elements.getHeaderTitle)(previousDescriptor.options, previousDescriptor.route.name)
|
|
157
170
|
} : undefined,
|
|
158
171
|
options,
|
|
159
172
|
route,
|
|
160
173
|
navigation
|
|
161
|
-
}) : /*#__PURE__*/React.createElement(_HeaderConfig.default, _extends({}, options, {
|
|
174
|
+
})))) : /*#__PURE__*/React.createElement(_HeaderConfig.default, _extends({}, options, {
|
|
162
175
|
route: route,
|
|
163
176
|
headerShown: isHeaderInPush,
|
|
177
|
+
headerHeight: headerHeight,
|
|
164
178
|
canGoBack: index !== 0
|
|
165
179
|
})), /*#__PURE__*/React.createElement(MaybeNestedStack, {
|
|
166
180
|
options: options,
|
|
167
181
|
route: route,
|
|
168
|
-
presentation: presentation
|
|
182
|
+
presentation: presentation,
|
|
183
|
+
headerHeight: headerHeight
|
|
169
184
|
}, render()))));
|
|
170
185
|
};
|
|
171
186
|
|
|
172
|
-
function NativeStackViewInner({
|
|
173
|
-
state,
|
|
174
|
-
navigation,
|
|
175
|
-
descriptors
|
|
176
|
-
}) {
|
|
187
|
+
function NativeStackViewInner(_ref3) {
|
|
177
188
|
var _state$routes$find;
|
|
178
189
|
|
|
190
|
+
let {
|
|
191
|
+
state,
|
|
192
|
+
navigation,
|
|
193
|
+
descriptors
|
|
194
|
+
} = _ref3;
|
|
179
195
|
const [nextDismissedKey, setNextDismissedKey] = React.useState(null);
|
|
180
196
|
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;
|
|
181
197
|
React.useEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["NativeStackView.native.tsx"],"names":["isAndroid","Platform","OS","MaybeNestedStack","options","route","presentation","children","colors","header","headerShown","contentStyle","isHeaderInModal","undefined","headerShownPreviousRef","React","useRef","useEffect","current","name","content","styles","container","backgroundColor","background","insets","dimensions","isLandscape","width","height","isPad","isTVOS","isFullScreenModal","topInset","top","headerHeight","StyleSheet","absoluteFill","SceneView","descriptor","previousDescriptor","index","onWillDisappear","onAppear","onDisappear","onDismissed","navigation","render","gestureEnabled","animationTypeForReplace","animation","orientation","statusBarAnimation","statusBarHidden","statusBarStyle","isHeaderInPush","isParentHeaderShown","useContext","HeaderShownContext","parentHeaderHeight","HeaderHeightContext","key","back","title","NativeStackViewInner","state","descriptors","nextDismissedKey","setNextDismissedKey","useState","dismissedRouteName","routes","find","message","console","error","map","previousKey","emit","type","data","closing","target","dispatch","StackActions","pop","source","NativeStackView","props","create","flex"],"mappings":";;;;;;;AAAA;;AAOA;;AAOA;;AACA;;AACA;;AAIA;;AAKA;;AAQA;;AACA;;;;;;;;;;AAEA,MAAMA,SAAS,GAAGC,sBAASC,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,MAAa,uBAAnB;AACA,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,WAAW,GAAG,IAAxB;AAA8BC,IAAAA;AAA9B,MAA+CP,OAArD;AAEA,QAAMQ,eAAe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A,IAAI,EAAE;AAAEC,YAAAA,OAAO,EAAE;AAAX,WAFQ;AAGdC,UAAAA,MAAM,EAAE7E,KAAK,CAACwD;AAHA,SAAhB;AAKD,OAzBH;AA0BE,MAAA,WAAW,EAAE,MAAM;AACjBf,QAAAA,UAAU,CAACqC,QAAX,CAAoB,EAClB,GAAGC,qBAAaC,GAAb,EADe;AAElBC,UAAAA,MAAM,EAAEjF,KAAK,CAACwD,GAFI;AAGlBqB,UAAAA,MAAM,EAAEjB,KAAK,CAACJ;AAHI,SAApB;AAMAO,QAAAA,mBAAmB,CAAC/D,KAAK,CAACwD,GAAP,CAAnB;AACD;AAlCH,MADF;AAsCD,GA7CA,CADH,CADF;AAkDD;;AAEc,SAAS0B,eAAT,CAAyBC,KAAzB,EAAuC;AACpD,sBACE,oBAAC,gCAAD,qBACE,oBAAC,oBAAD,EAA0BA,KAA1B,CADF,CADF;AAKD;;AAED,MAAMnE,MAAM,GAAGe,wBAAWqD,MAAX,CAAkB;AAC/BnE,EAAAA,SAAS,EAAE;AACToE,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 = 'push',\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 insets = useSafeAreaInsets();\n\n const isParentHeaderShown = React.useContext(HeaderShownContext);\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"]}
|
|
1
|
+
{"version":3,"sources":["NativeStackView.native.tsx"],"names":["isAndroid","Platform","OS","MaybeNestedStack","options","route","presentation","headerHeight","children","colors","header","headerShown","contentStyle","isHeaderInModal","undefined","headerShownPreviousRef","React","useRef","useEffect","current","name","content","styles","container","backgroundColor","background","StyleSheet","absoluteFill","SceneView","descriptor","previousDescriptor","index","onWillDisappear","onAppear","onDisappear","onDismissed","navigation","render","animation","animationTypeForReplace","customAnimationOnGesture","fullScreenGestureEnabled","gestureEnabled","orientation","statusBarAnimation","statusBarHidden","statusBarStyle","isHeaderInPush","insets","frame","isModal","isIPhone","isPad","isTVOS","isLandscape","width","height","topInset","top","isParentHeaderShown","useContext","HeaderShownContext","parentHeaderHeight","HeaderHeightContext","defaultHeaderHeight","customHeaderHeight","setCustomHeaderHeight","useState","key","e","nativeEvent","layout","back","title","NativeStackViewInner","state","descriptors","nextDismissedKey","setNextDismissedKey","dismissedRouteName","routes","find","message","console","error","map","previousKey","emit","type","data","closing","target","dispatch","StackActions","pop","source","NativeStackView","props","create","flex"],"mappings":";;;;;;;AAAA;;AAOA;;AASA;;AACA;;AACA;;AAIA;;AAKA;;AAQA;;AACA;;;;;;;;;;AAEA,MAAMA,SAAS,GAAGC,sBAASC,EAAT,KAAgB,SAAlC;;AAEA,MAAMC,gBAAgB,GAAG,QAYnB;AAAA,MAZoB;AACxBC,IAAAA,OADwB;AAExBC,IAAAA,KAFwB;AAGxBC,IAAAA,YAHwB;AAIxBC,IAAAA,YAJwB;AAKxBC,IAAAA;AALwB,GAYpB;AACJ,QAAM;AAAEC,IAAAA;AAAF,MAAa,uBAAnB;AACA,QAAM;AAAEC,I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A,SAAS,EAAE;AACT4E,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 NavigationContext,\n NavigationRouteContext,\n ParamListBase,\n Route,\n StackActions,\n StackNavigationState,\n useTheme,\n} from '@react-navigation/native';\nimport * as React from 'react';\nimport { Platform, StyleSheet, View } 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 headerHeight,\n children,\n}: {\n options: NativeStackNavigationOptions;\n route: Route<string>;\n presentation: Exclude<StackPresentationTypes, 'push'> | 'card';\n headerHeight: number;\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 if (isHeaderInModal) {\n return (\n <ScreenStack style={styles.container}>\n <Screen enabled style={StyleSheet.absoluteFill}>\n <HeaderConfig\n {...options}\n route={route}\n headerHeight={headerHeight}\n canGoBack\n />\n {content}\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 animation,\n animationTypeForReplace = 'push',\n customAnimationOnGesture,\n fullScreenGestureEnabled,\n gestureEnabled,\n header,\n headerShown,\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 insets = useSafeAreaInsets();\n const frame = useSafeAreaFrame();\n\n // `modal` and `formSheet` presentations do not take whole screen, so should not take the inset.\n const isModal = presentation === 'modal' || presentation === 'formSheet';\n\n // Modals are fullscreen in landscape only on iPhone\n const isIPhone =\n Platform.OS === 'ios' && !(Platform.isPad && Platform.isTVOS);\n const isLandscape = frame.width > frame.height;\n\n const topInset = isModal || (isIPhone && isLandscape) ? 0 : insets.top;\n\n const isParentHeaderShown = React.useContext(HeaderShownContext);\n const parentHeaderHeight = React.useContext(HeaderHeightContext);\n\n const defaultHeaderHeight = getDefaultHeaderHeight(frame, isModal, topInset);\n\n const [customHeaderHeight, setCustomHeaderHeight] =\n React.useState(defaultHeaderHeight);\n\n const headerHeight = header ? customHeaderHeight : defaultHeaderHeight;\n\n return (\n <Screen\n key={route.key}\n enabled\n style={StyleSheet.absoluteFill}\n customAnimationOnSwipe={customAnimationOnGesture}\n fullScreenSwipeEnabled={fullScreenGestureEnabled}\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 isNativeStack\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 <NavigationContext.Provider value={navigation}>\n <NavigationRouteContext.Provider value={route}>\n <View\n onLayout={(e) => {\n setCustomHeaderHeight(e.nativeEvent.layout.height);\n }}\n >\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 </View>\n </NavigationRouteContext.Provider>\n </NavigationContext.Provider>\n ) : (\n <HeaderConfig\n {...options}\n route={route}\n headerShown={isHeaderInPush}\n headerHeight={headerHeight}\n canGoBack={index !== 0}\n />\n )}\n <MaybeNestedStack\n options={options}\n route={route}\n presentation={presentation}\n headerHeight={headerHeight}\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] = React.useState<string | null>(\n null\n );\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"]}
|
package/lib/module/index.js
CHANGED
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["default","createNativeStackNavigator"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,IAAIC,0BAApB,QAAsD,yCAAtD;AAEA;AACA;AACA","sourcesContent":["/**\n * Navigators\n */\nexport { default as createNativeStackNavigator } from './navigators/createNativeStackNavigator';\n\n/**\n * Types\n */\nexport type {\n NativeStackHeaderProps,\n NativeStackNavigationOptions,\n NativeStackNavigationProp,\n NativeStackScreenProps,\n} from './types';\n"]}
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["default","createNativeStackNavigator","NativeStackView"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,IAAIC,0BAApB,QAAsD,yCAAtD;AAEA;AACA;AACA;;AACA,SAASD,OAAO,IAAIE,eAApB,QAA2C,yBAA3C;AAEA;AACA;AACA","sourcesContent":["/**\n * Navigators\n */\nexport { default as createNativeStackNavigator } from './navigators/createNativeStackNavigator';\n\n/**\n * Views\n */\nexport { default as NativeStackView } from './views/NativeStackView';\n\n/**\n * Types\n */\nexport type {\n NativeStackHeaderProps,\n NativeStackNavigationEventMap,\n NativeStackNavigationOptions,\n NativeStackNavigationProp,\n NativeStackScreenProps,\n} from './types';\n"]}
|
|
@@ -4,17 +4,19 @@ import { createNavigatorFactory, StackActions, StackRouter, useNavigationBuilder
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import NativeStackView from '../views/NativeStackView';
|
|
6
6
|
|
|
7
|
-
function NativeStackNavigator({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
function NativeStackNavigator(_ref) {
|
|
8
|
+
let {
|
|
9
|
+
initialRouteName,
|
|
10
|
+
children,
|
|
11
|
+
screenListeners,
|
|
12
|
+
screenOptions,
|
|
13
|
+
...rest
|
|
14
|
+
} = _ref;
|
|
14
15
|
const {
|
|
15
16
|
state,
|
|
16
17
|
descriptors,
|
|
17
|
-
navigation
|
|
18
|
+
navigation,
|
|
19
|
+
NavigationContent
|
|
18
20
|
} = useNavigationBuilder(StackRouter, {
|
|
19
21
|
initialRouteName,
|
|
20
22
|
children,
|
|
@@ -39,11 +41,11 @@ function NativeStackNavigator({
|
|
|
39
41
|
});
|
|
40
42
|
});
|
|
41
43
|
}, [navigation, state.index, state.key]);
|
|
42
|
-
return /*#__PURE__*/React.createElement(NativeStackView, _extends({}, rest, {
|
|
44
|
+
return /*#__PURE__*/React.createElement(NavigationContent, null, /*#__PURE__*/React.createElement(NativeStackView, _extends({}, rest, {
|
|
43
45
|
state: state,
|
|
44
46
|
navigation: navigation,
|
|
45
47
|
descriptors: descriptors
|
|
46
|
-
}));
|
|
48
|
+
})));
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
export default createNavigatorFactory(NativeStackNavigator);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["createNativeStackNavigator.tsx"],"names":["createNavigatorFactory","StackActions","StackRouter","useNavigationBuilder","React","NativeStackView","NativeStackNavigator","initialRouteName","children","screenListeners","screenOptions","rest","state","descriptors","navigation","useEffect","addListener","e","isFocused","requestAnimationFrame","index","defaultPrevented","dispatch","popToTop","target","key"],"mappings":";;AAAA,SACEA,sBADF,EAKEC,YALF,EAOEC,WAPF,EASEC,oBATF,QAUO,0BAVP;AAWA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AAOA,OAAOC,eAAP,MAA4B,0BAA5B;;AAEA,SAASC,oBAAT,
|
|
1
|
+
{"version":3,"sources":["createNativeStackNavigator.tsx"],"names":["createNavigatorFactory","StackActions","StackRouter","useNavigationBuilder","React","NativeStackView","NativeStackNavigator","initialRouteName","children","screenListeners","screenOptions","rest","state","descriptors","navigation","NavigationContent","useEffect","addListener","e","isFocused","requestAnimationFrame","index","defaultPrevented","dispatch","popToTop","target","key"],"mappings":";;AAAA,SACEA,sBADF,EAKEC,YALF,EAOEC,WAPF,EASEC,oBATF,QAUO,0BAVP;AAWA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AAOA,OAAOC,eAAP,MAA4B,0BAA5B;;AAEA,SAASC,oBAAT,OAM8B;AA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\n StackActionHelpers,\n StackActions,\n StackNavigationState,\n StackRouter,\n StackRouterOptions,\n useNavigationBuilder,\n} from '@react-navigation/native';\nimport * as React from 'react';\n\nimport type {\n NativeStackNavigationEventMap,\n NativeStackNavigationOptions,\n NativeStackNavigatorProps,\n} from '../types';\nimport NativeStackView from '../views/NativeStackView';\n\nfunction NativeStackNavigator({\n initialRouteName,\n children,\n screenListeners,\n screenOptions,\n ...rest\n}: NativeStackNavigatorProps) {\n const { state, descriptors, navigation, NavigationContent } =\n useNavigationBuilder<\n StackNavigationState<ParamListBase>,\n StackRouterOptions,\n StackActionHelpers<ParamListBase>,\n NativeStackNavigationOptions,\n NativeStackNavigationEventMap\n >(StackRouter, {\n initialRouteName,\n children,\n screenListeners,\n screenOptions,\n });\n\n React.useEffect(\n () =>\n navigation?.addListener?.('tabPress', (e: any) => {\n const isFocused = navigation.isFocused();\n\n // Run the operation in the next frame so we're sure all listeners have been run\n // This is necessary to know if preventDefault() has been called\n requestAnimationFrame(() => {\n if (\n state.index > 0 &&\n isFocused &&\n !(e as EventArg<'tabPress', true>).defaultPrevented\n ) {\n // When user taps on already focused tab and we're inside the tab,\n // reset the stack to replicate native behaviour\n navigation.dispatch({\n ...StackActions.popToTop(),\n target: state.key,\n });\n }\n });\n }),\n [navigation, state.index, state.key]\n );\n\n return (\n <NavigationContent>\n <NativeStackView\n {...rest}\n state={state}\n navigation={navigation}\n descriptors={descriptors}\n />\n </NavigationContent>\n );\n}\n\nexport default createNavigatorFactory<\n StackNavigationState<ParamListBase>,\n NativeStackNavigationOptions,\n NativeStackNavigationEventMap,\n typeof NativeStackNavigator\n>(NativeStackNavigator);\n"]}
|
|
@@ -3,37 +3,40 @@ import { useTheme } from '@react-navigation/native';
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { I18nManager, Platform, StyleSheet, View } from 'react-native';
|
|
5
5
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
6
|
-
import { ScreenStackHeaderBackButtonImage, ScreenStackHeaderCenterView, ScreenStackHeaderConfig, ScreenStackHeaderLeftView, ScreenStackHeaderRightView, ScreenStackHeaderSearchBarView, SearchBar } from 'react-native-screens';
|
|
6
|
+
import { isSearchBarAvailableForCurrentPlatform, ScreenStackHeaderBackButtonImage, ScreenStackHeaderCenterView, ScreenStackHeaderConfig, ScreenStackHeaderLeftView, ScreenStackHeaderRightView, ScreenStackHeaderSearchBarView, SearchBar } from 'react-native-screens';
|
|
7
7
|
import { processFonts } from './FontProcessor';
|
|
8
|
-
export default function HeaderConfig({
|
|
9
|
-
|
|
10
|
-
headerBackButtonMenuEnabled,
|
|
11
|
-
headerBackTitle,
|
|
12
|
-
headerBackTitleStyle,
|
|
13
|
-
headerBackTitleVisible = true,
|
|
14
|
-
headerBackVisible,
|
|
15
|
-
headerShadowVisible,
|
|
16
|
-
headerLargeStyle,
|
|
17
|
-
headerLargeTitle,
|
|
18
|
-
headerLargeTitleShadowVisible,
|
|
19
|
-
headerLargeTitleStyle,
|
|
20
|
-
headerLeft,
|
|
21
|
-
headerRight,
|
|
22
|
-
headerShown,
|
|
23
|
-
headerStyle,
|
|
24
|
-
headerBlurEffect,
|
|
25
|
-
headerTintColor,
|
|
26
|
-
headerTitle,
|
|
27
|
-
headerTitleAlign,
|
|
28
|
-
headerTitleStyle,
|
|
29
|
-
headerTransparent,
|
|
30
|
-
headerSearchBarOptions,
|
|
31
|
-
route,
|
|
32
|
-
title,
|
|
33
|
-
canGoBack
|
|
34
|
-
}) {
|
|
35
|
-
var _ref, _headerTitleStyleFlat, _headerStyleFlattened;
|
|
8
|
+
export default function HeaderConfig(_ref) {
|
|
9
|
+
var _ref2, _headerTitleStyleFlat, _headerStyleFlattened;
|
|
36
10
|
|
|
11
|
+
let {
|
|
12
|
+
headerHeight,
|
|
13
|
+
headerBackImageSource,
|
|
14
|
+
headerBackButtonMenuEnabled,
|
|
15
|
+
headerBackTitle,
|
|
16
|
+
headerBackTitleStyle,
|
|
17
|
+
headerBackTitleVisible = true,
|
|
18
|
+
headerBackVisible,
|
|
19
|
+
headerShadowVisible,
|
|
20
|
+
headerLargeStyle,
|
|
21
|
+
headerLargeTitle,
|
|
22
|
+
headerLargeTitleShadowVisible,
|
|
23
|
+
headerLargeTitleStyle,
|
|
24
|
+
headerBackground,
|
|
25
|
+
headerLeft,
|
|
26
|
+
headerRight,
|
|
27
|
+
headerShown,
|
|
28
|
+
headerStyle,
|
|
29
|
+
headerBlurEffect,
|
|
30
|
+
headerTintColor,
|
|
31
|
+
headerTitle,
|
|
32
|
+
headerTitleAlign,
|
|
33
|
+
headerTitleStyle,
|
|
34
|
+
headerTransparent,
|
|
35
|
+
headerSearchBarOptions,
|
|
36
|
+
route,
|
|
37
|
+
title,
|
|
38
|
+
canGoBack
|
|
39
|
+
} = _ref;
|
|
37
40
|
const insets = useSafeAreaInsets();
|
|
38
41
|
const {
|
|
39
42
|
colors
|
|
@@ -46,7 +49,7 @@ export default function HeaderConfig({
|
|
|
46
49
|
const headerLargeStyleFlattened = StyleSheet.flatten(headerLargeStyle) || {};
|
|
47
50
|
const [backTitleFontFamily, largeTitleFontFamily, titleFontFamily] = processFonts([headerBackTitleStyleFlattened.fontFamily, headerLargeTitleStyleFlattened.fontFamily, headerTitleStyleFlattened.fontFamily]);
|
|
48
51
|
const titleText = title !== undefined ? title : route.name;
|
|
49
|
-
const titleColor = (
|
|
52
|
+
const titleColor = (_ref2 = (_headerTitleStyleFlat = headerTitleStyleFlattened.color) !== null && _headerTitleStyleFlat !== void 0 ? _headerTitleStyleFlat : headerTintColor) !== null && _ref2 !== void 0 ? _ref2 : colors.text;
|
|
50
53
|
const titleFontSize = headerTitleStyleFlattened.fontSize;
|
|
51
54
|
const titleFontWeight = headerTitleStyleFlattened.fontWeight;
|
|
52
55
|
const headerTitleStyleSupported = {
|
|
@@ -67,18 +70,22 @@ export default function HeaderConfig({
|
|
|
67
70
|
|
|
68
71
|
const headerLeftElement = headerLeft === null || headerLeft === void 0 ? void 0 : headerLeft({
|
|
69
72
|
tintColor,
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
canGoBack,
|
|
74
|
+
label: headerBackTitle
|
|
72
75
|
});
|
|
73
76
|
const headerRightElement = headerRight === null || headerRight === void 0 ? void 0 : headerRight({
|
|
74
|
-
tintColor
|
|
77
|
+
tintColor,
|
|
78
|
+
canGoBack
|
|
75
79
|
});
|
|
76
80
|
const headerTitleElement = typeof headerTitle === 'function' ? headerTitle({
|
|
77
81
|
tintColor,
|
|
78
82
|
children: titleText
|
|
79
83
|
}) : null;
|
|
84
|
+
const supportsHeaderSearchBar = typeof isSearchBarAvailableForCurrentPlatform === 'boolean' ? isSearchBarAvailableForCurrentPlatform : // Fallback for older versions of react-native-screens
|
|
85
|
+
Platform.OS === 'ios' && SearchBar != null;
|
|
86
|
+
const hasHeaderSearchBar = supportsHeaderSearchBar && headerSearchBarOptions != null;
|
|
80
87
|
|
|
81
|
-
if (
|
|
88
|
+
if (headerSearchBarOptions != null && !supportsHeaderSearchBar) {
|
|
82
89
|
throw new Error(`The current version of 'react-native-screens' doesn't support SearchBar in the header. Please update to the latest version to use this option.`);
|
|
83
90
|
}
|
|
84
91
|
/**
|
|
@@ -89,9 +96,15 @@ export default function HeaderConfig({
|
|
|
89
96
|
|
|
90
97
|
|
|
91
98
|
const backButtonInCustomView = headerBackVisible ? headerLeftElement != null : Platform.OS === 'android' && headerTitleElement != null;
|
|
92
|
-
|
|
99
|
+
const translucent = headerBackground != null || headerTransparent || // When using a SearchBar or large title, the header needs to be translucent for it to work on iOS
|
|
100
|
+
(hasHeaderSearchBar || headerLargeTitle) && Platform.OS === 'ios' && headerTransparent !== false;
|
|
101
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, headerBackground != null ? /*#__PURE__*/React.createElement(View, {
|
|
102
|
+
style: [styles.background, headerTransparent ? styles.translucent : null, {
|
|
103
|
+
height: headerHeight
|
|
104
|
+
}]
|
|
105
|
+
}, headerBackground()) : null, /*#__PURE__*/React.createElement(ScreenStackHeaderConfig, {
|
|
93
106
|
backButtonInCustomView: backButtonInCustomView,
|
|
94
|
-
backgroundColor: (_headerStyleFlattened = headerStyleFlattened.backgroundColor) !== null && _headerStyleFlattened !== void 0 ? _headerStyleFlattened : headerTransparent ? 'transparent' : colors.card,
|
|
107
|
+
backgroundColor: (_headerStyleFlattened = headerStyleFlattened.backgroundColor) !== null && _headerStyleFlattened !== void 0 ? _headerStyleFlattened : headerBackground != null || headerTransparent ? 'transparent' : colors.card,
|
|
95
108
|
backTitle: headerBackTitleVisible ? headerBackTitle : ' ',
|
|
96
109
|
backTitleFontFamily: backTitleFontFamily,
|
|
97
110
|
backTitleFontSize: headerBackTitleStyleFlattened.fontSize,
|
|
@@ -101,7 +114,7 @@ export default function HeaderConfig({
|
|
|
101
114
|
disableBackButtonMenu: headerBackButtonMenuEnabled === false,
|
|
102
115
|
hidden: headerShown === false,
|
|
103
116
|
hideBackButton: headerBackVisible === false,
|
|
104
|
-
hideShadow: headerShadowVisible === false,
|
|
117
|
+
hideShadow: headerShadowVisible === false || headerBackground != null || headerTransparent,
|
|
105
118
|
largeTitle: headerLargeTitle,
|
|
106
119
|
largeTitleBackgroundColor: headerLargeStyleFlattened.backgroundColor,
|
|
107
120
|
largeTitleColor: headerLargeTitleStyleFlattened.color,
|
|
@@ -116,7 +129,7 @@ export default function HeaderConfig({
|
|
|
116
129
|
titleFontWeight: titleFontWeight,
|
|
117
130
|
topInsetEnabled: insets.top !== 0,
|
|
118
131
|
translucent: // This defaults to `true`, so we can't pass `undefined`
|
|
119
|
-
|
|
132
|
+
translucent === true
|
|
120
133
|
}, Platform.OS === 'ios' ? /*#__PURE__*/React.createElement(React.Fragment, null, headerLeftElement != null ? /*#__PURE__*/React.createElement(ScreenStackHeaderLeftView, null, headerLeftElement) : null, headerTitleElement != null ? /*#__PURE__*/React.createElement(ScreenStackHeaderCenterView, null, headerTitleElement) : null) : /*#__PURE__*/React.createElement(React.Fragment, null, headerLeftElement != null || typeof headerTitle === 'function' ? /*#__PURE__*/React.createElement(ScreenStackHeaderLeftView, null, /*#__PURE__*/React.createElement(View, {
|
|
121
134
|
style: styles.row
|
|
122
135
|
}, headerLeftElement, headerTitleAlign !== 'center' ? typeof headerTitle === 'function' ? headerTitleElement : /*#__PURE__*/React.createElement(HeaderTitle, {
|
|
@@ -127,12 +140,22 @@ export default function HeaderConfig({
|
|
|
127
140
|
style: headerTitleStyleSupported
|
|
128
141
|
}, titleText)) : null), headerBackImageSource !== undefined ? /*#__PURE__*/React.createElement(ScreenStackHeaderBackButtonImage, {
|
|
129
142
|
source: headerBackImageSource
|
|
130
|
-
}) : null, headerRightElement != null ? /*#__PURE__*/React.createElement(ScreenStackHeaderRightView, null, headerRightElement) : null,
|
|
143
|
+
}) : null, headerRightElement != null ? /*#__PURE__*/React.createElement(ScreenStackHeaderRightView, null, headerRightElement) : null, hasHeaderSearchBar ? /*#__PURE__*/React.createElement(ScreenStackHeaderSearchBarView, null, /*#__PURE__*/React.createElement(SearchBar, headerSearchBarOptions)) : null));
|
|
131
144
|
}
|
|
132
145
|
const styles = StyleSheet.create({
|
|
133
146
|
row: {
|
|
134
147
|
flexDirection: 'row',
|
|
135
148
|
alignItems: 'center'
|
|
149
|
+
},
|
|
150
|
+
translucent: {
|
|
151
|
+
position: 'absolute',
|
|
152
|
+
top: 0,
|
|
153
|
+
left: 0,
|
|
154
|
+
right: 0,
|
|
155
|
+
zIndex: 1
|
|
156
|
+
},
|
|
157
|
+
background: {
|
|
158
|
+
overflow: 'hidden'
|
|
136
159
|
}
|
|
137
160
|
});
|
|
138
161
|
//# sourceMappingURL=HeaderConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["HeaderConfig.tsx"],"names":["HeaderTitle","useTheme","React","I18nManager","Platform","StyleSheet","View","useSafeAreaInsets","ScreenStackHeaderBackButtonImage","ScreenStackHeaderCenterView","ScreenStackHeaderConfig","ScreenStackHeaderLeftView","ScreenStackHeaderRightView","ScreenStackHeaderSearchBarView","SearchBar","processFonts","HeaderConfig","headerBackImageSource","headerBackButtonMenuEnabled","headerBackTitle","headerBackTitleStyle","headerBackTitleVisible","headerBackVisible","headerShadowVisible","headerLargeStyle","headerLargeTitle","headerLargeTitleShadowVisible","headerLargeTitleStyle","headerLeft","headerRight","headerShown","headerStyle","headerBlurEffect","headerTintColor","headerTitle","headerTitleAlign","headerTitleStyle","headerTransparent","headerSearchBarOptions","route","title","canGoBack","insets","colors","tintColor","OS","primary","text","headerBackTitleStyleFlattened","flatten","headerLargeTitleStyleFlattened","headerTitleStyleFlattened","headerStyleFlattened","headerLargeStyleFlattened","backTitleFontFamily","largeTitleFontFamily","titleFontFamily","fontFamily","titleText","undefined","name","titleColor","color","titleFontSize","fontSize","titleFontWeight","fontWeight","headerTitleStyleSupported","headerLeftElement","label","headerRightElement","headerTitleElement","children","Error","backButtonInCustomView","backgroundColor","card","isRTL","top","styles","row","create","flexDirection","alignItems"],"mappings":"AAAA,SAASA,WAAT,QAA4B,4BAA5B;AACA,SAAgBC,QAAhB,QAAgC,0BAAhC;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SACEC,WADF,EAEEC,QAFF,EAGEC,UAHF,EAKEC,IALF,QAMO,cANP;AAOA,SAASC,iBAAT,QAAkC,gCAAlC;AACA,SACEC,gCADF,EAEEC,2BAFF,EAGEC,uBAHF,EAIEC,yBAJF,EAKEC,0BALF,EAMEC,8BANF,EAOEC,SAPF,QAQO,sBARP;AAWA,SAASC,YAAT,QAA6B,iBAA7B;AAOA,eAAe,SAASC,YAAT,CAAsB;AACnCC,EAAAA,qBADmC;AAEnCC,EAAAA,2BAFmC;AAGnCC,EAAAA,eAHmC;AAInCC,EAAAA,oBAJmC;AAKnCC,EAAAA,sBAAsB,GAAG,IALU;AAMnCC,EAAAA,iBANmC;AAOnCC,EAAAA,mBAPmC;AAQnCC,EAAAA,gBARmC;AASnCC,EAAAA,gBATmC;AAUnCC,EAAAA,6BAVmC;AAWnCC,EAAAA,q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ACGA,kBADH,CADD,GAIG,IA3FN,EA4FGlE,QAAQ,CAACyC,EAAT,KAAgB,KAAhB,IAAyBP,sBAAsB,IAAI,IAAnD,gBACC,oBAAC,8BAAD,qBACE,oBAAC,SAAD,EAAeA,sBAAf,CADF,CADD,GAIG,IAhGN,CADF;AAoGD;AAED,MAAMyC,MAAM,GAAG1E,UAAU,CAAC4E,MAAX,CAAkB;AAC/BD,EAAAA,GAAG,EAAE;AACHE,IAAAA,aAAa,EAAE,KADZ;AAEHC,IAAAA,UAAU,EAAE;AAFT;AAD0B,CAAlB,CAAf","sourcesContent":["import { HeaderTitle } from '@react-navigation/elements';\nimport { Route, useTheme } from '@react-navigation/native';\nimport * as React from 'react';\nimport {\n I18nManager,\n Platform,\n StyleSheet,\n TextStyle,\n View,\n} from 'react-native';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport {\n ScreenStackHeaderBackButtonImage,\n ScreenStackHeaderCenterView,\n ScreenStackHeaderConfig,\n ScreenStackHeaderLeftView,\n ScreenStackHeaderRightView,\n ScreenStackHeaderSearchBarView,\n SearchBar,\n} from 'react-native-screens';\n\nimport type { NativeStackNavigationOptions } from '../types';\nimport { processFonts } from './FontProcessor';\n\ntype Props = NativeStackNavigationOptions & {\n route: Route<string>;\n canGoBack: boolean;\n};\n\nexport default function HeaderConfig({\n headerBackImageSource,\n headerBackButtonMenuEnabled,\n headerBackTitle,\n headerBackTitleStyle,\n headerBackTitleVisible = true,\n headerBackVisible,\n headerShadowVisible,\n headerLargeStyle,\n headerLargeTitle,\n headerLargeTitleShadowVisible,\n headerLargeTitleStyle,\n headerLeft,\n headerRight,\n headerShown,\n headerStyle,\n headerBlurEffect,\n headerTintColor,\n headerTitle,\n headerTitleAlign,\n headerTitleStyle,\n headerTransparent,\n headerSearchBarOptions,\n route,\n title,\n canGoBack,\n}: Props): JSX.Element {\n const insets = useSafeAreaInsets();\n const { colors } = useTheme();\n const tintColor =\n headerTintColor ?? (Platform.OS === 'ios' ? colors.primary : colors.text);\n\n const headerBackTitleStyleFlattened =\n StyleSheet.flatten(headerBackTitleStyle) || {};\n const headerLargeTitleStyleFlattened =\n StyleSheet.flatten(headerLargeTitleStyle) || {};\n const headerTitleStyleFlattened = StyleSheet.flatten(headerTitleStyle) || {};\n const headerStyleFlattened = StyleSheet.flatten(headerStyle) || {};\n const headerLargeStyleFlattened = StyleSheet.flatten(headerLargeStyle) || {};\n\n const [backTitleFontFamily, largeTitleFontFamily, titleFontFamily] =\n processFonts([\n headerBackTitleStyleFlattened.fontFamily,\n headerLargeTitleStyleFlattened.fontFamily,\n headerTitleStyleFlattened.fontFamily,\n ]);\n\n const titleText = title !== undefined ? title : route.name;\n const titleColor =\n headerTitleStyleFlattened.color ?? headerTintColor ?? colors.text;\n const titleFontSize = headerTitleStyleFlattened.fontSize;\n const titleFontWeight = headerTitleStyleFlattened.fontWeight;\n\n const headerTitleStyleSupported: TextStyle = { color: titleColor };\n\n if (headerTitleStyleFlattened.fontFamily != null) {\n headerTitleStyleSupported.fontFamily = headerTitleStyleFlattened.fontFamily;\n }\n\n if (titleFontSize != null) {\n headerTitleStyleSupported.fontSize = titleFontSize;\n }\n\n if (titleFontWeight != null) {\n headerTitleStyleSupported.fontWeight = titleFontWeight;\n }\n\n const headerLeftElement = headerLeft?.({\n tintColor,\n label: headerBackTitle,\n canGoBack,\n });\n const headerRightElement = headerRight?.({ tintColor });\n const headerTitleElement =\n typeof headerTitle === 'function'\n ? headerTitle({ tintColor, children: titleText })\n : null;\n\n if (\n Platform.OS === 'ios' &&\n headerSearchBarOptions != null &&\n SearchBar == null\n ) {\n throw new Error(\n `The current version of 'react-native-screens' doesn't support SearchBar in the header. Please update to the latest version to use this option.`\n );\n }\n\n /**\n * We need to set this in if:\n * - Back button should stay visible when `headerLeft` is specified\n * - If `headerTitle` for Android is specified, so we only need to remove the title and keep the back button\n */\n const backButtonInCustomView = headerBackVisible\n ? headerLeftElement != null\n : Platform.OS === 'android' && headerTitleElement != null;\n\n return (\n <ScreenStackHeaderConfig\n backButtonInCustomView={backButtonInCustomView}\n backgroundColor={\n headerStyleFlattened.backgroundColor ??\n (headerTransparent ? 'transparent' : colors.card)\n }\n backTitle={headerBackTitleVisible ? headerBackTitle : ' '}\n backTitleFontFamily={backTitleFontFamily}\n backTitleFontSize={headerBackTitleStyleFlattened.fontSize}\n blurEffect={headerBlurEffect}\n color={tintColor}\n direction={I18nManager.isRTL ? 'rtl' : 'ltr'}\n disableBackButtonMenu={headerBackButtonMenuEnabled === false}\n hidden={headerShown === false}\n hideBackButton={headerBackVisible === false}\n hideShadow={headerShadowVisible === false}\n largeTitle={headerLargeTitle}\n largeTitleBackgroundColor={headerLargeStyleFlattened.backgroundColor}\n largeTitleColor={headerLargeTitleStyleFlattened.color}\n largeTitleFontFamily={largeTitleFontFamily}\n largeTitleFontSize={headerLargeTitleStyleFlattened.fontSize}\n largeTitleFontWeight={headerLargeTitleStyleFlattened.fontWeight}\n largeTitleHideShadow={headerLargeTitleShadowVisible === false}\n title={typeof headerTitle === 'string' ? headerTitle : titleText}\n titleColor={titleColor}\n titleFontFamily={titleFontFamily}\n titleFontSize={titleFontSize}\n titleFontWeight={titleFontWeight}\n topInsetEnabled={insets.top !== 0}\n translucent={\n // This defaults to `true`, so we can't pass `undefined`\n headerTransparent === true\n }\n >\n {Platform.OS === 'ios' ? (\n <>\n {headerLeftElement != null ? (\n <ScreenStackHeaderLeftView>\n {headerLeftElement}\n </ScreenStackHeaderLeftView>\n ) : null}\n {headerTitleElement != null ? (\n <ScreenStackHeaderCenterView>\n {headerTitleElement}\n </ScreenStackHeaderCenterView>\n ) : null}\n </>\n ) : (\n <>\n {headerLeftElement != null || typeof headerTitle === 'function' ? (\n <ScreenStackHeaderLeftView>\n <View style={styles.row}>\n {headerLeftElement}\n {headerTitleAlign !== 'center' ? (\n typeof headerTitle === 'function' ? (\n headerTitleElement\n ) : (\n <HeaderTitle\n tintColor={tintColor}\n style={headerTitleStyleSupported}\n >\n {titleText}\n </HeaderTitle>\n )\n ) : null}\n </View>\n </ScreenStackHeaderLeftView>\n ) : null}\n {headerTitleAlign === 'center' ? (\n <ScreenStackHeaderCenterView>\n {typeof headerTitle === 'function' ? (\n headerTitleElement\n ) : (\n <HeaderTitle\n tintColor={tintColor}\n style={headerTitleStyleSupported}\n >\n {titleText}\n </HeaderTitle>\n )}\n </ScreenStackHeaderCenterView>\n ) : null}\n </>\n )}\n {headerBackImageSource !== undefined ? (\n <ScreenStackHeaderBackButtonImage source={headerBackImageSource} />\n ) : null}\n {headerRightElement != null ? (\n <ScreenStackHeaderRightView>\n {headerRightElement}\n </ScreenStackHeaderRightView>\n ) : null}\n {Platform.OS === 'ios' && headerSearchBarOptions != null ? (\n <ScreenStackHeaderSearchBarView>\n <SearchBar {...headerSearchBarOptions} />\n </ScreenStackHeaderSearchBarView>\n ) : null}\n </ScreenStackHeaderConfig>\n );\n}\n\nconst styles = StyleSheet.create({\n row: {\n flexDirection: 'row',\n alignItems: 'center',\n },\n});\n"]}
|
|
1
|
+
{"version":3,"sources":["HeaderConfig.tsx"],"names":["HeaderTitle","useTheme","React","I18nManager","Platform","StyleSheet","View","useSafeAreaInsets","isSearchBarAvailableForCurrentPlatform","ScreenStackHeaderBackButtonImage","ScreenStackHeaderCenterView","ScreenStackHeaderConfig","ScreenStackHeaderLeftView","ScreenStackHeaderRightView","ScreenStackHeaderSearchBarView","SearchBar","processFonts","HeaderConfig","headerHeight","headerBackImageSource","headerBackButtonMenuEnabled","headerBackTitle","headerBackTitleStyle","headerBackTitleVisible","headerBackVisible","headerShadowVisible","headerLargeStyle","headerLargeTitle","headerLargeTitleShadowVisible","headerLargeTitleStyle","headerBackground","headerLeft","headerRight","headerShown","headerStyle","headerBlurEffect","headerTintColor","headerTitle","headerTitleAlign","headerTitleStyle","headerTransparent","headerSearchBarOptions","route","title","canGoBack","insets","colors","tintColor","OS","primary","text","headerBackTitleStyleFlattened","flatten","headerLargeTitleStyleFlattened","headerTitleStyleFlattened","headerStyleFlattened","headerLargeStyleFlattened","backTitleFontFamily","largeTitleFontFamily","titleFontFamily","fontFamily","titleText","undefined","name","titleColor","color","titleFontSize","fontSize","titleFontWeight","fontWeight","headerTitleStyleSupported","headerLeftElement","label","headerRightElement","headerTitleElement","children","supportsHeaderSearchBar","hasHeaderSearchBar","Error","backButtonInCustomView","translucent","styles","background","height","backgroundColor","card","isRTL","top","row","create","flexDirection","alignItems","position","left","right","zIndex","overflow"],"mappings":"AAAA,SAASA,WAAT,QAA4B,4BAA5B;AACA,SAAgBC,QAAhB,QAAgC,0BAAhC;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SACEC,WADF,EAEEC,QAFF,EAGEC,UAHF,EAKEC,IALF,QAMO,cANP;AAOA,SAASC,iBAAT,QAAkC,gCAAlC;AACA,SACEC,sCADF,EAEEC,gCAFF,EAGEC,2BAHF,EAIEC,uBAJF,EAKEC,yBALF,EAMEC,0BANF,EAOEC,8BAPF,EAQEC,SARF,QASO,sBATP;AAYA,SAASC,YAAT,QAA6B,iBAA7B;AAQA,eAAe,SAASC,YAAT,OA4BQ;AAAA;;AAAA,MA5Bc;AACnCC,IAAAA,YADmC;AAEnCC,IAAAA,qBAFmC;AAGnCC,IAAAA,2BAHmC;AAInCC,IAAAA,eAJmC;AAKnCC,IAAAA,oBALmC;AAMnCC,IAAAA,sBAAsB,GAAG,IANU;AAOnCC,IAAAA,iBAPmC;AAQnCC,IAAAA,mBARmC;AASnCC,IAAAA,gBATmC;AAUnCC,IAAAA,gBAVmC;AAWnCC,IAAAA,6BAXmC;AAYnCC,IAAAA,qBAZmC;AAanCC,IAAAA,gBAbmC;AAcnCC,IAAAA,UAdmC;AAenCC,IAAAA,WAfmC;AAgBnCC,IAAAA,WAhBmC;AAiBnCC,IAAAA,WAjBmC;AAkBnCC,IAAAA,gBAlBmC;AAmBnCC,IAAAA,eAnBmC;AAoBnCC,IAAAA,WApBmC;AAqBnCC,IAAAA,gBArBmC;AAsBnCC,IAAAA,gBA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E,IAAA,KAAK,EAAEuB;AAFT,KAIGT,SAJH,CAJH,GAWG,IAbN,CADF,CADD,GAkBG,IAnBN,EAoBGvB,gBAAgB,KAAK,QAArB,gBACC,oBAAC,2BAAD,QACG,OAAOD,WAAP,KAAuB,UAAvB,GACCqC,kBADD,gBAGC,oBAAC,WAAD;AACE,IAAA,SAAS,EAAE3B,SADb;AAEE,IAAA,KAAK,EAAEuB;AAFT,KAIGT,SAJH,CAJJ,CADD,GAaG,IAjCN,CAtDJ,EA0FG1C,qBAAqB,KAAK2C,SAA1B,gBACC,oBAAC,gCAAD;AAAkC,IAAA,MAAM,EAAE3C;AAA1C,IADD,GAEG,IA5FN,EA6FGsD,kBAAkB,IAAI,IAAtB,gBACC,oBAAC,0BAAD,QACGA,kBADH,CADD,GAIG,IAjGN,EAkGGI,kBAAkB,gBACjB,oBAAC,8BAAD,qBACE,oBAAC,SAAD,EAAepC,sBAAf,CADF,CADiB,GAIf,IAtGN,CAZF,CADF;AAuHD;AAED,MAAMwC,MAAM,GAAG5E,UAAU,CAACoF,MAAX,CAAkB;AAC/BD,EAAAA,GAAG,EAAE;AACHE,IAAAA,aAAa,EAAE,KADZ;AAEHC,IAAAA,UAAU,EAAE;AAFT,GAD0B;AAK/BX,EAAAA,WAAW,EAAE;AACXY,IAAAA,QAAQ,EAAE,UADC;AAEXL,IAAAA,GAAG,EAAE,CAFM;AAGXM,IAAAA,IAAI,EAAE,CAHK;AAIXC,IAAAA,KAAK,EAAE,CAJI;AAKXC,IAAAA,MAAM,EAAE;AALG,GALkB;AAY/Bb,EAAAA,UAAU,EAAE;AACVc,IAAAA,QAAQ,EAAE;AADA;AAZmB,CAAlB,CAAf","sourcesContent":["import { HeaderTitle } from '@react-navigation/elements';\nimport { Route, useTheme } from '@react-navigation/native';\nimport * as React from 'react';\nimport {\n I18nManager,\n Platform,\n StyleSheet,\n TextStyle,\n View,\n} from 'react-native';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\nimport {\n isSearchBarAvailableForCurrentPlatform,\n ScreenStackHeaderBackButtonImage,\n ScreenStackHeaderCenterView,\n ScreenStackHeaderConfig,\n ScreenStackHeaderLeftView,\n ScreenStackHeaderRightView,\n ScreenStackHeaderSearchBarView,\n SearchBar,\n} from 'react-native-screens';\n\nimport type { NativeStackNavigationOptions } from '../types';\nimport { processFonts } from './FontProcessor';\n\ntype Props = NativeStackNavigationOptions & {\n headerHeight: number;\n route: Route<string>;\n canGoBack: boolean;\n};\n\nexport default function HeaderConfig({\n headerHeight,\n headerBackImageSource,\n headerBackButtonMenuEnabled,\n headerBackTitle,\n headerBackTitleStyle,\n headerBackTitleVisible = true,\n headerBackVisible,\n headerShadowVisible,\n headerLargeStyle,\n headerLargeTitle,\n headerLargeTitleShadowVisible,\n headerLargeTitleStyle,\n headerBackground,\n headerLeft,\n headerRight,\n headerShown,\n headerStyle,\n headerBlurEffect,\n headerTintColor,\n headerTitle,\n headerTitleAlign,\n headerTitleStyle,\n headerTransparent,\n headerSearchBarOptions,\n route,\n title,\n canGoBack,\n}: Props): JSX.Element {\n const insets = useSafeAreaInsets();\n\n const { colors } = useTheme();\n const tintColor =\n headerTintColor ?? (Platform.OS === 'ios' ? colors.primary : colors.text);\n\n const headerBackTitleStyleFlattened =\n StyleSheet.flatten(headerBackTitleStyle) || {};\n const headerLargeTitleStyleFlattened =\n StyleSheet.flatten(headerLargeTitleStyle) || {};\n const headerTitleStyleFlattened = StyleSheet.flatten(headerTitleStyle) || {};\n const headerStyleFlattened = StyleSheet.flatten(headerStyle) || {};\n const headerLargeStyleFlattened = StyleSheet.flatten(headerLargeStyle) || {};\n\n const [backTitleFontFamily, largeTitleFontFamily, titleFontFamily] =\n processFonts([\n headerBackTitleStyleFlattened.fontFamily,\n headerLargeTitleStyleFlattened.fontFamily,\n headerTitleStyleFlattened.fontFamily,\n ]);\n\n const titleText = title !== undefined ? title : route.name;\n const titleColor =\n headerTitleStyleFlattened.color ?? headerTintColor ?? colors.text;\n const titleFontSize = headerTitleStyleFlattened.fontSize;\n const titleFontWeight = headerTitleStyleFlattened.fontWeight;\n\n const headerTitleStyleSupported: TextStyle = { color: titleColor };\n\n if (headerTitleStyleFlattened.fontFamily != null) {\n headerTitleStyleSupported.fontFamily = headerTitleStyleFlattened.fontFamily;\n }\n\n if (titleFontSize != null) {\n headerTitleStyleSupported.fontSize = titleFontSize;\n }\n\n if (titleFontWeight != null) {\n headerTitleStyleSupported.fontWeight = titleFontWeight;\n }\n\n const headerLeftElement = headerLeft?.({\n tintColor,\n canGoBack,\n label: headerBackTitle,\n });\n const headerRightElement = headerRight?.({\n tintColor,\n canGoBack,\n });\n const headerTitleElement =\n typeof headerTitle === 'function'\n ? headerTitle({ tintColor, children: titleText })\n : null;\n\n const supportsHeaderSearchBar =\n typeof isSearchBarAvailableForCurrentPlatform === 'boolean'\n ? isSearchBarAvailableForCurrentPlatform\n : // Fallback for older versions of react-native-screens\n Platform.OS === 'ios' && SearchBar != null;\n\n const hasHeaderSearchBar =\n supportsHeaderSearchBar && headerSearchBarOptions != null;\n\n if (headerSearchBarOptions != null && !supportsHeaderSearchBar) {\n throw new Error(\n `The current version of 'react-native-screens' doesn't support SearchBar in the header. Please update to the latest version to use this option.`\n );\n }\n\n /**\n * We need to set this in if:\n * - Back button should stay visible when `headerLeft` is specified\n * - If `headerTitle` for Android is specified, so we only need to remove the title and keep the back button\n */\n const backButtonInCustomView = headerBackVisible\n ? headerLeftElement != null\n : Platform.OS === 'android' && headerTitleElement != null;\n\n const translucent =\n headerBackground != null ||\n headerTransparent ||\n // When using a SearchBar or large title, the header needs to be translucent for it to work on iOS\n ((hasHeaderSearchBar || headerLargeTitle) &&\n Platform.OS === 'ios' &&\n headerTransparent !== false);\n\n return (\n <>\n {headerBackground != null ? (\n <View\n style={[\n styles.background,\n headerTransparent ? styles.translucent : null,\n { height: headerHeight },\n ]}\n >\n {headerBackground()}\n </View>\n ) : null}\n <ScreenStackHeaderConfig\n backButtonInCustomView={backButtonInCustomView}\n backgroundColor={\n headerStyleFlattened.backgroundColor ??\n (headerBackground != null || headerTransparent\n ? 'transparent'\n : colors.card)\n }\n backTitle={headerBackTitleVisible ? headerBackTitle : ' '}\n backTitleFontFamily={backTitleFontFamily}\n backTitleFontSize={headerBackTitleStyleFlattened.fontSize}\n blurEffect={headerBlurEffect}\n color={tintColor}\n direction={I18nManager.isRTL ? 'rtl' : 'ltr'}\n disableBackButtonMenu={headerBackButtonMenuEnabled === false}\n hidden={headerShown === false}\n hideBackButton={headerBackVisible === false}\n hideShadow={\n headerShadowVisible === false ||\n headerBackground != null ||\n headerTransparent\n }\n largeTitle={headerLargeTitle}\n largeTitleBackgroundColor={headerLargeStyleFlattened.backgroundColor}\n largeTitleColor={headerLargeTitleStyleFlattened.color}\n largeTitleFontFamily={largeTitleFontFamily}\n largeTitleFontSize={headerLargeTitleStyleFlattened.fontSize}\n largeTitleFontWeight={headerLargeTitleStyleFlattened.fontWeight}\n largeTitleHideShadow={headerLargeTitleShadowVisible === false}\n title={typeof headerTitle === 'string' ? headerTitle : titleText}\n titleColor={titleColor}\n titleFontFamily={titleFontFamily}\n titleFontSize={titleFontSize}\n titleFontWeight={titleFontWeight}\n topInsetEnabled={insets.top !== 0}\n translucent={\n // This defaults to `true`, so we can't pass `undefined`\n translucent === true\n }\n >\n {Platform.OS === 'ios' ? (\n <>\n {headerLeftElement != null ? (\n <ScreenStackHeaderLeftView>\n {headerLeftElement}\n </ScreenStackHeaderLeftView>\n ) : null}\n {headerTitleElement != null ? (\n <ScreenStackHeaderCenterView>\n {headerTitleElement}\n </ScreenStackHeaderCenterView>\n ) : null}\n </>\n ) : (\n <>\n {headerLeftElement != null || typeof headerTitle === 'function' ? (\n <ScreenStackHeaderLeftView>\n <View style={styles.row}>\n {headerLeftElement}\n {headerTitleAlign !== 'center' ? (\n typeof headerTitle === 'function' ? (\n headerTitleElement\n ) : (\n <HeaderTitle\n tintColor={tintColor}\n style={headerTitleStyleSupported}\n >\n {titleText}\n </HeaderTitle>\n )\n ) : null}\n </View>\n </ScreenStackHeaderLeftView>\n ) : null}\n {headerTitleAlign === 'center' ? (\n <ScreenStackHeaderCenterView>\n {typeof headerTitle === 'function' ? (\n headerTitleElement\n ) : (\n <HeaderTitle\n tintColor={tintColor}\n style={headerTitleStyleSupported}\n >\n {titleText}\n </HeaderTitle>\n )}\n </ScreenStackHeaderCenterView>\n ) : null}\n </>\n )}\n {headerBackImageSource !== undefined ? (\n <ScreenStackHeaderBackButtonImage source={headerBackImageSource} />\n ) : null}\n {headerRightElement != null ? (\n <ScreenStackHeaderRightView>\n {headerRightElement}\n </ScreenStackHeaderRightView>\n ) : null}\n {hasHeaderSearchBar ? (\n <ScreenStackHeaderSearchBarView>\n <SearchBar {...headerSearchBarOptions} />\n </ScreenStackHeaderSearchBarView>\n ) : null}\n </ScreenStackHeaderConfig>\n </>\n );\n}\n\nconst styles = StyleSheet.create({\n row: {\n flexDirection: 'row',\n alignItems: 'center',\n },\n translucent: {\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n zIndex: 1,\n },\n background: {\n overflow: 'hidden',\n },\n});\n"]}
|