@plexui/react-native 0.2.14 → 0.2.16
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/dist/es/components/SegmentedControl/SegmentedControl.js +26 -22
- package/dist/es/components/TabBar/TabBar.js +68 -4
- package/dist/types/components/SegmentedControl/SegmentedControl.d.ts +8 -1
- package/package.json +1 -1
- package/src/components/SegmentedControl/SegmentedControl.tsx +29 -15
- package/src/components/TabBar/TabBar.tsx +83 -3
|
@@ -70,7 +70,7 @@ const optionName = (option) => {
|
|
|
70
70
|
* iOS 26 apps (48pt; 40 in a Toolbar.Row), its thumb sliding to the selection; on Android a segmented capsule, white
|
|
71
71
|
* with a sliding pill of the accent. Props follow @plexui/ui (`SegmentedControl` and `SegmentedControl.Tab`).
|
|
72
72
|
*/
|
|
73
|
-
function SegmentedControlRoot({ value, onChange, onClick, "aria-label": ariaLabel, size = "md", disabled = false, block = false, mobileMaterial, mobileSegmentWidth = "equal", showBadges = false, style, testID, children, }) {
|
|
73
|
+
function SegmentedControlRoot({ value, onChange, onClick, "aria-label": ariaLabel, size = "md", disabled = false, block = false, mobileMaterial, mobileSegmentWidth = "equal", showBadges = false, badgeColor = "label", style, testID, children, }) {
|
|
74
74
|
const theme = useTheme();
|
|
75
75
|
const options = childrenOfType(children, SegmentedControlTab).map((child) => child.props);
|
|
76
76
|
const select = (option) => {
|
|
@@ -85,11 +85,11 @@ function SegmentedControlRoot({ value, onChange, onClick, "aria-label": ariaLabe
|
|
|
85
85
|
});
|
|
86
86
|
// Drawn counts differ from tab to tab, so each segment takes its own width with them, as a messenger's folder tabs
|
|
87
87
|
const counted = showBadges && options.some((option) => option.badge != null);
|
|
88
|
-
const common = { options, value, select, keys, disabled, block, equal: mobileSegmentWidth === "equal" && !counted, showBadges };
|
|
88
|
+
const common = { options, value, select, keys, disabled, block, equal: mobileSegmentWidth === "equal" && !counted, showBadges, badgeColor };
|
|
89
89
|
return (_jsx(View, { accessibilityRole: "tablist", "aria-label": ariaLabel, accessibilityState: { disabled }, testID: testID, style: [block ? styles.block : styles.hug, style], children: theme.isAndroid ? _jsx(AndroidControl, { ...common, size: size }) : _jsx(IOSControl, { ...common, size: size, material: mobileMaterial }) }));
|
|
90
90
|
}
|
|
91
91
|
SegmentedControlRoot.displayName = "SegmentedControl";
|
|
92
|
-
function IOSControl({ options, value, select, keys, disabled, block, equal, showBadges, size, material }) {
|
|
92
|
+
function IOSControl({ options, value, select, keys, disabled, block, equal, showBadges, badgeColor, size, material }) {
|
|
93
93
|
const theme = useTheme();
|
|
94
94
|
const inBar = !!useContext(BarItemContext);
|
|
95
95
|
const { inRow } = useContext(SegmentedControlRowContext);
|
|
@@ -102,8 +102,9 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
|
|
|
102
102
|
// A drawn count ends a label in a capsule of its own: the thumb keeps 10 beside the label and the capsule, so the
|
|
103
103
|
// capsule does not touch the thumb's end
|
|
104
104
|
const gutter = showBadges && options.some((option) => option.badge != null) ? Math.max(look.optionGutter, 10) : look.optionGutter;
|
|
105
|
-
// The large glass control held down
|
|
106
|
-
//
|
|
105
|
+
// The large glass control held down: the held label fades to 20%, as UISegmentedControl dims a segment under the
|
|
106
|
+
// finger; the capsule stays as it is, no growth and no whitening (owner 25.11: the control must not swell and snap
|
|
107
|
+
// back on a tap)
|
|
107
108
|
const largeGlass = look.glass && look.height >= 40;
|
|
108
109
|
const [held, setHeld] = useState(null);
|
|
109
110
|
// The thumb's place from the segments in their order, so a reorder moves it even when no box changes size
|
|
@@ -160,11 +161,11 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
|
|
|
160
161
|
], children: _jsxs(View, { onLayout: (event) => {
|
|
161
162
|
const w = Math.ceil(event.nativeEvent.layout.width);
|
|
162
163
|
setLabels((prev) => (prev[option.value] === w ? prev : { ...prev, [option.value]: w }));
|
|
163
|
-
}, style: [styles.label, held === option.value ? styles.heldLabel : null], children: [symbolOnly ? (_jsx(IconDefaultsProvider, { size: 20, color: color, children: option.icon })) : (_jsx(Text, { numberOfLines: 1, maxFontSizeMultiplier: maxScale, color: color, weight: isSelected ? look.selectedWeight : look.weight, style: { fontSize: look.fontSize, lineHeight: look.lineHeight }, children: option.children })), showBadges ? _jsx(SegmentCount, { badge: option.badge, selected: isSelected, off: off }) : null] }) }, option.value));
|
|
164
|
+
}, style: [styles.label, held === option.value ? styles.heldLabel : null], children: [symbolOnly ? (_jsx(IconDefaultsProvider, { size: 20, color: color, children: option.icon })) : (_jsx(Text, { numberOfLines: 1, maxFontSizeMultiplier: maxScale, color: color, weight: isSelected ? look.selectedWeight : look.weight, style: { fontSize: look.fontSize, lineHeight: look.lineHeight }, children: option.children })), showBadges ? _jsx(SegmentCount, { badge: option.badge, selected: isSelected, off: off, color: badgeColor }) : null] }) }, option.value));
|
|
164
165
|
})] }));
|
|
165
166
|
if (look.glass) {
|
|
166
167
|
// The glass keeps the control's fill over it: one flat layer, no sheen (touch.css)
|
|
167
|
-
return (_jsxs(Glass, { radius: look.height / 2, fillToken: look.height >= 40 ? "--segmented-control-mobile-glass-background" : undefined,
|
|
168
|
+
return (_jsxs(Glass, { radius: look.height / 2, fillToken: look.height >= 40 ? "--segmented-control-mobile-glass-background" : undefined, style: [track, block ? styles.stretch : null], children: [look.height < 40 && look.fill ? _jsx(View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, { borderRadius: look.height / 2, backgroundColor: look.fill }] }) : null, content] }));
|
|
168
169
|
}
|
|
169
170
|
return _jsx(View, { style: [track, { backgroundColor: look.fill }, block ? styles.stretch : null], children: content });
|
|
170
171
|
}
|
|
@@ -182,7 +183,7 @@ const ANDROID_MOVE = { duration: 320, easing: curves.easeOutQuint };
|
|
|
182
183
|
* its label in the accent, the others in the secondary gray. The pill slides to a new selection and takes its width.
|
|
183
184
|
* In a bar's row of controls the capsule takes the height of the circles beside it (46dp).
|
|
184
185
|
*/
|
|
185
|
-
function AndroidControl({ options, value, select, keys, disabled, block, equal, showBadges, size }) {
|
|
186
|
+
function AndroidControl({ options, value, select, keys, disabled, block, equal, showBadges, badgeColor, size }) {
|
|
186
187
|
const theme = useTheme();
|
|
187
188
|
const m = theme.material;
|
|
188
189
|
const bar = useContext(BarItemContext);
|
|
@@ -218,13 +219,13 @@ function AndroidControl({ options, value, select, keys, disabled, block, equal,
|
|
|
218
219
|
styles.androidRow,
|
|
219
220
|
{ height, borderRadius: height / 2, backgroundColor: barSurface(m, theme.scheme), boxShadow: barShadow(theme.scheme) },
|
|
220
221
|
block ? styles.stretch : null,
|
|
221
|
-
], children: [frame ? (_jsx(Animated.View, { pointerEvents: "none", style: [styles.androidPill, { height: inner, borderRadius: inner / 2, backgroundColor: withAlpha(m.primary, 0.12), left: x, width }] })) : null, options.map((option) => (_jsx(AndroidSegment, { option: option, selected: option.value === value, off: disabled || !!option.disabled, framed: frame, showBadges: showBadges, height: inner,
|
|
222
|
+
], children: [frame ? (_jsx(Animated.View, { pointerEvents: "none", style: [styles.androidPill, { height: inner, borderRadius: inner / 2, backgroundColor: withAlpha(m.primary, 0.12), left: x, width }] })) : null, options.map((option) => (_jsx(AndroidSegment, { option: option, selected: option.value === value, off: disabled || !!option.disabled, framed: frame, showBadges: showBadges, badgeColor: badgeColor, height: inner,
|
|
222
223
|
// In a filled row equal segments share the width and the others take their label and share what is left; a
|
|
223
224
|
// control that hugs its segments gives equal ones the widest one's width
|
|
224
225
|
size: block ? (equal ? styles.grow : styles.share) : widest ? { minWidth: widest } : null, keys: keys, select: select, onWidth: (w) => setWidths((prev) => (prev[option.value] === w ? prev : { ...prev, [option.value]: w })) }, option.value)))] }));
|
|
225
226
|
}
|
|
226
227
|
/** One segment of the capsule: its label turns from the gray to the accent as the pill comes, and back as it goes. */
|
|
227
|
-
function AndroidSegment({ option, selected, off, framed, showBadges, height, size, keys, select, onWidth }) {
|
|
228
|
+
function AndroidSegment({ option, selected, off, framed, showBadges, badgeColor, height, size, keys, select, onWidth }) {
|
|
228
229
|
const theme = useTheme();
|
|
229
230
|
const m = theme.material;
|
|
230
231
|
const [tint] = useState(() => new Animated.Value(selected ? 1 : 0));
|
|
@@ -250,14 +251,15 @@ function AndroidSegment({ option, selected, off, framed, showBadges, height, siz
|
|
|
250
251
|
selected && !framed ? { backgroundColor: withAlpha(m.primary, 0.12) } : null,
|
|
251
252
|
], children: [isRenderable(option.icon) ? (_jsx(IconDefaultsProvider, { size: 20, color: color, children: option.icon })) : null, isRenderable(option.children) ? (
|
|
252
253
|
// An Animated text, so its color can blend: the face, size and tracking of the kit's Text
|
|
253
|
-
_jsx(Animated.Text, { numberOfLines: 1, style: [textStyle(theme, { weight: "medium" }), { fontSize: 14, lineHeight: 20, letterSpacing: theme.tracking(14), color: label }], children: option.children })) : null, showBadges ? _jsx(SegmentCount, { badge: option.badge, selected: selected, off: off }) : null] }));
|
|
254
|
+
_jsx(Animated.Text, { numberOfLines: 1, style: [textStyle(theme, { weight: "medium" }), { fontSize: 14, lineHeight: 20, letterSpacing: theme.tracking(14), color: label }], children: option.children })) : null, showBadges ? _jsx(SegmentCount, { badge: option.badge, selected: selected, off: off, color: badgeColor }) : null] }));
|
|
254
255
|
}
|
|
255
256
|
/**
|
|
256
257
|
* A tab's count drawn after its label (`showBadges`): a capsule 18 tall, the digits 12 semibold in the screen's color.
|
|
257
258
|
* iOS: the label's color on the selected segment, so it reads on the thumb, the secondary label on the others.
|
|
258
|
-
* Android: the accent on the selected segment, as its label, the gray on the others.
|
|
259
|
+
* Android: the accent on the selected segment, as its label, the gray on the others. `accent`: the accent's capsule and
|
|
260
|
+
* white digits on every segment, on both platforms.
|
|
259
261
|
*/
|
|
260
|
-
function SegmentCount({ badge, selected, off }) {
|
|
262
|
+
function SegmentCount({ badge, selected, off, color }) {
|
|
261
263
|
const theme = useTheme();
|
|
262
264
|
const text = badge != null ? badgeText(badge) : undefined;
|
|
263
265
|
if (!text)
|
|
@@ -265,16 +267,19 @@ function SegmentCount({ badge, selected, off }) {
|
|
|
265
267
|
// iOS: the label's color in a capsule, the bar's ink in it; Android: the segment's own ink, the selected one's
|
|
266
268
|
// container in it (onSecondaryContainer on secondaryContainer), the others' onSurfaceVariant on the surface, so the
|
|
267
269
|
// small digits keep their contrast
|
|
270
|
+
const accent = color === "accent";
|
|
268
271
|
const fill = off
|
|
269
272
|
? theme.color("--alpha-20")
|
|
270
|
-
:
|
|
271
|
-
?
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
:
|
|
277
|
-
|
|
273
|
+
: accent
|
|
274
|
+
? theme.color("--color-background-accent-solid")
|
|
275
|
+
: theme.isAndroid
|
|
276
|
+
? selected
|
|
277
|
+
? theme.material.onSecondaryContainer
|
|
278
|
+
: theme.material.onSurfaceVariant
|
|
279
|
+
: selected
|
|
280
|
+
? theme.colors.text
|
|
281
|
+
: theme.colors.labelSecondary;
|
|
282
|
+
const ink = accent && !off ? theme.color("--color-text-accent-solid", "#FFFFFF") : theme.isAndroid ? (selected ? theme.material.secondaryContainer : theme.material.surface) : theme.colors.background;
|
|
278
283
|
return (_jsx(View, { "aria-hidden": true, style: [styles.count, { backgroundColor: fill }], children: _jsx(Text, { numberOfLines: 1, weight: "semibold", color: ink, style: styles.countText, children: text }) }));
|
|
279
284
|
}
|
|
280
285
|
export const SegmentedControl = Object.assign(SegmentedControlRoot, { Tab: SegmentedControlTab, Option: SegmentedControlTab });
|
|
@@ -284,7 +289,6 @@ const styles = StyleSheet.create({
|
|
|
284
289
|
grow: { flex: 1 },
|
|
285
290
|
// The control is in a column: it fills the width and keeps its own height
|
|
286
291
|
stretch: { alignSelf: "stretch" },
|
|
287
|
-
heldControl: { transform: [{ scale: 1.07 }] },
|
|
288
292
|
heldLabel: { opacity: 0.2 },
|
|
289
293
|
// 18 tall, taller with a larger text size: the capsule grows round its digits
|
|
290
294
|
count: { minWidth: 18, minHeight: 18, paddingHorizontal: 5, borderRadius: 999, alignItems: "center", justifyContent: "center" },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
3
3
|
import { Animated, Easing, StyleSheet, View } from "react-native";
|
|
4
4
|
import { Pressable } from "../../internal/Pressable";
|
|
5
5
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
@@ -70,7 +70,14 @@ function IOSTab({ value, label, icon, badge, badgeColor, disabled = false, onPre
|
|
|
70
70
|
// A minimized tab takes the touches of its whole 48pt circle, not only its 40pt face
|
|
71
71
|
hitSlop: collapsed ? capsulePadding : undefined,
|
|
72
72
|
// A tab bar's labels keep their size, as UIKit's: a large text size shows the tab in the large content viewer
|
|
73
|
-
accessibilityShowsLargeContentViewer: true, accessibilityLargeContentTitle: textOf(label) || undefined,
|
|
73
|
+
accessibilityShowsLargeContentViewer: true, accessibilityLargeContentTitle: textOf(label) || undefined, onLayout:
|
|
74
|
+
// An expanded tab only: a minimized one's 40pt face is not where the pill goes when the bar expands
|
|
75
|
+
!circle && !collapsed && context.onTabLayout
|
|
76
|
+
? (event) => {
|
|
77
|
+
const { y, width, height } = event.nativeEvent.layout;
|
|
78
|
+
context.onTabLayout?.(value, { y, width, height });
|
|
79
|
+
}
|
|
80
|
+
: undefined, style: [styles.iosItem, size, circle ? null : { flexShrink: 1, minWidth: 0 }], children: [selected && !collapsed && (circle || context.slidingPill !== value) ? _jsx(View, { pointerEvents: "none", style: [styles.pill, pill, { backgroundColor: theme.color("--tab-bar-item-background-selected") }] }) : null, _jsx(View, { style: [styles.iosIcon, { height: theme.length("--tab-bar-icon-box", 28) }], children: _jsx(IconDefaultsProvider, { size: theme.length("--tab-bar-icon-size", 28), color: color, children: icon }) }), showLabel ? (_jsx(Text, { numberOfLines: 1, allowFontScaling: false, weight: "semibold", color: color, style: { fontSize: theme.length("--tab-bar-label-font-size", 10), lineHeight: theme.length("--tab-bar-label-line-height", 12), maxWidth: "100%" }, children: label })) : null, hasBadge(badge) && !circle ? (_jsx(View, { pointerEvents: "none", style: [styles.iosBadge, iosBadgeStyle(theme, badgeColor ?? context.badgeColor), { top: badgeTop, marginLeft: badgeStart }], children: badge === true ? null : (_jsx(Text, { color: (badgeColor ?? context.badgeColor) === "accent" ? theme.color("--color-text-accent-solid", "#FFFFFF") : theme.color("--tab-bar-badge-color"), style: iosBadgeText(theme), numberOfLines: 1, allowFontScaling: false, children: badge })) })) : null] }));
|
|
74
81
|
}
|
|
75
82
|
const iosBadgeStyle = (theme, color) => {
|
|
76
83
|
const size = theme.length("--tab-bar-badge-size", 18);
|
|
@@ -346,7 +353,61 @@ function TabBarRoot({ value: valueProp, defaultValue, onValueChange, search, pro
|
|
|
346
353
|
const visible = shown.length ? shown : capsuleTabs.slice(0, 1);
|
|
347
354
|
const reachable = [...visible, ...(circle ? [circle] : [])];
|
|
348
355
|
const keys = useTabKeys(reachable, value, select);
|
|
349
|
-
|
|
356
|
+
// iOS 26 slides the selection to the new tab: one pill in the capsule, under the tabs, moving from tab to tab
|
|
357
|
+
const [frames, setFrames] = useState({});
|
|
358
|
+
const onTabLayout = useCallback((tab, next) => {
|
|
359
|
+
setFrames((current) => {
|
|
360
|
+
const prev = current[tab];
|
|
361
|
+
return prev && prev.y === next.y && prev.width === next.width && prev.height === next.height ? current : { ...current, [tab]: next };
|
|
362
|
+
});
|
|
363
|
+
}, []);
|
|
364
|
+
// The pill's place from the start of the capsule: its padding and the widths of the tabs before it, in their order
|
|
365
|
+
// (a reorder moves it with no resize to report; the start edge, so a right-to-left bar mirrors it as its tabs)
|
|
366
|
+
const capsuleInline = theme.length("--tab-bar-capsule-padding-inline", 10);
|
|
367
|
+
const selectedIndex = value != null && !minimized ? visible.findIndex((tab) => tab.value === value) : -1;
|
|
368
|
+
const before = selectedIndex >= 0 ? visible.slice(0, selectedIndex) : [];
|
|
369
|
+
const frame = selectedIndex >= 0 && theme.isIOS ? frames[visible[selectedIndex].value] : undefined;
|
|
370
|
+
const pillFrame = frame && before.every((tab) => frames[tab.value] != null)
|
|
371
|
+
? { ...frame, x: capsuleInline + before.reduce((sum, tab) => sum + frames[tab.value].width, 0) }
|
|
372
|
+
: undefined;
|
|
373
|
+
const context = {
|
|
374
|
+
value,
|
|
375
|
+
badgeColor,
|
|
376
|
+
minimized,
|
|
377
|
+
select,
|
|
378
|
+
expand,
|
|
379
|
+
keys,
|
|
380
|
+
onTabLayout: theme.isIOS ? onTabLayout : undefined,
|
|
381
|
+
slidingPill: pillFrame ? value : undefined,
|
|
382
|
+
};
|
|
383
|
+
const pillOutset = theme.length("--tab-bar-pill-outset", 6);
|
|
384
|
+
const [pillX] = useState(() => new Animated.Value(0));
|
|
385
|
+
const [pillWidth] = useState(() => new Animated.Value(0));
|
|
386
|
+
const pillShown = useRef(false);
|
|
387
|
+
const pillLeft = pillFrame ? pillFrame.x - pillOutset : undefined;
|
|
388
|
+
const pillSpan = pillFrame ? pillFrame.width + 2 * pillOutset : undefined;
|
|
389
|
+
// Before the paint, so the pill never shows a frame at its old place or at 0
|
|
390
|
+
useLayoutEffect(() => {
|
|
391
|
+
if (pillLeft == null || pillSpan == null) {
|
|
392
|
+
pillShown.current = false;
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
// It appears in place (the first frame, back from a minimized bar or the circle's tab), then slides: CSS `ease`
|
|
396
|
+
// over 300ms, as SegmentedControl's thumb
|
|
397
|
+
if (!pillShown.current || theme.reducedMotion) {
|
|
398
|
+
pillX.setValue(pillLeft);
|
|
399
|
+
pillWidth.setValue(pillSpan);
|
|
400
|
+
pillShown.current = true;
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
const easing = Easing.bezier(0.25, 0.1, 0.25, 1);
|
|
404
|
+
const animation = Animated.parallel([
|
|
405
|
+
Animated.timing(pillX, { toValue: pillLeft, duration: 300, easing, useNativeDriver: false }),
|
|
406
|
+
Animated.timing(pillWidth, { toValue: pillSpan, duration: 300, easing, useNativeDriver: false }),
|
|
407
|
+
]);
|
|
408
|
+
animation.start();
|
|
409
|
+
return () => animation.stop();
|
|
410
|
+
}, [pillLeft, pillSpan, theme.reducedMotion, pillX, pillWidth]);
|
|
350
411
|
if (theme.isAndroid) {
|
|
351
412
|
return (_jsx(TabBarContext.Provider, { value: context, children: _jsx(AndroidBar, { context: context, tabs: capsuleTabs, circle: circle, accent: !!prominentTab, accessory: accessory, background: background, scrolled: scrolled, canvasColor: canvasColor, safeArea: safeArea, ariaLabel: ariaLabel, rest: rest, style: style }) }));
|
|
352
413
|
}
|
|
@@ -376,7 +437,10 @@ function TabBarRoot({ value: valueProp, defaultValue, onValueChange, search, pro
|
|
|
376
437
|
{ paddingTop: padTop + (accessory ? accessoryHeight + accessoryGap : 0), paddingBottom },
|
|
377
438
|
physicalPadding(sideLeft, sideRight),
|
|
378
439
|
style,
|
|
379
|
-
], children: [backdrop, accessory ? (_jsx(Glass, { radius: accessoryHeight / 2, elevation: "raised", style: [styles.accessory, accessoryPlace], children: accessory }, "accessory")) : null, _jsxs(View, { style: [styles.iosRow, { gap: theme.length("--tab-bar-gap", 8), justifyContent: circle || minimized ? "space-between" : "center" }], children: [
|
|
440
|
+
], children: [backdrop, accessory ? (_jsx(Glass, { radius: accessoryHeight / 2, elevation: "raised", style: [styles.accessory, accessoryPlace], children: accessory }, "accessory")) : null, _jsxs(View, { style: [styles.iosRow, { gap: theme.length("--tab-bar-gap", 8), justifyContent: circle || minimized ? "space-between" : "center" }], children: [_jsxs(Glass, { radius: 999, elevation: "raised", style: [styles.capsule, minimized ? { padding: capsulePadding } : { paddingVertical: capsulePadding, paddingHorizontal: theme.length("--tab-bar-capsule-padding-inline", 10) }], children: [pillFrame ? (_jsx(Animated.View, { pointerEvents: "none", style: [
|
|
441
|
+
styles.pill,
|
|
442
|
+
{ top: pillFrame.y, height: pillFrame.height, start: pillX, width: pillWidth, backgroundColor: theme.color("--tab-bar-item-background-selected") },
|
|
443
|
+
] })) : null, visible.map((tab) => (_jsx(Tab, { ...tab, context: context }, tab.value)))] }), circle ? (_jsx(Glass, { radius: circleSize / 2, elevation: "raised", style: { width: circleSize, height: circleSize }, children: _jsx(Tab, { ...circle, context: { ...context, minimized: false }, kind: "circle", hideLabel: true }) })) : null] })] }) }));
|
|
380
444
|
}
|
|
381
445
|
TabBarRoot.displayName = "TabBar";
|
|
382
446
|
export const TabBar = Object.assign(TabBarRoot, { Item: TabBarItem });
|
|
@@ -40,6 +40,13 @@ export type SegmentedControlProps<T extends string> = {
|
|
|
40
40
|
* count. Off, the count is only read with the segment's name, as the native controls draw none. @default false
|
|
41
41
|
*/
|
|
42
42
|
showBadges?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The drawn counts' color. `label`: the label's on the selected segment, the secondary one on the others (Android:
|
|
45
|
+
* the selected segment's ink, the gray on the others), so a count changes with the selection. `accent`: one accent
|
|
46
|
+
* capsule with white digits on every segment, as TabBar's `badgeColor="accent"`, the same whichever is selected.
|
|
47
|
+
* @default "label"
|
|
48
|
+
*/
|
|
49
|
+
badgeColor?: "label" | "accent";
|
|
43
50
|
style?: StyleProp<ViewStyle>;
|
|
44
51
|
testID?: string;
|
|
45
52
|
/** `SegmentedControl.Tab` elements. */
|
|
@@ -78,7 +85,7 @@ declare namespace SegmentedControlTab {
|
|
|
78
85
|
* iOS 26 apps (48pt; 40 in a Toolbar.Row), its thumb sliding to the selection; on Android a segmented capsule, white
|
|
79
86
|
* with a sliding pill of the accent. Props follow @plexui/ui (`SegmentedControl` and `SegmentedControl.Tab`).
|
|
80
87
|
*/
|
|
81
|
-
declare function SegmentedControlRoot<T extends string>({ value, onChange, onClick, "aria-label": ariaLabel, size, disabled, block, mobileMaterial, mobileSegmentWidth, showBadges, style, testID, children, }: SegmentedControlProps<T>): import("react").JSX.Element;
|
|
88
|
+
declare function SegmentedControlRoot<T extends string>({ value, onChange, onClick, "aria-label": ariaLabel, size, disabled, block, mobileMaterial, mobileSegmentWidth, showBadges, badgeColor, style, testID, children, }: SegmentedControlProps<T>): import("react").JSX.Element;
|
|
82
89
|
declare namespace SegmentedControlRoot {
|
|
83
90
|
var displayName: string;
|
|
84
91
|
}
|
package/package.json
CHANGED
|
@@ -51,6 +51,13 @@ export type SegmentedControlProps<T extends string> = {
|
|
|
51
51
|
* count. Off, the count is only read with the segment's name, as the native controls draw none. @default false
|
|
52
52
|
*/
|
|
53
53
|
showBadges?: boolean
|
|
54
|
+
/**
|
|
55
|
+
* The drawn counts' color. `label`: the label's on the selected segment, the secondary one on the others (Android:
|
|
56
|
+
* the selected segment's ink, the gray on the others), so a count changes with the selection. `accent`: one accent
|
|
57
|
+
* capsule with white digits on every segment, as TabBar's `badgeColor="accent"`, the same whichever is selected.
|
|
58
|
+
* @default "label"
|
|
59
|
+
*/
|
|
60
|
+
badgeColor?: "label" | "accent"
|
|
54
61
|
style?: StyleProp<ViewStyle>
|
|
55
62
|
testID?: string
|
|
56
63
|
/** `SegmentedControl.Tab` elements. */
|
|
@@ -172,6 +179,7 @@ function SegmentedControlRoot<T extends string>({
|
|
|
172
179
|
mobileMaterial,
|
|
173
180
|
mobileSegmentWidth = "equal",
|
|
174
181
|
showBadges = false,
|
|
182
|
+
badgeColor = "label",
|
|
175
183
|
style,
|
|
176
184
|
testID,
|
|
177
185
|
children,
|
|
@@ -192,7 +200,7 @@ function SegmentedControlRoot<T extends string>({
|
|
|
192
200
|
)
|
|
193
201
|
// Drawn counts differ from tab to tab, so each segment takes its own width with them, as a messenger's folder tabs
|
|
194
202
|
const counted = showBadges && options.some((option) => option.badge != null)
|
|
195
|
-
const common = { options, value, select, keys, disabled, block, equal: mobileSegmentWidth === "equal" && !counted, showBadges }
|
|
203
|
+
const common = { options, value, select, keys, disabled, block, equal: mobileSegmentWidth === "equal" && !counted, showBadges, badgeColor }
|
|
196
204
|
return (
|
|
197
205
|
<View accessibilityRole="tablist" aria-label={ariaLabel} accessibilityState={{ disabled }} testID={testID} style={[block ? styles.block : styles.hug, style]}>
|
|
198
206
|
{theme.isAndroid ? <AndroidControl {...common} size={size} /> : <IOSControl {...common} size={size} material={mobileMaterial} />}
|
|
@@ -210,9 +218,10 @@ type ControlProps = {
|
|
|
210
218
|
block: boolean
|
|
211
219
|
equal: boolean
|
|
212
220
|
showBadges: boolean
|
|
221
|
+
badgeColor: "label" | "accent"
|
|
213
222
|
}
|
|
214
223
|
|
|
215
|
-
function IOSControl({ options, value, select, keys, disabled, block, equal, showBadges, size, material }: ControlProps & { size: ControlSize; material?: "glass" | "flat" }) {
|
|
224
|
+
function IOSControl({ options, value, select, keys, disabled, block, equal, showBadges, badgeColor, size, material }: ControlProps & { size: ControlSize; material?: "glass" | "flat" }) {
|
|
216
225
|
const theme = useTheme()
|
|
217
226
|
const inBar = !!useContext(BarItemContext)
|
|
218
227
|
const { inRow } = useContext(SegmentedControlRowContext)
|
|
@@ -225,8 +234,9 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
|
|
|
225
234
|
// A drawn count ends a label in a capsule of its own: the thumb keeps 10 beside the label and the capsule, so the
|
|
226
235
|
// capsule does not touch the thumb's end
|
|
227
236
|
const gutter = showBadges && options.some((option) => option.badge != null) ? Math.max(look.optionGutter, 10) : look.optionGutter
|
|
228
|
-
// The large glass control held down
|
|
229
|
-
//
|
|
237
|
+
// The large glass control held down: the held label fades to 20%, as UISegmentedControl dims a segment under the
|
|
238
|
+
// finger; the capsule stays as it is, no growth and no whitening (owner 25.11: the control must not swell and snap
|
|
239
|
+
// back on a tap)
|
|
230
240
|
const largeGlass = look.glass && look.height >= 40
|
|
231
241
|
const [held, setHeld] = useState<string | null>(null)
|
|
232
242
|
// The thumb's place from the segments in their order, so a reorder moves it even when no box changes size
|
|
@@ -325,7 +335,7 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
|
|
|
325
335
|
{option.children}
|
|
326
336
|
</Text>
|
|
327
337
|
)}
|
|
328
|
-
{showBadges ? <SegmentCount badge={option.badge} selected={isSelected} off={off} /> : null}
|
|
338
|
+
{showBadges ? <SegmentCount badge={option.badge} selected={isSelected} off={off} color={badgeColor} /> : null}
|
|
329
339
|
</View>
|
|
330
340
|
</Pressable>
|
|
331
341
|
)
|
|
@@ -338,8 +348,7 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
|
|
|
338
348
|
<Glass
|
|
339
349
|
radius={look.height / 2}
|
|
340
350
|
fillToken={look.height >= 40 ? "--segmented-control-mobile-glass-background" : undefined}
|
|
341
|
-
|
|
342
|
-
style={[track, block ? styles.stretch : null, largeGlass && held != null ? styles.heldControl : null]}
|
|
351
|
+
style={[track, block ? styles.stretch : null]}
|
|
343
352
|
>
|
|
344
353
|
{look.height < 40 && look.fill ? <View pointerEvents="none" style={[StyleSheet.absoluteFill, { borderRadius: look.height / 2, backgroundColor: look.fill }]} /> : null}
|
|
345
354
|
{content}
|
|
@@ -365,7 +374,7 @@ const ANDROID_MOVE = { duration: 320, easing: curves.easeOutQuint }
|
|
|
365
374
|
* its label in the accent, the others in the secondary gray. The pill slides to a new selection and takes its width.
|
|
366
375
|
* In a bar's row of controls the capsule takes the height of the circles beside it (46dp).
|
|
367
376
|
*/
|
|
368
|
-
function AndroidControl({ options, value, select, keys, disabled, block, equal, showBadges, size }: ControlProps & { size: ControlSize }) {
|
|
377
|
+
function AndroidControl({ options, value, select, keys, disabled, block, equal, showBadges, badgeColor, size }: ControlProps & { size: ControlSize }) {
|
|
369
378
|
const theme = useTheme()
|
|
370
379
|
const m = theme.material
|
|
371
380
|
const bar = useContext(BarItemContext)
|
|
@@ -418,6 +427,7 @@ function AndroidControl({ options, value, select, keys, disabled, block, equal,
|
|
|
418
427
|
off={disabled || !!option.disabled}
|
|
419
428
|
framed={frame}
|
|
420
429
|
showBadges={showBadges}
|
|
430
|
+
badgeColor={badgeColor}
|
|
421
431
|
height={inner}
|
|
422
432
|
// In a filled row equal segments share the width and the others take their label and share what is left; a
|
|
423
433
|
// control that hugs its segments gives equal ones the widest one's width
|
|
@@ -438,6 +448,7 @@ type AndroidSegmentProps = {
|
|
|
438
448
|
/** The pill is placed: the selected segment draws none of its own. */
|
|
439
449
|
framed: boolean
|
|
440
450
|
showBadges: boolean
|
|
451
|
+
badgeColor: "label" | "accent"
|
|
441
452
|
height: number
|
|
442
453
|
size: ViewStyle | null
|
|
443
454
|
keys: ReturnType<typeof useTabKeys>
|
|
@@ -446,7 +457,7 @@ type AndroidSegmentProps = {
|
|
|
446
457
|
}
|
|
447
458
|
|
|
448
459
|
/** One segment of the capsule: its label turns from the gray to the accent as the pill comes, and back as it goes. */
|
|
449
|
-
function AndroidSegment({ option, selected, off, framed, showBadges, height, size, keys, select, onWidth }: AndroidSegmentProps) {
|
|
460
|
+
function AndroidSegment({ option, selected, off, framed, showBadges, badgeColor, height, size, keys, select, onWidth }: AndroidSegmentProps) {
|
|
450
461
|
const theme = useTheme()
|
|
451
462
|
const m = theme.material
|
|
452
463
|
const [tint] = useState(() => new Animated.Value(selected ? 1 : 0))
|
|
@@ -494,7 +505,7 @@ function AndroidSegment({ option, selected, off, framed, showBadges, height, siz
|
|
|
494
505
|
{option.children}
|
|
495
506
|
</Animated.Text>
|
|
496
507
|
) : null}
|
|
497
|
-
{showBadges ? <SegmentCount badge={option.badge} selected={selected} off={off} /> : null}
|
|
508
|
+
{showBadges ? <SegmentCount badge={option.badge} selected={selected} off={off} color={badgeColor} /> : null}
|
|
498
509
|
</Pressable>
|
|
499
510
|
)
|
|
500
511
|
}
|
|
@@ -502,25 +513,29 @@ function AndroidSegment({ option, selected, off, framed, showBadges, height, siz
|
|
|
502
513
|
/**
|
|
503
514
|
* A tab's count drawn after its label (`showBadges`): a capsule 18 tall, the digits 12 semibold in the screen's color.
|
|
504
515
|
* iOS: the label's color on the selected segment, so it reads on the thumb, the secondary label on the others.
|
|
505
|
-
* Android: the accent on the selected segment, as its label, the gray on the others.
|
|
516
|
+
* Android: the accent on the selected segment, as its label, the gray on the others. `accent`: the accent's capsule and
|
|
517
|
+
* white digits on every segment, on both platforms.
|
|
506
518
|
*/
|
|
507
|
-
function SegmentCount({ badge, selected, off }: { badge: SegmentedControlBadgeProp | undefined; selected: boolean; off: boolean }) {
|
|
519
|
+
function SegmentCount({ badge, selected, off, color }: { badge: SegmentedControlBadgeProp | undefined; selected: boolean; off: boolean; color: "label" | "accent" }) {
|
|
508
520
|
const theme = useTheme()
|
|
509
521
|
const text = badge != null ? badgeText(badge) : undefined
|
|
510
522
|
if (!text) return null
|
|
511
523
|
// iOS: the label's color in a capsule, the bar's ink in it; Android: the segment's own ink, the selected one's
|
|
512
524
|
// container in it (onSecondaryContainer on secondaryContainer), the others' onSurfaceVariant on the surface, so the
|
|
513
525
|
// small digits keep their contrast
|
|
526
|
+
const accent = color === "accent"
|
|
514
527
|
const fill = off
|
|
515
528
|
? theme.color("--alpha-20")
|
|
516
|
-
:
|
|
529
|
+
: accent
|
|
530
|
+
? theme.color("--color-background-accent-solid")
|
|
531
|
+
: theme.isAndroid
|
|
517
532
|
? selected
|
|
518
533
|
? theme.material.onSecondaryContainer
|
|
519
534
|
: theme.material.onSurfaceVariant
|
|
520
535
|
: selected
|
|
521
536
|
? theme.colors.text
|
|
522
537
|
: theme.colors.labelSecondary
|
|
523
|
-
const ink = theme.isAndroid ? (selected ? theme.material.secondaryContainer : theme.material.surface) : theme.colors.background
|
|
538
|
+
const ink = accent && !off ? theme.color("--color-text-accent-solid", "#FFFFFF") : theme.isAndroid ? (selected ? theme.material.secondaryContainer : theme.material.surface) : theme.colors.background
|
|
524
539
|
return (
|
|
525
540
|
<View aria-hidden style={[styles.count, { backgroundColor: fill }]}>
|
|
526
541
|
<Text numberOfLines={1} weight="semibold" color={ink} style={styles.countText}>
|
|
@@ -538,7 +553,6 @@ const styles = StyleSheet.create({
|
|
|
538
553
|
grow: { flex: 1 },
|
|
539
554
|
// The control is in a column: it fills the width and keeps its own height
|
|
540
555
|
stretch: { alignSelf: "stretch" },
|
|
541
|
-
heldControl: { transform: [{ scale: 1.07 }] },
|
|
542
556
|
heldLabel: { opacity: 0.2 },
|
|
543
557
|
// 18 tall, taller with a larger text size: the capsule grows round its digits
|
|
544
558
|
count: { minWidth: 18, minHeight: 18, paddingHorizontal: 5, borderRadius: 999, alignItems: "center", justifyContent: "center" },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useCallback, useContext, useEffect, useRef, useState, type ReactElement, type ReactNode } from "react"
|
|
1
|
+
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, type ReactElement, type ReactNode } from "react"
|
|
2
2
|
import { Animated, Easing, StyleSheet, View, type LayoutChangeEvent, type NativeScrollEvent, type NativeSyntheticEvent, type StyleProp, type ViewProps, type ViewStyle } from "react-native"
|
|
3
3
|
import { Pressable } from "../../internal/Pressable"
|
|
4
4
|
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
|
@@ -115,8 +115,15 @@ type TabBarContextValue = {
|
|
|
115
115
|
select: (value: string) => void
|
|
116
116
|
expand: () => void
|
|
117
117
|
keys: ReturnType<typeof useTabKeys>
|
|
118
|
+
/** iOS: the capsule draws one selection pill that slides between the tabs; each tab reports its frame for it. */
|
|
119
|
+
onTabLayout?: (value: string, frame: TabFrame) => void
|
|
120
|
+
/** The tab whose pill the capsule draws (its frame is known); until then the selected tab draws its own. */
|
|
121
|
+
slidingPill?: string
|
|
118
122
|
}
|
|
119
123
|
|
|
124
|
+
/** A tab's size and its top in the capsule (its place along the row comes from the tabs' order and widths). */
|
|
125
|
+
type TabFrame = { y: number; width: number; height: number }
|
|
126
|
+
|
|
120
127
|
const TabBarContext = createContext<TabBarContextValue | null>(null)
|
|
121
128
|
|
|
122
129
|
/** A badge shows unless it is empty: nothing, false, an empty text or a count of 0 (iOS hides `.badge(0)`). */
|
|
@@ -190,9 +197,18 @@ function IOSTab({ value, label, icon, badge, badgeColor, disabled = false, onPre
|
|
|
190
197
|
// A tab bar's labels keep their size, as UIKit's: a large text size shows the tab in the large content viewer
|
|
191
198
|
accessibilityShowsLargeContentViewer
|
|
192
199
|
accessibilityLargeContentTitle={textOf(label) || undefined}
|
|
200
|
+
onLayout={
|
|
201
|
+
// An expanded tab only: a minimized one's 40pt face is not where the pill goes when the bar expands
|
|
202
|
+
!circle && !collapsed && context.onTabLayout
|
|
203
|
+
? (event: LayoutChangeEvent) => {
|
|
204
|
+
const { y, width, height } = event.nativeEvent.layout
|
|
205
|
+
context.onTabLayout?.(value, { y, width, height })
|
|
206
|
+
}
|
|
207
|
+
: undefined
|
|
208
|
+
}
|
|
193
209
|
style={[styles.iosItem, size, circle ? null : { flexShrink: 1, minWidth: 0 }]}
|
|
194
210
|
>
|
|
195
|
-
{selected && !collapsed ? <View pointerEvents="none" style={[styles.pill, pill, { backgroundColor: theme.color("--tab-bar-item-background-selected") }]} /> : null}
|
|
211
|
+
{selected && !collapsed && (circle || context.slidingPill !== value) ? <View pointerEvents="none" style={[styles.pill, pill, { backgroundColor: theme.color("--tab-bar-item-background-selected") }]} /> : null}
|
|
196
212
|
<View style={[styles.iosIcon, { height: theme.length("--tab-bar-icon-box", 28) }]}>
|
|
197
213
|
<IconDefaultsProvider size={theme.length("--tab-bar-icon-size", 28)} color={color}>
|
|
198
214
|
{icon}
|
|
@@ -686,7 +702,62 @@ function TabBarRoot({
|
|
|
686
702
|
const visible = shown.length ? shown : capsuleTabs.slice(0, 1)
|
|
687
703
|
const reachable = [...visible, ...(circle ? [circle] : [])]
|
|
688
704
|
const keys = useTabKeys(reachable, value, select)
|
|
689
|
-
|
|
705
|
+
// iOS 26 slides the selection to the new tab: one pill in the capsule, under the tabs, moving from tab to tab
|
|
706
|
+
const [frames, setFrames] = useState<Record<string, TabFrame>>({})
|
|
707
|
+
const onTabLayout = useCallback((tab: string, next: TabFrame) => {
|
|
708
|
+
setFrames((current) => {
|
|
709
|
+
const prev = current[tab]
|
|
710
|
+
return prev && prev.y === next.y && prev.width === next.width && prev.height === next.height ? current : { ...current, [tab]: next }
|
|
711
|
+
})
|
|
712
|
+
}, [])
|
|
713
|
+
// The pill's place from the start of the capsule: its padding and the widths of the tabs before it, in their order
|
|
714
|
+
// (a reorder moves it with no resize to report; the start edge, so a right-to-left bar mirrors it as its tabs)
|
|
715
|
+
const capsuleInline = theme.length("--tab-bar-capsule-padding-inline", 10)
|
|
716
|
+
const selectedIndex = value != null && !minimized ? visible.findIndex((tab) => tab.value === value) : -1
|
|
717
|
+
const before = selectedIndex >= 0 ? visible.slice(0, selectedIndex) : []
|
|
718
|
+
const frame = selectedIndex >= 0 && theme.isIOS ? frames[visible[selectedIndex].value] : undefined
|
|
719
|
+
const pillFrame =
|
|
720
|
+
frame && before.every((tab) => frames[tab.value] != null)
|
|
721
|
+
? { ...frame, x: capsuleInline + before.reduce((sum, tab) => sum + frames[tab.value].width, 0) }
|
|
722
|
+
: undefined
|
|
723
|
+
const context: TabBarContextValue = {
|
|
724
|
+
value,
|
|
725
|
+
badgeColor,
|
|
726
|
+
minimized,
|
|
727
|
+
select,
|
|
728
|
+
expand,
|
|
729
|
+
keys,
|
|
730
|
+
onTabLayout: theme.isIOS ? onTabLayout : undefined,
|
|
731
|
+
slidingPill: pillFrame ? value : undefined,
|
|
732
|
+
}
|
|
733
|
+
const pillOutset = theme.length("--tab-bar-pill-outset", 6)
|
|
734
|
+
const [pillX] = useState(() => new Animated.Value(0))
|
|
735
|
+
const [pillWidth] = useState(() => new Animated.Value(0))
|
|
736
|
+
const pillShown = useRef(false)
|
|
737
|
+
const pillLeft = pillFrame ? pillFrame.x - pillOutset : undefined
|
|
738
|
+
const pillSpan = pillFrame ? pillFrame.width + 2 * pillOutset : undefined
|
|
739
|
+
// Before the paint, so the pill never shows a frame at its old place or at 0
|
|
740
|
+
useLayoutEffect(() => {
|
|
741
|
+
if (pillLeft == null || pillSpan == null) {
|
|
742
|
+
pillShown.current = false
|
|
743
|
+
return
|
|
744
|
+
}
|
|
745
|
+
// It appears in place (the first frame, back from a minimized bar or the circle's tab), then slides: CSS `ease`
|
|
746
|
+
// over 300ms, as SegmentedControl's thumb
|
|
747
|
+
if (!pillShown.current || theme.reducedMotion) {
|
|
748
|
+
pillX.setValue(pillLeft)
|
|
749
|
+
pillWidth.setValue(pillSpan)
|
|
750
|
+
pillShown.current = true
|
|
751
|
+
return
|
|
752
|
+
}
|
|
753
|
+
const easing = Easing.bezier(0.25, 0.1, 0.25, 1)
|
|
754
|
+
const animation = Animated.parallel([
|
|
755
|
+
Animated.timing(pillX, { toValue: pillLeft, duration: 300, easing, useNativeDriver: false }),
|
|
756
|
+
Animated.timing(pillWidth, { toValue: pillSpan, duration: 300, easing, useNativeDriver: false }),
|
|
757
|
+
])
|
|
758
|
+
animation.start()
|
|
759
|
+
return () => animation.stop()
|
|
760
|
+
}, [pillLeft, pillSpan, theme.reducedMotion, pillX, pillWidth])
|
|
690
761
|
|
|
691
762
|
if (theme.isAndroid) {
|
|
692
763
|
return (
|
|
@@ -761,6 +832,15 @@ function TabBarRoot({
|
|
|
761
832
|
elevation="raised"
|
|
762
833
|
style={[styles.capsule, minimized ? { padding: capsulePadding } : { paddingVertical: capsulePadding, paddingHorizontal: theme.length("--tab-bar-capsule-padding-inline", 10) }]}
|
|
763
834
|
>
|
|
835
|
+
{pillFrame ? (
|
|
836
|
+
<Animated.View
|
|
837
|
+
pointerEvents="none"
|
|
838
|
+
style={[
|
|
839
|
+
styles.pill,
|
|
840
|
+
{ top: pillFrame.y, height: pillFrame.height, start: pillX, width: pillWidth, backgroundColor: theme.color("--tab-bar-item-background-selected") },
|
|
841
|
+
]}
|
|
842
|
+
/>
|
|
843
|
+
) : null}
|
|
764
844
|
{visible.map((tab) => (
|
|
765
845
|
<Tab key={tab.value} {...tab} context={context} />
|
|
766
846
|
))}
|