@plexui/react-native 0.2.22 → 0.2.23
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
|
-
import { Animated, Platform, StyleSheet, View } from "react-native";
|
|
3
|
+
import { Animated, Easing, Platform, StyleSheet, View } from "react-native";
|
|
4
4
|
import { isRTL } from "../../internal/direction";
|
|
5
5
|
import { curves } from "../../internal/motion";
|
|
6
6
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
@@ -46,17 +46,73 @@ const SCRUB_THRESHOLD = 8;
|
|
|
46
46
|
* page and back as it moves), in a 48dp target, with no capsule at all. For a screen reader it is adjustable: swipe
|
|
47
47
|
* up or down for the next or previous page.
|
|
48
48
|
*/
|
|
49
|
-
export function PageControl({ count, value: valueProp, defaultValue = 0, onChange, background = "automatic", indicator = "dots", tone = "default", direction = "horizontal", size = "md", valueText = defaultValueText, "aria-label": ariaLabel = "Pages", testID, style, }) {
|
|
49
|
+
export function PageControl({ count, value: valueProp, defaultValue = 0, position: positionProp, onChange, background = "automatic", indicator = "dots", tone = "default", direction = "horizontal", size = "md", valueText = defaultValueText, "aria-label": ariaLabel = "Pages", testID, style, }) {
|
|
50
50
|
const theme = useTheme();
|
|
51
51
|
const [own, setOwn] = useState(defaultValue);
|
|
52
52
|
const current = clampIndex(valueProp ?? own, count);
|
|
53
53
|
const [press, setPress] = useState(null);
|
|
54
54
|
// Where the dots stand inside the target, which can be wider than them (x is physical, from the left)
|
|
55
55
|
const [capsule, setCapsule] = useState({ x: 0, width: 0 });
|
|
56
|
+
// The fractional page the marks follow: the app's own `position`, or one that moves to `value` by itself
|
|
57
|
+
const [ownPosition] = useState(() => new Animated.Value(typeof positionProp === "number" ? positionProp : current));
|
|
58
|
+
const driven = positionProp != null && typeof positionProp === "object";
|
|
59
|
+
const scrubbed = useRef(false);
|
|
60
|
+
const shown = useRef(null);
|
|
61
|
+
// The page nearest the position: the dots' window from seven pages follows it, so the marks it passes stay drawn
|
|
62
|
+
const [near, setNear] = useState(current);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (typeof positionProp === "number") {
|
|
65
|
+
ownPosition.setValue(positionProp);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const source = driven ? positionProp : ownPosition;
|
|
69
|
+
const follow = (value) => {
|
|
70
|
+
// The own position keeps up with an app's, so it moves on from there when the app's goes
|
|
71
|
+
if (driven)
|
|
72
|
+
ownPosition.setValue(value);
|
|
73
|
+
const page = clampIndex(Math.round(value), count);
|
|
74
|
+
setNear((last) => (last === page ? last : page));
|
|
75
|
+
};
|
|
76
|
+
const id = source.addListener(({ value }) => follow(value));
|
|
77
|
+
// A listener hears only what comes next: a new source's value now sets the window at once
|
|
78
|
+
const read = () => source.__getValue?.();
|
|
79
|
+
let live = true;
|
|
80
|
+
void Promise.resolve().then(() => {
|
|
81
|
+
// Read as it runs, so a change in between is not undone
|
|
82
|
+
const now = read();
|
|
83
|
+
if (live && typeof now === "number")
|
|
84
|
+
follow(now);
|
|
85
|
+
});
|
|
86
|
+
return () => {
|
|
87
|
+
live = false;
|
|
88
|
+
source.removeListener(id);
|
|
89
|
+
};
|
|
90
|
+
}, [positionProp, driven, ownPosition, count]);
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (positionProp != null)
|
|
93
|
+
return;
|
|
94
|
+
const still = shown.current == null || theme.reducedMotion || scrubbed.current;
|
|
95
|
+
shown.current = current;
|
|
96
|
+
scrubbed.current = false;
|
|
97
|
+
if (still) {
|
|
98
|
+
ownPosition.setValue(current);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const animation = Animated.timing(ownPosition, { toValue: current, ...(theme.isAndroid ? ANDROID_SLIDE : IOS_SLIDE), useNativeDriver: false });
|
|
102
|
+
animation.start();
|
|
103
|
+
return () => animation.stop();
|
|
104
|
+
}, [current, positionProp, ownPosition, theme.reducedMotion, theme.isAndroid]);
|
|
105
|
+
// An overscroll past the first or the last page stands on it, so its mark keeps the whole pill
|
|
106
|
+
const position = (driven ? positionProp : ownPosition).interpolate({
|
|
107
|
+
inputRange: [0, Math.max(1, count - 1)],
|
|
108
|
+
outputRange: [0, Math.max(0, count - 1)],
|
|
109
|
+
extrapolate: "clamp",
|
|
110
|
+
});
|
|
56
111
|
const go = (index, scrubbing = false) => {
|
|
57
112
|
const next = clampIndex(index, count);
|
|
58
113
|
if (next === current)
|
|
59
114
|
return;
|
|
115
|
+
scrubbed.current = scrubbing;
|
|
60
116
|
if (valueProp === undefined)
|
|
61
117
|
setOwn(next);
|
|
62
118
|
onChange?.(next, { scrubbing });
|
|
@@ -69,7 +125,7 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
|
|
|
69
125
|
const padding = small ? 6 : theme.length("--page-control-padding-inline", 12);
|
|
70
126
|
const pitch = dot + gap;
|
|
71
127
|
// Android draws every page's dot at full size; the iOS kit shrinks the ends from seven pages
|
|
72
|
-
const sizes = android ? Array.from({ length: Math.max(0, count) }, () => "full") : pageControlDots(count,
|
|
128
|
+
const sizes = android ? Array.from({ length: Math.max(0, count) }, () => "full") : pageControlDots(count, clampIndex(typeof positionProp === "number" ? Math.round(positionProp) : near, count));
|
|
73
129
|
// The small and smaller ends keep their share of a full dot (6 and 4 of 8 on iOS)
|
|
74
130
|
const dotSize = (kind) => kind === "full"
|
|
75
131
|
? dot
|
|
@@ -77,8 +133,9 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
|
|
|
77
133
|
? Math.max(2, dot - (kind === "small" ? 1 : 2))
|
|
78
134
|
: (dot / 8) * (kind === "small" ? theme.length("--page-control-dot-size-small", 6) : theme.length("--page-control-dot-size-smaller", 4));
|
|
79
135
|
const pill = indicator === "pill";
|
|
80
|
-
// A pill: the current page two and a half dots long (
|
|
81
|
-
const
|
|
136
|
+
// A pill: the current page two and a half dots long (14 at `sm`), along the direction
|
|
137
|
+
const pillLength = small ? 14 : dot * 2.5;
|
|
138
|
+
const dotWidth = (kind, index) => (pill && index === current ? pillLength : dotSize(kind));
|
|
82
139
|
// The center of the current dot, for a tap on either side of it
|
|
83
140
|
let x = padding;
|
|
84
141
|
let currentCenter = padding;
|
|
@@ -93,8 +150,9 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
|
|
|
93
150
|
const on = onColor ? "#FFFFFF" : android ? theme.material.primary : theme.color("--page-control-dot-color-current", theme.colors.text);
|
|
94
151
|
// Android's page dots: #BBBBBB, #555555 in a dark theme
|
|
95
152
|
const off = onColor ? "rgba(255, 255, 255, 0.4)" : android ? (theme.scheme === "dark" ? "#555555" : "#BBBBBB") : theme.color("--page-control-dot-color", theme.colors.labelTertiary);
|
|
96
|
-
// Android's current dot is drawn over the gray ones (it stretches between pages)
|
|
97
|
-
|
|
153
|
+
// Android's current dot is drawn over the gray ones (it stretches between pages) unless the pages' scroll drives the
|
|
154
|
+
// dots, when their color crosses over as on iOS; a pill is a dot of its own
|
|
155
|
+
const worm = android && !pill && positionProp == null;
|
|
98
156
|
// Android draws no capsule, not even for `prominent`
|
|
99
157
|
const capsuleHeight = small ? 16 : theme.length("--page-control-height", 24);
|
|
100
158
|
const target = android ? 48 : theme.length("--page-control-target-size", 44);
|
|
@@ -152,13 +210,27 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
|
|
|
152
210
|
? { flexDirection: "column", width: capsuleHeight, paddingVertical: padding, gap, borderRadius: capsuleHeight / 2 }
|
|
153
211
|
: { height: capsuleHeight, paddingHorizontal: padding, gap, borderRadius: capsuleHeight / 2 },
|
|
154
212
|
showBackground ? { backgroundColor: onColor ? "rgba(255, 255, 255, 0.2)" : theme.color("--page-control-background") } : null,
|
|
155
|
-
], children: [sizes.map((size, index) =>
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
213
|
+
], children: [sizes.map((size, index) => {
|
|
214
|
+
if (size === "hidden")
|
|
215
|
+
return null;
|
|
216
|
+
const across = dotSize(size);
|
|
217
|
+
if (worm)
|
|
218
|
+
return _jsx(View, { style: { width: vertical ? across : dotWidth(size, index), height: vertical ? dotWidth(size, index) : across, borderRadius: dot / 2, backgroundColor: off } }, index);
|
|
219
|
+
// How much of the current page this mark is: 1 on its page, 0 a page away, a line between
|
|
220
|
+
const weight = position.interpolate(pageControlWeight(index));
|
|
221
|
+
const along = pill ? weight.interpolate({ inputRange: [0, 1], outputRange: [across, pillLength] }) : across;
|
|
222
|
+
return (_jsx(Animated.View, { testID: testID ? `${testID}-mark-${index}` : undefined, style: { width: vertical ? across : along, height: vertical ? along : across, borderRadius: dot / 2, backgroundColor: off }, children: _jsx(Animated.View, { style: [StyleSheet.absoluteFill, { borderRadius: dot / 2, backgroundColor: on, opacity: weight }] }) }, index));
|
|
223
|
+
}), worm ? _jsx(AndroidCurrent, { start: currentCenter - dot / 2, color: on, reduced: theme.reducedMotion, dot: dot, vertical: vertical }) : null] }) }));
|
|
161
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* The interpolation of a mark's share of the current page from the pages' position: 1 on its own page, 0 from a page
|
|
227
|
+
* away, a line between. Two neighbours share one page between them, so a pill's length moves from one to the other and
|
|
228
|
+
* the row keeps its length.
|
|
229
|
+
*/
|
|
230
|
+
export const pageControlWeight = (index) => ({ inputRange: [index - 1, index, index + 1], outputRange: [0, 1, 0], extrapolate: "clamp" });
|
|
231
|
+
/** A new `value` with no `position`: iOS's default UIView curve, Material's standard easing and its medium duration. */
|
|
232
|
+
const IOS_SLIDE = { duration: 250, easing: curves.easeInOut };
|
|
233
|
+
const ANDROID_SLIDE = { duration: 300, easing: Easing.bezier(0.2, 0, 0, 1) };
|
|
162
234
|
/** Android's page dots: 5dp, 11dp from one to the next. */
|
|
163
235
|
const ANDROID_DOT = 5;
|
|
164
236
|
const ANDROID_GAP = 6;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type StyleProp, type ViewStyle } from "react-native";
|
|
1
|
+
import { Animated, type StyleProp, type ViewStyle } from "react-native";
|
|
2
2
|
export type PageControlDotSize = "full" | "small" | "smaller" | "hidden";
|
|
3
3
|
export type PageControlChangeDetails = {
|
|
4
4
|
/** The change came from scrubbing: show the page without the scrolling animation, as the HIG asks. */
|
|
@@ -11,6 +11,16 @@ export type PageControlProps = {
|
|
|
11
11
|
value?: number;
|
|
12
12
|
/** @default 0 */
|
|
13
13
|
defaultValue?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Where the pages stand as they scroll: the page index with its fraction (the scroll offset over the page's length),
|
|
16
|
+
* a number or an `Animated` value, so a pager's scroll drives the control on every frame without a render. The
|
|
17
|
+
* pill flows from one page's mark to the next and the dots' color crosses over with it, under the finger and then
|
|
18
|
+
* with the pager's own settle. Without it the control moves to a new `value` over a short standard transition (at
|
|
19
|
+
* once while scrubbing and with reduced motion). The current page for a screen reader, a tap and the keys stays
|
|
20
|
+
* `value`. An `Animated` value drives the marks' length, so it moves on the JavaScript driver
|
|
21
|
+
* (`Animated.event(…, { useNativeDriver: false })`), as the package's own animations do.
|
|
22
|
+
*/
|
|
23
|
+
position?: number | Animated.Value | Animated.AnimatedInterpolation<number>;
|
|
14
24
|
/** Called with the index of the next page. */
|
|
15
25
|
onChange?: (index: number, details: PageControlChangeDetails) => void;
|
|
16
26
|
/**
|
|
@@ -62,4 +72,14 @@ export declare const pageControlDots: (count: number, current: number) => PageCo
|
|
|
62
72
|
* page and back as it moves), in a 48dp target, with no capsule at all. For a screen reader it is adjustable: swipe
|
|
63
73
|
* up or down for the next or previous page.
|
|
64
74
|
*/
|
|
65
|
-
export declare function PageControl({ count, value: valueProp, defaultValue, onChange, background, indicator, tone, direction, size, valueText, "aria-label": ariaLabel, testID, style, }: PageControlProps): import("react").JSX.Element;
|
|
75
|
+
export declare function PageControl({ count, value: valueProp, defaultValue, position: positionProp, onChange, background, indicator, tone, direction, size, valueText, "aria-label": ariaLabel, testID, style, }: PageControlProps): import("react").JSX.Element;
|
|
76
|
+
/**
|
|
77
|
+
* The interpolation of a mark's share of the current page from the pages' position: 1 on its own page, 0 from a page
|
|
78
|
+
* away, a line between. Two neighbours share one page between them, so a pill's length moves from one to the other and
|
|
79
|
+
* the row keeps its length.
|
|
80
|
+
*/
|
|
81
|
+
export declare const pageControlWeight: (index: number) => {
|
|
82
|
+
inputRange: number[];
|
|
83
|
+
outputRange: number[];
|
|
84
|
+
extrapolate: "clamp";
|
|
85
|
+
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from "react"
|
|
2
|
-
import { Animated, Platform, StyleSheet, View, type AccessibilityActionEvent, type GestureResponderEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
2
|
+
import { Animated, Easing, Platform, StyleSheet, View, type AccessibilityActionEvent, type GestureResponderEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
3
3
|
import { isRTL } from "../../internal/direction"
|
|
4
4
|
import { curves } from "../../internal/motion"
|
|
5
5
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
@@ -18,6 +18,16 @@ export type PageControlProps = {
|
|
|
18
18
|
value?: number
|
|
19
19
|
/** @default 0 */
|
|
20
20
|
defaultValue?: number
|
|
21
|
+
/**
|
|
22
|
+
* Where the pages stand as they scroll: the page index with its fraction (the scroll offset over the page's length),
|
|
23
|
+
* a number or an `Animated` value, so a pager's scroll drives the control on every frame without a render. The
|
|
24
|
+
* pill flows from one page's mark to the next and the dots' color crosses over with it, under the finger and then
|
|
25
|
+
* with the pager's own settle. Without it the control moves to a new `value` over a short standard transition (at
|
|
26
|
+
* once while scrubbing and with reduced motion). The current page for a screen reader, a tap and the keys stays
|
|
27
|
+
* `value`. An `Animated` value drives the marks' length, so it moves on the JavaScript driver
|
|
28
|
+
* (`Animated.event(…, { useNativeDriver: false })`), as the package's own animations do.
|
|
29
|
+
*/
|
|
30
|
+
position?: number | Animated.Value | Animated.AnimatedInterpolation<number>
|
|
21
31
|
/** Called with the index of the next page. */
|
|
22
32
|
onChange?: (index: number, details: PageControlChangeDetails) => void
|
|
23
33
|
/**
|
|
@@ -105,6 +115,7 @@ export function PageControl({
|
|
|
105
115
|
count,
|
|
106
116
|
value: valueProp,
|
|
107
117
|
defaultValue = 0,
|
|
118
|
+
position: positionProp,
|
|
108
119
|
onChange,
|
|
109
120
|
background = "automatic",
|
|
110
121
|
indicator = "dots",
|
|
@@ -122,9 +133,62 @@ export function PageControl({
|
|
|
122
133
|
const [press, setPress] = useState<Press | null>(null)
|
|
123
134
|
// Where the dots stand inside the target, which can be wider than them (x is physical, from the left)
|
|
124
135
|
const [capsule, setCapsule] = useState({ x: 0, width: 0 })
|
|
136
|
+
// The fractional page the marks follow: the app's own `position`, or one that moves to `value` by itself
|
|
137
|
+
const [ownPosition] = useState(() => new Animated.Value(typeof positionProp === "number" ? positionProp : current))
|
|
138
|
+
const driven = positionProp != null && typeof positionProp === "object"
|
|
139
|
+
const scrubbed = useRef(false)
|
|
140
|
+
const shown = useRef<number | null>(null)
|
|
141
|
+
// The page nearest the position: the dots' window from seven pages follows it, so the marks it passes stay drawn
|
|
142
|
+
const [near, setNear] = useState(current)
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (typeof positionProp === "number") {
|
|
145
|
+
ownPosition.setValue(positionProp)
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
const source = driven ? (positionProp as Animated.Value) : ownPosition
|
|
149
|
+
const follow = (value: number) => {
|
|
150
|
+
// The own position keeps up with an app's, so it moves on from there when the app's goes
|
|
151
|
+
if (driven) ownPosition.setValue(value)
|
|
152
|
+
const page = clampIndex(Math.round(value), count)
|
|
153
|
+
setNear((last) => (last === page ? last : page))
|
|
154
|
+
}
|
|
155
|
+
const id = source.addListener(({ value }) => follow(value))
|
|
156
|
+
// A listener hears only what comes next: a new source's value now sets the window at once
|
|
157
|
+
const read = () => (source as unknown as { __getValue?: () => number }).__getValue?.()
|
|
158
|
+
let live = true
|
|
159
|
+
void Promise.resolve().then(() => {
|
|
160
|
+
// Read as it runs, so a change in between is not undone
|
|
161
|
+
const now = read()
|
|
162
|
+
if (live && typeof now === "number") follow(now)
|
|
163
|
+
})
|
|
164
|
+
return () => {
|
|
165
|
+
live = false
|
|
166
|
+
source.removeListener(id)
|
|
167
|
+
}
|
|
168
|
+
}, [positionProp, driven, ownPosition, count])
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
if (positionProp != null) return
|
|
171
|
+
const still = shown.current == null || theme.reducedMotion || scrubbed.current
|
|
172
|
+
shown.current = current
|
|
173
|
+
scrubbed.current = false
|
|
174
|
+
if (still) {
|
|
175
|
+
ownPosition.setValue(current)
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
const animation = Animated.timing(ownPosition, { toValue: current, ...(theme.isAndroid ? ANDROID_SLIDE : IOS_SLIDE), useNativeDriver: false })
|
|
179
|
+
animation.start()
|
|
180
|
+
return () => animation.stop()
|
|
181
|
+
}, [current, positionProp, ownPosition, theme.reducedMotion, theme.isAndroid])
|
|
182
|
+
// An overscroll past the first or the last page stands on it, so its mark keeps the whole pill
|
|
183
|
+
const position = (driven ? (positionProp as Animated.Value) : ownPosition).interpolate({
|
|
184
|
+
inputRange: [0, Math.max(1, count - 1)],
|
|
185
|
+
outputRange: [0, Math.max(0, count - 1)],
|
|
186
|
+
extrapolate: "clamp",
|
|
187
|
+
})
|
|
125
188
|
const go = (index: number, scrubbing = false) => {
|
|
126
189
|
const next = clampIndex(index, count)
|
|
127
190
|
if (next === current) return
|
|
191
|
+
scrubbed.current = scrubbing
|
|
128
192
|
if (valueProp === undefined) setOwn(next)
|
|
129
193
|
onChange?.(next, { scrubbing })
|
|
130
194
|
}
|
|
@@ -136,7 +200,7 @@ export function PageControl({
|
|
|
136
200
|
const padding = small ? 6 : theme.length("--page-control-padding-inline", 12)
|
|
137
201
|
const pitch = dot + gap
|
|
138
202
|
// Android draws every page's dot at full size; the iOS kit shrinks the ends from seven pages
|
|
139
|
-
const sizes = android ? Array.from({ length: Math.max(0, count) }, (): PageControlDotSize => "full") : pageControlDots(count,
|
|
203
|
+
const sizes = android ? Array.from({ length: Math.max(0, count) }, (): PageControlDotSize => "full") : pageControlDots(count, clampIndex(typeof positionProp === "number" ? Math.round(positionProp) : near, count))
|
|
140
204
|
// The small and smaller ends keep their share of a full dot (6 and 4 of 8 on iOS)
|
|
141
205
|
const dotSize = (kind: PageControlDotSize) =>
|
|
142
206
|
kind === "full"
|
|
@@ -145,8 +209,9 @@ export function PageControl({
|
|
|
145
209
|
? Math.max(2, dot - (kind === "small" ? 1 : 2))
|
|
146
210
|
: (dot / 8) * (kind === "small" ? theme.length("--page-control-dot-size-small", 6) : theme.length("--page-control-dot-size-smaller", 4))
|
|
147
211
|
const pill = indicator === "pill"
|
|
148
|
-
// A pill: the current page two and a half dots long (
|
|
149
|
-
const
|
|
212
|
+
// A pill: the current page two and a half dots long (14 at `sm`), along the direction
|
|
213
|
+
const pillLength = small ? 14 : dot * 2.5
|
|
214
|
+
const dotWidth = (kind: PageControlDotSize, index: number) => (pill && index === current ? pillLength : dotSize(kind))
|
|
150
215
|
// The center of the current dot, for a tap on either side of it
|
|
151
216
|
let x = padding
|
|
152
217
|
let currentCenter = padding
|
|
@@ -159,8 +224,9 @@ export function PageControl({
|
|
|
159
224
|
const on = onColor ? "#FFFFFF" : android ? theme.material.primary : theme.color("--page-control-dot-color-current", theme.colors.text)
|
|
160
225
|
// Android's page dots: #BBBBBB, #555555 in a dark theme
|
|
161
226
|
const off = onColor ? "rgba(255, 255, 255, 0.4)" : android ? (theme.scheme === "dark" ? "#555555" : "#BBBBBB") : theme.color("--page-control-dot-color", theme.colors.labelTertiary)
|
|
162
|
-
// Android's current dot is drawn over the gray ones (it stretches between pages)
|
|
163
|
-
|
|
227
|
+
// Android's current dot is drawn over the gray ones (it stretches between pages) unless the pages' scroll drives the
|
|
228
|
+
// dots, when their color crosses over as on iOS; a pill is a dot of its own
|
|
229
|
+
const worm = android && !pill && positionProp == null
|
|
164
230
|
// Android draws no capsule, not even for `prominent`
|
|
165
231
|
const capsuleHeight = small ? 16 : theme.length("--page-control-height", 24)
|
|
166
232
|
const target = android ? 48 : theme.length("--page-control-target-size", 44)
|
|
@@ -242,25 +308,40 @@ export function PageControl({
|
|
|
242
308
|
showBackground ? { backgroundColor: onColor ? "rgba(255, 255, 255, 0.2)" : theme.color("--page-control-background") } : null,
|
|
243
309
|
]}
|
|
244
310
|
>
|
|
245
|
-
{sizes.map((size, index) =>
|
|
246
|
-
size === "hidden"
|
|
247
|
-
|
|
311
|
+
{sizes.map((size, index) => {
|
|
312
|
+
if (size === "hidden") return null
|
|
313
|
+
const across = dotSize(size)
|
|
314
|
+
if (worm) return <View key={index} style={{ width: vertical ? across : dotWidth(size, index), height: vertical ? dotWidth(size, index) : across, borderRadius: dot / 2, backgroundColor: off }} />
|
|
315
|
+
// How much of the current page this mark is: 1 on its page, 0 a page away, a line between
|
|
316
|
+
const weight = position.interpolate(pageControlWeight(index))
|
|
317
|
+
const along = pill ? weight.interpolate({ inputRange: [0, 1], outputRange: [across, pillLength] }) : across
|
|
318
|
+
return (
|
|
319
|
+
<Animated.View
|
|
248
320
|
key={index}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
),
|
|
257
|
-
)}
|
|
321
|
+
testID={testID ? `${testID}-mark-${index}` : undefined}
|
|
322
|
+
style={{ width: vertical ? across : along, height: vertical ? along : across, borderRadius: dot / 2, backgroundColor: off }}
|
|
323
|
+
>
|
|
324
|
+
<Animated.View style={[StyleSheet.absoluteFill, { borderRadius: dot / 2, backgroundColor: on, opacity: weight }]} />
|
|
325
|
+
</Animated.View>
|
|
326
|
+
)
|
|
327
|
+
})}
|
|
258
328
|
{worm ? <AndroidCurrent start={currentCenter - dot / 2} color={on} reduced={theme.reducedMotion} dot={dot} vertical={vertical} /> : null}
|
|
259
329
|
</View>
|
|
260
330
|
</View>
|
|
261
331
|
)
|
|
262
332
|
}
|
|
263
333
|
|
|
334
|
+
/**
|
|
335
|
+
* The interpolation of a mark's share of the current page from the pages' position: 1 on its own page, 0 from a page
|
|
336
|
+
* away, a line between. Two neighbours share one page between them, so a pill's length moves from one to the other and
|
|
337
|
+
* the row keeps its length.
|
|
338
|
+
*/
|
|
339
|
+
export const pageControlWeight = (index: number) => ({ inputRange: [index - 1, index, index + 1], outputRange: [0, 1, 0], extrapolate: "clamp" as const })
|
|
340
|
+
|
|
341
|
+
/** A new `value` with no `position`: iOS's default UIView curve, Material's standard easing and its medium duration. */
|
|
342
|
+
const IOS_SLIDE = { duration: 250, easing: curves.easeInOut }
|
|
343
|
+
const ANDROID_SLIDE = { duration: 300, easing: Easing.bezier(0.2, 0, 0, 1) }
|
|
344
|
+
|
|
264
345
|
/** Android's page dots: 5dp, 11dp from one to the next. */
|
|
265
346
|
const ANDROID_DOT = 5
|
|
266
347
|
const ANDROID_GAP = 6
|