@momo-kits/foundation 0.168.1-beta.39 → 0.168.1-beta.40
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.tsx +398 -86
- package/Application/BottomTab/BottomTabBar.tsx +275 -215
- package/Application/BottomTab/CustomBottomTabItem.tsx +107 -131
- package/Application/BottomTab/DuoBarCompression.tsx +28 -14
- package/Application/BottomTab/DuoTabBar.tsx +540 -32
- package/Application/BottomTab/TabBarIcon.tsx +72 -146
- package/Application/BottomTab/index.tsx +353 -89
- package/Application/BottomTab/useLiquidSelection.ts +374 -0
- package/Application/Components/BackgroundImageView.tsx +0 -4
- package/Application/Components/DuoGlassBackground.tsx +5 -7
- package/Application/Components/HeaderAnimated.tsx +13 -41
- package/Application/Components/HeaderBackground.tsx +3 -20
- package/Application/Components/HeaderExtendHeader.tsx +46 -66
- package/Application/Components/HeaderLeft.tsx +18 -5
- package/Application/Components/HeaderRight.tsx +529 -8
- package/Application/Components/HeaderTitle.tsx +579 -16
- package/Application/Components/NavigationButton.tsx +11 -18
- package/Application/Components/SearchHeader.tsx +18 -38
- package/Application/Localize.ts +0 -7
- package/Application/ModalScreen.tsx +18 -41
- package/Application/Navigation.ts +17 -15
- package/Application/NavigationContainer.tsx +21 -23
- package/Application/Navigator.ts +48 -20
- package/Application/ScaleSizeProvider.tsx +6 -13
- package/Application/StackScreen.tsx +172 -27
- package/Application/TooltipPortal.tsx +5 -12
- package/Application/WidgetContainer.tsx +7 -20
- package/Application/device.ts +52 -0
- package/Application/index.ts +1 -23
- package/Application/types.ts +242 -17
- package/Application/utils.tsx +493 -0
- package/Badge/Badge.tsx +0 -5
- package/Badge/BadgeDot.tsx +0 -1
- package/Badge/BadgeDotAnimation.tsx +7 -15
- package/Badge/BadgeRibbon.tsx +39 -47
- package/Badge/Shape.tsx +0 -2
- package/Badge/styles.ts +0 -2
- package/Badge/types.ts +2 -2
- package/Button/index.tsx +152 -21
- package/Button/styles.ts +1 -1
- package/CheckBox/index.tsx +6 -5
- package/Consts/theme.ts +10 -10
- package/Context/index.ts +1 -5
- package/Divider/DashDivider.tsx +11 -11
- package/Divider/index.tsx +7 -21
- package/FoundationList/index.tsx +0 -4
- package/Icon/index.tsx +6 -6
- package/Icon/types.ts +1 -1
- package/IconButton/index.tsx +12 -4
- package/Image/index.tsx +7 -9
- package/Input/Input.tsx +12 -10
- package/Input/InputDropDown.tsx +13 -10
- package/Input/InputMoney.tsx +152 -45
- package/Input/InputOTP.tsx +34 -36
- package/Input/InputPhoneNumber.tsx +5 -8
- package/Input/InputSearch.tsx +111 -19
- package/Input/InputTextArea.tsx +5 -5
- package/Input/SystemTextInput.tsx +2 -7
- package/Input/TextTyping.tsx +0 -4
- package/Input/common.tsx +17 -31
- package/Input/index.tsx +21 -24
- package/Input/styles.ts +5 -25
- package/Input/utils.ts +12 -14
- package/Layout/Card.tsx +4 -7
- package/Layout/FloatingButton.tsx +21 -26
- package/Layout/Item.tsx +2 -6
- package/Layout/ItemList.tsx +7 -9
- package/Layout/ItemSectionList.tsx +1 -2
- package/Layout/ReservedRegions.tsx +17 -34
- package/Layout/Screen.tsx +696 -122
- package/Layout/Section.tsx +7 -9
- package/Layout/TrackingScope.tsx +0 -1
- package/Layout/index.ts +4 -10
- package/Layout/styles.ts +0 -2
- package/Layout/types.ts +4 -2
- package/Layout/utils.ts +181 -40
- package/Loader/DotLoader.tsx +3 -11
- package/Loader/Loader.tsx +0 -4
- package/Loader/ProgressBar.tsx +6 -3
- package/Loader/Spinner.tsx +3 -11
- package/Loader/styles.ts +0 -4
- package/Loader/utils.ts +7 -11
- package/Pagination/Dot.tsx +0 -4
- package/Pagination/PaginationDot.tsx +0 -1
- package/Pagination/PaginationNumber.tsx +3 -5
- package/Pagination/PaginationScroll.tsx +0 -5
- package/Pagination/PaginationWhiteDot.tsx +0 -1
- package/Pagination/index.tsx +0 -4
- package/Pagination/types.ts +2 -2
- package/Popup/PopupNotify.tsx +102 -94
- package/Popup/PopupPromotion.tsx +11 -9
- package/Popup/types.ts +4 -11
- package/Popup/utils.ts +18 -50
- package/Radio/index.tsx +10 -6
- package/Radio/styles.ts +0 -6
- package/Skeleton/index.tsx +9 -9
- package/Skeleton/styles.ts +0 -1
- package/Switch/index.tsx +0 -1
- package/Tag/index.tsx +4 -8
- package/Tag/types.ts +3 -3
- package/Text/index.tsx +5 -25
- package/Text/styles.ts +1 -1
- package/Text/types.ts +6 -1
- package/Text/utils.ts +4 -20
- package/Title/index.tsx +40 -42
- package/Title/styles.ts +0 -6
- package/ViewBoundary/index.tsx +2 -4
- package/index.ts +6 -0
- package/package.json +1 -2
- package/Application/BottomSheet.hooks.ts +0 -195
- package/Application/BottomSheet.parts.tsx +0 -157
- package/Application/BottomSheet.styles.ts +0 -43
- package/Application/BottomTab/ActiveIndicator.tsx +0 -91
- package/Application/BottomTab/BottomTabBar.styles.ts +0 -65
- package/Application/BottomTab/BottomTabInset.tsx +0 -18
- package/Application/BottomTab/CurvedContainer.tsx +0 -155
- package/Application/BottomTab/DuoRailTabBar.tsx +0 -223
- package/Application/BottomTab/DuoTabBar.styles.ts +0 -81
- package/Application/BottomTab/TabScreen.tsx +0 -160
- package/Application/BottomTab/metrics.ts +0 -164
- package/Application/BottomTab/tabItems.ts +0 -46
- package/Application/BottomTab/usePressLift.ts +0 -32
- package/Application/Components/HeaderRight.styles.ts +0 -146
- package/Application/Components/HeaderTitle.shared.ts +0 -44
- package/Application/Components/HeaderTitle.styles.ts +0 -125
- package/Application/Components/HeaderToolkitAction.tsx +0 -180
- package/Application/Components/SwipeBackHaptic.tsx +0 -95
- package/Application/Components/TitleJourney.tsx +0 -110
- package/Application/Components/TitleLocation.tsx +0 -73
- package/Application/Components/TitleUser.tsx +0 -304
- package/Application/Components/useToolkitActions.tsx +0 -218
- package/Application/ModalIconButton.tsx +0 -66
- package/Application/StackScreen.tracking.ts +0 -143
- package/Application/headerLayout.ts +0 -158
- package/Application/hooks.ts +0 -137
- package/Application/modalLayout.ts +0 -176
- package/Application/navigationOptions.tsx +0 -212
- package/Application/types.header.ts +0 -121
- package/Application/types.tabs.ts +0 -48
- package/Application/types.theme.ts +0 -87
- package/Application/utils.ts +0 -107
- package/Button/utils.ts +0 -133
- package/Input/InputMoneyView.tsx +0 -194
- package/Input/SearchTextTyping.tsx +0 -108
- package/Input/moneyUtils.ts +0 -23
- package/Layout/layoutMetrics.ts +0 -58
- package/Layout/layoutTypes.ts +0 -86
- package/Layout/screenContent.tsx +0 -92
- package/Layout/screenFooter.tsx +0 -63
- package/Layout/screenHeader.tsx +0 -321
- package/Layout/screenQuickReturn.tsx +0 -64
- package/Layout/screenScroll.ts +0 -107
- package/Layout/screenTypes.ts +0 -143
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { useCallback, useContext, useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { Gesture } from 'react-native-gesture-handler';
|
|
3
|
+
import {
|
|
4
|
+
clamp,
|
|
5
|
+
useAnimatedReaction,
|
|
6
|
+
useAnimatedStyle,
|
|
7
|
+
useReducedMotion,
|
|
8
|
+
useSharedValue,
|
|
9
|
+
withSequence,
|
|
10
|
+
withSpring,
|
|
11
|
+
withTiming,
|
|
12
|
+
} from 'react-native-reanimated';
|
|
13
|
+
import { scheduleOnRN } from 'react-native-worklets';
|
|
14
|
+
import { ApplicationContext } from '../../Context';
|
|
15
|
+
|
|
16
|
+
type Axis = 'x' | 'y';
|
|
17
|
+
|
|
18
|
+
type Options = {
|
|
19
|
+
count: number;
|
|
20
|
+
// distance between two neighbouring tab centers
|
|
21
|
+
pitch: number;
|
|
22
|
+
// position of the first tab's center inside the gesture view
|
|
23
|
+
firstCenter: number;
|
|
24
|
+
axis: Axis;
|
|
25
|
+
index: number;
|
|
26
|
+
onSelect: (index: number) => void;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const SPRING = { damping: 18, stiffness: 220, mass: 0.8 };
|
|
30
|
+
// the lens trails the finger a little while dragged, like the system tab bar
|
|
31
|
+
const DRAG_SPRING = { damping: 24, stiffness: 600, mass: 0.6 };
|
|
32
|
+
const REDUCED_TIMING = { duration: 200 };
|
|
33
|
+
// while pressed the selection bubble grows into a lens past the bar's edges (80x54 to about 96x70)
|
|
34
|
+
const LENS_SCALE_X = 1.2;
|
|
35
|
+
const LENS_SCALE_Y = 1.3;
|
|
36
|
+
// a moving lens stretches along its path and thins across it, eased per frame so the
|
|
37
|
+
// shape follows the speed smoothly
|
|
38
|
+
const STRETCH_PER_POINT = 0.012;
|
|
39
|
+
const MAX_STRETCH = 0.25;
|
|
40
|
+
const STRETCH_EASING = 0.25;
|
|
41
|
+
// once eased below this the lens is round again
|
|
42
|
+
const REST_STRETCH = 0.002;
|
|
43
|
+
// a tap is shorter than the lift: the lens finishes rising, then settles, one smooth pulse
|
|
44
|
+
const TAP_LIFT_DURATION = 120;
|
|
45
|
+
// the bar swells a little under the finger
|
|
46
|
+
const BAR_SWELL = 0.04;
|
|
47
|
+
// the tab the lens lands on pops
|
|
48
|
+
const ICON_POP = 1.15;
|
|
49
|
+
// movement before a press turns into a drag, below it the tab's touchable handles the tap
|
|
50
|
+
const DRAG_SLOP = 10;
|
|
51
|
+
// UIScrollView rubber band constant
|
|
52
|
+
const RUBBER_BAND = 0.55;
|
|
53
|
+
// a cancelled press or a prevented switch: the lens returns to the selected tab after this
|
|
54
|
+
const RESYNC_DELAY = 100;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* resistance past the first and last tab, the further the finger goes the less the lens follows
|
|
58
|
+
*/
|
|
59
|
+
const rubberBand = (value: number, max: number, dimension: number) => {
|
|
60
|
+
'worklet';
|
|
61
|
+
const band = (overshoot: number) =>
|
|
62
|
+
(1 - 1 / ((overshoot * RUBBER_BAND) / dimension + 1)) * dimension;
|
|
63
|
+
if (value < 0) {
|
|
64
|
+
return -band(-value);
|
|
65
|
+
}
|
|
66
|
+
if (value > max) {
|
|
67
|
+
return max + band(value - max);
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* iOS 26 tab bar selection motion, without the glass material:
|
|
74
|
+
* - press lifts the selection into a lens over the pressed tab and swells the bar, release
|
|
75
|
+
* settles it back (the tab's touchable drives this through pressIn / pressOut)
|
|
76
|
+
* - dragging slides the lens under the finger, stretched by its speed and rubber banded
|
|
77
|
+
* past the ends, with a tick on each tab it enters; releasing selects the tab under it.
|
|
78
|
+
* The drag cancels the touchable once it activates, so a press is either a tap or a drag
|
|
79
|
+
*/
|
|
80
|
+
const useLiquidSelection = ({
|
|
81
|
+
count,
|
|
82
|
+
pitch,
|
|
83
|
+
firstCenter,
|
|
84
|
+
axis,
|
|
85
|
+
index,
|
|
86
|
+
onSelect,
|
|
87
|
+
}: Options) => {
|
|
88
|
+
const { navigator } = useContext<any>(ApplicationContext);
|
|
89
|
+
const reduceMotion = useReducedMotion();
|
|
90
|
+
|
|
91
|
+
const offset = useSharedValue(index * pitch);
|
|
92
|
+
// where the lens is heading, so a re-render doesn't restart a spring already going there
|
|
93
|
+
const destination = useSharedValue(index * pitch);
|
|
94
|
+
const selected = useSharedValue(index);
|
|
95
|
+
const hovered = useSharedValue(index);
|
|
96
|
+
const lift = useSharedValue(0);
|
|
97
|
+
const dragging = useSharedValue(false);
|
|
98
|
+
const stretch = useSharedValue(0);
|
|
99
|
+
const metrics = useSharedValue({ count, pitch, firstCenter });
|
|
100
|
+
const measured = useRef(pitch > 0);
|
|
101
|
+
|
|
102
|
+
const indexRef = useRef(index);
|
|
103
|
+
const pitchRef = useRef(pitch);
|
|
104
|
+
// read through refs so the gesture is never rebuilt mid drag
|
|
105
|
+
const callbacks = useRef({ onSelect, navigator });
|
|
106
|
+
indexRef.current = index;
|
|
107
|
+
pitchRef.current = pitch;
|
|
108
|
+
callbacks.current = { onSelect, navigator };
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
metrics.value = { count, pitch, firstCenter };
|
|
112
|
+
}, [count, pitch, firstCenter, metrics]);
|
|
113
|
+
|
|
114
|
+
const move = useCallback(
|
|
115
|
+
(target: number, velocity: number, config: typeof SPRING) => {
|
|
116
|
+
'worklet';
|
|
117
|
+
if (destination.value === target && velocity === 0) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
destination.value = target;
|
|
121
|
+
offset.value = reduceMotion
|
|
122
|
+
? withTiming(target, REDUCED_TIMING)
|
|
123
|
+
: withSpring(target, { ...config, velocity });
|
|
124
|
+
},
|
|
125
|
+
[offset, destination, reduceMotion],
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
const target = index * pitch;
|
|
130
|
+
selected.value = index;
|
|
131
|
+
// snap on first layout so the lens doesn't slide in from the leading edge
|
|
132
|
+
if (measured.current) {
|
|
133
|
+
move(target, 0, SPRING);
|
|
134
|
+
} else {
|
|
135
|
+
destination.value = target;
|
|
136
|
+
offset.value = target;
|
|
137
|
+
}
|
|
138
|
+
measured.current = pitch > 0;
|
|
139
|
+
}, [index, pitch, offset, destination, selected, move]);
|
|
140
|
+
|
|
141
|
+
useAnimatedReaction(
|
|
142
|
+
() => offset.value,
|
|
143
|
+
(current, previous) => {
|
|
144
|
+
if (previous === null || reduceMotion) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const target = Math.min(
|
|
148
|
+
Math.abs(current - previous) * STRETCH_PER_POINT,
|
|
149
|
+
MAX_STRETCH,
|
|
150
|
+
);
|
|
151
|
+
// eased both ways: a slow frame (e.g. the spring turning at its overshoot) must not
|
|
152
|
+
// snap the shape
|
|
153
|
+
const next = stretch.value + (target - stretch.value) * STRETCH_EASING;
|
|
154
|
+
stretch.value = next < REST_STRETCH ? 0 : next;
|
|
155
|
+
},
|
|
156
|
+
[reduceMotion],
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* returns the lens to the selected tab unless a switch to where it is heading happened
|
|
161
|
+
*/
|
|
162
|
+
const resync = useCallback(() => {
|
|
163
|
+
setTimeout(() => {
|
|
164
|
+
const target = indexRef.current * pitchRef.current;
|
|
165
|
+
if (!dragging.value && destination.value !== target) {
|
|
166
|
+
move(target, 0, SPRING);
|
|
167
|
+
}
|
|
168
|
+
}, RESYNC_DELAY);
|
|
169
|
+
}, [destination, dragging, move]);
|
|
170
|
+
|
|
171
|
+
const pressIn = (itemIndex: number) => {
|
|
172
|
+
// the lens heads to the pressed tab, not only the selected one
|
|
173
|
+
move(itemIndex * pitch, 0, SPRING);
|
|
174
|
+
if (!reduceMotion) {
|
|
175
|
+
lift.value = withSpring(1, SPRING);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* false when a drag took the press over
|
|
181
|
+
*/
|
|
182
|
+
const pressOut = () => {
|
|
183
|
+
// a drag taking over cancels the touchable, the drag owns the lens from there
|
|
184
|
+
if (dragging.value) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
if (!reduceMotion) {
|
|
188
|
+
lift.value = withSequence(
|
|
189
|
+
withTiming(1, { duration: TAP_LIFT_DURATION }),
|
|
190
|
+
withSpring(0, SPRING),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
// the lens keeps heading to the pressed tab: onPress switches to it, and a cancelled
|
|
194
|
+
// press brings it back
|
|
195
|
+
resync();
|
|
196
|
+
return true;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const tick = useCallback(() => {
|
|
200
|
+
callbacks.current.navigator?.maxApi?.triggerEventVibration?.('light');
|
|
201
|
+
}, []);
|
|
202
|
+
|
|
203
|
+
const select = useCallback(
|
|
204
|
+
(target: number) => {
|
|
205
|
+
callbacks.current.onSelect(target);
|
|
206
|
+
resync();
|
|
207
|
+
},
|
|
208
|
+
[resync],
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const gesture = useMemo(() => {
|
|
212
|
+
const position = (e: { x: number; y: number }) => {
|
|
213
|
+
'worklet';
|
|
214
|
+
return (axis === 'x' ? e.x : e.y) - metrics.value.firstCenter;
|
|
215
|
+
};
|
|
216
|
+
const nearest = (value: number) => {
|
|
217
|
+
'worklet';
|
|
218
|
+
const { count: tabs, pitch: step } = metrics.value;
|
|
219
|
+
return step > 0 ? clamp(Math.round(value / step), 0, tabs - 1) : 0;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
return Gesture.Pan()
|
|
223
|
+
.minDistance(DRAG_SLOP)
|
|
224
|
+
.shouldCancelWhenOutside(false)
|
|
225
|
+
.onStart(e => {
|
|
226
|
+
dragging.value = true;
|
|
227
|
+
hovered.value = nearest(position(e));
|
|
228
|
+
if (!reduceMotion) {
|
|
229
|
+
lift.value = withSpring(1, SPRING);
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
.onUpdate(e => {
|
|
233
|
+
const { count: tabs, pitch: step } = metrics.value;
|
|
234
|
+
const value = position(e);
|
|
235
|
+
const target = nearest(value);
|
|
236
|
+
if (target !== hovered.value) {
|
|
237
|
+
hovered.value = target;
|
|
238
|
+
scheduleOnRN(tick);
|
|
239
|
+
}
|
|
240
|
+
const follow = rubberBand(value, (tabs - 1) * step, step);
|
|
241
|
+
if (reduceMotion) {
|
|
242
|
+
destination.value = follow;
|
|
243
|
+
offset.value = follow;
|
|
244
|
+
} else {
|
|
245
|
+
move(follow, 0, DRAG_SPRING);
|
|
246
|
+
}
|
|
247
|
+
})
|
|
248
|
+
.onEnd((e, success) => {
|
|
249
|
+
dragging.value = false;
|
|
250
|
+
lift.value = reduceMotion ? 0 : withSpring(0, SPRING);
|
|
251
|
+
const raw = axis === 'x' ? e.velocityX : e.velocityY;
|
|
252
|
+
const velocity = Number.isFinite(raw) ? raw : 0;
|
|
253
|
+
if (!success) {
|
|
254
|
+
move(selected.value * metrics.value.pitch, velocity, SPRING);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const target = nearest(position(e));
|
|
258
|
+
move(target * metrics.value.pitch, velocity, SPRING);
|
|
259
|
+
scheduleOnRN(select, target);
|
|
260
|
+
});
|
|
261
|
+
}, [
|
|
262
|
+
axis,
|
|
263
|
+
reduceMotion,
|
|
264
|
+
offset,
|
|
265
|
+
destination,
|
|
266
|
+
selected,
|
|
267
|
+
hovered,
|
|
268
|
+
lift,
|
|
269
|
+
dragging,
|
|
270
|
+
metrics,
|
|
271
|
+
move,
|
|
272
|
+
tick,
|
|
273
|
+
select,
|
|
274
|
+
]);
|
|
275
|
+
|
|
276
|
+
const bubbleStyle = useAnimatedStyle(() => {
|
|
277
|
+
const along = 1 + stretch.value;
|
|
278
|
+
const across = 1 - stretch.value * 0.5;
|
|
279
|
+
const lensX = 1 + lift.value * (LENS_SCALE_X - 1);
|
|
280
|
+
const lensY = 1 + lift.value * (LENS_SCALE_Y - 1);
|
|
281
|
+
return {
|
|
282
|
+
transform:
|
|
283
|
+
axis === 'x'
|
|
284
|
+
? [
|
|
285
|
+
{ translateX: offset.value },
|
|
286
|
+
{ scaleX: lensX * along },
|
|
287
|
+
{ scaleY: lensY * across },
|
|
288
|
+
]
|
|
289
|
+
: [
|
|
290
|
+
{ translateY: offset.value },
|
|
291
|
+
{ scaleX: lensX * across },
|
|
292
|
+
{ scaleY: lensY * along },
|
|
293
|
+
],
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
const barStyle = useAnimatedStyle(() => ({
|
|
298
|
+
transform: [{ scale: 1 + lift.value * BAR_SWELL }],
|
|
299
|
+
}));
|
|
300
|
+
|
|
301
|
+
return {
|
|
302
|
+
gesture,
|
|
303
|
+
bubbleStyle,
|
|
304
|
+
barStyle,
|
|
305
|
+
pressIn,
|
|
306
|
+
pressOut,
|
|
307
|
+
offset,
|
|
308
|
+
selected,
|
|
309
|
+
pitch,
|
|
310
|
+
reduceMotion,
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
type LiquidSelection = ReturnType<typeof useLiquidSelection>;
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* active tint of a tab follows the lens over it, and the tab the lens lands on pops
|
|
318
|
+
*/
|
|
319
|
+
const useLiquidItem = (
|
|
320
|
+
{ offset, selected, pitch, reduceMotion }: LiquidSelection,
|
|
321
|
+
itemIndex: number,
|
|
322
|
+
) => {
|
|
323
|
+
const pop = useSharedValue(1);
|
|
324
|
+
|
|
325
|
+
useAnimatedReaction(
|
|
326
|
+
() => selected.value === itemIndex,
|
|
327
|
+
(isSelected, wasSelected) => {
|
|
328
|
+
if (isSelected && wasSelected === false && !reduceMotion) {
|
|
329
|
+
pop.value = withSequence(
|
|
330
|
+
withTiming(ICON_POP, { duration: 120 }),
|
|
331
|
+
withSpring(1, SPRING),
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
[itemIndex, reduceMotion],
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
const activeStyle = useAnimatedStyle(() => {
|
|
339
|
+
if (pitch <= 0) {
|
|
340
|
+
return { opacity: selected.value === itemIndex ? 1 : 0 };
|
|
341
|
+
}
|
|
342
|
+
const distance = Math.abs(offset.value - itemIndex * pitch) / pitch;
|
|
343
|
+
return { opacity: clamp(1 - distance, 0, 1) };
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
const popStyle = useAnimatedStyle(() => ({
|
|
347
|
+
transform: [{ scale: pop.value }],
|
|
348
|
+
}));
|
|
349
|
+
|
|
350
|
+
return { activeStyle, popStyle };
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* lift for a single button, e.g. the compressed rail
|
|
355
|
+
*/
|
|
356
|
+
const usePressLift = () => {
|
|
357
|
+
const reduceMotion = useReducedMotion();
|
|
358
|
+
const lift = useSharedValue(0);
|
|
359
|
+
const style = useAnimatedStyle(() => ({
|
|
360
|
+
transform: [{ scale: 1 + lift.value * (LENS_SCALE_X - 1) * 0.5 }],
|
|
361
|
+
}));
|
|
362
|
+
const onPressIn = () => {
|
|
363
|
+
if (!reduceMotion) {
|
|
364
|
+
lift.value = withSpring(1, SPRING);
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
const onPressOut = () => {
|
|
368
|
+
lift.value = withSpring(0, SPRING);
|
|
369
|
+
};
|
|
370
|
+
return { style, onPressIn, onPressOut };
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
export type { LiquidSelection };
|
|
374
|
+
export { useLiquidSelection, useLiquidItem, usePressLift };
|
|
@@ -17,10 +17,6 @@ type BackgroundImageViewProps = {
|
|
|
17
17
|
animatedValue: SharedValue<number>;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
/**
|
|
21
|
-
* Header surface (shadow or divider) and image, fading in over the first 52pt of
|
|
22
|
-
* scroll. iOS keeps the surface out of the clipped view so its shadow isn't cut.
|
|
23
|
-
*/
|
|
24
20
|
const BackgroundImageView: FC<BackgroundImageViewProps> = ({
|
|
25
21
|
useShadowHeader = true,
|
|
26
22
|
headerBackground = null,
|
|
@@ -9,8 +9,7 @@ import Animated, {
|
|
|
9
9
|
import { ApplicationContext } from '../../Context';
|
|
10
10
|
import { Shadow } from '../../Consts';
|
|
11
11
|
import { Image } from '../../Image';
|
|
12
|
-
import {
|
|
13
|
-
import { useNormalizedSharedValue } from '../hooks';
|
|
12
|
+
import { AnimatedCompatValue, useNormalizedSharedValue } from '../utils';
|
|
14
13
|
import { useScreenLayout } from '../../Layout';
|
|
15
14
|
|
|
16
15
|
const EXTENDED_GRADIENT_EXTRA = 52;
|
|
@@ -30,7 +29,6 @@ const DuoGlassBackground: React.FC<{
|
|
|
30
29
|
const { headerHeight } = useScreenLayout();
|
|
31
30
|
const sharedValue = useNormalizedSharedValue(animatedValue);
|
|
32
31
|
const fadeStart = Math.max(bannerBottom - headerHeight, 0);
|
|
33
|
-
const translucentColor = theme.colors.background.surface + TRANSLUCENT_ALPHA;
|
|
34
32
|
|
|
35
33
|
const fadeStyle = useAnimatedStyle(() => ({
|
|
36
34
|
opacity: interpolate(
|
|
@@ -48,7 +46,8 @@ const DuoGlassBackground: React.FC<{
|
|
|
48
46
|
StyleSheet.absoluteFill,
|
|
49
47
|
styles.translucentBar,
|
|
50
48
|
{
|
|
51
|
-
backgroundColor:
|
|
49
|
+
backgroundColor:
|
|
50
|
+
theme.colors.background.surface + TRANSLUCENT_ALPHA,
|
|
52
51
|
borderBottomColor: theme.colors.border.default,
|
|
53
52
|
},
|
|
54
53
|
fadeStyle,
|
|
@@ -59,9 +58,8 @@ const DuoGlassBackground: React.FC<{
|
|
|
59
58
|
};
|
|
60
59
|
|
|
61
60
|
/**
|
|
62
|
-
*
|
|
63
|
-
* header-high,
|
|
64
|
-
* scrolls it away with the content instead of fading it.
|
|
61
|
+
* pink header gradient drawn under the content, fading out on scroll as main's extended
|
|
62
|
+
* header does: header-high for default headers, 52 taller (collapsing) for extended
|
|
65
63
|
*/
|
|
66
64
|
const DuoScrollGradient: React.FC<{
|
|
67
65
|
animatedValue?: AnimatedCompatValue;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { StyleSheet
|
|
2
|
-
import LinearGradient from 'react-native-linear-gradient';
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
3
2
|
import Animated, {
|
|
4
3
|
Extrapolation,
|
|
5
4
|
interpolate,
|
|
@@ -9,8 +8,7 @@ import { type HeaderAnimatedProps } from '../types';
|
|
|
9
8
|
import React from 'react';
|
|
10
9
|
import { Image } from '../../Image';
|
|
11
10
|
import { Colors } from '../../Consts';
|
|
12
|
-
import { useNormalizedSharedValue } from '../
|
|
13
|
-
import { HeaderBarMetrics, useHeaderLayout } from '../headerLayout';
|
|
11
|
+
import { useNormalizedSharedValue } from '../utils';
|
|
14
12
|
|
|
15
13
|
const ASPECT_RATIOS: Record<
|
|
16
14
|
NonNullable<HeaderAnimatedProps['aspectRatio']>,
|
|
@@ -21,21 +19,14 @@ const ASPECT_RATIOS: Record<
|
|
|
21
19
|
'1/1': 1 / 1,
|
|
22
20
|
};
|
|
23
21
|
|
|
24
|
-
/**
|
|
25
|
-
* Parallax header image (or `children`): stretches when pulled down and fades out
|
|
26
|
-
* as the content scrolls up. Wide windows keep it at phone size, centered.
|
|
27
|
-
*/
|
|
28
22
|
const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
|
|
29
23
|
animatedValue,
|
|
30
24
|
image,
|
|
31
25
|
useScale = true,
|
|
32
26
|
aspectRatio = '16/9',
|
|
33
|
-
bannerBackgroundColor,
|
|
34
27
|
children,
|
|
35
28
|
}) => {
|
|
36
29
|
const sharedValue = useNormalizedSharedValue(animatedValue);
|
|
37
|
-
const { isWide, bannerWidth } = useHeaderLayout();
|
|
38
|
-
const ratio = ASPECT_RATIOS[aspectRatio];
|
|
39
30
|
const animatedStyle = useAnimatedStyle(() => {
|
|
40
31
|
let scale = 1;
|
|
41
32
|
if (useScale) {
|
|
@@ -64,36 +55,22 @@ const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
|
|
|
64
55
|
};
|
|
65
56
|
});
|
|
66
57
|
|
|
67
|
-
const content = children ?? (
|
|
68
|
-
<Image
|
|
69
|
-
source={{
|
|
70
|
-
uri: image,
|
|
71
|
-
}}
|
|
72
|
-
style={styles.full}
|
|
73
|
-
/>
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
if (!isWide) {
|
|
77
|
-
return (
|
|
78
|
-
<Animated.View
|
|
79
|
-
style={[styles.container, { aspectRatio: ratio }, animatedStyle]}
|
|
80
|
-
>
|
|
81
|
-
{content}
|
|
82
|
-
</Animated.View>
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
58
|
return (
|
|
87
59
|
<Animated.View
|
|
88
|
-
style={[
|
|
60
|
+
style={[
|
|
61
|
+
styles.container,
|
|
62
|
+
{ aspectRatio: ASPECT_RATIOS[aspectRatio] },
|
|
63
|
+
animatedStyle,
|
|
64
|
+
]}
|
|
89
65
|
>
|
|
90
|
-
{
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
|
|
66
|
+
{children ?? (
|
|
67
|
+
<Image
|
|
68
|
+
source={{
|
|
69
|
+
uri: image,
|
|
70
|
+
}}
|
|
71
|
+
style={styles.full}
|
|
94
72
|
/>
|
|
95
73
|
)}
|
|
96
|
-
<View style={styles.phoneBanner}>{content}</View>
|
|
97
74
|
</Animated.View>
|
|
98
75
|
);
|
|
99
76
|
};
|
|
@@ -109,11 +86,6 @@ const styles = StyleSheet.create({
|
|
|
109
86
|
alignSelf: 'center',
|
|
110
87
|
},
|
|
111
88
|
full: { width: '100%', height: '100%' },
|
|
112
|
-
phoneBanner: {
|
|
113
|
-
width: HeaderBarMetrics.bannerWidth,
|
|
114
|
-
height: '100%',
|
|
115
|
-
alignSelf: 'center',
|
|
116
|
-
},
|
|
117
89
|
});
|
|
118
90
|
|
|
119
91
|
export { HeaderAnimated };
|
|
@@ -7,14 +7,8 @@ import { ApplicationContext, MiniAppContext } from '../../Context';
|
|
|
7
7
|
import { Colors, Styles } from '../../Consts';
|
|
8
8
|
import { Image } from '../../Image';
|
|
9
9
|
import BackgroundImageView from './BackgroundImageView';
|
|
10
|
-
import { useNormalizedSharedValue } from '../
|
|
11
|
-
import { HeaderBarMetrics, useHeaderLayout } from '../headerLayout';
|
|
10
|
+
import { useNormalizedSharedValue } from '../utils';
|
|
12
11
|
|
|
13
|
-
/**
|
|
14
|
-
* Header background: surface and image that fade in on scroll, with an optional
|
|
15
|
-
* gradient (custom or theme) on top, at phone height on wide windows. Outlined
|
|
16
|
-
* when `showBaseLineDebug` is on.
|
|
17
|
-
*/
|
|
18
12
|
const HeaderBackground: React.FC<HeaderBackgroundProps> = ({
|
|
19
13
|
animatedValue,
|
|
20
14
|
useGradient = true,
|
|
@@ -27,7 +21,6 @@ const HeaderBackground: React.FC<HeaderBackgroundProps> = ({
|
|
|
27
21
|
const gradientColor = customGradientColor ?? theme.colors.gradient;
|
|
28
22
|
const headerImage = headerBackground ?? theme.assets?.headerBackground;
|
|
29
23
|
const sharedValue = useNormalizedSharedValue(animatedValue);
|
|
30
|
-
const { isWide } = useHeaderLayout();
|
|
31
24
|
|
|
32
25
|
const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
|
|
33
26
|
|
|
@@ -41,19 +34,14 @@ const HeaderBackground: React.FC<HeaderBackgroundProps> = ({
|
|
|
41
34
|
/>
|
|
42
35
|
<View style={styles.gradientContainer}>
|
|
43
36
|
{useGradient && !!gradientColor && (
|
|
44
|
-
<Animated.View
|
|
45
|
-
style={[styles.extendedHeader, isWide && styles.phoneHeight]}
|
|
46
|
-
>
|
|
37
|
+
<Animated.View style={styles.extendedHeader}>
|
|
47
38
|
<LinearGradient
|
|
48
39
|
colors={[gradientColor, gradientColor + '00']}
|
|
49
40
|
style={StyleSheet.absoluteFill}
|
|
50
41
|
>
|
|
51
42
|
{!!headerImage && (
|
|
52
43
|
<Image
|
|
53
|
-
style={
|
|
54
|
-
styles.headerBackground,
|
|
55
|
-
isWide && styles.phoneHeight,
|
|
56
|
-
]}
|
|
44
|
+
style={styles.headerBackground}
|
|
57
45
|
source={{ uri: headerImage }}
|
|
58
46
|
loading={false}
|
|
59
47
|
/>
|
|
@@ -83,11 +71,6 @@ const styles = StyleSheet.create({
|
|
|
83
71
|
position: 'absolute',
|
|
84
72
|
aspectRatio: 375 / 154,
|
|
85
73
|
},
|
|
86
|
-
// wide windows keep the phone gradient height instead of scaling with the width
|
|
87
|
-
phoneHeight: {
|
|
88
|
-
aspectRatio: undefined,
|
|
89
|
-
height: HeaderBarMetrics.gradientHeight,
|
|
90
|
-
},
|
|
91
74
|
debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
|
|
92
75
|
});
|
|
93
76
|
|