@momo-kits/foundation 0.168.1-rn862.1 → 0.169.2
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/Application/BottomSheet.hooks.ts +195 -0
- package/Application/BottomSheet.parts.tsx +147 -0
- package/Application/BottomSheet.styles.ts +43 -0
- package/Application/BottomSheet.tsx +76 -279
- package/Application/BottomTab/ActiveIndicator.tsx +90 -0
- package/Application/BottomTab/BottomTabBar.styles.ts +65 -0
- package/Application/BottomTab/BottomTabBar.tsx +229 -276
- package/Application/BottomTab/BottomTabInset.tsx +14 -0
- package/Application/BottomTab/CurvedContainer.tsx +153 -0
- package/Application/BottomTab/CustomBottomTabItem.tsx +132 -108
- package/Application/BottomTab/DuoBarCompression.tsx +4 -12
- package/Application/BottomTab/DuoRailTabBar.tsx +227 -0
- package/Application/BottomTab/DuoTabBar.styles.ts +81 -0
- package/Application/BottomTab/DuoTabBar.tsx +29 -495
- package/Application/BottomTab/TabBarIcon.tsx +160 -72
- package/Application/BottomTab/TabScreen.tsx +164 -0
- package/Application/BottomTab/index.tsx +84 -351
- package/Application/BottomTab/metrics.ts +164 -0
- package/Application/BottomTab/tabItems.ts +46 -0
- package/Application/BottomTab/usePressLift.ts +32 -0
- package/Application/Components/DuoGlassBackground.tsx +7 -9
- package/Application/Components/HeaderAnimated.tsx +1 -1
- package/Application/Components/HeaderBackground.tsx +1 -1
- package/Application/Components/HeaderExtendHeader.tsx +17 -11
- package/Application/Components/HeaderRight.styles.ts +144 -0
- package/Application/Components/HeaderRight.tsx +6 -528
- package/Application/Components/HeaderTitle.shared.ts +43 -0
- package/Application/Components/HeaderTitle.styles.ts +125 -0
- package/Application/Components/HeaderTitle.tsx +12 -576
- package/Application/Components/HeaderToolkitAction.tsx +208 -0
- package/Application/Components/NavigationButton.tsx +9 -6
- package/Application/Components/SearchHeader.tsx +1 -1
- package/Application/Components/SwipeBackHaptic.tsx +95 -0
- package/Application/Components/TitleJourney.tsx +110 -0
- package/Application/Components/TitleLocation.tsx +73 -0
- package/Application/Components/TitleUser.tsx +304 -0
- package/Application/Components/useToolkitActions.tsx +233 -0
- package/Application/ModalIconButton.tsx +66 -0
- package/Application/ModalScreen.tsx +39 -18
- package/Application/Navigation.ts +1 -1
- package/Application/NavigationContainer.tsx +7 -8
- package/Application/StackScreen.tracking.ts +158 -0
- package/Application/StackScreen.tsx +10 -137
- package/Application/WidgetContainer.tsx +10 -3
- package/Application/__tests__/modalLayout.test.ts +128 -0
- package/Application/hooks.ts +137 -0
- package/Application/index.ts +13 -1
- package/Application/modalLayout.ts +177 -0
- package/Application/navigationOptions.tsx +217 -0
- package/Application/types.header.ts +116 -0
- package/Application/types.tabs.ts +48 -0
- package/Application/types.theme.ts +87 -0
- package/Application/types.ts +12 -244
- package/Application/utils.ts +107 -0
- package/Badge/BadgeRibbon.tsx +3 -3
- package/Badge/styles.ts +2 -0
- package/Button/index.tsx +16 -136
- package/Button/styles.ts +1 -1
- package/Button/utils.ts +139 -0
- package/CheckBox/index.tsx +1 -6
- package/Divider/DashDivider.tsx +10 -11
- package/Divider/index.tsx +18 -8
- package/Image/index.tsx +1 -46
- package/Input/Input.tsx +7 -8
- package/Input/InputDropDown.tsx +3 -4
- package/Input/InputMoney.tsx +38 -164
- package/Input/InputMoneyView.tsx +187 -0
- package/Input/InputOTP.tsx +1 -1
- package/Input/InputPhoneNumber.tsx +5 -1
- package/Input/InputSearch.tsx +2 -108
- package/Input/InputTextArea.tsx +1 -5
- package/Input/SearchTextTyping.tsx +104 -0
- package/Input/common.tsx +4 -4
- package/Input/moneyUtils.ts +17 -0
- package/Input/styles.ts +26 -2
- package/Layout/FloatingButton.tsx +22 -21
- package/Layout/ReservedRegions.tsx +21 -4
- package/Layout/Screen.tsx +74 -670
- package/Layout/Section.tsx +1 -2
- package/Layout/index.ts +10 -4
- package/Layout/layoutMetrics.ts +58 -0
- package/Layout/layoutTypes.ts +86 -0
- package/Layout/screenContent.tsx +90 -0
- package/Layout/screenFooter.tsx +53 -0
- package/Layout/screenHeader.tsx +315 -0
- package/Layout/screenQuickReturn.tsx +67 -0
- package/Layout/screenScroll.ts +110 -0
- package/Layout/screenTypes.ts +134 -0
- package/Layout/styles.ts +2 -0
- package/Layout/utils.ts +10 -144
- package/Loader/DotLoader.tsx +7 -3
- package/Loader/ProgressBar.tsx +2 -6
- package/Loader/Spinner.tsx +7 -3
- package/Loader/styles.ts +4 -0
- package/Popup/PopupNotify.tsx +70 -64
- package/Popup/PopupPromotion.tsx +5 -4
- package/Popup/types.ts +7 -0
- package/Popup/utils.ts +46 -24
- package/Radio/index.tsx +2 -10
- package/Radio/styles.ts +6 -0
- package/Skeleton/index.tsx +1 -9
- package/Skeleton/styles.ts +1 -0
- package/Tag/index.tsx +3 -3
- package/Text/index.tsx +11 -2
- package/Title/index.tsx +2 -9
- package/Title/styles.ts +6 -0
- package/package.json +21 -22
- package/Application/device.ts +0 -29
- package/Application/utils.tsx +0 -497
package/Layout/Screen.tsx
CHANGED
|
@@ -1,189 +1,41 @@
|
|
|
1
|
-
import { StackNavigationOptions } from '@react-navigation/stack';
|
|
2
1
|
import { useHeaderHeight } from '@react-navigation/elements';
|
|
3
2
|
import React, {
|
|
4
3
|
forwardRef,
|
|
5
|
-
Fragment,
|
|
6
|
-
ReactNode,
|
|
7
|
-
Ref,
|
|
8
|
-
useCallback,
|
|
9
4
|
useContext,
|
|
10
5
|
useEffect,
|
|
11
6
|
useImperativeHandle,
|
|
12
|
-
|
|
7
|
+
useLayoutEffect,
|
|
13
8
|
useRef,
|
|
14
9
|
} from 'react';
|
|
15
10
|
import {
|
|
16
11
|
Animated,
|
|
17
12
|
KeyboardAvoidingView,
|
|
18
|
-
NativeScrollEvent,
|
|
19
|
-
NativeSyntheticEvent,
|
|
20
13
|
Platform,
|
|
21
14
|
ScrollView,
|
|
22
|
-
ScrollViewProps,
|
|
23
|
-
StatusBar,
|
|
24
|
-
StatusBarStyle,
|
|
25
15
|
View,
|
|
26
|
-
ViewProps,
|
|
27
16
|
} from 'react-native';
|
|
28
|
-
import {
|
|
29
|
-
useAnimatedReaction,
|
|
30
|
-
useSharedValue,
|
|
31
|
-
withTiming,
|
|
32
|
-
} from 'react-native-reanimated';
|
|
17
|
+
import { useSharedValue } from 'react-native-reanimated';
|
|
33
18
|
import {
|
|
34
19
|
useSafeAreaFrame,
|
|
35
20
|
useSafeAreaInsets,
|
|
36
21
|
} from 'react-native-safe-area-context';
|
|
37
22
|
import { ApplicationContext, ScreenContext } from '../Context';
|
|
38
|
-
import
|
|
39
|
-
import {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} from '../Application/
|
|
45
|
-
import {
|
|
46
|
-
import {
|
|
47
|
-
import
|
|
48
|
-
import {
|
|
49
|
-
import {
|
|
50
|
-
import {
|
|
51
|
-
import {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
HeaderBackground,
|
|
55
|
-
HeaderExtendHeader,
|
|
56
|
-
HeaderLeft,
|
|
57
|
-
HeaderTitle,
|
|
58
|
-
SearchHeader,
|
|
59
|
-
} from '../Application';
|
|
60
|
-
import {
|
|
61
|
-
DuoGlassBackground,
|
|
62
|
-
DuoScrollGradient,
|
|
63
|
-
} from '../Application/Components/DuoGlassBackground';
|
|
64
|
-
import { DuoQuickReturnHeader } from '../Application/Components/DuoQuickReturnHeader';
|
|
65
|
-
import { useDuoTabBarInset } from '../Application/BottomTab/DuoTabBar';
|
|
66
|
-
|
|
67
|
-
export interface ScreenProps extends ViewProps {
|
|
68
|
-
/**
|
|
69
|
-
* ReactNode representing the content of the screen.
|
|
70
|
-
*/
|
|
71
|
-
children: React.ReactNode;
|
|
72
|
-
/**
|
|
73
|
-
* Optional. Navigation object for handling navigation actions.
|
|
74
|
-
*/
|
|
75
|
-
navigation?: Navigation;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Optional. If `true`, enable keyboard avoiding view for the screen.
|
|
79
|
-
*/
|
|
80
|
-
enableKeyboardAvoidingView?: boolean;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Optional. If `true`, the screen content is scrollable.
|
|
84
|
-
*/
|
|
85
|
-
scrollable?: boolean;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Optional. Set type of header.
|
|
89
|
-
*/
|
|
90
|
-
headerType?: HeaderType;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Optional. Props for the animated component or bool used top navigation animated.
|
|
94
|
-
*/
|
|
95
|
-
animatedHeader?: AnimatedHeader;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Optional. Props for the underlying ScrollView component when `scrollable` is `true`.
|
|
99
|
-
*/
|
|
100
|
-
scrollViewProps?: ScrollViewProps;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Optional. ReactNode representing the header component of the screen.
|
|
104
|
-
*/
|
|
105
|
-
headerComponent?: ReactNode;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Optional. ReactNode representing the footer component of the screen.
|
|
109
|
-
*/
|
|
110
|
-
footerComponent?: ReactNode;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Optional. If `true`, the footer is inset by the standard horizontal margin
|
|
114
|
-
* (12pt each side). Set `false` for a footer that should span the full width —
|
|
115
|
-
* e.g. one that already carries its own horizontal padding.
|
|
116
|
-
* Defaults to `true`, on every platform.
|
|
117
|
-
*/
|
|
118
|
-
marginFooter?: boolean;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Optional. Background color of the screen.
|
|
122
|
-
*/
|
|
123
|
-
backgroundColor?: string;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Optional. layout card offset overlap header banner.
|
|
127
|
-
*/
|
|
128
|
-
layoutOffset?: -8 | -24 | -56 | number;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Optional. Width of the right header. Defaults to the toolkit width (73), or 0 when
|
|
132
|
-
* iPhone Duo floats the toolkit into its side bar.
|
|
133
|
-
*/
|
|
134
|
-
headerRightWidth?: 0 | 73 | 110 | number;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Optional. Props for the floating action button.
|
|
138
|
-
*/
|
|
139
|
-
floatingButtonProps?: Omit<FloatingButtonProps, 'animatedValue' | 'bottom'>;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Optional. Keyboard vertical offset.
|
|
143
|
-
*/
|
|
144
|
-
keyboardVerticalOffset?: number;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Optional. If `true`, the screen content is using grid layout by span.
|
|
148
|
-
*/
|
|
149
|
-
useGridLayout?: boolean;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Optional. specs for input search.
|
|
153
|
-
*/
|
|
154
|
-
inputSearchProps?: SearchHeaderProps;
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Optional. Ref for input search.
|
|
158
|
-
*/
|
|
159
|
-
inputSearchRef?: Ref<InputRef>;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Optional. React Native animated value for header.
|
|
163
|
-
* Internally, Screen mirrors it into a reanimated shared value.
|
|
164
|
-
*/
|
|
165
|
-
animatedValue?: Animated.Value;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Optional. If `true`, use shadow header.
|
|
169
|
-
*/
|
|
170
|
-
useShadowHeader?: boolean;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Optional. Custom header Gradient Color.
|
|
174
|
-
*/
|
|
175
|
-
gradientColor?: string;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Optional. Custom headerBackground Image
|
|
179
|
-
*/
|
|
180
|
-
headerBackground?: string;
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Optional. Custom tracking params
|
|
184
|
-
*/
|
|
185
|
-
trackingParams?: ScreenTrackingParams;
|
|
186
|
-
}
|
|
23
|
+
import { NavigationOptions } from '../Application/types';
|
|
24
|
+
import { Spacing, Styles } from '../Consts';
|
|
25
|
+
import { FloatingButton } from './FloatingButton';
|
|
26
|
+
import { getOptions } from '../Application/navigationOptions';
|
|
27
|
+
import { useScreenLayout } from './utils';
|
|
28
|
+
import { HeaderExtendHeader } from '../Application';
|
|
29
|
+
import { DuoScrollGradient } from '../Application/Components/DuoGlassBackground';
|
|
30
|
+
import { BottomTabInsetContext } from '../Application/BottomTab/BottomTabInset';
|
|
31
|
+
import { ScreenProps } from './screenTypes';
|
|
32
|
+
import { renderAnimatedHeader, renderContent } from './screenContent';
|
|
33
|
+
import { createScrollHandlers } from './screenScroll';
|
|
34
|
+
import { ScreenFooter } from './screenFooter';
|
|
35
|
+
import { useScreenHeader } from './screenHeader';
|
|
36
|
+
import { useScreenQuickReturn } from './screenQuickReturn';
|
|
37
|
+
|
|
38
|
+
export type { ScreenProps };
|
|
187
39
|
|
|
188
40
|
const Screen = forwardRef(
|
|
189
41
|
(
|
|
@@ -222,19 +74,6 @@ const Screen = forwardRef(
|
|
|
222
74
|
const frame = useSafeAreaFrame();
|
|
223
75
|
const heightHeader = useHeaderHeight();
|
|
224
76
|
|
|
225
|
-
/**
|
|
226
|
-
* Dual animation source:
|
|
227
|
-
* - `animatedValue` is a react-native `Animated.Value` driven natively by the
|
|
228
|
-
* scroll event. It is what legacy consumers receive (`animatedValue`).
|
|
229
|
-
* - `sharedValue` is a reanimated `SharedValue` consumed by every internal
|
|
230
|
-
* foundation component (and offered to modern consumers). It is kept in
|
|
231
|
-
* sync from the scroll `listener` (see below), which fires on the JS
|
|
232
|
-
* thread even when the scroll uses the native driver.
|
|
233
|
-
* If a legacy value is driven outside of Screen, its listener also
|
|
234
|
-
* mirrors JS-driven updates into the shared value.
|
|
235
|
-
* Consumers pass only `Animated.Value`; the reanimated shared value stays
|
|
236
|
-
* an internal implementation detail.
|
|
237
|
-
*/
|
|
238
77
|
const animatedValue = useRef<Animated.Value>(
|
|
239
78
|
customAnimatedValue ?? new Animated.Value(0),
|
|
240
79
|
);
|
|
@@ -255,58 +94,32 @@ const Screen = forwardRef(
|
|
|
255
94
|
};
|
|
256
95
|
}, [customAnimatedValue, internalShared]);
|
|
257
96
|
|
|
258
|
-
const currentTint = useRef<string | undefined>(undefined);
|
|
259
|
-
|
|
260
97
|
const isTab = !!screen?.bottomTab;
|
|
261
|
-
|
|
262
|
-
const duoTabInset =
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
98
|
+
const tabBarInset = useContext(BottomTabInsetContext);
|
|
99
|
+
const duoTabInset = isTab ? tabBarInset.inset : 0;
|
|
100
|
+
const claimTabBarInset = tabBarInset.claim;
|
|
101
|
+
// this screen keeps its content clear of the floating tab bar, so the tab stops padding it
|
|
102
|
+
useLayoutEffect(() => {
|
|
103
|
+
if (duoTabInset) {
|
|
104
|
+
claimTabBarInset?.();
|
|
105
|
+
}
|
|
106
|
+
}, [duoTabInset, claimTabBarInset]);
|
|
266
107
|
|
|
267
108
|
const isIOS = Platform.OS === 'ios';
|
|
268
109
|
const bottomInset = isIOS ? Math.min(insets.bottom, 21) : insets.bottom;
|
|
269
110
|
const hasSideBar = !!layout.sideBar;
|
|
270
|
-
// iPhone Duo: content scrolls under a glass header instead of starting below it
|
|
271
111
|
const useDuoGlass =
|
|
272
112
|
hasSideBar &&
|
|
273
113
|
(headerType === 'default' || headerType === 'extended') &&
|
|
274
114
|
!animatedHeader &&
|
|
275
115
|
!inputSearchProps;
|
|
276
116
|
|
|
277
|
-
// iPhone Duo: the header leaves with the content and returns on a reverse scroll
|
|
278
117
|
const useQuickReturn =
|
|
279
118
|
hasSideBar && scrollable && (useDuoGlass || !!animatedHeader);
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
() => sharedValue.value,
|
|
285
|
-
y => {
|
|
286
|
-
const delta = y - lastScrollY.value;
|
|
287
|
-
lastScrollY.value = y;
|
|
288
|
-
if (!useQuickReturn || y <= 0) {
|
|
289
|
-
headerHide.value = 0;
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
headerHide.value = Math.min(
|
|
293
|
-
Math.max(headerHide.value + delta, 0),
|
|
294
|
-
heightHeader,
|
|
295
|
-
);
|
|
296
|
-
},
|
|
297
|
-
[useQuickReturn, heightHeader],
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
const quickReturnOptions: StackNavigationOptions = useMemo(
|
|
301
|
-
() =>
|
|
302
|
-
useQuickReturn
|
|
303
|
-
? {
|
|
304
|
-
header: (props: any) => (
|
|
305
|
-
<DuoQuickReturnHeader {...props} offset={headerHide} />
|
|
306
|
-
),
|
|
307
|
-
}
|
|
308
|
-
: { header: undefined },
|
|
309
|
-
[useQuickReturn, headerHide],
|
|
119
|
+
const { quickReturnOptions, snapQuickReturnHeader } = useScreenQuickReturn(
|
|
120
|
+
sharedValue,
|
|
121
|
+
useQuickReturn,
|
|
122
|
+
heightHeader,
|
|
310
123
|
);
|
|
311
124
|
|
|
312
125
|
let keyboardOffset = heightHeader - bottomInset;
|
|
@@ -324,264 +137,20 @@ const Screen = forwardRef(
|
|
|
324
137
|
*/
|
|
325
138
|
screen?.onSetParams?.(trackingParams);
|
|
326
139
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
let options: StackNavigationOptions;
|
|
334
|
-
switch (headerType) {
|
|
335
|
-
case 'none':
|
|
336
|
-
options = {
|
|
337
|
-
headerTransparent: true,
|
|
338
|
-
headerBackground: () => null,
|
|
339
|
-
headerShown: false,
|
|
340
|
-
};
|
|
341
|
-
break;
|
|
342
|
-
|
|
343
|
-
case 'extended':
|
|
344
|
-
options = {
|
|
345
|
-
...quickReturnOptions,
|
|
346
|
-
headerShown: true,
|
|
347
|
-
headerTransparent: true,
|
|
348
|
-
headerBackground: () =>
|
|
349
|
-
hasSideBar ? (
|
|
350
|
-
<DuoGlassBackground animatedValue={sharedValue} />
|
|
351
|
-
) : null,
|
|
352
|
-
headerTitle: (props: any) => <HeaderTitle {...props} />,
|
|
353
|
-
};
|
|
354
|
-
if (inputSearchProps) {
|
|
355
|
-
options = {
|
|
356
|
-
headerShown: true,
|
|
357
|
-
headerTransparent: true,
|
|
358
|
-
headerBackground: () => null,
|
|
359
|
-
headerTitle: (props: any) => (
|
|
360
|
-
<HeaderTitle
|
|
361
|
-
{...props}
|
|
362
|
-
interpolate={{
|
|
363
|
-
inputRange: [0, 50],
|
|
364
|
-
outputRange: [1, 0],
|
|
365
|
-
}}
|
|
366
|
-
animatedValue={sharedValue}
|
|
367
|
-
/>
|
|
368
|
-
),
|
|
369
|
-
};
|
|
370
|
-
}
|
|
371
|
-
break;
|
|
372
|
-
|
|
373
|
-
default:
|
|
374
|
-
if (hasSideBar && !inputSearchProps) {
|
|
375
|
-
options = {
|
|
376
|
-
...quickReturnOptions,
|
|
377
|
-
headerTransparent: true,
|
|
378
|
-
headerTintColor: Colors.black_17,
|
|
379
|
-
headerShown: true,
|
|
380
|
-
headerBackground: () => (
|
|
381
|
-
<DuoGlassBackground animatedValue={sharedValue} />
|
|
382
|
-
),
|
|
383
|
-
headerTitle: (props: any) => <HeaderTitle {...props} />,
|
|
384
|
-
};
|
|
385
|
-
break;
|
|
386
|
-
}
|
|
387
|
-
options = {
|
|
388
|
-
headerTransparent: false,
|
|
389
|
-
headerTintColor: Colors.black_17,
|
|
390
|
-
headerShown: true,
|
|
391
|
-
headerBackground: (props: any) => (
|
|
392
|
-
<HeaderBackground
|
|
393
|
-
{...props}
|
|
394
|
-
animatedValue={sharedValue}
|
|
395
|
-
useShadowHeader={useShadowHeader}
|
|
396
|
-
headerBackground={headerBackground}
|
|
397
|
-
gradientColor={gradientColor}
|
|
398
|
-
/>
|
|
399
|
-
),
|
|
400
|
-
headerTitle: (props: any) => <HeaderTitle {...props} />,
|
|
401
|
-
};
|
|
402
|
-
if (inputSearchProps) {
|
|
403
|
-
options = {
|
|
404
|
-
headerShown: true,
|
|
405
|
-
headerTransparent: true,
|
|
406
|
-
headerBackground: () => null,
|
|
407
|
-
headerTitle: (props: any) => (
|
|
408
|
-
<HeaderTitle
|
|
409
|
-
{...props}
|
|
410
|
-
interpolate={{
|
|
411
|
-
inputRange: [0, 50],
|
|
412
|
-
outputRange: [1, 0],
|
|
413
|
-
}}
|
|
414
|
-
animatedValue={sharedValue}
|
|
415
|
-
/>
|
|
416
|
-
),
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
navigation?.instance?.setOptions({ header: undefined, ...options });
|
|
422
|
-
},
|
|
423
|
-
[
|
|
424
|
-
gradientColor,
|
|
425
|
-
headerBackground,
|
|
426
|
-
inputSearchProps,
|
|
427
|
-
navigation?.instance,
|
|
428
|
-
sharedValue,
|
|
429
|
-
useShadowHeader,
|
|
430
|
-
hasSideBar,
|
|
431
|
-
quickReturnOptions,
|
|
432
|
-
],
|
|
433
|
-
);
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* export animatedHeader options for screen
|
|
437
|
-
* @param animatedHeader
|
|
438
|
-
*/
|
|
439
|
-
const setAnimatedHeader = useCallback(
|
|
440
|
-
(animatedHeader: AnimatedHeader) => {
|
|
441
|
-
let options: StackNavigationOptions;
|
|
442
|
-
if (!currentTint.current) {
|
|
443
|
-
currentTint.current = animatedHeader?.headerTintColor;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
options = {
|
|
447
|
-
...quickReturnOptions,
|
|
448
|
-
headerTintColor: currentTint.current ?? Colors.black_17,
|
|
449
|
-
headerTransparent: true,
|
|
450
|
-
headerBackground: (props: any) =>
|
|
451
|
-
hasSideBar ? (
|
|
452
|
-
// glass shows once the banner has scrolled under the header
|
|
453
|
-
<DuoGlassBackground
|
|
454
|
-
animatedValue={sharedValue}
|
|
455
|
-
fadeStart={Math.max(210 + layoutOffset - heightHeader, 0)}
|
|
456
|
-
/>
|
|
457
|
-
) : (
|
|
458
|
-
<HeaderBackground
|
|
459
|
-
{...props}
|
|
460
|
-
animatedValue={sharedValue}
|
|
461
|
-
useGradient={false}
|
|
462
|
-
useShadowHeader={useShadowHeader}
|
|
463
|
-
headerBackground={headerBackground}
|
|
464
|
-
gradientColor={gradientColor}
|
|
465
|
-
/>
|
|
466
|
-
),
|
|
467
|
-
headerTitle: (props: any) => {
|
|
468
|
-
return <HeaderTitle {...props} />;
|
|
469
|
-
},
|
|
470
|
-
};
|
|
471
|
-
|
|
472
|
-
if (animatedHeader.headerTitle) {
|
|
473
|
-
options = {
|
|
474
|
-
...options,
|
|
475
|
-
...exportHeaderTitle(animatedHeader),
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
navigation?.instance?.setOptions(options);
|
|
480
|
-
},
|
|
481
|
-
[
|
|
482
|
-
gradientColor,
|
|
483
|
-
headerBackground,
|
|
484
|
-
navigation?.instance,
|
|
485
|
-
sharedValue,
|
|
486
|
-
useShadowHeader,
|
|
487
|
-
hasSideBar,
|
|
488
|
-
layoutOffset,
|
|
489
|
-
heightHeader,
|
|
490
|
-
quickReturnOptions,
|
|
491
|
-
],
|
|
492
|
-
);
|
|
493
|
-
|
|
494
|
-
/**
|
|
495
|
-
* export animatedHeader options for screen
|
|
496
|
-
*/
|
|
497
|
-
const setAnimatedSearch = useCallback(() => {
|
|
498
|
-
const options: StackNavigationOptions = {
|
|
499
|
-
headerShown: true,
|
|
500
|
-
headerTransparent: true,
|
|
501
|
-
headerBackground: () => null,
|
|
502
|
-
headerTitle: (props: any) => (
|
|
503
|
-
<HeaderTitle
|
|
504
|
-
{...props}
|
|
505
|
-
interpolate={{
|
|
506
|
-
inputRange: [0, 50],
|
|
507
|
-
outputRange: [1, 0],
|
|
508
|
-
}}
|
|
509
|
-
animatedValue={sharedValue}
|
|
510
|
-
/>
|
|
511
|
-
),
|
|
512
|
-
};
|
|
513
|
-
|
|
514
|
-
navigation?.instance?.setOptions({ header: undefined, ...options });
|
|
515
|
-
}, [navigation?.instance, sharedValue]);
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* export search header
|
|
519
|
-
*/
|
|
520
|
-
const setSearchHeader = (params: SearchHeaderProps) => {
|
|
521
|
-
let searchWidth = layout.width - 24;
|
|
522
|
-
let searchLeft = Spacing.M;
|
|
523
|
-
if (layout.sideBar) {
|
|
524
|
-
// back floats in the side bar: the search spans the content width
|
|
525
|
-
searchWidth = layout.contentWidth - Spacing.M * 2;
|
|
526
|
-
searchLeft = Spacing.M - getHeaderMargin(layout.width);
|
|
527
|
-
}
|
|
528
|
-
if (layout.statusBarClearance) {
|
|
529
|
-
searchWidth -=
|
|
530
|
-
layout.statusBarClearance.left + layout.statusBarClearance.right;
|
|
531
|
-
}
|
|
532
|
-
const options: StackNavigationOptions = {
|
|
533
|
-
headerRight: undefined,
|
|
534
|
-
headerTitleContainerStyle: {
|
|
535
|
-
width: searchWidth,
|
|
536
|
-
maxWidth: searchWidth,
|
|
537
|
-
marginLeft: 0,
|
|
538
|
-
marginEnd: 0,
|
|
539
|
-
marginStart: 0,
|
|
540
|
-
marginHorizontal: 0,
|
|
541
|
-
marginVertical: 0,
|
|
542
|
-
margin: 0,
|
|
543
|
-
left: searchLeft,
|
|
544
|
-
},
|
|
545
|
-
headerLeft: (props: any) =>
|
|
546
|
-
params?.hiddenBack ? null : <HeaderLeft {...props} floating />,
|
|
547
|
-
headerTitle: () => (
|
|
548
|
-
<SearchHeader {...params} animatedValue={sharedValue} />
|
|
549
|
-
),
|
|
550
|
-
};
|
|
551
|
-
|
|
552
|
-
navigation?.instance?.setOptions(options);
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
useEffect(() => {
|
|
556
|
-
const focus = navigation?.instance?.addListener?.('focus', () => {
|
|
557
|
-
let barStyle: StatusBarStyle = 'dark-content';
|
|
558
|
-
if (currentTint.current === Colors.black_01) {
|
|
559
|
-
barStyle = 'light-content';
|
|
560
|
-
}
|
|
561
|
-
StatusBar.setBarStyle(barStyle, true);
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
if (animatedHeader) {
|
|
565
|
-
setAnimatedHeader(animatedHeader);
|
|
566
|
-
} else if (inputSearchProps) {
|
|
567
|
-
setAnimatedSearch();
|
|
568
|
-
} else {
|
|
569
|
-
setHeaderType(headerType);
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
return () => {
|
|
573
|
-
focus?.();
|
|
574
|
-
};
|
|
575
|
-
}, [
|
|
140
|
+
const { setSearchHeader, currentTint } = useScreenHeader({
|
|
141
|
+
navigation,
|
|
142
|
+
layout,
|
|
143
|
+
sharedValue,
|
|
144
|
+
quickReturnOptions,
|
|
145
|
+
hasSideBar,
|
|
576
146
|
headerType,
|
|
577
147
|
animatedHeader,
|
|
578
148
|
inputSearchProps,
|
|
579
149
|
useShadowHeader,
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
]);
|
|
150
|
+
gradientColor,
|
|
151
|
+
headerBackground,
|
|
152
|
+
layoutOffset,
|
|
153
|
+
});
|
|
585
154
|
|
|
586
155
|
/**
|
|
587
156
|
* expose ref for screen
|
|
@@ -596,171 +165,21 @@ const Screen = forwardRef(
|
|
|
596
165
|
});
|
|
597
166
|
});
|
|
598
167
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
useNativeDriver: true,
|
|
614
|
-
listener: (e: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
615
|
-
const offsetY = e.nativeEvent.contentOffset.y;
|
|
616
|
-
// keep the reanimated source in sync for the internal components.
|
|
617
|
-
sharedValue.value = offsetY;
|
|
618
|
-
scrollViewProps?.onScroll?.(e);
|
|
619
|
-
if (animatedHeader) {
|
|
620
|
-
let color = animatedHeader?.headerTintColor ?? Colors.black_17;
|
|
621
|
-
if (offsetY > 50) {
|
|
622
|
-
color = Colors.black_17;
|
|
623
|
-
}
|
|
624
|
-
if (color !== currentTint.current) {
|
|
625
|
-
currentTint.current = color;
|
|
626
|
-
navigation?.setOptions({
|
|
627
|
-
headerTintColor: color,
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
let barStyle: StatusBarStyle = 'dark-content';
|
|
631
|
-
if (currentTint.current === Colors.black_01) {
|
|
632
|
-
barStyle = 'light-content';
|
|
633
|
-
}
|
|
634
|
-
StatusBar.setBarStyle(barStyle, true);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
},
|
|
638
|
-
},
|
|
639
|
-
);
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
/**
|
|
643
|
-
* handle scroll end
|
|
644
|
-
* @param e
|
|
645
|
-
*/
|
|
646
|
-
/**
|
|
647
|
-
* a half-shown quick return header settles fully in or out
|
|
648
|
-
*/
|
|
649
|
-
const snapQuickReturnHeader = (offsetY: number) => {
|
|
650
|
-
const hide = headerHide.value;
|
|
651
|
-
// above heightHeader the header still sits on the content
|
|
652
|
-
if (
|
|
653
|
-
!useQuickReturn ||
|
|
654
|
-
offsetY < heightHeader ||
|
|
655
|
-
hide <= 0 ||
|
|
656
|
-
hide >= heightHeader
|
|
657
|
-
) {
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
|
-
headerHide.value = withTiming(
|
|
661
|
-
hide > heightHeader / 2 ? heightHeader : 0,
|
|
662
|
-
{ duration: 200 },
|
|
663
|
-
);
|
|
664
|
-
};
|
|
665
|
-
|
|
666
|
-
const handleMomentumScrollEnd = (
|
|
667
|
-
e: NativeSyntheticEvent<NativeScrollEvent>,
|
|
668
|
-
) => {
|
|
669
|
-
snapQuickReturnHeader(e.nativeEvent.contentOffset.y);
|
|
670
|
-
scrollViewProps?.onMomentumScrollEnd?.(e);
|
|
671
|
-
};
|
|
672
|
-
|
|
673
|
-
const handleScrollEnd = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
674
|
-
const offsetY = e.nativeEvent.contentOffset.y;
|
|
675
|
-
snapQuickReturnHeader(offsetY);
|
|
676
|
-
if (inputSearchProps && offsetY < 100 && offsetY > 0) {
|
|
677
|
-
Animated.timing(animatedValue.current, {
|
|
678
|
-
toValue: 0,
|
|
679
|
-
useNativeDriver: true,
|
|
680
|
-
duration: 300,
|
|
681
|
-
}).start();
|
|
682
|
-
sharedValue.value = withTiming(0, { duration: 300 });
|
|
683
|
-
ref?.scrollTo?.({ y: 0, animated: true });
|
|
684
|
-
}
|
|
685
|
-
scrollViewProps?.onScrollEndDrag?.(e);
|
|
686
|
-
};
|
|
687
|
-
|
|
688
|
-
/**
|
|
689
|
-
* render top navigation banner
|
|
690
|
-
*/
|
|
691
|
-
const renderAnimatedHeader = () => {
|
|
692
|
-
if (typeof animatedHeader?.component === 'function') {
|
|
693
|
-
return (
|
|
694
|
-
<View
|
|
695
|
-
style={[styles.screenBanner, { maxHeight: 210 + layoutOffset }]}
|
|
696
|
-
>
|
|
697
|
-
{animatedHeader?.component({
|
|
698
|
-
// legacy consumers read `animatedValue` (Animated.Value),
|
|
699
|
-
// modern consumers read `sharedValue` (SharedValue).
|
|
700
|
-
animatedValue: animatedValue.current,
|
|
701
|
-
sharedValue: sharedValue,
|
|
702
|
-
})}
|
|
703
|
-
</View>
|
|
704
|
-
);
|
|
705
|
-
}
|
|
706
|
-
};
|
|
707
|
-
|
|
708
|
-
/**
|
|
709
|
-
* build content for screen for grid rule
|
|
710
|
-
*/
|
|
711
|
-
const renderContent = (children: any): any => {
|
|
712
|
-
const results = validateChildren(children, [undefined]);
|
|
713
|
-
if (Array.isArray(results)) {
|
|
714
|
-
return results.map((item, index) => {
|
|
715
|
-
const space = item?.props?.useMargin === false ? 0 : Spacing.M;
|
|
716
|
-
if (item?.type === Fragment) {
|
|
717
|
-
return renderContent(item?.props?.children);
|
|
718
|
-
}
|
|
719
|
-
if (item) {
|
|
720
|
-
return (
|
|
721
|
-
<View
|
|
722
|
-
key={`ScreenItem${index}`}
|
|
723
|
-
style={{
|
|
724
|
-
marginTop: space,
|
|
725
|
-
marginLeft: layout.insetLeft,
|
|
726
|
-
marginRight: layout.insetRight,
|
|
727
|
-
flex: item.props?.expanded ? 1 : undefined,
|
|
728
|
-
}}
|
|
729
|
-
onLayout={item.props?.onLayout}
|
|
730
|
-
>
|
|
731
|
-
{item}
|
|
732
|
-
</View>
|
|
733
|
-
);
|
|
734
|
-
}
|
|
735
|
-
});
|
|
736
|
-
} else {
|
|
737
|
-
const item: any = children;
|
|
738
|
-
const space = item?.props?.useMargin === false ? 0 : Spacing.M;
|
|
739
|
-
if (item?.type === Fragment) {
|
|
740
|
-
return renderContent(item?.props?.children);
|
|
741
|
-
}
|
|
742
|
-
return (
|
|
743
|
-
<View
|
|
744
|
-
key={`ScreenItem`}
|
|
745
|
-
style={{
|
|
746
|
-
marginTop: space,
|
|
747
|
-
marginLeft: layout.insetLeft,
|
|
748
|
-
marginRight: layout.insetRight,
|
|
749
|
-
flex: item?.props?.expanded ? 1 : undefined,
|
|
750
|
-
}}
|
|
751
|
-
onLayout={item?.props?.onLayout}
|
|
752
|
-
>
|
|
753
|
-
{children}
|
|
754
|
-
</View>
|
|
755
|
-
);
|
|
756
|
-
}
|
|
757
|
-
};
|
|
168
|
+
const { handleScroll, handleScrollEnd, handleMomentumScrollEnd } =
|
|
169
|
+
createScrollHandlers({
|
|
170
|
+
scrollable,
|
|
171
|
+
animatedValue: animatedValue.current,
|
|
172
|
+
sharedValue,
|
|
173
|
+
scrollViewProps,
|
|
174
|
+
animatedHeader,
|
|
175
|
+
inputSearchProps,
|
|
176
|
+
currentTint,
|
|
177
|
+
navigation,
|
|
178
|
+
snapQuickReturnHeader,
|
|
179
|
+
ref,
|
|
180
|
+
});
|
|
181
|
+
const Component: any = scrollable ? Animated.ScrollView : View;
|
|
758
182
|
|
|
759
|
-
// Cap the screen container height so a scrollable body with a sticky footer
|
|
760
|
-
// can't push the footer past the visible frame (web previews measure the
|
|
761
|
-
// safe-area frame from the seeded SafeAreaProvider metrics). Subtract the
|
|
762
|
-
// bottom tab bar when present and the header unless it's an animated/extended
|
|
763
|
-
// header (those overlay rather than offset the body).
|
|
764
183
|
const getHeight = () => {
|
|
765
184
|
let newHeight = frame.height;
|
|
766
185
|
if (isTab) {
|
|
@@ -772,8 +191,6 @@ const Screen = forwardRef(
|
|
|
772
191
|
return newHeight;
|
|
773
192
|
};
|
|
774
193
|
|
|
775
|
-
// without the grid, the content container keeps clear of the horizontal insets.
|
|
776
|
-
// Only set when there are insets, so a caller's paddingHorizontal is never overridden.
|
|
777
194
|
const hasContentInset = layout.insetLeft > 0 || layout.insetRight > 0;
|
|
778
195
|
const needsContentInset = !useGridLayout && hasContentInset;
|
|
779
196
|
const contentInsetStyle = needsContentInset && {
|
|
@@ -796,8 +213,6 @@ const Screen = forwardRef(
|
|
|
796
213
|
Styles.flex,
|
|
797
214
|
{
|
|
798
215
|
backgroundColor: backgroundColor ?? theme.colors.background.default,
|
|
799
|
-
// Web-only cap so a scrollable body with a sticky footer can't push
|
|
800
|
-
// the footer past the frame. Native handles this without a cap.
|
|
801
216
|
maxHeight: Platform.OS === 'web' ? getHeight() : undefined,
|
|
802
217
|
},
|
|
803
218
|
]}
|
|
@@ -861,9 +276,14 @@ const Screen = forwardRef(
|
|
|
861
276
|
scrollViewProps?.contentContainerStyle,
|
|
862
277
|
]}
|
|
863
278
|
>
|
|
864
|
-
{renderAnimatedHeader(
|
|
865
|
-
|
|
866
|
-
|
|
279
|
+
{renderAnimatedHeader(
|
|
280
|
+
animatedHeader,
|
|
281
|
+
layoutOffset,
|
|
282
|
+
animatedValue.current,
|
|
283
|
+
sharedValue,
|
|
284
|
+
)}
|
|
285
|
+
|
|
286
|
+
{useGridLayout ? renderContent(children, layout) : children}
|
|
867
287
|
</Component>
|
|
868
288
|
|
|
869
289
|
{floatingButtonProps && (
|
|
@@ -882,33 +302,17 @@ const Screen = forwardRef(
|
|
|
882
302
|
)}
|
|
883
303
|
|
|
884
304
|
{Footer && (
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
<View
|
|
897
|
-
style={[
|
|
898
|
-
styles.shadow,
|
|
899
|
-
{
|
|
900
|
-
paddingBottom:
|
|
901
|
-
(isTab && duoTabInset ? duoTabInset : bottomInset) +
|
|
902
|
-
Spacing.S,
|
|
903
|
-
backgroundColor: theme.colors.background.surface,
|
|
904
|
-
},
|
|
905
|
-
]}
|
|
906
|
-
>
|
|
907
|
-
{/* The footer inset is a caller decision, not a platform one — a footer
|
|
908
|
-
that carries its own horizontal padding passes `marginFooter={false}`. */}
|
|
909
|
-
<Section useMargin={marginFooter}>{Footer}</Section>
|
|
910
|
-
</View>
|
|
911
|
-
</View>
|
|
305
|
+
<ScreenFooter
|
|
306
|
+
footer={Footer}
|
|
307
|
+
marginFooter={marginFooter}
|
|
308
|
+
insetLeft={layout.insetLeft}
|
|
309
|
+
insetRight={layout.insetRight}
|
|
310
|
+
hasContentInset={hasContentInset}
|
|
311
|
+
isTab={isTab}
|
|
312
|
+
duoTabInset={duoTabInset}
|
|
313
|
+
bottomInset={bottomInset}
|
|
314
|
+
surfaceColor={theme.colors.background.surface}
|
|
315
|
+
/>
|
|
912
316
|
)}
|
|
913
317
|
</KeyboardAvoidingView>
|
|
914
318
|
</View>
|