@plexui/react-native 0.2.7 → 0.2.9
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/ActionSheet/ActionSheet.js +2 -1
- package/dist/es/components/Alert/Alert.js +2 -1
- package/dist/es/components/Avatar/Avatar.js +2 -1
- package/dist/es/components/Badge/Badge.js +2 -1
- package/dist/es/components/BottomActions/BottomActions.js +3 -3
- package/dist/es/components/BottomSheet/BottomSheet.js +2 -1
- package/dist/es/components/Button/Button.js +2 -1
- package/dist/es/components/Card/Card.js +2 -1
- package/dist/es/components/Checkbox/Checkbox.js +2 -1
- package/dist/es/components/Chip/Chip.js +2 -1
- package/dist/es/components/DatePicker/Calendar.js +2 -1
- package/dist/es/components/DatePicker/DatePicker.js +2 -1
- package/dist/es/components/DatePicker/TimeDial.js +2 -1
- package/dist/es/components/DatePicker/Wheel.js +2 -1
- package/dist/es/components/Dialog/Dialog.js +2 -1
- package/dist/es/components/Input/Input.js +2 -1
- package/dist/es/components/InputGroup/InputGroup.js +2 -1
- package/dist/es/components/IntroHeader/IntroHeader.js +32 -0
- package/dist/es/components/List/List.js +45 -18
- package/dist/es/components/Menu/Menu.js +2 -1
- package/dist/es/components/RadioGroup/RadioGroup.js +2 -1
- package/dist/es/components/SegmentedControl/SegmentedControl.js +52 -54
- package/dist/es/components/Select/Select.js +2 -1
- package/dist/es/components/Stepper/Stepper.js +2 -1
- package/dist/es/components/Switch/Switch.js +2 -1
- package/dist/es/components/TabBar/TabBar.js +2 -1
- package/dist/es/components/TagInput/TagInput.js +2 -1
- package/dist/es/components/Tip/Tip.js +2 -1
- package/dist/es/components/Toast/Toast.js +2 -1
- package/dist/es/index.js +1 -0
- package/dist/es/internal/Pressable.js +10 -0
- package/dist/es/theme/material.js +11 -2
- package/dist/types/components/BottomActions/BottomActions.d.ts +10 -1
- package/dist/types/components/IntroHeader/IntroHeader.d.ts +33 -0
- package/dist/types/components/List/List.d.ts +1 -1
- package/dist/types/components/SegmentedControl/SegmentedControl.d.ts +11 -2
- package/dist/types/index.d.ts +2 -1
- package/dist/types/internal/Pressable.d.ts +3 -0
- package/package.json +2 -2
- package/src/components/ActionSheet/ActionSheet.tsx +2 -1
- package/src/components/Alert/Alert.tsx +2 -1
- package/src/components/Avatar/Avatar.tsx +2 -1
- package/src/components/Badge/Badge.tsx +2 -1
- package/src/components/BottomActions/BottomActions.tsx +14 -2
- package/src/components/BottomSheet/BottomSheet.tsx +2 -1
- package/src/components/Button/Button.tsx +2 -13
- package/src/components/Card/Card.tsx +2 -1
- package/src/components/Checkbox/Checkbox.tsx +2 -1
- package/src/components/Chip/Chip.tsx +2 -1
- package/src/components/DatePicker/Calendar.tsx +2 -1
- package/src/components/DatePicker/DatePicker.tsx +2 -1
- package/src/components/DatePicker/TimeDial.tsx +2 -1
- package/src/components/DatePicker/Wheel.tsx +2 -1
- package/src/components/Dialog/Dialog.tsx +2 -1
- package/src/components/Input/Input.tsx +2 -17
- package/src/components/InputGroup/InputGroup.tsx +2 -1
- package/src/components/IntroHeader/IntroHeader.tsx +79 -0
- package/src/components/List/List.tsx +55 -20
- package/src/components/Menu/Menu.tsx +2 -1
- package/src/components/RadioGroup/RadioGroup.tsx +2 -1
- package/src/components/SegmentedControl/SegmentedControl.tsx +68 -48
- package/src/components/Select/Select.tsx +2 -1
- package/src/components/Stepper/Stepper.tsx +2 -1
- package/src/components/Switch/Switch.tsx +2 -1
- package/src/components/TabBar/TabBar.tsx +2 -13
- package/src/components/TagInput/TagInput.tsx +2 -1
- package/src/components/Tip/Tip.tsx +2 -1
- package/src/components/Toast/Toast.tsx +2 -1
- package/src/index.ts +2 -1
- package/src/internal/Pressable.tsx +17 -0
- package/src/theme/material.ts +9 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
3
|
-
import { Animated, Platform,
|
|
3
|
+
import { Animated, Platform, ScrollView, StyleSheet, View, useWindowDimensions } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
5
6
|
import { FloatingPanel } from "../../internal/FloatingPanel";
|
|
6
7
|
import { Glass } from "../../internal/Glass";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { cloneElement, isValidElement, useState } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { StyleSheet, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import CheckCircle from "../../icons/plex/CheckCircle";
|
|
5
6
|
import InfoCircle from "../../icons/plex/InfoCircle";
|
|
6
7
|
import Warning from "../../icons/plex/Warning";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Children, isValidElement, useId, useState } from "react";
|
|
3
|
-
import { Animated, Easing, Platform,
|
|
3
|
+
import { Animated, Easing, Platform, StyleSheet, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import Svg, { Circle, Defs, LinearGradient, Stop } from "react-native-svg";
|
|
5
6
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
6
7
|
import { Text } from "../Text/Text";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useLayoutEffect, useRef, useState } from "react";
|
|
3
|
-
import { Animated,
|
|
3
|
+
import { Animated, StyleSheet, Text as NativeText, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import CloseBold from "../../icons/plex/CloseBold";
|
|
5
6
|
import { flattenChildren } from "../../internal/children";
|
|
6
7
|
import { curves } from "../../internal/motion";
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { Children, cloneElement, isValidElement } from "react";
|
|
3
3
|
import { StyleSheet, View } from "react-native";
|
|
4
4
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
5
|
-
import { ANDROID_FADE_ALPHA, ANDROID_FADE_STOPS, SoftBottomEdge } from "../../internal/BarBackdrop";
|
|
5
|
+
import { ANDROID_FADE_ALPHA, ANDROID_FADE_STOPS, SoftBottomEdge, TabBarFade } from "../../internal/BarBackdrop";
|
|
6
6
|
import { withAlpha } from "../../theme/material";
|
|
7
7
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
8
8
|
import { Button } from "../Button/Button";
|
|
@@ -13,7 +13,7 @@ import { Button } from "../Button/Button";
|
|
|
13
13
|
* action stands under it, 8 apart. Android: the Plex Android look's 48dp full-width button, 16dp from the sides and
|
|
14
14
|
* 16 above the gesture bar. Each Button inside is a block of the size `3xl` unless it sets its own.
|
|
15
15
|
*/
|
|
16
|
-
export function BottomActions({ children, floating = false, canvasColor, testID, style }) {
|
|
16
|
+
export function BottomActions({ children, floating = false, background = "soft", canvasColor, testID, style }) {
|
|
17
17
|
const theme = useTheme();
|
|
18
18
|
const insets = useSafeAreaInsets();
|
|
19
19
|
const android = theme.isAndroid;
|
|
@@ -40,7 +40,7 @@ export function BottomActions({ children, floating = false, canvasColor, testID,
|
|
|
40
40
|
style: [{ minHeight: height, borderRadius: height / 2 }, props.style],
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
|
-
return (_jsxs(View, { testID: testID, pointerEvents: "box-none", style: [styles.bar, { paddingHorizontal: side, paddingTop, paddingBottom: bottom, gap: 8 }, floating ? styles.floating : null, style], children: [floating ? (android ? (_jsx(SoftBottomEdge, { fill: withAlpha(canvas, ANDROID_FADE_ALPHA), top: paddingTop - 13 + 60, tail: 60, blur: 0, stops: ANDROID_FADE_STOPS })) : (_jsx(SoftBottomEdge, { fill: canvas, top: paddingTop, tail: 27, blur: theme.length("--toolbar-edge-blur-small", 3) }))) : null, actions] }));
|
|
43
|
+
return (_jsxs(View, { testID: testID, pointerEvents: "box-none", style: [styles.bar, { paddingHorizontal: side, paddingTop, paddingBottom: bottom, gap: 8 }, floating ? styles.floating : null, style], children: [floating ? (android ? (_jsx(SoftBottomEdge, { fill: withAlpha(canvas, ANDROID_FADE_ALPHA), top: paddingTop - 13 + 60, tail: 60, blur: 0, stops: ANDROID_FADE_STOPS })) : background === "fade" ? (_jsx(TabBarFade, { fill: canvas, top: paddingTop })) : (_jsx(SoftBottomEdge, { fill: canvas, top: paddingTop, tail: 27, blur: theme.length("--toolbar-edge-blur-small", 3) }))) : null, actions] }));
|
|
44
44
|
}
|
|
45
45
|
const styles = StyleSheet.create({
|
|
46
46
|
bar: { alignSelf: "stretch" },
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { isValidElement, useId, useLayoutEffect, useMemo, useState } from "react";
|
|
3
|
-
import { Animated, Easing, PanResponder, Platform,
|
|
3
|
+
import { Animated, Easing, PanResponder, Platform, ScrollView, StyleSheet, View, useWindowDimensions } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
5
6
|
import { childrenOfType, flattenChildren } from "../../internal/children";
|
|
6
7
|
import { useKeyboardHeight } from "../../internal/keyboard";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, Fragment, isValidElement, useContext, useEffect, useState } from "react";
|
|
3
|
-
import { ActivityIndicator, Animated, Easing, Platform,
|
|
3
|
+
import { ActivityIndicator, Animated, Easing, Platform, StyleSheet, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import Svg, { Circle } from "react-native-svg";
|
|
5
6
|
import { flattenChildren } from "../../internal/children";
|
|
6
7
|
import { Glass } from "../../internal/Glass";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { cloneElement, createContext, isValidElement, useContext } from "react";
|
|
3
|
-
import { Image, Platform,
|
|
3
|
+
import { Image, Platform, StyleSheet, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import { flattenChildren } from "../../internal/children";
|
|
5
6
|
import { space } from "../../internal/spacing";
|
|
6
7
|
import { controlHighlight, withAlpha } from "../../theme/material";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useContext, useEffect, useState } from "react";
|
|
3
|
-
import { Animated, Easing,
|
|
3
|
+
import { Animated, Easing, StyleSheet, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import Svg, { Path } from "react-native-svg";
|
|
5
6
|
import CheckMd from "../../icons/plex/CheckMd";
|
|
6
7
|
import Minus from "../../icons/plex/Minus";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
|
-
import { Animated, Easing, Platform,
|
|
3
|
+
import { Animated, Easing, Platform, StyleSheet, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import ChevronDownSm from "../../icons/plex/ChevronDownSm";
|
|
5
6
|
import CloseBold from "../../icons/plex/CloseBold";
|
|
6
7
|
import XCircleFilled from "../../icons/plex/XCircleFilled";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo, useState } from "react";
|
|
3
|
-
import { Platform,
|
|
3
|
+
import { Platform, StyleSheet, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import ChevronLeftLg from "../../icons/plex/ChevronLeftLg";
|
|
5
6
|
import ChevronRightLg from "../../icons/plex/ChevronRightLg";
|
|
6
7
|
import { isRTL } from "../../internal/direction";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useContext, useEffect, useRef, useState } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { StyleSheet, View, useWindowDimensions } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import { RowEndContext, RowHoldContext, rowHold } from "../../internal/row";
|
|
5
6
|
import { withAlpha } from "../../theme/material";
|
|
6
7
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useRef, useState } from "react";
|
|
3
|
-
import { Platform,
|
|
3
|
+
import { Platform, StyleSheet, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import Svg, { Circle, Line } from "react-native-svg";
|
|
5
6
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
6
7
|
import { Text } from "../Text/Text";
|
|
@@ -1,6 +1,7 @@
|
|
|
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,
|
|
3
|
+
import { Animated, Platform, ScrollView, StyleSheet, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import { withAlpha } from "../../theme/material";
|
|
5
6
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
6
7
|
/** iOS: a row of UIDatePicker's wheels, 32 apart (the band of iOS 27.2, 32 tall). Android: a NumberPicker's 48dp rows. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useId, useState } from "react";
|
|
3
|
-
import { Animated, KeyboardAvoidingView, Platform,
|
|
3
|
+
import { Animated, KeyboardAvoidingView, Platform, ScrollView, StyleSheet, View, useWindowDimensions } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
5
6
|
import { Glass } from "../../internal/Glass";
|
|
6
7
|
import { useRipple } from "../../internal/ripple";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
3
|
-
import { Animated, Easing, PixelRatio, Platform,
|
|
3
|
+
import { Animated, Easing, PixelRatio, Platform, StyleSheet, Text as NativeText, TextInput, View, processColor } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import XCircleFilled from "../../icons/plex/XCircleFilled";
|
|
5
6
|
import { useAndroidGlass } from "../../internal/BarBackdrop";
|
|
6
7
|
import { FieldStack, FloatLabelContext } from "../../internal/fieldStack";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, isValidElement, useContext } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { StyleSheet, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import { flattenChildren } from "../../internal/children";
|
|
5
6
|
import { RowEndContext } from "../../internal/row";
|
|
6
7
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Platform, StyleSheet, View } from "react-native";
|
|
3
|
+
import { useRTL } from "../../internal/direction";
|
|
4
|
+
import { useTheme } from "../../theme/ThemeProvider";
|
|
5
|
+
import { IconDefaultsProvider } from "../Icon/createIcon";
|
|
6
|
+
import { Text } from "../Text/Text";
|
|
7
|
+
/**
|
|
8
|
+
* The header of a step in a sheet or a setup flow: an optional symbol, the step's title and what it asks, as iOS 27's
|
|
9
|
+
* own steps set them (Apple Account, Add Email Address, Recovery Key, Pair Hearing Device, Set Up eSIM, Health's
|
|
10
|
+
* medication steps). Measured on a 430pt phone: the symbol's drawing about 70pt, in the middle, its bottom about 31pt
|
|
11
|
+
* over the title's line; the title in Title 2 bold and the description in Title 2 in the secondary label right under
|
|
12
|
+
* it, both at the start of the column. The header keeps no space round it: the screen sets it 24 under its bar and the
|
|
13
|
+
* content 24 under it. Android: the setup wizard's header, a 40dp symbol in the primary at the start 16 over a Headline
|
|
14
|
+
* Small title, the description in Body Large 16 under it in onSurfaceVariant.
|
|
15
|
+
*/
|
|
16
|
+
export function IntroHeader({ title, description, media, align = "cells", testID, style }) {
|
|
17
|
+
const theme = useTheme();
|
|
18
|
+
const android = theme.isAndroid;
|
|
19
|
+
// On the rows' text: Android's list rows keep their text 21 in (List's ANDROID_INSET), iOS's the row inset
|
|
20
|
+
const inset = align === "text" ? (android ? 21 : theme.length("--list-row-inset", 20)) : 0;
|
|
21
|
+
// The text at the start: React Native turns `left` to the right in a right-to-left layout on a phone, the web keeps
|
|
22
|
+
// it left, so there the side is read from the header's direction
|
|
23
|
+
const { ref, rtl } = useRTL();
|
|
24
|
+
const start = { textAlign: Platform.OS === "web" && rtl ? "right" : "left" };
|
|
25
|
+
return (_jsxs(View, { ref: ref, testID: testID, style: [{ paddingHorizontal: inset }, style], children: [media != null ? (_jsx(View, { "aria-hidden": true, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants",
|
|
26
|
+
// A symbol's box keeps about 7 round its drawing at 80: 24 under the box is the drawing's 31 over the title
|
|
27
|
+
style: [styles.media, { alignSelf: android ? "flex-start" : "center", marginBottom: android ? 16 : 24 }], children: _jsx(IconDefaultsProvider, { size: android ? 40 : 80, color: android ? theme.material.primary : theme.colors.accent, children: media }) })) : null, _jsx(Text, { variant: "title2", weight: android ? "regular" : "bold", accessibilityRole: "header", style: start, children: title }), description != null ? (_jsx(Text, { variant: android ? "body" : "title2", color: "secondary", style: [start, android ? styles.androidDescription : null], children: description })) : null] }));
|
|
28
|
+
}
|
|
29
|
+
const styles = StyleSheet.create({
|
|
30
|
+
media: { alignItems: "center", justifyContent: "center" },
|
|
31
|
+
androidDescription: { marginTop: 16 },
|
|
32
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { cloneElement, createContext, isValidElement, useCallback, useContext, useMemo, useRef, useState } from "react";
|
|
3
|
-
import {
|
|
2
|
+
import { cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { Animated, Easing, Platform, StyleSheet, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import Disclosure from "../../icons/plex/Disclosure";
|
|
5
6
|
import ExclamationMarkCircle from "../../icons/plex/ExclamationMarkCircle";
|
|
6
7
|
import { spaceToggles, useDescription } from "../../internal/a11y";
|
|
@@ -104,7 +105,7 @@ export function List({ children, header, description, footer, error, surface = "
|
|
|
104
105
|
}, children: error ?? footer })) : null] }));
|
|
105
106
|
}
|
|
106
107
|
/**
|
|
107
|
-
* A row of a List: the label (17/22, `--field-row-*`: 52 tall,
|
|
108
|
+
* A row of a List: the label (17/22, `--field-row-*`: 52 tall, 62 with a description, 12 above and below the text at
|
|
108
109
|
* least) with a description, a leading symbol, a value (wrapping within 60% of the row, or under the label: `valuePlacement`) or a control, and the chevron
|
|
109
110
|
* of a drill-in (`Disclosure`, in the tertiary label, turned over right to left). A row with `checked` is a switch
|
|
110
111
|
* row. On Android a row of a settings screen: 50dp tall at least (64 with a description, its text 12 from the row's
|
|
@@ -162,7 +163,7 @@ export function ListItem({ label, description, leading, leadingColor, value, val
|
|
|
162
163
|
const nativeRipple = theme.isAndroid && Platform.OS === "android";
|
|
163
164
|
// iOS lights a held choice row, not a switch row, as the web's phone rows
|
|
164
165
|
const lit = !switchRow && control?.kind !== "switch";
|
|
165
|
-
const row =
|
|
166
|
+
const row = theme.isAndroid ? styles.androidRow : iosRow(theme, last, description != null || error != null);
|
|
166
167
|
// A finger on the control at the end holds the row, as one on the row's text does
|
|
167
168
|
const [held, setHeld] = useState(false);
|
|
168
169
|
// Android's press is the list selector's ripple from the touch point, clipped to the row (and the card's corners):
|
|
@@ -191,18 +192,20 @@ export function ListItem({ label, description, leading, leadingColor, value, val
|
|
|
191
192
|
const drawn = theme.isAndroid && !nativeRipple;
|
|
192
193
|
return (_jsx(Pressable, { ref: frameNode, collapsable: false, ...described.props, ...(switchRow ? spaceToggles(toggle) : null),
|
|
193
194
|
// A row that toggles its control is not a second element for a screen reader or a Tab stop: the control is
|
|
194
|
-
accessible: endOwnsFocus ? false : undefined, focusable: endOwnsFocus ? false : undefined, tabIndex: endOwnsFocus ? -1 : undefined, accessibilityRole: endOwnsFocus ? undefined : switchRow ? "switch" : "button", accessibilityLabel: endOwnsFocus ? undefined : name, accessibilityState: endOwnsFocus ? undefined : switchRow ? { checked, disabled } : { disabled }, "aria-checked": switchRow ? checked : undefined, disabled: disabled, onPress: press, onLongPress: onLongPress, delayLongPress: onLongPress ? 500 : undefined, accessibilityActions: onLongPress ? [{ name: "longpress" }] : undefined, onAccessibilityAction: onLongPress ? (event) => event.nativeEvent.actionName === "longpress" && onLongPress() : undefined, onPressIn: drawn ? ripple.start : undefined, onPressOut: drawn ? ripple.end : undefined, android_ripple: nativeRipple ? { color: highlight, foreground: true } : undefined, testID: testID, style:
|
|
195
|
+
accessible: endOwnsFocus ? false : undefined, focusable: endOwnsFocus ? false : undefined, tabIndex: endOwnsFocus ? -1 : undefined, accessibilityRole: endOwnsFocus ? undefined : switchRow ? "switch" : "button", accessibilityLabel: endOwnsFocus ? undefined : name, accessibilityState: endOwnsFocus ? undefined : switchRow ? { checked, disabled } : { disabled }, "aria-checked": switchRow ? checked : undefined, disabled: disabled, onPress: press, onLongPress: onLongPress, delayLongPress: onLongPress ? 500 : undefined, accessibilityActions: onLongPress ? [{ name: "longpress" }] : undefined, onAccessibilityAction: onLongPress ? (event) => event.nativeEvent.actionName === "longpress" && onLongPress() : undefined, onPressIn: drawn ? ripple.start : undefined, onPressOut: drawn ? ripple.end : undefined, android_ripple: nativeRipple ? { color: highlight, foreground: true } : undefined, testID: testID, style: row, children: ({ pressed }) => (_jsxs(RowHoldContext.Provider, { value: disabled ? null : theme.isAndroid ? hold : setHeld, children: [ripple.layer, theme.isAndroid ? null : _jsx(RowHighlight, { on: (pressed || held) && lit, last: last }), content(pressed || held)] })) }));
|
|
195
196
|
}
|
|
196
197
|
// A row that only shows (a detail, a value) is one element named by `accessibilityLabel` when it has one; with a
|
|
197
198
|
// control at its end it stays a group, so the control is still reached
|
|
198
199
|
const named = accessibilityLabel != null && trailing == null && found == null;
|
|
199
|
-
return (_jsx(View, { ref: frameNode, collapsable: false, testID: testID, accessible: named || undefined, accessibilityLabel: accessibilityLabel, accessibilityRole: named && Platform.OS !== "web" ? "text" : undefined, role: named && Platform.OS === "web" ? "group" : undefined, style: row
|
|
200
|
+
return (_jsx(View, { ref: frameNode, collapsable: false, testID: testID, accessible: named || undefined, accessibilityLabel: accessibilityLabel, accessibilityRole: named && Platform.OS !== "web" ? "text" : undefined, role: named && Platform.OS === "web" ? "group" : undefined, style: row, children: content(false) }));
|
|
200
201
|
}
|
|
201
202
|
/** A Button among a List's rows: the row is the button (`ListActionContext`), the hairline under it from the text's start. */
|
|
202
203
|
function ActionRow({ children }) {
|
|
203
204
|
const theme = useTheme();
|
|
204
205
|
const { last } = useContext(PlaceContext);
|
|
205
|
-
return (_jsxs(View, { style: styles.actionRow, children: [_jsx(ListActionContext.Provider, { value: "row", children: children }), last ? null : (_jsx(View, { pointerEvents: "none",
|
|
206
|
+
return (_jsxs(View, { style: styles.actionRow, children: [_jsx(ListActionContext.Provider, { value: "row", children: children }), last ? null : (_jsx(View, { pointerEvents: "none",
|
|
207
|
+
// iOS: from the text to 20 before the group's end, as the other rows' lines
|
|
208
|
+
style: [styles.actionSeparator, theme.isAndroid ? { start: ANDROID_INSET } : { start: theme.length("--list-row-inset", 20), end: theme.length("--list-row-inset", 20) }, { backgroundColor: theme.isAndroid ? divider(theme) : theme.colors.separator }] }))] }));
|
|
206
209
|
}
|
|
207
210
|
/**
|
|
208
211
|
* A field row whose value is a line of its own, as the web's `Field row` with `orientation="vertical"` or `hideLabel`
|
|
@@ -237,7 +240,7 @@ export function ListStackedRow({ label, description, error, disabled = false, ac
|
|
|
237
240
|
const errorOffset = theme.length("--mobile-field-error-offset", 4);
|
|
238
241
|
const errorLine = theme.length("--mobile-field-error-line-height", 20);
|
|
239
242
|
const iconSize = theme.length("--mobile-field-error-icon-size", 16);
|
|
240
|
-
return (_jsx(View, { testID: testID, style: [styles.stackedRow, { paddingStart: inset }], children: _jsxs(View, { style: [styles.stackedColumn, { paddingEnd: inset, paddingVertical: padding, gap: android ? 4 : 0 }], children: [last ? null : _jsx(View, { pointerEvents: "none", style: [styles.iosSeparator, { backgroundColor: android ? divider(theme) : theme.colors.separator }] }), labelText != null && action != null ? (_jsxs(View, { style: [styles.pair, { gap: 8 }, !android && error != null ? { marginBottom: theme.length("--mobile-field-error-offset", 4) } : null], children: [labelText, action] })) : (labelText), _jsx(RowEndContext.Provider, { value: rowEnd, children: children }), description != null ? (_jsx(Text, { color: secondary, style: android ? styles.androidDescription : { fontSize: theme.length("--field-row-description-font-size", 15), lineHeight: theme.length("--field-row-description-line-height", 20) }, children: description })) : null, error == null ? null : android ? (_jsx(Text, { color: dangerText(theme), accessibilityLiveRegion: "polite", style: styles.androidDescription, children: error })) : (_jsxs(View, { accessibilityLiveRegion: "polite", style: [styles.iosError, { marginTop: errorOffset, gap: theme.length("--mobile-field-error-icon-gap", 4) }], children: [_jsx(ExclamationMarkCircle, { size: iconSize, color: errorColor(theme), style: { marginTop: (errorLine - iconSize) / 2 } }), _jsx(Text, { color: errorColor(theme), style: [styles.shrink, { fontSize: theme.length("--mobile-field-error-font-size", 15), lineHeight: errorLine }], children: error })] }))] }) }));
|
|
243
|
+
return (_jsx(View, { testID: testID, style: [styles.stackedRow, { paddingStart: inset }], children: _jsxs(View, { style: [styles.stackedColumn, { paddingEnd: inset, paddingVertical: padding, gap: android ? 4 : 0 }], children: [last ? null : _jsx(View, { pointerEvents: "none", style: [styles.iosSeparator, { backgroundColor: android ? divider(theme) : theme.colors.separator }, android ? null : { end: inset }] }), labelText != null && action != null ? (_jsxs(View, { style: [styles.pair, { gap: 8 }, !android && error != null ? { marginBottom: theme.length("--mobile-field-error-offset", 4) } : null], children: [labelText, action] })) : (labelText), _jsx(RowEndContext.Provider, { value: rowEnd, children: children }), description != null ? (_jsx(Text, { color: secondary, style: android ? styles.androidDescription : { fontSize: theme.length("--field-row-description-font-size", 15), lineHeight: theme.length("--field-row-description-line-height", 20) }, children: description })) : null, error == null ? null : android ? (_jsx(Text, { color: dangerText(theme), accessibilityLiveRegion: "polite", style: styles.androidDescription, children: error })) : (_jsxs(View, { accessibilityLiveRegion: "polite", style: [styles.iosError, { marginTop: errorOffset, gap: theme.length("--mobile-field-error-icon-gap", 4) }], children: [_jsx(ExclamationMarkCircle, { size: iconSize, color: errorColor(theme), style: { marginTop: (errorLine - iconSize) / 2 } }), _jsx(Text, { color: errorColor(theme), style: [styles.shrink, { fontSize: theme.length("--mobile-field-error-font-size", 15), lineHeight: errorLine }], children: error })] }))] }) }));
|
|
241
244
|
}
|
|
242
245
|
/** A Switch, a Checkbox or (inside its RadioGroup) an option given as a row's `trailing`, which the row's press toggles. */
|
|
243
246
|
function rowControl(trailing, inGroup) {
|
|
@@ -281,21 +284,43 @@ function endControl(found, own, setOwn, rowDisabled, name) {
|
|
|
281
284
|
: cloneElement(found.element, { checked: state, onCheckedChange: change, accessibilityLabel });
|
|
282
285
|
return { kind: found.kind, node, toggle: rowDisabled || props.disabled ? undefined : () => change(state !== true) };
|
|
283
286
|
}
|
|
284
|
-
/** A row's least height: 52,
|
|
285
|
-
const iosMinHeight = (theme, described) => described ? theme.length("--field-row-description-min-height",
|
|
286
|
-
function iosRow(theme,
|
|
287
|
+
/** A row's least height: 52, 62 with a description (as Settings, iOS 26 and 27) (`--field-row-description-min-height`), as the web's NavigationRow. */
|
|
288
|
+
const iosMinHeight = (theme, described) => described ? theme.length("--field-row-description-min-height", 62) : theme.length("--field-row-min-height", 52);
|
|
289
|
+
function iosRow(theme, last, described) {
|
|
287
290
|
const inset = theme.length("--list-row-inset", 20);
|
|
288
291
|
return {
|
|
289
292
|
flexDirection: "row",
|
|
290
293
|
alignItems: "center",
|
|
291
294
|
minHeight: iosMinHeight(theme, described),
|
|
292
295
|
paddingStart: inset,
|
|
293
|
-
|
|
294
|
-
// The press fills the row to the group's rounded ends
|
|
296
|
+
// The press is RowHighlight's, under the content; the row's rounded end clips it to the group's
|
|
295
297
|
borderBottomLeftRadius: last ? theme.length("--field-group-radius", 26) : 0,
|
|
296
298
|
borderBottomRightRadius: last ? theme.length("--field-group-radius", 26) : 0,
|
|
297
299
|
};
|
|
298
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* iOS's press on a row: the row lights at once under a finger and, when it lifts, the light fades out over 0.3s, as
|
|
303
|
+
* UIKit deselects a cell (the system gray 4 of `--field-row-press-background`); at once with reduced motion.
|
|
304
|
+
*/
|
|
305
|
+
function RowHighlight({ on, last }) {
|
|
306
|
+
const theme = useTheme();
|
|
307
|
+
const opacity = useRef(new Animated.Value(0)).current;
|
|
308
|
+
useEffect(() => {
|
|
309
|
+
if (on || theme.reducedMotion) {
|
|
310
|
+
opacity.stopAnimation();
|
|
311
|
+
opacity.setValue(on ? 1 : 0);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const fade = Animated.timing(opacity, { toValue: 0, duration: 300, easing: Easing.out(Easing.quad), useNativeDriver: Platform.OS !== "web" });
|
|
315
|
+
fade.start();
|
|
316
|
+
return () => fade.stop();
|
|
317
|
+
}, [on, opacity, theme.reducedMotion]);
|
|
318
|
+
const radius = last ? theme.length("--field-group-radius", 26) : 0;
|
|
319
|
+
return (_jsx(Animated.View, { pointerEvents: "none", style: [
|
|
320
|
+
StyleSheet.absoluteFill,
|
|
321
|
+
{ opacity, backgroundColor: theme.color("--field-row-press-background"), borderBottomLeftRadius: radius, borderBottomRightRadius: radius },
|
|
322
|
+
] }));
|
|
323
|
+
}
|
|
299
324
|
/**
|
|
300
325
|
* Whether a row's value goes under its label: `below`, or `auto` when the label and the value do not fit beside each
|
|
301
326
|
* other on one line. As the web's NavigationRow measures them unwrapped in the end layout's limits, a hidden probe
|
|
@@ -327,14 +352,16 @@ function IOSContent({ theme, label, description, descriptionId, leading, leading
|
|
|
327
352
|
// The text's padding centres one line (or a label and its description) in the row's least height, 12 at least, as the
|
|
328
353
|
// web's: a row of more lines (a wrapped label, a value below) keeps those 15 (14) above and below
|
|
329
354
|
// A row with a control at its end is the web's form row (`Field row`): its text keeps the control's 44pt line, 4 above
|
|
330
|
-
// and below it, or
|
|
355
|
+
// and below it, or 10 around a description, so a wrapped label or description grows the row by its own lines only
|
|
331
356
|
const target = theme.length("--control-size-lg", 44);
|
|
332
357
|
const formRow = trailing != null;
|
|
358
|
+
// A two-line row keeps 10 over its label and under its description, as Settings (62 in all)
|
|
359
|
+
const descriptionPadding = theme.length("--field-row-description-padding-block", 10);
|
|
333
360
|
const textPadding = formRow
|
|
334
361
|
? description != null
|
|
335
|
-
?
|
|
362
|
+
? descriptionPadding
|
|
336
363
|
: (iosMinHeight(theme, false) - target) / 2
|
|
337
|
-
: Math.max(theme.length("--field-row-text-padding-block", 12), (iosMinHeight(theme, description != null) - labelType.lineHeight - (description != null ? descriptionLine : 0)) / 2);
|
|
364
|
+
: Math.max(description != null ? descriptionPadding : theme.length("--field-row-text-padding-block", 12), (iosMinHeight(theme, description != null) - labelType.lineHeight - (description != null ? descriptionLine : 0)) / 2);
|
|
338
365
|
// A field at the end fills the room after the label (`RowEnd.fill`)
|
|
339
366
|
const [fill, setFill] = useState(false);
|
|
340
367
|
// In a List with `columns` a field's value starts at one column, 40% into the row (`--field-row-column-width`)
|
|
@@ -360,9 +387,9 @@ function IOSContent({ theme, label, description, descriptionId, leading, leading
|
|
|
360
387
|
error != null ? styles.iosColumn : styles.iosMain,
|
|
361
388
|
{ minHeight: iosMinHeight(theme, description != null || error != null), paddingEnd: inset },
|
|
362
389
|
error != null
|
|
363
|
-
? { paddingVertical: Math.max(
|
|
390
|
+
? { paddingVertical: Math.max(descriptionPadding, (iosMinHeight(theme, true) - labelType.lineHeight - errorOffset - errorLine) / 2) }
|
|
364
391
|
: { gap: below ? disclosureGap : gap },
|
|
365
|
-
], children: [last ? null : _jsx(View, { pointerEvents: "none", style: [styles.iosSeparator, { backgroundColor: theme.colors.separator }] }), probe, line(_jsxs(_Fragment, { children: [_jsxs(View, { style: [columns ? styles.column : fill ? styles.iosTextHug : styles.iosText, { paddingVertical: error != null ? 0 : textPadding }, formRow && description == null && error == null ? { minHeight: target, justifyContent: "center" } : null], children: [_jsx(Text, { color: labelColor, style: labelType, children: label }), below ? (
|
|
392
|
+
], children: [last ? null : _jsx(View, { pointerEvents: "none", style: [styles.iosSeparator, { backgroundColor: theme.colors.separator, end: inset }] }), probe, line(_jsxs(_Fragment, { children: [_jsxs(View, { style: [columns ? styles.column : fill ? styles.iosTextHug : styles.iosText, { paddingVertical: error != null ? 0 : textPadding }, formRow && description == null && error == null ? { minHeight: target, justifyContent: "center" } : null], children: [_jsx(Text, { color: labelColor, style: labelType, children: label }), below ? (
|
|
366
393
|
// Under the label, the lines touching as a subtitle cell's, at the text's start
|
|
367
394
|
_jsx(Text, { color: secondary, style: labelType, children: value })) : null, description != null ? (_jsx(Text, { nativeID: descriptionId, color: secondary, style: { fontSize: theme.length("--field-row-description-font-size", 15), lineHeight: descriptionLine }, children: description })) : null] }), (value != null && !below) || trailing != null || chevron ? (_jsxs(View, { style: [fill || columns ? styles.endFill : styles.end, columns && !startsColumn ? styles.endAtEdge : null, { gap: disclosureGap }], children: [value != null && !below ? (
|
|
368
395
|
// A long value wraps within the 60% the end takes, as the web's, rather than losing its end; set at the
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Children, cloneElement, createContext, Fragment, isValidElement, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
|
-
import { Animated, Easing, I18nManager, PanResponder, Platform,
|
|
3
|
+
import { Animated, Easing, I18nManager, PanResponder, Platform, ScrollView, StyleSheet, View, useWindowDimensions } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
5
6
|
import Svg, { Path } from "react-native-svg";
|
|
6
7
|
import ArrowLeftLg from "../../icons/plex/ArrowLeftLg";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useContext, useEffect, useState } from "react";
|
|
3
|
-
import { Animated, Platform,
|
|
3
|
+
import { Animated, Platform, StyleSheet, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import CheckMd from "../../icons/plex/CheckMd";
|
|
5
6
|
import { useDescription } from "../../internal/a11y";
|
|
6
7
|
import { ControlLabel } from "../../internal/ControlLabel";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, isValidElement, useContext, useEffect, useRef, useState } from "react";
|
|
3
|
-
import { Animated, Easing,
|
|
3
|
+
import { Animated, Easing, StyleSheet, View } from "react-native";
|
|
4
|
+
import { Pressable } from "../../internal/Pressable";
|
|
4
5
|
import { childrenOfType, isRenderable, textOf } from "../../internal/children";
|
|
5
6
|
import { Glass } from "../../internal/Glass";
|
|
6
7
|
import { curves } from "../../internal/motion";
|
|
@@ -29,7 +30,7 @@ function iosLook(theme, size, material, inBar, inRow) {
|
|
|
29
30
|
glass: true,
|
|
30
31
|
fill: theme.color("--segmented-control-mobile-glass-background"),
|
|
31
32
|
thumb: theme.color("--segmented-control-mobile-thumb-background"),
|
|
32
|
-
duration:
|
|
33
|
+
duration: 300,
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
return {
|
|
@@ -47,43 +48,6 @@ function iosLook(theme, size, material, inBar, inRow) {
|
|
|
47
48
|
duration: 250,
|
|
48
49
|
};
|
|
49
50
|
}
|
|
50
|
-
/**
|
|
51
|
-
* The curve the large control's lens lands on (touch.css `--tabs-thumb-transition-easing`, iOS 27.2 frame by frame):
|
|
52
|
-
* CSS `linear()` stops, each [progress, time], read between them as the browser does.
|
|
53
|
-
*/
|
|
54
|
-
const LENS_STOPS = [
|
|
55
|
-
[0, 0],
|
|
56
|
-
[0.2, 0.03],
|
|
57
|
-
[0.33, 0.0625],
|
|
58
|
-
[0.45, 0.1],
|
|
59
|
-
[0.538, 0.1225],
|
|
60
|
-
[0.623, 0.1625],
|
|
61
|
-
[0.69, 0.2],
|
|
62
|
-
[0.747, 0.2425],
|
|
63
|
-
[0.793, 0.2875],
|
|
64
|
-
[0.83, 0.325],
|
|
65
|
-
[0.862, 0.3675],
|
|
66
|
-
[0.887, 0.41],
|
|
67
|
-
[0.908, 0.45],
|
|
68
|
-
[0.925, 0.4925],
|
|
69
|
-
[0.943, 0.535],
|
|
70
|
-
[0.956, 0.58],
|
|
71
|
-
[0.975, 0.66],
|
|
72
|
-
[0.981, 0.7],
|
|
73
|
-
[0.989, 0.7475],
|
|
74
|
-
[0.994, 0.825],
|
|
75
|
-
[1, 1],
|
|
76
|
-
];
|
|
77
|
-
const lensEasing = (t) => {
|
|
78
|
-
if (t <= 0)
|
|
79
|
-
return 0;
|
|
80
|
-
if (t >= 1)
|
|
81
|
-
return 1;
|
|
82
|
-
const after = LENS_STOPS.findIndex(([, at]) => at >= t);
|
|
83
|
-
const [fromValue, fromAt] = LENS_STOPS[after - 1];
|
|
84
|
-
const [toValue, toAt] = LENS_STOPS[after];
|
|
85
|
-
return fromValue + ((toValue - fromValue) * (t - fromAt)) / (toAt - fromAt);
|
|
86
|
-
};
|
|
87
51
|
/** A Toolbar.Row tells the control in it that it is in a row, not in the bar's own row. */
|
|
88
52
|
export const SegmentedControlRowContext = createContext({ inRow: false });
|
|
89
53
|
function SegmentedControlTab(_) {
|
|
@@ -106,7 +70,7 @@ const optionName = (option) => {
|
|
|
106
70
|
* iOS 26 apps (48pt; 40 in a Toolbar.Row), its thumb sliding to the selection; on Android a segmented capsule, white
|
|
107
71
|
* with a sliding pill of the accent. Props follow @plexui/ui (`SegmentedControl` and `SegmentedControl.Tab`).
|
|
108
72
|
*/
|
|
109
|
-
function SegmentedControlRoot({ value, onChange, onClick, "aria-label": ariaLabel, size = "md", disabled = false, block = false, mobileMaterial, mobileSegmentWidth = "equal", style, testID, children, }) {
|
|
73
|
+
function SegmentedControlRoot({ value, onChange, onClick, "aria-label": ariaLabel, size = "md", disabled = false, block = false, mobileMaterial, mobileSegmentWidth = "equal", showBadges = false, style, testID, children, }) {
|
|
110
74
|
const theme = useTheme();
|
|
111
75
|
const options = childrenOfType(children, SegmentedControlTab).map((child) => child.props);
|
|
112
76
|
const select = (option) => {
|
|
@@ -119,11 +83,13 @@ function SegmentedControlRoot({ value, onChange, onClick, "aria-label": ariaLabe
|
|
|
119
83
|
if (option)
|
|
120
84
|
select(option);
|
|
121
85
|
});
|
|
122
|
-
|
|
86
|
+
// Drawn counts differ from tab to tab, so each segment takes its own width with them, as a messenger's folder tabs
|
|
87
|
+
const counted = showBadges && options.some((option) => option.badge != null);
|
|
88
|
+
const common = { options, value, select, keys, disabled, block, equal: mobileSegmentWidth === "equal" && !counted, showBadges };
|
|
123
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 }) }));
|
|
124
90
|
}
|
|
125
91
|
SegmentedControlRoot.displayName = "SegmentedControl";
|
|
126
|
-
function IOSControl({ options, value, select, keys, disabled, block, equal, size, material }) {
|
|
92
|
+
function IOSControl({ options, value, select, keys, disabled, block, equal, showBadges, size, material }) {
|
|
127
93
|
const theme = useTheme();
|
|
128
94
|
const inBar = !!useContext(BarItemContext);
|
|
129
95
|
const { inRow } = useContext(SegmentedControlRowContext);
|
|
@@ -133,6 +99,9 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, size
|
|
|
133
99
|
const [widths, setWidths] = useState({});
|
|
134
100
|
const widest = Math.max(0, ...options.map((option) => labels[option.value] ?? 0));
|
|
135
101
|
const optionRadius = look.height / 2 - look.gutter;
|
|
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
|
+
// capsule does not touch the thumb's end
|
|
104
|
+
const gutter = showBadges && options.some((option) => option.badge != null) ? Math.max(look.optionGutter, 10) : look.optionGutter;
|
|
136
105
|
// The large glass control held down, as the phone CSS ports it: the capsule grows 7% and whitens, the held label
|
|
137
106
|
// fades to 20%, with no capsule of its own under the finger
|
|
138
107
|
const largeGlass = look.glass && look.height >= 40;
|
|
@@ -156,13 +125,14 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, size
|
|
|
156
125
|
placed.current = true;
|
|
157
126
|
return;
|
|
158
127
|
}
|
|
159
|
-
// The
|
|
160
|
-
|
|
128
|
+
// The thumb eases (CSS `ease`): in 300ms on the large control, 250 on the small one. The lens's own curve (fast,
|
|
129
|
+
// then a long settle) reads as a jump and a crawl when no lens is drawn over it (owner, 24.11)
|
|
130
|
+
const easing = Easing.bezier(0.25, 0.1, 0.25, 1);
|
|
161
131
|
Animated.parallel([
|
|
162
132
|
Animated.timing(x, { toValue: selectedX, duration: look.duration, easing, useNativeDriver: false }),
|
|
163
133
|
Animated.timing(width, { toValue: selectedWidth, duration: look.duration, easing, useNativeDriver: false }),
|
|
164
134
|
]).start();
|
|
165
|
-
}, [selectedX, selectedWidth, look.duration,
|
|
135
|
+
}, [selectedX, selectedWidth, look.duration, theme.reducedMotion, x, width]);
|
|
166
136
|
// The segments take the capsule's whole height, so a press anywhere on it lands (the thumb keeps its inset); a
|
|
167
137
|
// minimum, so text a person enlarges is not cut
|
|
168
138
|
const track = {
|
|
@@ -185,12 +155,12 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, size
|
|
|
185
155
|
setWidths((prev) => (prev[option.value] === w ? prev : { ...prev, [option.value]: w }));
|
|
186
156
|
}, style: [
|
|
187
157
|
styles.option,
|
|
188
|
-
{ paddingHorizontal:
|
|
189
|
-
block ? styles.grow : equal && widest ? { width: widest + 2 *
|
|
190
|
-
], children:
|
|
158
|
+
{ paddingHorizontal: gutter, borderRadius: look.height / 2 },
|
|
159
|
+
block ? styles.grow : equal && widest ? { width: widest + 2 * gutter } : null,
|
|
160
|
+
], children: _jsxs(View, { onLayout: (event) => {
|
|
191
161
|
const w = Math.ceil(event.nativeEvent.layout.width);
|
|
192
162
|
setLabels((prev) => (prev[option.value] === w ? prev : { ...prev, [option.value]: w }));
|
|
193
|
-
}, 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 })) }) }, option.value));
|
|
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));
|
|
194
164
|
})] }));
|
|
195
165
|
if (look.glass) {
|
|
196
166
|
// The glass keeps the control's fill over it: one flat layer, no sheen (touch.css)
|
|
@@ -212,7 +182,7 @@ const ANDROID_MOVE = { duration: 320, easing: curves.easeOutQuint };
|
|
|
212
182
|
* its label in the accent, the others in the secondary gray. The pill slides to a new selection and takes its width.
|
|
213
183
|
* In a bar's row of controls the capsule takes the height of the circles beside it (46dp).
|
|
214
184
|
*/
|
|
215
|
-
function AndroidControl({ options, value, select, keys, disabled, block, equal, size }) {
|
|
185
|
+
function AndroidControl({ options, value, select, keys, disabled, block, equal, showBadges, size }) {
|
|
216
186
|
const theme = useTheme();
|
|
217
187
|
const m = theme.material;
|
|
218
188
|
const bar = useContext(BarItemContext);
|
|
@@ -248,13 +218,13 @@ function AndroidControl({ options, value, select, keys, disabled, block, equal,
|
|
|
248
218
|
styles.androidRow,
|
|
249
219
|
{ height, borderRadius: height / 2, backgroundColor: barSurface(m, theme.scheme), boxShadow: barShadow(theme.scheme) },
|
|
250
220
|
block ? styles.stretch : null,
|
|
251
|
-
], 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, height: inner,
|
|
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,
|
|
252
222
|
// In a filled row equal segments share the width and the others take their label and share what is left; a
|
|
253
223
|
// control that hugs its segments gives equal ones the widest one's width
|
|
254
224
|
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)))] }));
|
|
255
225
|
}
|
|
256
226
|
/** One segment of the capsule: its label turns from the gray to the accent as the pill comes, and back as it goes. */
|
|
257
|
-
function AndroidSegment({ option, selected, off, framed, height, size, keys, select, onWidth }) {
|
|
227
|
+
function AndroidSegment({ option, selected, off, framed, showBadges, height, size, keys, select, onWidth }) {
|
|
258
228
|
const theme = useTheme();
|
|
259
229
|
const m = theme.material;
|
|
260
230
|
const [tint] = useState(() => new Animated.Value(selected ? 1 : 0));
|
|
@@ -280,7 +250,32 @@ function AndroidSegment({ option, selected, off, framed, height, size, keys, sel
|
|
|
280
250
|
selected && !framed ? { backgroundColor: withAlpha(m.primary, 0.12) } : null,
|
|
281
251
|
], children: [isRenderable(option.icon) ? (_jsx(IconDefaultsProvider, { size: 20, color: color, children: option.icon })) : null, isRenderable(option.children) ? (
|
|
282
252
|
// An Animated text, so its color can blend: the face, size and tracking of the kit's Text
|
|
283
|
-
_jsx(Animated.Text, { numberOfLines: 1, style: [textStyle(theme, { weight: "medium" }), { fontSize: 14, lineHeight: 20, letterSpacing: theme.tracking(14), color: label }], children: option.children })) : null] }));
|
|
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
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* A tab's count drawn after its label (`showBadges`): a capsule 18 tall, the digits 12 semibold in the screen's color.
|
|
257
|
+
* 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
|
+
*/
|
|
260
|
+
function SegmentCount({ badge, selected, off }) {
|
|
261
|
+
const theme = useTheme();
|
|
262
|
+
const text = badge != null ? badgeText(badge) : undefined;
|
|
263
|
+
if (!text)
|
|
264
|
+
return null;
|
|
265
|
+
// 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
|
+
// container in it (onSecondaryContainer on secondaryContainer), the others' onSurfaceVariant on the surface, so the
|
|
267
|
+
// small digits keep their contrast
|
|
268
|
+
const fill = off
|
|
269
|
+
? theme.color("--alpha-20")
|
|
270
|
+
: theme.isAndroid
|
|
271
|
+
? selected
|
|
272
|
+
? theme.material.onSecondaryContainer
|
|
273
|
+
: theme.material.onSurfaceVariant
|
|
274
|
+
: selected
|
|
275
|
+
? theme.colors.text
|
|
276
|
+
: theme.colors.labelSecondary;
|
|
277
|
+
const ink = theme.isAndroid ? (selected ? theme.material.secondaryContainer : theme.material.surface) : theme.colors.background;
|
|
278
|
+
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 }) }));
|
|
284
279
|
}
|
|
285
280
|
export const SegmentedControl = Object.assign(SegmentedControlRoot, { Tab: SegmentedControlTab, Option: SegmentedControlTab });
|
|
286
281
|
const styles = StyleSheet.create({
|
|
@@ -291,6 +286,9 @@ const styles = StyleSheet.create({
|
|
|
291
286
|
stretch: { alignSelf: "stretch" },
|
|
292
287
|
heldControl: { transform: [{ scale: 1.07 }] },
|
|
293
288
|
heldLabel: { opacity: 0.2 },
|
|
289
|
+
// 18 tall, taller with a larger text size: the capsule grows round its digits
|
|
290
|
+
count: { minWidth: 18, minHeight: 18, paddingHorizontal: 5, borderRadius: 999, alignItems: "center", justifyContent: "center" },
|
|
291
|
+
countText: { fontSize: 12, lineHeight: 16, fontVariant: ["tabular-nums"] },
|
|
294
292
|
thumb: { position: "absolute", borderCurve: "continuous" },
|
|
295
293
|
option: { alignItems: "center", justifyContent: "center", minWidth: 0 },
|
|
296
294
|
label: { flexDirection: "row", alignItems: "center", justifyContent: "center", gap: 8 },
|