@react-navigation/stack 8.0.0-alpha.6 → 8.0.0-alpha.60
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/TransitionConfigs/CardStyleInterpolators.js +280 -84
- package/lib/module/TransitionConfigs/CardStyleInterpolators.js.map +1 -1
- package/lib/module/TransitionConfigs/HeaderStyleInterpolators.js +11 -44
- package/lib/module/TransitionConfigs/HeaderStyleInterpolators.js.map +1 -1
- package/lib/module/TransitionConfigs/TransitionEasings.js +71 -0
- package/lib/module/TransitionConfigs/TransitionEasings.js.map +1 -0
- package/lib/module/TransitionConfigs/TransitionPresets.js +50 -10
- package/lib/module/TransitionConfigs/TransitionPresets.js.map +1 -1
- package/lib/module/TransitionConfigs/TransitionSpecs.js +69 -34
- package/lib/module/TransitionConfigs/TransitionSpecs.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/navigators/createStackNavigator.js +37 -33
- package/lib/module/navigators/createStackNavigator.js.map +1 -1
- package/lib/module/utils/GestureHandlerContext.js +5 -0
- package/lib/module/utils/GestureHandlerContext.js.map +1 -0
- package/lib/module/utils/gestureActivationCriteria.js +10 -8
- package/lib/module/utils/gestureActivationCriteria.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/useGestureHandler.js +9 -0
- package/lib/module/utils/useGestureHandler.js.map +1 -0
- package/lib/module/utils/useKeyboardManager.js +71 -26
- package/lib/module/utils/useKeyboardManager.js.map +1 -1
- package/lib/module/views/GestureHandler.js +15 -14
- package/lib/module/views/GestureHandler.js.map +1 -1
- package/lib/module/views/GestureHandlerNative.js +16 -10
- package/lib/module/views/GestureHandlerNative.js.map +1 -1
- package/lib/module/views/Header/Header.js +4 -2
- package/lib/module/views/Header/Header.js.map +1 -1
- package/lib/module/views/Header/HeaderContainer.js +60 -21
- package/lib/module/views/Header/HeaderContainer.js.map +1 -1
- package/lib/module/views/Header/HeaderSegment.js +6 -9
- package/lib/module/views/Header/HeaderSegment.js.map +1 -1
- package/lib/module/views/Stack/Card.js +170 -123
- package/lib/module/views/Stack/Card.js.map +1 -1
- package/lib/module/views/Stack/CardContainer.js +96 -98
- package/lib/module/views/Stack/CardContainer.js.map +1 -1
- package/lib/module/views/Stack/CardContent.js +10 -37
- package/lib/module/views/Stack/CardContent.js.map +1 -1
- package/lib/module/views/Stack/CardStack.js +211 -147
- package/lib/module/views/Stack/CardStack.js.map +1 -1
- package/lib/module/views/Stack/StackView.js +106 -57
- package/lib/module/views/Stack/StackView.js.map +1 -1
- package/lib/typescript/src/TransitionConfigs/CardStyleInterpolators.d.ts +20 -12
- package/lib/typescript/src/TransitionConfigs/CardStyleInterpolators.d.ts.map +1 -1
- package/lib/typescript/src/TransitionConfigs/HeaderStyleInterpolators.d.ts +4 -4
- package/lib/typescript/src/TransitionConfigs/HeaderStyleInterpolators.d.ts.map +1 -1
- package/lib/typescript/src/TransitionConfigs/TransitionEasings.d.ts +38 -0
- package/lib/typescript/src/TransitionConfigs/TransitionEasings.d.ts.map +1 -0
- package/lib/typescript/src/TransitionConfigs/TransitionPresets.d.ts +15 -3
- package/lib/typescript/src/TransitionConfigs/TransitionPresets.d.ts.map +1 -1
- package/lib/typescript/src/TransitionConfigs/TransitionSpecs.d.ts +44 -15
- package/lib/typescript/src/TransitionConfigs/TransitionSpecs.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +12 -12
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/navigators/createStackNavigator.d.ts +10 -15
- package/lib/typescript/src/navigators/createStackNavigator.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +120 -108
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/CardAnimationContext.d.ts +1 -1
- package/lib/typescript/src/utils/CardAnimationContext.d.ts.map +1 -1
- package/lib/typescript/src/utils/GestureHandlerContext.d.ts +3 -0
- package/lib/typescript/src/utils/GestureHandlerContext.d.ts.map +1 -0
- package/lib/typescript/src/utils/gestureActivationCriteria.d.ts +4 -51
- package/lib/typescript/src/utils/gestureActivationCriteria.d.ts.map +1 -1
- package/lib/typescript/src/utils/getDistanceForDirection.d.ts +1 -1
- package/lib/typescript/src/utils/getDistanceForDirection.d.ts.map +1 -1
- package/lib/typescript/src/utils/getInvertedMultiplier.d.ts +1 -1
- package/lib/typescript/src/utils/getInvertedMultiplier.d.ts.map +1 -1
- package/lib/typescript/src/utils/getModalRoutesKeys.d.ts +1 -1
- package/lib/typescript/src/utils/getModalRoutesKeys.d.ts.map +1 -1
- package/lib/typescript/src/utils/getShadowStyle.d.ts +5 -5
- package/lib/typescript/src/utils/useCardAnimation.d.ts +1 -1
- package/lib/typescript/src/utils/useCardAnimation.d.ts.map +1 -1
- package/lib/typescript/src/utils/useGestureHandler.d.ts +2 -0
- package/lib/typescript/src/utils/useGestureHandler.d.ts.map +1 -0
- package/lib/typescript/src/utils/useKeyboardManager.d.ts +12 -2
- package/lib/typescript/src/utils/useKeyboardManager.d.ts.map +1 -1
- package/lib/typescript/src/views/GestureHandler.android.d.ts +1 -1
- package/lib/typescript/src/views/GestureHandler.android.d.ts.map +1 -1
- package/lib/typescript/src/views/GestureHandler.d.ts +7 -11
- package/lib/typescript/src/views/GestureHandler.d.ts.map +1 -1
- package/lib/typescript/src/views/GestureHandler.ios.d.ts +1 -1
- package/lib/typescript/src/views/GestureHandler.ios.d.ts.map +1 -1
- package/lib/typescript/src/views/GestureHandlerNative.d.ts +9 -4
- package/lib/typescript/src/views/GestureHandlerNative.d.ts.map +1 -1
- package/lib/typescript/src/views/Header/Header.d.ts +2 -2
- package/lib/typescript/src/views/Header/Header.d.ts.map +1 -1
- package/lib/typescript/src/views/Header/HeaderContainer.d.ts +9 -3
- package/lib/typescript/src/views/Header/HeaderContainer.d.ts.map +1 -1
- package/lib/typescript/src/views/Header/HeaderSegment.d.ts +6 -4
- package/lib/typescript/src/views/Header/HeaderSegment.d.ts.map +1 -1
- package/lib/typescript/src/views/Stack/Card.d.ts +14 -8
- package/lib/typescript/src/views/Stack/Card.d.ts.map +1 -1
- package/lib/typescript/src/views/Stack/CardContainer.d.ts +7 -7
- package/lib/typescript/src/views/Stack/CardContainer.d.ts.map +1 -1
- package/lib/typescript/src/views/Stack/CardContent.d.ts +1 -1
- package/lib/typescript/src/views/Stack/CardContent.d.ts.map +1 -1
- package/lib/typescript/src/views/Stack/CardStack.d.ts +10 -6
- package/lib/typescript/src/views/Stack/CardStack.d.ts.map +1 -1
- package/lib/typescript/src/views/Stack/StackView.d.ts +14 -17
- package/lib/typescript/src/views/Stack/StackView.d.ts.map +1 -1
- package/package.json +23 -24
- package/src/TransitionConfigs/CardStyleInterpolators.tsx +399 -100
- package/src/TransitionConfigs/HeaderStyleInterpolators.tsx +15 -46
- package/src/TransitionConfigs/TransitionEasings.tsx +90 -0
- package/src/TransitionConfigs/TransitionPresets.tsx +56 -10
- package/src/TransitionConfigs/TransitionSpecs.tsx +68 -34
- package/src/index.tsx +3 -2
- package/src/navigators/createStackNavigator.tsx +74 -91
- package/src/types.tsx +149 -123
- package/src/utils/GestureHandlerContext.tsx +5 -0
- package/src/utils/gestureActivationCriteria.tsx +14 -10
- package/src/utils/useCardAnimation.tsx +1 -1
- package/src/utils/useGestureHandler.tsx +9 -0
- package/src/utils/useKeyboardManager.tsx +96 -33
- package/src/views/GestureHandler.tsx +24 -16
- package/src/views/GestureHandlerNative.tsx +24 -13
- package/src/views/Header/Header.tsx +4 -2
- package/src/views/Header/HeaderContainer.tsx +79 -37
- package/src/views/Header/HeaderSegment.tsx +10 -11
- package/src/views/Stack/Card.tsx +241 -154
- package/src/views/Stack/CardContainer.tsx +111 -127
- package/src/views/Stack/CardContent.tsx +13 -51
- package/src/views/Stack/CardStack.tsx +478 -335
- package/src/views/Stack/StackView.tsx +181 -82
- package/lib/module/utils/GestureHandlerRefContext.js +0 -5
- package/lib/module/utils/GestureHandlerRefContext.js.map +0 -1
- package/lib/module/utils/findLastIndex.js +0 -11
- package/lib/module/utils/findLastIndex.js.map +0 -1
- package/lib/module/utils/useGestureHandlerRef.js +0 -12
- package/lib/module/utils/useGestureHandlerRef.js.map +0 -1
- package/lib/module/views/Stack/CardA11yWrapper.js +0 -43
- package/lib/module/views/Stack/CardA11yWrapper.js.map +0 -1
- package/lib/typescript/src/utils/GestureHandlerRefContext.d.ts +0 -3
- package/lib/typescript/src/utils/GestureHandlerRefContext.d.ts.map +0 -1
- package/lib/typescript/src/utils/findLastIndex.d.ts +0 -2
- package/lib/typescript/src/utils/findLastIndex.d.ts.map +0 -1
- package/lib/typescript/src/utils/useGestureHandlerRef.d.ts +0 -3
- package/lib/typescript/src/utils/useGestureHandlerRef.d.ts.map +0 -1
- package/lib/typescript/src/views/Stack/CardA11yWrapper.d.ts +0 -15
- package/lib/typescript/src/views/Stack/CardA11yWrapper.d.ts.map +0 -1
- package/src/utils/GestureHandlerRefContext.tsx +0 -5
- package/src/utils/findLastIndex.tsx +0 -9
- package/src/utils/useGestureHandlerRef.tsx +0 -15
- package/src/views/Stack/CardA11yWrapper.tsx +0 -67
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createNavigatorFactory,
|
|
3
|
+
createScreenFactory,
|
|
3
4
|
type EventArg,
|
|
5
|
+
type NavigatorTypeBagBase,
|
|
4
6
|
type ParamListBase,
|
|
5
7
|
type StackActionHelpers,
|
|
6
8
|
StackActions,
|
|
7
9
|
type StackNavigationState,
|
|
8
10
|
StackRouter,
|
|
9
11
|
type StackRouterOptions,
|
|
10
|
-
type StaticConfig,
|
|
11
|
-
type StaticParamList,
|
|
12
|
-
type StaticScreenConfig,
|
|
13
|
-
type StaticScreenConfigLinking,
|
|
14
|
-
type StaticScreenConfigScreen,
|
|
15
|
-
type TypedNavigator,
|
|
16
12
|
useLocale,
|
|
17
13
|
useNavigationBuilder,
|
|
18
14
|
} from '@react-navigation/native';
|
|
@@ -21,11 +17,16 @@ import * as React from 'react';
|
|
|
21
17
|
import type {
|
|
22
18
|
StackNavigationEventMap,
|
|
23
19
|
StackNavigationOptions,
|
|
24
|
-
StackNavigationProp,
|
|
25
20
|
StackNavigatorProps,
|
|
26
21
|
} from '../types';
|
|
27
22
|
import { StackView } from '../views/Stack/StackView';
|
|
28
23
|
|
|
24
|
+
type TabPressEventArg = EventArg<
|
|
25
|
+
'tabPress',
|
|
26
|
+
true,
|
|
27
|
+
{ behavior?: { popToTop?: boolean } } | undefined
|
|
28
|
+
>;
|
|
29
|
+
|
|
29
30
|
function StackNavigator({
|
|
30
31
|
initialRouteName,
|
|
31
32
|
routeNamesChangeBehavior,
|
|
@@ -39,98 +40,80 @@ function StackNavigator({
|
|
|
39
40
|
}: StackNavigatorProps) {
|
|
40
41
|
const { direction } = useLocale();
|
|
41
42
|
|
|
42
|
-
const { state, descriptors, navigation,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
43
|
+
const { state, descriptors, navigation, render } = useNavigationBuilder<
|
|
44
|
+
StackNavigationState<ParamListBase>,
|
|
45
|
+
StackRouterOptions,
|
|
46
|
+
StackActionHelpers<ParamListBase>,
|
|
47
|
+
StackNavigationOptions,
|
|
48
|
+
StackNavigationEventMap
|
|
49
|
+
>(StackRouter, {
|
|
50
|
+
initialRouteName,
|
|
51
|
+
routeNamesChangeBehavior,
|
|
52
|
+
children,
|
|
53
|
+
layout,
|
|
54
|
+
screenListeners,
|
|
55
|
+
screenOptions,
|
|
56
|
+
screenLayout,
|
|
57
|
+
router,
|
|
58
|
+
});
|
|
59
59
|
|
|
60
|
-
React.useEffect(
|
|
61
|
-
|
|
62
|
-
// @ts-expect-error: there may not be a tab navigator in parent
|
|
63
|
-
navigation.addListener?.('tabPress', (e) => {
|
|
64
|
-
const isFocused = navigation.isFocused();
|
|
60
|
+
React.useEffect(() => {
|
|
61
|
+
let handle: ReturnType<typeof requestAnimationFrame> | undefined;
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
isFocused &&
|
|
72
|
-
!(e as unknown as EventArg<'tabPress', true>).defaultPrevented
|
|
73
|
-
) {
|
|
74
|
-
// When user taps on already focused tab and we're inside the tab,
|
|
75
|
-
// reset the stack to replicate native behaviour
|
|
76
|
-
navigation.dispatch({
|
|
77
|
-
...StackActions.popToTop(),
|
|
78
|
-
target: state.key,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}),
|
|
83
|
-
[navigation, state.index, state.key]
|
|
84
|
-
);
|
|
63
|
+
// @ts-expect-error: there may not be a tab navigator in parent
|
|
64
|
+
const unsubscribe = navigation.addListener?.('tabPress', (e) => {
|
|
65
|
+
const isFocused = navigation.isFocused();
|
|
66
|
+
|
|
67
|
+
cancelAnimationFrame(handle);
|
|
85
68
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
69
|
+
// Run the operation in the next frame so we're sure all listeners have been run
|
|
70
|
+
// This is necessary to know if preventDefault() has been called
|
|
71
|
+
handle = requestAnimationFrame(() => {
|
|
72
|
+
const currentState = navigation.getState();
|
|
73
|
+
const event = e as TabPressEventArg;
|
|
74
|
+
|
|
75
|
+
if (
|
|
76
|
+
isFocused &&
|
|
77
|
+
event.data?.behavior?.popToTop !== false &&
|
|
78
|
+
(currentState.index > 0 || currentState.routes[0]?.history?.length) &&
|
|
79
|
+
!event.defaultPrevented
|
|
80
|
+
) {
|
|
81
|
+
// When user taps on already focused tab and we're inside the tab,
|
|
82
|
+
// reset the stack to replicate native behaviour
|
|
83
|
+
navigation.dispatch({
|
|
84
|
+
...StackActions.popToTop(),
|
|
85
|
+
target: currentState.key,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return () => {
|
|
92
|
+
cancelAnimationFrame(handle);
|
|
93
|
+
unsubscribe?.();
|
|
94
|
+
};
|
|
95
|
+
}, [navigation]);
|
|
96
|
+
|
|
97
|
+
return render(
|
|
98
|
+
<StackView
|
|
99
|
+
{...rest}
|
|
100
|
+
direction={direction}
|
|
101
|
+
state={state}
|
|
102
|
+
descriptors={descriptors}
|
|
103
|
+
navigation={navigation}
|
|
104
|
+
/>
|
|
96
105
|
);
|
|
97
106
|
}
|
|
98
107
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
State: StackNavigationState<ParamList>;
|
|
108
|
+
export interface StackTypeBag extends NavigatorTypeBagBase {
|
|
109
|
+
State: StackNavigationState<this['ParamList']>;
|
|
102
110
|
ScreenOptions: StackNavigationOptions;
|
|
103
111
|
EventMap: StackNavigationEventMap;
|
|
104
|
-
|
|
105
|
-
[RouteName in keyof ParamList]: StackNavigationProp<ParamList, RouteName>;
|
|
106
|
-
};
|
|
112
|
+
ActionHelpers: StackActionHelpers<this['ParamList']>;
|
|
107
113
|
Navigator: typeof StackNavigator;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export function createStackNavigator<
|
|
111
|
-
const ParamList extends ParamListBase,
|
|
112
|
-
>(): TypedNavigator<StackTypeBag<ParamList>, undefined>;
|
|
113
|
-
export function createStackNavigator<
|
|
114
|
-
const Config extends StaticConfig<StackTypeBag<ParamListBase>>,
|
|
115
|
-
>(
|
|
116
|
-
config: Config
|
|
117
|
-
): TypedNavigator<StackTypeBag<StaticParamList<{ config: Config }>>, Config>;
|
|
118
|
-
export function createStackNavigator(config?: unknown) {
|
|
119
|
-
return createNavigatorFactory(StackNavigator)(config);
|
|
120
114
|
}
|
|
121
115
|
|
|
122
|
-
export
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
>(
|
|
126
|
-
config: StaticScreenConfig<
|
|
127
|
-
Linking,
|
|
128
|
-
Screen,
|
|
129
|
-
StackNavigationState<ParamListBase>,
|
|
130
|
-
StackNavigationOptions,
|
|
131
|
-
StackNavigationEventMap,
|
|
132
|
-
StackNavigationProp<ParamListBase>
|
|
133
|
-
>
|
|
134
|
-
) {
|
|
135
|
-
return config;
|
|
136
|
-
}
|
|
116
|
+
export const createStackNavigator =
|
|
117
|
+
createNavigatorFactory<StackTypeBag>(StackNavigator);
|
|
118
|
+
|
|
119
|
+
export const createStackScreen = createScreenFactory<StackTypeBag>();
|