@react-navigation/stack 8.0.0-alpha.3 → 8.0.0-alpha.30
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/module/index.js.map +1 -1
- package/lib/module/navigators/createStackNavigator.js +3 -7
- package/lib/module/navigators/createStackNavigator.js.map +1 -1
- package/lib/module/utils/useCardAnimation.js +1 -1
- package/lib/module/utils/useCardAnimation.js.map +1 -1
- package/lib/module/utils/useGestureHandlerRef.js +1 -1
- package/lib/module/utils/useGestureHandlerRef.js.map +1 -1
- package/lib/module/utils/useKeyboardManager.js +50 -26
- package/lib/module/utils/useKeyboardManager.js.map +1 -1
- package/lib/module/views/Header/Header.js +2 -2
- package/lib/module/views/Header/Header.js.map +1 -1
- package/lib/module/views/Header/HeaderContainer.js +32 -16
- package/lib/module/views/Header/HeaderContainer.js.map +1 -1
- package/lib/module/views/Header/HeaderSegment.js +2 -2
- package/lib/module/views/Header/HeaderSegment.js.map +1 -1
- package/lib/module/views/Stack/Card.js +25 -20
- package/lib/module/views/Stack/Card.js.map +1 -1
- package/lib/module/views/Stack/CardA11yWrapper.js +6 -7
- package/lib/module/views/Stack/CardA11yWrapper.js.map +1 -1
- package/lib/module/views/Stack/CardContainer.js +18 -19
- package/lib/module/views/Stack/CardContainer.js.map +1 -1
- package/lib/module/views/Stack/CardStack.js +105 -133
- package/lib/module/views/Stack/CardStack.js.map +1 -1
- package/lib/module/views/Stack/StackView.js +82 -49
- package/lib/module/views/Stack/StackView.js.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/navigators/createStackNavigator.d.ts +8 -14
- package/lib/typescript/src/navigators/createStackNavigator.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +46 -53
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/gestureActivationCriteria.d.ts +1 -1
- package/lib/typescript/src/utils/gestureActivationCriteria.d.ts.map +1 -1
- package/lib/typescript/src/utils/useKeyboardManager.d.ts +9 -2
- package/lib/typescript/src/utils/useKeyboardManager.d.ts.map +1 -1
- package/lib/typescript/src/views/Header/Header.d.ts +1 -1
- package/lib/typescript/src/views/Header/Header.d.ts.map +1 -1
- package/lib/typescript/src/views/Header/HeaderContainer.d.ts +2 -1
- package/lib/typescript/src/views/Header/HeaderContainer.d.ts.map +1 -1
- package/lib/typescript/src/views/Header/HeaderSegment.d.ts +2 -2
- package/lib/typescript/src/views/Header/HeaderSegment.d.ts.map +1 -1
- package/lib/typescript/src/views/Stack/Card.d.ts +3 -3
- package/lib/typescript/src/views/Stack/Card.d.ts.map +1 -1
- package/lib/typescript/src/views/Stack/CardA11yWrapper.d.ts +2 -2
- package/lib/typescript/src/views/Stack/CardA11yWrapper.d.ts.map +1 -1
- package/lib/typescript/src/views/Stack/CardContainer.d.ts +2 -2
- package/lib/typescript/src/views/Stack/CardContainer.d.ts.map +1 -1
- package/lib/typescript/src/views/Stack/CardStack.d.ts +1 -1
- package/lib/typescript/src/views/Stack/CardStack.d.ts.map +1 -1
- package/lib/typescript/src/views/Stack/StackView.d.ts +6 -9
- package/lib/typescript/src/views/Stack/StackView.d.ts.map +1 -1
- package/package.json +20 -22
- package/src/index.tsx +1 -0
- package/src/navigators/createStackNavigator.tsx +9 -40
- package/src/types.tsx +73 -73
- package/src/utils/gestureActivationCriteria.tsx +1 -1
- package/src/utils/useCardAnimation.tsx +1 -1
- package/src/utils/useGestureHandlerRef.tsx +1 -1
- package/src/utils/useKeyboardManager.tsx +67 -33
- package/src/views/Header/Header.tsx +2 -2
- package/src/views/Header/HeaderContainer.tsx +37 -18
- package/src/views/Header/HeaderSegment.tsx +4 -4
- package/src/views/Stack/Card.tsx +32 -23
- package/src/views/Stack/CardA11yWrapper.tsx +40 -51
- package/src/views/Stack/CardContainer.tsx +10 -21
- package/src/views/Stack/CardStack.tsx +291 -328
- package/src/views/Stack/StackView.tsx +138 -66
package/src/types.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
HeaderBackButton,
|
|
3
2
|
HeaderBackButtonDisplayMode,
|
|
4
3
|
HeaderBackButtonProps,
|
|
5
4
|
HeaderOptions,
|
|
6
5
|
HeaderTitleProps,
|
|
6
|
+
Icon,
|
|
7
7
|
} from '@react-navigation/elements';
|
|
8
8
|
import type {
|
|
9
9
|
DefaultNavigatorOptions,
|
|
@@ -138,12 +138,12 @@ export type SceneProgress = {
|
|
|
138
138
|
* Progress value for the screen after this one in the stack.
|
|
139
139
|
* This can be `undefined` in case the screen animating is the last one.
|
|
140
140
|
*/
|
|
141
|
-
next?: Animated.AnimatedInterpolation<number
|
|
141
|
+
next?: Animated.AnimatedInterpolation<number> | undefined;
|
|
142
142
|
/**
|
|
143
143
|
* Progress value for the screen before this one in the stack.
|
|
144
144
|
* This can be `undefined` in case the screen animating is the first one.
|
|
145
145
|
*/
|
|
146
|
-
previous?: Animated.AnimatedInterpolation<number
|
|
146
|
+
previous?: Animated.AnimatedInterpolation<number> | undefined;
|
|
147
147
|
};
|
|
148
148
|
|
|
149
149
|
export type StackHeaderMode = 'float' | 'screen';
|
|
@@ -187,14 +187,14 @@ export type StackHeaderOptions = Omit<
|
|
|
187
187
|
* Defaults to the previous screen's title, or "Back" if there's not enough space.
|
|
188
188
|
* Use `headerBackButtonDisplayMode` to customize the behavior.
|
|
189
189
|
*/
|
|
190
|
-
headerBackTitle?: string;
|
|
190
|
+
headerBackTitle?: string | undefined;
|
|
191
191
|
/**
|
|
192
192
|
* Title string used by the back button when `headerBackTitle` doesn't fit on the screen.
|
|
193
193
|
* Use `headerBackButtonDisplayMode` to customize the behavior.
|
|
194
194
|
*
|
|
195
195
|
* Defaults to "Back".
|
|
196
196
|
*/
|
|
197
|
-
headerBackTruncatedTitle?: string;
|
|
197
|
+
headerBackTruncatedTitle?: string | undefined;
|
|
198
198
|
/**
|
|
199
199
|
* How the back button displays icon and title.
|
|
200
200
|
*
|
|
@@ -211,27 +211,47 @@ export type StackHeaderOptions = Omit<
|
|
|
211
211
|
*/
|
|
212
212
|
headerBackTitleStyle?: StyleProp<TextStyle>;
|
|
213
213
|
/**
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
|
|
218
|
-
|
|
214
|
+
* Icon to display in the header in the back button.
|
|
215
|
+
*
|
|
216
|
+
* Supported types:
|
|
217
|
+
* - image: custom image source
|
|
218
|
+
* - sfSymbol: SF Symbol icon (iOS only)
|
|
219
|
+
* - materialSymbol: material symbol icon (Android only)
|
|
220
|
+
* - React Node: function that returns a React Element
|
|
221
|
+
*
|
|
222
|
+
* Defaults to back icon image for the platform
|
|
223
|
+
* - A chevron on iOS
|
|
224
|
+
* - An arrow on Android
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```js
|
|
228
|
+
* headerBackIcon: {
|
|
229
|
+
* type: 'image',
|
|
230
|
+
* source: require('./back-icon.png'),
|
|
231
|
+
* }
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
headerBackIcon?:
|
|
235
|
+
| Icon
|
|
236
|
+
| ((props: { tintColor: ColorValue | undefined }) => React.ReactNode);
|
|
219
237
|
};
|
|
220
238
|
|
|
221
239
|
export type StackHeaderProps = {
|
|
222
240
|
/**
|
|
223
241
|
* Options for the back button.
|
|
224
242
|
*/
|
|
225
|
-
back?:
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
243
|
+
back?:
|
|
244
|
+
| {
|
|
245
|
+
/**
|
|
246
|
+
* Title of the previous screen.
|
|
247
|
+
*/
|
|
248
|
+
title: string | undefined;
|
|
249
|
+
/**
|
|
250
|
+
* The `href` to use for the anchor tag on web
|
|
251
|
+
*/
|
|
252
|
+
href: string | undefined;
|
|
253
|
+
}
|
|
254
|
+
| undefined;
|
|
235
255
|
/**
|
|
236
256
|
* Animated nodes representing the progress of the animation.
|
|
237
257
|
*/
|
|
@@ -258,26 +278,26 @@ export type StackHeaderRightProps = {
|
|
|
258
278
|
/**
|
|
259
279
|
* Tint color for the header button.
|
|
260
280
|
*/
|
|
261
|
-
tintColor?: ColorValue;
|
|
281
|
+
tintColor?: ColorValue | undefined;
|
|
262
282
|
/**
|
|
263
283
|
* Color for material ripple (Android >= 5.0 only).
|
|
264
284
|
*/
|
|
265
|
-
pressColor?: ColorValue;
|
|
285
|
+
pressColor?: ColorValue | undefined;
|
|
266
286
|
/**
|
|
267
287
|
* Opacity when the button is pressed, used when ripple is not supported.
|
|
268
288
|
*/
|
|
269
|
-
pressOpacity?: number;
|
|
289
|
+
pressOpacity?: number | undefined;
|
|
270
290
|
/**
|
|
271
291
|
* Whether it's possible to navigate back in stack.
|
|
272
292
|
*/
|
|
273
|
-
canGoBack?: boolean;
|
|
293
|
+
canGoBack?: boolean | undefined;
|
|
274
294
|
};
|
|
275
295
|
|
|
276
296
|
export type StackHeaderLeftProps = HeaderBackButtonProps & {
|
|
277
297
|
/**
|
|
278
298
|
* Whether it's possible to navigate back in stack.
|
|
279
299
|
*/
|
|
280
|
-
canGoBack?: boolean;
|
|
300
|
+
canGoBack?: boolean | undefined;
|
|
281
301
|
};
|
|
282
302
|
|
|
283
303
|
export type StackDescriptor = Descriptor<
|
|
@@ -326,15 +346,6 @@ export type StackNavigationOptions = StackHeaderOptions &
|
|
|
326
346
|
/**
|
|
327
347
|
* Style object for the card in stack.
|
|
328
348
|
* You can provide a custom background color to use instead of the default background here.
|
|
329
|
-
*
|
|
330
|
-
* You can also specify `{ backgroundColor: 'transparent' }` to make the previous screen visible underneath.
|
|
331
|
-
* This is useful to implement things like modal dialogs.
|
|
332
|
-
*
|
|
333
|
-
* You should also specify `detachPreviousScreen: false` in options when using a transparent background
|
|
334
|
-
* so that the previous screen isn't detached and stays below the current screen.
|
|
335
|
-
*
|
|
336
|
-
* You might also need to change the animation of the screen using `cardStyleInterpolator`
|
|
337
|
-
* so that the previous screen isn't transformed or invisible.
|
|
338
349
|
*/
|
|
339
350
|
cardStyle?: StyleProp<ViewStyle>;
|
|
340
351
|
/**
|
|
@@ -348,7 +359,6 @@ export type StackNavigationOptions = StackHeaderOptions &
|
|
|
348
359
|
* - `transparentModal`: Similar to `modal`. This changes following things:
|
|
349
360
|
* - Sets `headerMode` to `screen` for the screen unless specified otherwise.
|
|
350
361
|
* - Sets background color of the screen to transparent, so previous screen is visible
|
|
351
|
-
* - Adjusts the `detachPreviousScreen` option so that the previous screen stays rendered.
|
|
352
362
|
* - Prevents the previous screen from animating from its last position.
|
|
353
363
|
* - Changes the screen animation to a vertical slide animation.
|
|
354
364
|
*
|
|
@@ -390,43 +400,29 @@ export type StackNavigationOptions = StackHeaderOptions &
|
|
|
390
400
|
* Not supported on Web.
|
|
391
401
|
*/
|
|
392
402
|
gestureVelocityImpact?: number;
|
|
393
|
-
/**
|
|
394
|
-
* Whether to detach the previous screen from the view hierarchy to save memory.
|
|
395
|
-
* Set it to `false` if you need the previous screen to be seen through the active screen.
|
|
396
|
-
* Only applicable if `detachInactiveScreens` isn't set to `false`.
|
|
397
|
-
* Defaults to `false` for the last screen for modals, otherwise `true`.
|
|
398
|
-
*/
|
|
399
|
-
detachPreviousScreen?: boolean;
|
|
400
403
|
/**
|
|
401
404
|
* If `false`, the keyboard will NOT automatically dismiss when navigating to a new screen from this screen.
|
|
402
405
|
* Defaults to `true`.
|
|
403
406
|
*/
|
|
404
407
|
keyboardHandlingEnabled?: boolean;
|
|
408
|
+
|
|
405
409
|
/**
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
410
|
+
* What should happen when screens become inactive.
|
|
411
|
+
* - `pause`: Effects are cleaned up
|
|
412
|
+
* - `unmount`: Screen is unmounted
|
|
413
|
+
* - `none`: Screen renders normally
|
|
409
414
|
*
|
|
410
|
-
*
|
|
411
|
-
*/
|
|
412
|
-
freezeOnBlur?: boolean;
|
|
413
|
-
/**
|
|
414
|
-
* Whether the home indicator should prefer to stay hidden on this screen. Defaults to `false`.
|
|
415
|
+
* Defaults to `pause`.
|
|
415
416
|
*
|
|
416
|
-
*
|
|
417
|
+
* Preloaded screens won't be paused until after navigated to.
|
|
418
|
+
* This makes sure that effects are run to initialize the screen.
|
|
419
|
+
*
|
|
420
|
+
* Screens with nested navigators and last 2 screens won't be unmounted.
|
|
417
421
|
*/
|
|
418
|
-
|
|
422
|
+
inactiveBehavior?: 'pause' | 'unmount' | 'none' | undefined;
|
|
419
423
|
};
|
|
420
424
|
|
|
421
|
-
export type StackNavigationConfig = {
|
|
422
|
-
/**
|
|
423
|
-
* Whether inactive screens should be detached from the view hierarchy to save memory.
|
|
424
|
-
* This will have no effect if you disable `react-native-screens`.
|
|
425
|
-
*
|
|
426
|
-
* Defaults to `true`.
|
|
427
|
-
*/
|
|
428
|
-
detachInactiveScreens?: boolean;
|
|
429
|
-
};
|
|
425
|
+
export type StackNavigationConfig = {};
|
|
430
426
|
|
|
431
427
|
export type TransitionSpec =
|
|
432
428
|
| {
|
|
@@ -458,12 +454,14 @@ export type StackCardInterpolationProps = {
|
|
|
458
454
|
* Values for the screen after this one in the stack.
|
|
459
455
|
* This can be `undefined` in case the screen animating is the last one.
|
|
460
456
|
*/
|
|
461
|
-
next?:
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
457
|
+
next?:
|
|
458
|
+
| {
|
|
459
|
+
/**
|
|
460
|
+
* Animated node representing the progress value of the next screen.
|
|
461
|
+
*/
|
|
462
|
+
progress: Animated.AnimatedInterpolation<number>;
|
|
463
|
+
}
|
|
464
|
+
| undefined;
|
|
467
465
|
/**
|
|
468
466
|
* The index of the card with this interpolation in the stack.
|
|
469
467
|
*/
|
|
@@ -537,12 +535,14 @@ export type StackHeaderInterpolationProps = {
|
|
|
537
535
|
* Values for the screen after this one in the stack.
|
|
538
536
|
* This can be `undefined` in case the screen animating is the last one.
|
|
539
537
|
*/
|
|
540
|
-
next?:
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
538
|
+
next?:
|
|
539
|
+
| {
|
|
540
|
+
/**
|
|
541
|
+
* Animated node representing the progress value of the next screen.
|
|
542
|
+
*/
|
|
543
|
+
progress: Animated.AnimatedInterpolation<number>;
|
|
544
|
+
}
|
|
545
|
+
| undefined;
|
|
546
546
|
/**
|
|
547
547
|
* Writing direction of the layout.
|
|
548
548
|
*/
|
|
@@ -17,7 +17,7 @@ export const gestureActivationCriteria = ({
|
|
|
17
17
|
}: {
|
|
18
18
|
direction: LocaleDirection;
|
|
19
19
|
gestureDirection: GestureDirection;
|
|
20
|
-
gestureResponseDistance?: number;
|
|
20
|
+
gestureResponseDistance?: number | undefined;
|
|
21
21
|
layout: Layout;
|
|
22
22
|
}) => {
|
|
23
23
|
const enableTrackpadTwoFingerGesture = true;
|
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import { CardAnimationContext } from './CardAnimationContext';
|
|
4
4
|
|
|
5
5
|
export function useCardAnimation() {
|
|
6
|
-
const animation = React.
|
|
6
|
+
const animation = React.use(CardAnimationContext);
|
|
7
7
|
|
|
8
8
|
if (animation === undefined) {
|
|
9
9
|
throw new Error(
|
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import { GestureHandlerRefContext } from './GestureHandlerRefContext';
|
|
4
4
|
|
|
5
5
|
export function useGestureHandlerRef() {
|
|
6
|
-
const ref = React.
|
|
6
|
+
const ref = React.use(GestureHandlerRefContext);
|
|
7
7
|
|
|
8
8
|
if (ref === undefined) {
|
|
9
9
|
throw new Error(
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { type HostInstance, Keyboard, TextInput } from 'react-native';
|
|
3
3
|
|
|
4
|
-
export function useKeyboardManager(
|
|
4
|
+
export function useKeyboardManager({
|
|
5
|
+
enabled,
|
|
6
|
+
focused,
|
|
7
|
+
}: {
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
focused: boolean;
|
|
10
|
+
}) {
|
|
5
11
|
// Numeric id of the previously focused text input
|
|
6
12
|
// When a gesture didn't change the tab, we can restore the focused input with this
|
|
7
13
|
const previouslyFocusedTextInputRef = React.useRef<HostInstance>(undefined);
|
|
8
14
|
const startTimestampRef = React.useRef<number>(0);
|
|
9
|
-
const keyboardTimeoutRef =
|
|
15
|
+
const keyboardTimeoutRef =
|
|
16
|
+
React.useRef<ReturnType<typeof setTimeout>>(undefined);
|
|
17
|
+
const enabledRef = React.useRef(enabled);
|
|
10
18
|
|
|
11
19
|
const clearKeyboardTimeout = React.useCallback(() => {
|
|
12
20
|
if (keyboardTimeoutRef.current !== undefined) {
|
|
@@ -16,7 +24,7 @@ export function useKeyboardManager(isEnabled: () => boolean) {
|
|
|
16
24
|
}, []);
|
|
17
25
|
|
|
18
26
|
const onPageChangeStart = React.useCallback(() => {
|
|
19
|
-
if (!
|
|
27
|
+
if (!enabledRef.current) {
|
|
20
28
|
return;
|
|
21
29
|
}
|
|
22
30
|
|
|
@@ -32,37 +40,10 @@ export function useKeyboardManager(isEnabled: () => boolean) {
|
|
|
32
40
|
|
|
33
41
|
// Store timestamp for touch start
|
|
34
42
|
startTimestampRef.current = Date.now();
|
|
35
|
-
}, [clearKeyboardTimeout
|
|
36
|
-
|
|
37
|
-
const onPageChangeConfirm = React.useCallback(
|
|
38
|
-
(force: boolean) => {
|
|
39
|
-
if (!isEnabled()) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
clearKeyboardTimeout();
|
|
44
|
-
|
|
45
|
-
if (force) {
|
|
46
|
-
// Always dismiss input, even if we don't have a ref to it
|
|
47
|
-
// We might not have the ref if onPageChangeStart was never called
|
|
48
|
-
// This can happen if page change was not from a gesture
|
|
49
|
-
Keyboard.dismiss();
|
|
50
|
-
} else {
|
|
51
|
-
const input = previouslyFocusedTextInputRef.current;
|
|
52
|
-
|
|
53
|
-
// Dismiss the keyboard only if an input was a focused before
|
|
54
|
-
// This makes sure we don't dismiss input on going back and focusing an input
|
|
55
|
-
input?.blur();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Cleanup the ID on successful page change
|
|
59
|
-
previouslyFocusedTextInputRef.current = undefined;
|
|
60
|
-
},
|
|
61
|
-
[clearKeyboardTimeout, isEnabled]
|
|
62
|
-
);
|
|
43
|
+
}, [clearKeyboardTimeout]);
|
|
63
44
|
|
|
64
45
|
const onPageChangeCancel = React.useCallback(() => {
|
|
65
|
-
if (!
|
|
46
|
+
if (!enabledRef.current) {
|
|
66
47
|
return;
|
|
67
48
|
}
|
|
68
49
|
|
|
@@ -89,7 +70,60 @@ export function useKeyboardManager(isEnabled: () => boolean) {
|
|
|
89
70
|
previouslyFocusedTextInputRef.current = undefined;
|
|
90
71
|
}
|
|
91
72
|
}
|
|
92
|
-
}, [clearKeyboardTimeout
|
|
73
|
+
}, [clearKeyboardTimeout]);
|
|
74
|
+
|
|
75
|
+
const onPageChangeConfirm = React.useCallback(
|
|
76
|
+
({
|
|
77
|
+
gesture,
|
|
78
|
+
active,
|
|
79
|
+
closing,
|
|
80
|
+
}: {
|
|
81
|
+
gesture: boolean;
|
|
82
|
+
active: boolean;
|
|
83
|
+
closing: boolean;
|
|
84
|
+
}) => {
|
|
85
|
+
if (!enabledRef.current) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!closing) {
|
|
90
|
+
onPageChangeCancel();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
clearKeyboardTimeout();
|
|
95
|
+
|
|
96
|
+
if (!gesture) {
|
|
97
|
+
// Always dismiss input, even if we don't have a ref to it
|
|
98
|
+
// We might not have the ref if onPageChangeStart was never called
|
|
99
|
+
// This can happen if page change was not from a gesture
|
|
100
|
+
Keyboard.dismiss();
|
|
101
|
+
} else if (active) {
|
|
102
|
+
const input = previouslyFocusedTextInputRef.current;
|
|
103
|
+
|
|
104
|
+
// Dismiss the keyboard only if an input was a focused before
|
|
105
|
+
// This makes sure we don't dismiss input on going back and focusing an input
|
|
106
|
+
input?.blur();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Cleanup the ID on successful page change
|
|
110
|
+
previouslyFocusedTextInputRef.current = undefined;
|
|
111
|
+
},
|
|
112
|
+
[clearKeyboardTimeout, onPageChangeCancel]
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
// Dismiss keyboard when screen loses focus (e.g. when pushing a new screen).
|
|
116
|
+
// This handles the "navigate forward" case so we don't dismiss the new screen's
|
|
117
|
+
// auto-focused input from handleTransition.
|
|
118
|
+
React.useLayoutEffect(() => {
|
|
119
|
+
if (enabledRef.current && !focused) {
|
|
120
|
+
Keyboard.dismiss();
|
|
121
|
+
}
|
|
122
|
+
}, [focused]);
|
|
123
|
+
|
|
124
|
+
React.useLayoutEffect(() => {
|
|
125
|
+
enabledRef.current = enabled;
|
|
126
|
+
});
|
|
93
127
|
|
|
94
128
|
React.useEffect(() => {
|
|
95
129
|
return () => clearKeyboardTimeout();
|
|
@@ -41,8 +41,8 @@ export const Header = React.memo(function Header({
|
|
|
41
41
|
[navigation, route.key]
|
|
42
42
|
);
|
|
43
43
|
|
|
44
|
-
const isModal = React.
|
|
45
|
-
const isParentHeaderShown = React.
|
|
44
|
+
const isModal = React.use(ModalPresentationContext);
|
|
45
|
+
const isParentHeaderShown = React.use(HeaderShownContext);
|
|
46
46
|
|
|
47
47
|
const statusBarHeight =
|
|
48
48
|
options.headerStatusBarHeight !== undefined
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getHeaderTitle, HeaderBackContext } from '@react-navigation/elements';
|
|
2
|
+
import { ActivityView } from '@react-navigation/elements/internal';
|
|
2
3
|
import {
|
|
3
4
|
NavigationProvider,
|
|
4
5
|
type ParamListBase,
|
|
@@ -27,6 +28,7 @@ export type Props = {
|
|
|
27
28
|
scenes: (Scene | undefined)[];
|
|
28
29
|
getPreviousScene: (props: { route: Route<string> }) => Scene | undefined;
|
|
29
30
|
getFocusedRoute: () => Route<string>;
|
|
31
|
+
contentHeight: number | undefined;
|
|
30
32
|
onContentHeightChange?: (props: {
|
|
31
33
|
route: Route<string>;
|
|
32
34
|
height: number;
|
|
@@ -39,11 +41,12 @@ export function HeaderContainer({
|
|
|
39
41
|
scenes,
|
|
40
42
|
getPreviousScene,
|
|
41
43
|
getFocusedRoute,
|
|
44
|
+
contentHeight,
|
|
42
45
|
onContentHeightChange,
|
|
43
46
|
style,
|
|
44
47
|
}: Props) {
|
|
45
48
|
const focusedRoute = getFocusedRoute();
|
|
46
|
-
const parentHeaderBack = React.
|
|
49
|
+
const parentHeaderBack = React.use(HeaderBackContext);
|
|
47
50
|
const { buildHref } = useLinkBuilder();
|
|
48
51
|
|
|
49
52
|
return (
|
|
@@ -144,31 +147,47 @@ export function HeaderContainer({
|
|
|
144
147
|
route={scene.descriptor.route}
|
|
145
148
|
>
|
|
146
149
|
<View
|
|
147
|
-
onLayout={
|
|
148
|
-
onContentHeightChange
|
|
149
|
-
? (e) => {
|
|
150
|
-
const { height } = e.nativeEvent.layout;
|
|
151
|
-
|
|
152
|
-
onContentHeightChange({
|
|
153
|
-
route: scene.descriptor.route,
|
|
154
|
-
height,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
: undefined
|
|
158
|
-
}
|
|
159
|
-
aria-hidden={!isFocused}
|
|
160
150
|
style={[
|
|
161
|
-
// Avoid positioning the focused header
|
|
151
|
+
// Avoid absolutely positioning the focused header unnecessarily
|
|
162
152
|
// Otherwise accessibility tools don't seem to be able to find it
|
|
163
153
|
(mode === 'float' && !isFocused) || headerTransparent
|
|
164
|
-
?
|
|
154
|
+
? [
|
|
155
|
+
styles.absolute,
|
|
156
|
+
mode === 'screen'
|
|
157
|
+
? // For transparent headers, specify a min height
|
|
158
|
+
// This is needed for screen readers, and testing tools on Android
|
|
159
|
+
// For float header, it's handled in CardStack
|
|
160
|
+
{ minHeight: contentHeight }
|
|
161
|
+
: null,
|
|
162
|
+
]
|
|
165
163
|
: null,
|
|
166
164
|
{
|
|
167
165
|
pointerEvents: isFocused ? 'box-none' : 'none',
|
|
168
166
|
},
|
|
169
167
|
]}
|
|
170
168
|
>
|
|
171
|
-
|
|
169
|
+
<View
|
|
170
|
+
onLayout={
|
|
171
|
+
onContentHeightChange
|
|
172
|
+
? (e) => {
|
|
173
|
+
const { height } = e.nativeEvent.layout;
|
|
174
|
+
|
|
175
|
+
onContentHeightChange({
|
|
176
|
+
route: scene.descriptor.route,
|
|
177
|
+
height,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
: undefined
|
|
181
|
+
}
|
|
182
|
+
style={{ pointerEvents: 'box-none' }}
|
|
183
|
+
>
|
|
184
|
+
<ActivityView
|
|
185
|
+
mode={isFocused ? 'normal' : 'inert'}
|
|
186
|
+
visible={true}
|
|
187
|
+
>
|
|
188
|
+
{header !== undefined ? header(props) : <Header {...props} />}
|
|
189
|
+
</ActivityView>
|
|
190
|
+
</View>
|
|
172
191
|
</View>
|
|
173
192
|
</NavigationProvider>
|
|
174
193
|
);
|
|
@@ -181,7 +200,7 @@ const styles = StyleSheet.create({
|
|
|
181
200
|
container: {
|
|
182
201
|
pointerEvents: 'box-none',
|
|
183
202
|
},
|
|
184
|
-
|
|
203
|
+
absolute: {
|
|
185
204
|
position: 'absolute',
|
|
186
205
|
top: 0,
|
|
187
206
|
start: 0,
|
|
@@ -20,8 +20,8 @@ type Props = Omit<StackHeaderOptions, 'headerStatusBarHeight'> & {
|
|
|
20
20
|
headerStatusBarHeight: number;
|
|
21
21
|
title: string;
|
|
22
22
|
modal: boolean;
|
|
23
|
-
onGoBack?: () => void;
|
|
24
|
-
backHref?: string;
|
|
23
|
+
onGoBack?: (() => void) | undefined;
|
|
24
|
+
backHref?: string | undefined;
|
|
25
25
|
progress: SceneProgress;
|
|
26
26
|
styleInterpolator: StackHeaderStyleInterpolator;
|
|
27
27
|
};
|
|
@@ -40,7 +40,7 @@ export function HeaderSegment(props: Props) {
|
|
|
40
40
|
? (props: HeaderBackButtonProps) => <HeaderBackButton {...props} />
|
|
41
41
|
: undefined,
|
|
42
42
|
headerRight: right,
|
|
43
|
-
|
|
43
|
+
headerBackIcon,
|
|
44
44
|
headerBackTitle,
|
|
45
45
|
headerBackButtonDisplayMode,
|
|
46
46
|
headerBackTruncatedTitle,
|
|
@@ -93,7 +93,7 @@ export function HeaderSegment(props: Props) {
|
|
|
93
93
|
left({
|
|
94
94
|
...props,
|
|
95
95
|
href: backHref,
|
|
96
|
-
|
|
96
|
+
icon: headerBackIcon,
|
|
97
97
|
accessibilityLabel: headerBackAccessibilityLabel,
|
|
98
98
|
testID: headerBackTestID,
|
|
99
99
|
allowFontScaling: headerBackAllowFontScaling,
|