@plexui/react-native 0.1.1 → 0.2.1
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/README.md +34 -0
- package/dist/es/components/ActionSheet/ActionSheet.js +67 -19
- package/dist/es/components/Alert/Alert.js +163 -0
- package/dist/es/components/Avatar/Avatar.js +20 -8
- package/dist/es/components/BottomActions/BottomActions.js +34 -0
- package/dist/es/components/BottomSheet/BottomSheet.js +85 -17
- package/dist/es/components/Button/Button.js +108 -28
- package/dist/es/components/Card/Card.js +16 -8
- package/dist/es/components/Checkbox/Checkbox.js +67 -99
- package/dist/es/components/Chip/Chip.js +39 -19
- package/dist/es/components/Dialog/Dialog.js +38 -24
- package/dist/es/components/Field/Field.js +91 -0
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +59 -0
- package/dist/es/components/Icon/createIcon.js +13 -2
- package/dist/es/components/Indicator/CircularProgress.js +80 -0
- package/dist/es/components/Indicator/LoadingDots.js +46 -0
- package/dist/es/components/Indicator/LoadingIndicator.js +101 -0
- package/dist/es/components/Indicator/index.js +3 -0
- package/dist/es/components/Input/Input.js +69 -60
- package/dist/es/components/InputGroup/InputGroup.js +130 -0
- package/dist/es/components/List/List.js +175 -59
- package/dist/es/components/Menu/Menu.js +69 -40
- package/dist/es/components/NavigationButton/NavigationButton.js +20 -4
- package/dist/es/components/OTPInput/OTPInput.js +9 -3
- package/dist/es/components/PageControl/PageControl.js +13 -7
- package/dist/es/components/Popover/Popover.js +128 -0
- package/dist/es/components/Progress/Progress.js +142 -0
- package/dist/es/components/ProgressSteps/ProgressSteps.js +207 -0
- package/dist/es/components/RollingNumber/RollingNumber.js +125 -0
- package/dist/es/components/Select/Select.js +97 -34
- package/dist/es/components/Separator/Separator.js +31 -0
- package/dist/es/components/ShimmerText/ShimmerText.js +98 -0
- package/dist/es/components/Stepper/Stepper.js +219 -0
- package/dist/es/components/Switch/Switch.js +26 -12
- package/dist/es/components/TagInput/TagInput.js +121 -0
- package/dist/es/components/Text/Text.js +7 -4
- package/dist/es/components/TextLink/TextLink.js +42 -0
- package/dist/es/components/Textarea/Textarea.js +12 -0
- package/dist/es/components/Tip/Tip.js +193 -0
- package/dist/es/components/Toolbar/Toolbar.js +6 -2
- package/dist/es/components/Tooltip/Tooltip.js +272 -0
- package/dist/es/index.js +20 -2
- package/dist/es/internal/FloatingPanel.js +111 -0
- package/dist/es/internal/fieldStack.js +73 -0
- package/dist/es/internal/floating.js +97 -0
- package/dist/es/internal/ripple.js +119 -0
- package/dist/es/internal/row.js +2 -1
- package/dist/es/internal/transition.js +113 -0
- package/dist/es/theme/ThemeProvider.js +41 -9
- package/dist/es/theme/material.js +37 -7
- package/dist/types/components/ActionSheet/ActionSheet.d.ts +15 -7
- package/dist/types/components/Alert/Alert.d.ts +51 -0
- package/dist/types/components/Avatar/Avatar.d.ts +4 -2
- package/dist/types/components/BottomActions/BottomActions.d.ts +18 -0
- package/dist/types/components/BottomSheet/BottomSheet.d.ts +4 -2
- package/dist/types/components/Button/Button.d.ts +20 -5
- package/dist/types/components/Card/Card.d.ts +14 -1
- package/dist/types/components/Checkbox/Checkbox.d.ts +4 -3
- package/dist/types/components/Chip/Chip.d.ts +23 -4
- package/dist/types/components/Dialog/Dialog.d.ts +9 -5
- package/dist/types/components/Field/Field.d.ts +64 -0
- package/dist/types/components/FloatingLabelInput/FloatingLabelInput.d.ts +42 -0
- package/dist/types/components/Indicator/CircularProgress.d.ts +34 -0
- package/dist/types/components/Indicator/LoadingDots.d.ts +17 -0
- package/dist/types/components/Indicator/LoadingIndicator.d.ts +46 -0
- package/dist/types/components/Indicator/index.d.ts +3 -0
- package/dist/types/components/Input/Input.d.ts +13 -3
- package/dist/types/components/InputGroup/InputGroup.d.ts +71 -0
- package/dist/types/components/List/List.d.ts +57 -14
- package/dist/types/components/Menu/Menu.d.ts +4 -0
- package/dist/types/components/NavigationButton/NavigationButton.d.ts +11 -3
- package/dist/types/components/OTPInput/OTPInput.d.ts +10 -1
- package/dist/types/components/PageControl/PageControl.d.ts +11 -1
- package/dist/types/components/Popover/Popover.d.ts +86 -0
- package/dist/types/components/Progress/Progress.d.ts +56 -0
- package/dist/types/components/ProgressSteps/ProgressSteps.d.ts +61 -0
- package/dist/types/components/RollingNumber/RollingNumber.d.ts +36 -0
- package/dist/types/components/Select/Select.d.ts +36 -8
- package/dist/types/components/Separator/Separator.d.ts +19 -0
- package/dist/types/components/ShimmerText/ShimmerText.d.ts +28 -0
- package/dist/types/components/Stepper/Stepper.d.ts +61 -0
- package/dist/types/components/Switch/Switch.d.ts +5 -5
- package/dist/types/components/TagInput/TagInput.d.ts +44 -0
- package/dist/types/components/TextLink/TextLink.d.ts +30 -0
- package/dist/types/components/Textarea/Textarea.d.ts +19 -0
- package/dist/types/components/Tip/Tip.d.ts +71 -0
- package/dist/types/components/Toolbar/Toolbar.d.ts +9 -1
- package/dist/types/components/Tooltip/Tooltip.d.ts +84 -0
- package/dist/types/index.d.ts +20 -2
- package/dist/types/internal/FloatingPanel.d.ts +70 -0
- package/dist/types/internal/fieldStack.d.ts +48 -0
- package/dist/types/internal/floating.d.ts +71 -0
- package/dist/types/internal/ripple.d.ts +17 -0
- package/dist/types/internal/row.d.ts +15 -3
- package/dist/types/internal/transition.d.ts +37 -0
- package/dist/types/theme/ThemeProvider.d.ts +28 -4
- package/dist/types/theme/material.d.ts +20 -6
- package/dist/types/theme/types.d.ts +8 -0
- package/package.json +2 -2
- package/src/components/ActionSheet/ActionSheet.tsx +123 -38
- package/src/components/Alert/Alert.tsx +279 -0
- package/src/components/Avatar/Avatar.tsx +21 -9
- package/src/components/BottomActions/BottomActions.tsx +54 -0
- package/src/components/BottomSheet/BottomSheet.tsx +111 -25
- package/src/components/Button/Button.tsx +170 -35
- package/src/components/Card/Card.tsx +33 -9
- package/src/components/Checkbox/Checkbox.tsx +89 -124
- package/src/components/Chip/Chip.tsx +83 -20
- package/src/components/Dialog/Dialog.tsx +68 -37
- package/src/components/Field/Field.tsx +227 -0
- package/src/components/FloatingLabelInput/FloatingLabelInput.tsx +144 -0
- package/src/components/Icon/createIcon.tsx +16 -6
- package/src/components/Indicator/CircularProgress.tsx +141 -0
- package/src/components/Indicator/LoadingDots.tsx +79 -0
- package/src/components/Indicator/LoadingIndicator.tsx +166 -0
- package/src/components/Indicator/index.ts +3 -0
- package/src/components/Input/Input.tsx +126 -97
- package/src/components/InputGroup/InputGroup.tsx +261 -0
- package/src/components/List/List.tsx +345 -88
- package/src/components/Menu/Menu.tsx +83 -41
- package/src/components/NavigationButton/NavigationButton.tsx +35 -5
- package/src/components/OTPInput/OTPInput.tsx +21 -2
- package/src/components/PageControl/PageControl.tsx +36 -8
- package/src/components/Popover/Popover.tsx +261 -0
- package/src/components/Progress/Progress.tsx +255 -0
- package/src/components/ProgressSteps/ProgressSteps.tsx +415 -0
- package/src/components/RollingNumber/RollingNumber.tsx +189 -0
- package/src/components/Select/Select.tsx +175 -71
- package/src/components/Separator/Separator.tsx +51 -0
- package/src/components/ShimmerText/ShimmerText.tsx +144 -0
- package/src/components/Stepper/Stepper.tsx +386 -0
- package/src/components/Switch/Switch.tsx +26 -12
- package/src/components/TagInput/TagInput.tsx +227 -0
- package/src/components/Text/Text.tsx +8 -4
- package/src/components/TextLink/TextLink.tsx +77 -0
- package/src/components/Textarea/Textarea.tsx +23 -0
- package/src/components/Tip/Tip.tsx +410 -0
- package/src/components/Toolbar/Toolbar.tsx +27 -2
- package/src/components/Tooltip/Tooltip.tsx +478 -0
- package/src/index.ts +36 -2
- package/src/internal/FloatingPanel.tsx +199 -0
- package/src/internal/fieldStack.tsx +179 -0
- package/src/internal/floating.ts +131 -0
- package/src/internal/ripple.tsx +132 -0
- package/src/internal/row.ts +16 -3
- package/src/internal/transition.ts +124 -0
- package/src/theme/ThemeProvider.tsx +65 -15
- package/src/theme/material.ts +39 -7
- package/src/theme/types.ts +8 -0
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { useContext, useEffect, useState, type ReactNode } from "react"
|
|
1
|
+
import { useContext, useEffect, useLayoutEffect, useState, type ReactNode } from "react"
|
|
2
2
|
import { Platform, Pressable, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
|
|
3
|
+
import Svg, { Path } from "react-native-svg"
|
|
3
4
|
import ChevronUpDown from "../../icons/plex/ChevronUpDown"
|
|
4
5
|
import { spaceToggles } from "../../internal/a11y"
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import { useRipple } from "../../internal/ripple"
|
|
7
|
+
import { RowEndContext, RowFrameContext, RowHoldContext, rowHold } from "../../internal/row"
|
|
8
|
+
import { androidSelector, withAlpha } from "../../theme/material"
|
|
7
9
|
import { MaterialArrowDropDown } from "../Icon/material"
|
|
8
10
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
9
11
|
import type { ControlSize } from "../Button/Button"
|
|
10
|
-
import {
|
|
12
|
+
import { ChoiceDialog } from "../Dialog/Dialog"
|
|
11
13
|
import { FieldOutline, fieldLook, type InputVariant } from "../Input/Input"
|
|
12
14
|
import { Menu, menuKeyDown, MenuSurface, useMenuAnchor } from "../Menu/Menu"
|
|
13
15
|
import { selectionColor } from "../Switch/Switch"
|
|
@@ -20,13 +22,27 @@ export type SelectOption<V extends string = string> = {
|
|
|
20
22
|
disabled?: boolean
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
|
|
25
|
+
type SingleSelectProps<T extends SelectOption> = {
|
|
26
|
+
/** Several options can be chosen. @default false */
|
|
27
|
+
multiple?: false
|
|
26
28
|
/** The value of the chosen option. */
|
|
27
29
|
value: T["value"] | null | undefined
|
|
28
30
|
/** Called with the option a person chooses, as on the web. */
|
|
29
31
|
onChange: (option: T) => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type MultipleSelectProps<T extends SelectOption> = {
|
|
35
|
+
/** Several options can be chosen. @default false */
|
|
36
|
+
multiple: true
|
|
37
|
+
/** The values of the chosen options. */
|
|
38
|
+
value: readonly T["value"][]
|
|
39
|
+
/** Called with the options chosen, in the options' order, as on the web. */
|
|
40
|
+
onChange: (options: T[]) => void
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type SelectProps<T extends SelectOption> = (SingleSelectProps<T> | MultipleSelectProps<T>) & {
|
|
44
|
+
/** The options, as @plexui/ui's `options`. */
|
|
45
|
+
options: readonly T[]
|
|
30
46
|
/** @default "Select…" */
|
|
31
47
|
placeholder?: string
|
|
32
48
|
disabled?: boolean
|
|
@@ -38,54 +54,96 @@ export type SelectProps<T extends SelectOption> = {
|
|
|
38
54
|
/** Fill the width. @default true on a phone */
|
|
39
55
|
block?: boolean
|
|
40
56
|
"aria-label"?: string
|
|
41
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Android: what a press opens. `dialog`, Android's choice dialog: the setting's name over a row for each option, and
|
|
59
|
+
* Cancel; with one choice a row has a radio and a press on it chooses it and closes the dialog, a `multiple` select's
|
|
60
|
+
* rows have a checkbox and OK applies the rows checked. `menu`, the popup of the options from the field (in a List
|
|
61
|
+
* row, the row's menu, as the web's), a check at the end of each chosen one. iOS always opens its menu.
|
|
62
|
+
* @default "dialog", or "menu" for a `multiple` select
|
|
63
|
+
*/
|
|
64
|
+
picker?: "dialog" | "menu"
|
|
65
|
+
/** Android: the title of the picker dialog (`picker="dialog"`), the setting's name. @default the `aria-label` */
|
|
42
66
|
title?: string
|
|
43
|
-
/** Android: the button that closes the picker dialog. @default "Cancel" */
|
|
67
|
+
/** Android: the button that closes the picker dialog (`picker="dialog"`) with no change. @default "Cancel" */
|
|
44
68
|
cancelLabel?: string
|
|
69
|
+
/** Android: the button of a `multiple` select's picker dialog (`picker="dialog"`) that applies the rows checked. @default "OK" */
|
|
70
|
+
okLabel?: string
|
|
71
|
+
/** The field's text when a `multiple` select has every option chosen. @default "All selected" */
|
|
72
|
+
allSelectedLabel?: string
|
|
45
73
|
testID?: string
|
|
46
74
|
style?: StyleProp<ViewStyle>
|
|
47
75
|
}
|
|
48
76
|
|
|
49
77
|
/**
|
|
50
|
-
* A choice of one option: the field of an Input with the chosen label and a chevron. iOS 26: UIKit's pop-up button
|
|
78
|
+
* A choice of one option (or several, `multiple`): the field of an Input with the chosen label and a chevron. iOS 26: UIKit's pop-up button
|
|
51
79
|
* field with `chevron.up.chevron.down`, opening the glass menu of the options with a checkmark at the chosen one; at
|
|
52
80
|
* the end of an iOS List row it is the row's pop-up, as the web's in a phone row: the value in the row's type (the
|
|
53
81
|
* secondary label, the placeholder in the tertiary), the menu picker's chevrons after it, and the menu opening over it
|
|
54
82
|
* at its end. Android: the field with Material's dropdown arrow (at a List row's end, the row's value in the accent,
|
|
55
83
|
* as an Android value row), opening Android's single-choice dialog: the setting's name over 50dp rows with a radio,
|
|
56
|
-
* and Cancel. Choosing a row closes it.
|
|
84
|
+
* and Cancel. Choosing a row closes it. With `picker="menu"` Android opens the popup of the options instead: under the
|
|
85
|
+
* field, or from a List row the row's menu (the screen dimmed around the lit row), its chosen row checked at the end.
|
|
86
|
+
* A `multiple` select opens the menu, where each press checks or unchecks an option and the menu stays open; on
|
|
87
|
+
* Android `picker="dialog"` opens the dialog of checkbox rows instead, whose OK applies them.
|
|
57
88
|
*/
|
|
58
|
-
export function Select<T extends SelectOption>({
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
89
|
+
export function Select<T extends SelectOption>(props: SelectProps<T>) {
|
|
90
|
+
const {
|
|
91
|
+
options,
|
|
92
|
+
multiple = false,
|
|
93
|
+
placeholder = "Select…",
|
|
94
|
+
disabled = false,
|
|
95
|
+
invalid = false,
|
|
96
|
+
variant = "outline",
|
|
97
|
+
size = "md",
|
|
98
|
+
pill = false,
|
|
99
|
+
block = true,
|
|
100
|
+
"aria-label": ariaLabel,
|
|
101
|
+
picker = multiple ? "menu" : "dialog",
|
|
102
|
+
title,
|
|
103
|
+
cancelLabel = "Cancel",
|
|
104
|
+
okLabel = "OK",
|
|
105
|
+
allSelectedLabel = "All selected",
|
|
106
|
+
testID,
|
|
107
|
+
style,
|
|
108
|
+
} = props
|
|
75
109
|
const theme = useTheme()
|
|
76
110
|
const [open, setOpen] = useState(false)
|
|
77
111
|
// A field disabled while its menu is open closes the menu: nothing can be chosen from it any more
|
|
78
112
|
if (disabled && open) setOpen(false)
|
|
79
113
|
const shown = open && !disabled
|
|
80
114
|
const android = theme.isAndroid
|
|
81
|
-
// Android's dialog stands in the middle of the screen: only iOS's menu follows the field
|
|
82
|
-
const
|
|
115
|
+
// Android's dialog stands in the middle of the screen: only a menu (iOS's, Android's `picker="menu"`) follows the field
|
|
116
|
+
const dialog = android && picker !== "menu"
|
|
117
|
+
const { anchor, row: menuRow, place, setTrigger, setRowFrame } = useMenuAnchor(shown && !dialog)
|
|
118
|
+
const values: readonly string[] = props.multiple ? props.value : props.value != null ? [props.value] : []
|
|
119
|
+
const chosenOptions = options.filter((option) => values.includes(option.value))
|
|
120
|
+
// A multiple select's dialog keeps its checked rows here from its opening until OK applies them
|
|
121
|
+
const [checked, setChecked] = useState<readonly string[]>([])
|
|
122
|
+
const [wasShown, setWasShown] = useState(shown)
|
|
123
|
+
if (wasShown !== shown) {
|
|
124
|
+
setWasShown(shown)
|
|
125
|
+
if (shown) setChecked(values)
|
|
126
|
+
}
|
|
127
|
+
const apply = (next: readonly string[]) => {
|
|
128
|
+
if (props.multiple) props.onChange(options.filter((option) => next.includes(option.value)))
|
|
129
|
+
}
|
|
83
130
|
const choose = (option: T) => {
|
|
84
131
|
if (disabled || option.disabled) return
|
|
85
|
-
|
|
132
|
+
// A multiple select's option checks or unchecks itself
|
|
133
|
+
if (props.multiple) apply(values.includes(option.value) ? values.filter((item) => item !== option.value) : [...values, option.value])
|
|
134
|
+
else props.onChange(option)
|
|
86
135
|
}
|
|
87
|
-
|
|
88
|
-
const
|
|
136
|
+
// The field's text, the web's: the chosen label; for several, the one label, "3 selected", or every one chosen
|
|
137
|
+
const shownLabel = !multiple
|
|
138
|
+
? chosenOptions[0]?.label
|
|
139
|
+
: chosenOptions.length && chosenOptions.length >= options.length
|
|
140
|
+
? allSelectedLabel
|
|
141
|
+
: chosenOptions.length === 0
|
|
142
|
+
? undefined
|
|
143
|
+
: chosenOptions.length === 1
|
|
144
|
+
? chosenOptions[0].label
|
|
145
|
+
: `${chosenOptions.length} selected`
|
|
146
|
+
const look = fieldLook(theme, { variant, size, pill }, { focused: open, filled: shownLabel != null, disabled, invalid })
|
|
89
147
|
const row = useContext(RowEndContext)
|
|
90
148
|
const hold = useContext(RowHoldContext)
|
|
91
149
|
const rowEnd = row != null
|
|
@@ -93,53 +151,63 @@ export function Select<T extends SelectOption>({
|
|
|
93
151
|
// At the end of an Android row the select is the row's value, as in an Android value row, and a press anywhere
|
|
94
152
|
// on the row opens its choice
|
|
95
153
|
const androidRow = rowEnd && android
|
|
154
|
+
// Alone in a row whose label is hidden (a label-hidden `Field row`): the value from the row's text start and the
|
|
155
|
+
// chevrons at its end, on the row's line
|
|
156
|
+
const stacked = row?.stacked === true && block
|
|
96
157
|
const handRow = androidRow && !disabled ? row?.press : undefined
|
|
97
158
|
useEffect(() => {
|
|
98
159
|
if (!handRow) return
|
|
99
|
-
handRow(() => setOpen(true))
|
|
160
|
+
handRow(dialog ? () => setOpen(true) : () => place(() => setOpen(true)))
|
|
100
161
|
return () => handRow(null)
|
|
101
|
-
}, [handRow])
|
|
162
|
+
}, [handRow, dialog, place])
|
|
163
|
+
// Android's menu from a List row is the row's: it dims the screen around the row and stands under it
|
|
164
|
+
const frame = useContext(RowFrameContext)
|
|
165
|
+
const rowMenu = !dialog && androidRow ? frame : null
|
|
166
|
+
useLayoutEffect(() => {
|
|
167
|
+
setRowFrame(rowMenu)
|
|
168
|
+
return () => setRowFrame(null)
|
|
169
|
+
}, [rowMenu, setRowFrame])
|
|
102
170
|
const tertiary = theme.colors.labelTertiary
|
|
103
171
|
const m = theme.material
|
|
104
172
|
return (
|
|
105
173
|
// A field that moves while its menu is open takes the menu with it
|
|
106
|
-
<View ref={setTrigger as never} collapsable={false} onLayout={shown && !
|
|
174
|
+
<View ref={setTrigger as never} collapsable={false} onLayout={shown && !dialog ? () => place() : undefined} style={[block ? styles.block : styles.hug, style]}>
|
|
107
175
|
<Pressable
|
|
108
176
|
accessibilityRole="button"
|
|
109
|
-
accessibilityLabel={ariaLabel ? `${ariaLabel}, ${
|
|
177
|
+
accessibilityLabel={ariaLabel ? `${ariaLabel}, ${shownLabel ?? placeholder}` : undefined}
|
|
110
178
|
accessibilityState={{ disabled, expanded: open }}
|
|
111
|
-
aria-haspopup={
|
|
179
|
+
aria-haspopup={dialog ? "dialog" : "menu"}
|
|
112
180
|
aria-expanded={open}
|
|
113
181
|
disabled={disabled}
|
|
114
182
|
{...rowHold(hold)}
|
|
115
|
-
onPress={() => (
|
|
183
|
+
onPress={() => (dialog ? setOpen(true) : place(() => setOpen(true)))}
|
|
116
184
|
// A row's value takes the presses of the row's height (where the row does not hand it its own)
|
|
117
185
|
hitSlop={androidRow && !row?.press ? ROW_SLOP : undefined}
|
|
118
186
|
testID={testID}
|
|
119
187
|
// The arrow sits in Compose's trailing icon slot, 12 from the edge
|
|
120
|
-
style={[styles.box, inRow ? styles.row : androidRow ? null : [look.box, { gap: look.gap }], android && !androidRow ? { paddingEnd: 12 } : null]}
|
|
188
|
+
style={[styles.box, inRow ? styles.row : androidRow ? null : [look.box, { gap: look.gap }], android && !androidRow ? { paddingEnd: 12 } : null, stacked ? styles.stacked : null]}
|
|
121
189
|
>
|
|
122
190
|
{android && !androidRow ? <FieldOutline frame={look.frame} /> : null}
|
|
123
191
|
{androidRow ? (
|
|
124
192
|
// A value row's value: 16sp in the accent, the placeholder in the hint's gray, faded to half when disabled
|
|
125
193
|
<Text
|
|
126
194
|
numberOfLines={1}
|
|
127
|
-
color={withAlpha(
|
|
128
|
-
style={[styles.shrink, styles.androidValue]}
|
|
195
|
+
color={withAlpha(shownLabel != null ? m.primary : withAlpha(m.onSurface, 0.35), disabled ? 0.5 : 1)}
|
|
196
|
+
style={[stacked ? styles.grow : styles.shrink, styles.androidValue, stacked ? styles.startText : null]}
|
|
129
197
|
>
|
|
130
|
-
{
|
|
198
|
+
{shownLabel ?? placeholder}
|
|
131
199
|
</Text>
|
|
132
200
|
) : inRow ? (
|
|
133
201
|
<Text
|
|
134
202
|
numberOfLines={1}
|
|
135
|
-
color={
|
|
136
|
-
style={[styles.shrink, { fontSize: theme.length("--field-row-label-font-size", 17), lineHeight: theme.length("--field-row-label-line-height", 22) }]}
|
|
203
|
+
color={shownLabel != null && !disabled ? theme.colors.labelSecondary : tertiary}
|
|
204
|
+
style={[stacked ? styles.grow : styles.shrink, { fontSize: theme.length("--field-row-label-font-size", 17), lineHeight: theme.length("--field-row-label-line-height", 22) }]}
|
|
137
205
|
>
|
|
138
|
-
{
|
|
206
|
+
{shownLabel ?? placeholder}
|
|
139
207
|
</Text>
|
|
140
208
|
) : (
|
|
141
|
-
<Text numberOfLines={1} color={
|
|
142
|
-
{
|
|
209
|
+
<Text numberOfLines={1} color={shownLabel != null ? look.text.color : look.placeholder} style={[styles.grow, { fontSize: look.text.fontSize, lineHeight: look.text.lineHeight }]}>
|
|
210
|
+
{shownLabel ?? placeholder}
|
|
143
211
|
</Text>
|
|
144
212
|
)}
|
|
145
213
|
{inRow ? (
|
|
@@ -156,17 +224,20 @@ export function Select<T extends SelectOption>({
|
|
|
156
224
|
<ChevronUpDown size={17} color={theme.color("--mobile-label-secondary")} />
|
|
157
225
|
)}
|
|
158
226
|
</Pressable>
|
|
159
|
-
{
|
|
227
|
+
{dialog ? (
|
|
160
228
|
<ChoiceDialog
|
|
161
229
|
open={shown}
|
|
162
230
|
onClose={() => setOpen(false)}
|
|
163
231
|
title={title ?? ariaLabel}
|
|
164
232
|
cancelLabel={cancelLabel}
|
|
165
|
-
|
|
233
|
+
okLabel={multiple ? okLabel : undefined}
|
|
234
|
+
onOk={multiple ? () => apply(checked) : undefined}
|
|
235
|
+
// The web reads the rows as a menu of radio items (the roles of the iOS menu), of checkbox items for several;
|
|
236
|
+
// TalkBack as radio buttons or checkboxes
|
|
166
237
|
listProps={
|
|
167
238
|
Platform.OS === "web"
|
|
168
239
|
? { role: "menu", "aria-label": title ?? ariaLabel, onKeyDown: (event: unknown) => menuKeyDown(event) }
|
|
169
|
-
: { accessibilityRole: "radiogroup", accessibilityLabel: title ?? ariaLabel }
|
|
240
|
+
: { accessibilityRole: multiple ? undefined : "radiogroup", accessibilityLabel: title ?? ariaLabel }
|
|
170
241
|
}
|
|
171
242
|
testID={testID ? `${testID}-menu` : undefined}
|
|
172
243
|
>
|
|
@@ -174,10 +245,16 @@ export function Select<T extends SelectOption>({
|
|
|
174
245
|
<ChoiceRow
|
|
175
246
|
key={option.value}
|
|
176
247
|
option={option}
|
|
177
|
-
|
|
248
|
+
check={multiple}
|
|
249
|
+
chosen={multiple ? checked.includes(option.value) : values.includes(option.value)}
|
|
178
250
|
disabled={disabled || !!option.disabled}
|
|
179
251
|
onChoose={() => {
|
|
180
252
|
if (disabled || option.disabled || !shown) return
|
|
253
|
+
// A checkbox row checks or unchecks itself until OK; a radio row chooses and closes
|
|
254
|
+
if (multiple) {
|
|
255
|
+
setChecked((current) => (current.includes(option.value) ? current.filter((item) => item !== option.value) : [...current, option.value]))
|
|
256
|
+
return
|
|
257
|
+
}
|
|
181
258
|
choose(option)
|
|
182
259
|
setOpen(false)
|
|
183
260
|
}}
|
|
@@ -191,16 +268,19 @@ export function Select<T extends SelectOption>({
|
|
|
191
268
|
anchor={anchor}
|
|
192
269
|
onClose={() => setOpen(false)}
|
|
193
270
|
check
|
|
271
|
+
multiple={multiple}
|
|
194
272
|
cover={inRow}
|
|
195
273
|
align={inRow ? "end" : "start"}
|
|
196
|
-
|
|
274
|
+
// Android's: a row's menu fits its items; a field's list is the field's width (Compose's exposed dropdown)
|
|
275
|
+
row={android ? menuRow : undefined}
|
|
276
|
+
width={android ? (androidRow ? undefined : anchor?.width) : Math.max(theme.length("--menu-default-width", 250), anchor?.width ?? 0)}
|
|
197
277
|
aria-label={ariaLabel}
|
|
198
278
|
testID={testID ? `${testID}-menu` : undefined}
|
|
199
279
|
>
|
|
200
280
|
{options.map((option) => (
|
|
201
281
|
<Menu.Item
|
|
202
282
|
key={option.value}
|
|
203
|
-
checked={option.value
|
|
283
|
+
checked={values.includes(option.value)}
|
|
204
284
|
disabled={disabled || option.disabled}
|
|
205
285
|
description={option.description}
|
|
206
286
|
onSelect={() => choose(option)}
|
|
@@ -215,34 +295,54 @@ export function Select<T extends SelectOption>({
|
|
|
215
295
|
)
|
|
216
296
|
}
|
|
217
297
|
|
|
218
|
-
type ChoiceRowProps = { option: SelectOption; chosen: boolean; disabled: boolean; onChoose: () => void; testID?: string }
|
|
298
|
+
type ChoiceRowProps = { option: SelectOption; check: boolean; chosen: boolean; disabled: boolean; onChoose: () => void; testID?: string }
|
|
219
299
|
|
|
220
300
|
/**
|
|
221
|
-
* A row of Android's
|
|
222
|
-
*
|
|
223
|
-
*
|
|
301
|
+
* A row of Android's choice dialog (4 in from the dialog's sides): 50dp, a 20dp radio in a 22dp frame 22 in and 14
|
|
302
|
+
* down, the label 16sp at 55 (a description 14sp gray under it); its press the list selector's ripple from the touch
|
|
303
|
+
* point (the platform's on a device, drawn on the web). The radio: a 2dp ring in the light gray (the web's #afafaf,
|
|
304
|
+
* #5d5d5d at night), the selection color with a 10dp dot when chosen. A multiple choice's row has an 18dp square with
|
|
305
|
+
* 4dp corners in the same frame (24 in, as the web's; the reference's checkbox cell has it 1 further in and its label
|
|
306
|
+
* 1 nearer): empty, a 1.5 outline in the mid gray (#767676); checked, the selection color with a white check 2 wide.
|
|
224
307
|
*/
|
|
225
|
-
function ChoiceRow({ option, chosen, disabled, onChoose, testID }: ChoiceRowProps) {
|
|
308
|
+
function ChoiceRow({ option, check, chosen, disabled, onChoose, testID }: ChoiceRowProps) {
|
|
226
309
|
const theme = useTheme()
|
|
227
310
|
const m = theme.material
|
|
228
311
|
const on = selectionColor(theme)
|
|
229
|
-
const
|
|
312
|
+
const dark = theme.scheme === "dark"
|
|
313
|
+
const off = check ? theme.color(dark ? "--gray-550" : "--gray-450") : theme.color(dark ? "--gray-500" : "--gray-300")
|
|
314
|
+
const nativeRipple = Platform.OS === "android"
|
|
315
|
+
const ripple = useRipple(androidSelector(theme.scheme), !nativeRipple, theme.reducedMotion)
|
|
230
316
|
const semantics =
|
|
231
317
|
Platform.OS === "web"
|
|
232
|
-
? { role: "menuitemradio" as "menuitem", "aria-checked": chosen, accessibilityState: { checked: chosen, disabled }, ...spaceToggles(onChoose) }
|
|
233
|
-
: { accessibilityRole: "radio" as const, accessibilityState: { checked: chosen, disabled } }
|
|
318
|
+
? { role: (check ? "menuitemcheckbox" : "menuitemradio") as "menuitem", "aria-checked": chosen, accessibilityState: { checked: chosen, disabled }, ...spaceToggles(onChoose) }
|
|
319
|
+
: { accessibilityRole: check ? ("checkbox" as const) : ("radio" as const), accessibilityState: { checked: chosen, disabled } }
|
|
234
320
|
return (
|
|
235
321
|
<Pressable
|
|
236
322
|
{...semantics}
|
|
237
323
|
disabled={disabled}
|
|
238
324
|
onPress={onChoose}
|
|
325
|
+
onPressIn={nativeRipple ? undefined : ripple.start}
|
|
326
|
+
onPressOut={nativeRipple ? undefined : ripple.end}
|
|
327
|
+
android_ripple={nativeRipple ? { color: androidSelector(theme.scheme), foreground: true } : undefined}
|
|
239
328
|
testID={testID}
|
|
240
|
-
style={
|
|
329
|
+
style={[styles.choice, { opacity: disabled ? 0.5 : 1 }]}
|
|
241
330
|
>
|
|
331
|
+
{ripple.layer}
|
|
242
332
|
<View style={styles.choiceRadio}>
|
|
243
|
-
|
|
333
|
+
{check ? (
|
|
334
|
+
<View style={[styles.square, chosen ? { backgroundColor: on } : { borderWidth: 1.5, borderColor: off }]}>
|
|
335
|
+
{chosen ? (
|
|
336
|
+
<Svg width={18} height={18} viewBox="0 0 18 18">
|
|
337
|
+
<Path d="M4 10l3 3 7-7" fill="none" stroke={theme.color(`--color-text-${theme.selectionColor}-solid`, "#FFFFFF")} strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" />
|
|
338
|
+
</Svg>
|
|
339
|
+
) : null}
|
|
340
|
+
</View>
|
|
341
|
+
) : (
|
|
342
|
+
<View style={[styles.ring, { borderColor: chosen ? on : off }]}>{chosen ? <View style={[styles.dot, { backgroundColor: on }]} /> : null}</View>
|
|
343
|
+
)}
|
|
244
344
|
</View>
|
|
245
|
-
<View style={styles.choiceText}>
|
|
345
|
+
<View style={[styles.choiceText, option.description != null ? styles.choiceDescribed : null]}>
|
|
246
346
|
<Text color={m.onSurface} numberOfLines={1} style={styles.choiceLabel}>
|
|
247
347
|
{option.label}
|
|
248
348
|
</Text>
|
|
@@ -256,9 +356,6 @@ function ChoiceRow({ option, chosen, disabled, onChoose, testID }: ChoiceRowProp
|
|
|
256
356
|
)
|
|
257
357
|
}
|
|
258
358
|
|
|
259
|
-
/** Android's list selector: black at 6% over a light card, white at 5% at night. */
|
|
260
|
-
const listPress = (scheme: "light" | "dark") => (scheme === "dark" ? "rgba(255, 255, 255, 0.05)" : "rgba(0, 0, 0, 0.06)")
|
|
261
|
-
|
|
262
359
|
/** A row's value reaches the 50dp row: 15 over and under its 20 line. */
|
|
263
360
|
const ROW_SLOP = { top: 15, bottom: 15, left: 8, right: 8 }
|
|
264
361
|
|
|
@@ -271,6 +368,8 @@ const styles = StyleSheet.create({
|
|
|
271
368
|
shrink: { flexShrink: 1, minWidth: 0 },
|
|
272
369
|
// A row's pop-up: no field, 34 tall, the value 8 before its chevrons
|
|
273
370
|
row: { minHeight: 34, gap: 8 },
|
|
371
|
+
stacked: { minHeight: 0 },
|
|
372
|
+
startText: { textAlign: "left" },
|
|
274
373
|
rowChevrons: { width: 8.5, height: 22, marginStart: -2, marginEnd: 2, alignItems: "center", justifyContent: "center", overflow: "visible" },
|
|
275
374
|
androidValue: { fontSize: 16, lineHeight: 20, textAlign: "right" },
|
|
276
375
|
// A radio row in the dialog: 4 of padding and the row's 18 before the radio's frame, 21 and 4 after the text
|
|
@@ -278,8 +377,13 @@ const styles = StyleSheet.create({
|
|
|
278
377
|
choiceRadio: { width: 22, height: 22, marginTop: 14, alignItems: "center", justifyContent: "center" },
|
|
279
378
|
ring: { width: 20, height: 20, borderRadius: 10, borderWidth: 2, alignItems: "center", justifyContent: "center" },
|
|
280
379
|
dot: { width: 10, height: 10, borderRadius: 5 },
|
|
281
|
-
|
|
282
|
-
|
|
380
|
+
square: { width: 18, height: 18, borderRadius: 4, overflow: "hidden" },
|
|
381
|
+
// The label at 55: 11 past the radio's frame, 15 under the row's top (its baseline 31 into the row, the reference's
|
|
382
|
+
// 30.5), as the web's; one line keeps the row 50
|
|
383
|
+
choiceText: { flex: 1, minWidth: 0, marginStart: 11, paddingTop: 15, paddingBottom: 15, gap: 4 },
|
|
384
|
+
// A description: its first baseline 52.3 into the row, lines 16.4 apart (14sp Roboto's), 15 under its last line and
|
|
385
|
+
// the font's 2 of padding (a two-line description makes the row 89, as the web's)
|
|
386
|
+
choiceDescribed: { paddingBottom: 17 },
|
|
283
387
|
choiceLabel: { fontSize: 16, lineHeight: 20 },
|
|
284
|
-
choiceDescription: { fontSize: 14, lineHeight:
|
|
388
|
+
choiceDescription: { fontSize: 14, lineHeight: 16.4 },
|
|
285
389
|
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Platform, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
|
|
2
|
+
import { divider } from "../../theme/material"
|
|
3
|
+
import { useTheme } from "../../theme/ThemeProvider"
|
|
4
|
+
|
|
5
|
+
export type SeparatorProps = {
|
|
6
|
+
/** A line across (between rows) or standing up (between inline items, as tall as its row). @default "horizontal" */
|
|
7
|
+
orientation?: "horizontal" | "vertical"
|
|
8
|
+
/**
|
|
9
|
+
* Hidden from screen readers, as a line that only draws. `false` makes it a `separator` element, for a line that
|
|
10
|
+
* marks a real grouping. @default true
|
|
11
|
+
*/
|
|
12
|
+
decorative?: boolean
|
|
13
|
+
testID?: string
|
|
14
|
+
style?: StyleProp<ViewStyle>
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A thin line that divides content, as @plexui/ui's Separator: `--separator-color` (`--color-border`) at
|
|
19
|
+
* `--separator-thickness` (1) on iOS, as the web draws it on a phone. On Android the line between the rows of a card
|
|
20
|
+
* in the Plex Android look: one device pixel of the divider gray (a light gray over a light card, the darkest gray at
|
|
21
|
+
* night). A vertical one stretches to the height of its row, at least a line of text.
|
|
22
|
+
*/
|
|
23
|
+
export function Separator({ orientation = "horizontal", decorative = true, testID, style }: SeparatorProps) {
|
|
24
|
+
const theme = useTheme()
|
|
25
|
+
const color = theme.isAndroid ? divider(theme) : theme.color("--separator-color", theme.colors.border)
|
|
26
|
+
// One device pixel on Android (a hairline); the token's 1 elsewhere, the web's phone line
|
|
27
|
+
const thickness = theme.isAndroid ? StyleSheet.hairlineWidth : theme.length("--separator-thickness", 1)
|
|
28
|
+
const vertical = orientation === "vertical"
|
|
29
|
+
const a11y = decorative
|
|
30
|
+
? { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants" as const, "aria-hidden": true }
|
|
31
|
+
: { role: "separator" as const, ...(Platform.OS === "web" ? { "aria-orientation": orientation } : null) }
|
|
32
|
+
return (
|
|
33
|
+
<View
|
|
34
|
+
{...a11y}
|
|
35
|
+
testID={testID}
|
|
36
|
+
style={[
|
|
37
|
+
styles.line,
|
|
38
|
+
{ backgroundColor: color },
|
|
39
|
+
vertical ? { width: thickness, alignSelf: "stretch", minHeight: MIN_VERTICAL } : { height: thickness, alignSelf: "stretch" },
|
|
40
|
+
style,
|
|
41
|
+
]}
|
|
42
|
+
/>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A vertical line is at least a line of the body text tall (the web's `min-height: 1em`). */
|
|
47
|
+
const MIN_VERTICAL = 16
|
|
48
|
+
|
|
49
|
+
const styles = StyleSheet.create({
|
|
50
|
+
line: { flexShrink: 0 },
|
|
51
|
+
})
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState, type ReactNode } from "react"
|
|
2
|
+
import { Animated, Easing, Platform, StyleSheet, View, type LayoutChangeEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
3
|
+
import { cssEase, nativeDriver } from "../../internal/transition"
|
|
4
|
+
import { useTheme } from "../../theme/ThemeProvider"
|
|
5
|
+
import type { Theme } from "../../theme/types"
|
|
6
|
+
import { Text, type TextProps } from "../Text/Text"
|
|
7
|
+
|
|
8
|
+
type Element = "p" | "span" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "div"
|
|
9
|
+
|
|
10
|
+
export type ShimmerTextProps = Omit<TextProps, "children" | "style"> & {
|
|
11
|
+
/** The element it stands for: `h1` to `h6` are read as a heading of that level. @default "div" */
|
|
12
|
+
as?: Element
|
|
13
|
+
children: ReactNode
|
|
14
|
+
/** The style of the text. */
|
|
15
|
+
style?: TextProps["style"]
|
|
16
|
+
/** The style of the box around the text. */
|
|
17
|
+
containerStyle?: StyleProp<ViewStyle>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type ShimmerableTextProps = ShimmerTextProps & {
|
|
21
|
+
/** Whether the shimmer animation is active. Turned off, it finishes its sweep and stops. @default false */
|
|
22
|
+
shimmer?: boolean
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The band is drawn in slices, each a copy of the text at its share of the highlight, as the web's gradient is. */
|
|
26
|
+
const SLICES = 16
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The sweep. iOS, as the web's: a band half the text's width, the text color to the highlight and back, goes from
|
|
30
|
+
* just before the text to past it in 70% of 3s (ease) and rests for the rest; the first after 0.6s. Android, the Plex
|
|
31
|
+
* Android look's flicker: a 160dp band crosses the text and twice its width in 1200ms, linear, and rests 240ms.
|
|
32
|
+
*/
|
|
33
|
+
function sweepOf(theme: Theme, width: number) {
|
|
34
|
+
if (theme.isAndroid) {
|
|
35
|
+
const band = 160
|
|
36
|
+
return { band, from: -band, to: width + band, period: 1440, pass: 1200, delay: 0, easing: Easing.linear }
|
|
37
|
+
}
|
|
38
|
+
const band = width / 2
|
|
39
|
+
return { band, from: -band, to: 1.25 * width, period: 3000, pass: 2100, delay: 600, easing: cssEase }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Text with a shimmer for loading and in-progress states, as @plexui/ui's ShimmerText: a light band sweeps across it,
|
|
44
|
+
* over and over. It takes the props of `Text` for its type and color. With reduced motion it is plain text.
|
|
45
|
+
*/
|
|
46
|
+
export function ShimmerText(props: ShimmerTextProps) {
|
|
47
|
+
return <ShimmerableText {...props} shimmer />
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Text whose shimmer turns on and off, as @plexui/ui's ShimmerableText: with `shimmer` on it sweeps as ShimmerText;
|
|
52
|
+
* turned off, it finishes the current sweep and then stops, with no abrupt cut.
|
|
53
|
+
*/
|
|
54
|
+
export function ShimmerableText({ as = "div", shimmer = false, children, style, containerStyle, ...text }: ShimmerableTextProps) {
|
|
55
|
+
const theme = useTheme()
|
|
56
|
+
const [width, setWidth] = useState(0)
|
|
57
|
+
const [height, setHeight] = useState(0)
|
|
58
|
+
const [running, setRunning] = useState(shimmer && !theme.reducedMotion)
|
|
59
|
+
const wanted = useRef(shimmer)
|
|
60
|
+
useLayoutEffect(() => {
|
|
61
|
+
wanted.current = shimmer
|
|
62
|
+
})
|
|
63
|
+
const [clock] = useState(() => new Animated.Value(0))
|
|
64
|
+
const sweep = sweepOf(theme, width)
|
|
65
|
+
|
|
66
|
+
// On: run at once. Off: the running sweep ends its turn, then stops (with reduced motion at once)
|
|
67
|
+
if (shimmer && !running && !theme.reducedMotion) setRunning(true)
|
|
68
|
+
if (running && theme.reducedMotion) setRunning(false)
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (!running || width <= 0) return
|
|
72
|
+
let animation: Animated.CompositeAnimation | null = null
|
|
73
|
+
let cancelled = false
|
|
74
|
+
const turn = () => {
|
|
75
|
+
clock.setValue(0)
|
|
76
|
+
animation = Animated.timing(clock, { toValue: sweep.period, duration: sweep.period, easing: Easing.linear, useNativeDriver: nativeDriver, isInteraction: false })
|
|
77
|
+
animation.start(({ finished }) => {
|
|
78
|
+
if (!finished || cancelled) return
|
|
79
|
+
if (wanted.current) turn()
|
|
80
|
+
else setRunning(false)
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
clock.setValue(0)
|
|
84
|
+
const timer = setTimeout(turn, sweep.delay)
|
|
85
|
+
return () => {
|
|
86
|
+
cancelled = true
|
|
87
|
+
clearTimeout(timer)
|
|
88
|
+
animation?.stop()
|
|
89
|
+
}
|
|
90
|
+
}, [running, width, sweep.period, sweep.delay, clock])
|
|
91
|
+
|
|
92
|
+
const onLayout = (event: LayoutChangeEvent) => {
|
|
93
|
+
const { width: w, height: h } = event.nativeEvent.layout
|
|
94
|
+
setWidth((old) => (old === w ? old : w))
|
|
95
|
+
setHeight((old) => (old === h ? old : h))
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const level = /^h([1-6])$/.exec(as)?.[1]
|
|
99
|
+
const heading = level ? { accessibilityRole: "header" as const, ...(Platform.OS === "web" ? { "aria-level": Number(level) } : null) } : null
|
|
100
|
+
const highlight = theme.value("light-dark(var(--gray-200), var(--gray-900))")
|
|
101
|
+
const highlightColor = typeof highlight === "string" ? highlight : theme.color(theme.scheme === "dark" ? "--gray-900" : "--gray-200")
|
|
102
|
+
const slice = sweep.band / SLICES
|
|
103
|
+
const x = clock.interpolate({ inputRange: [0, sweep.pass, sweep.period], outputRange: [sweep.from, sweep.to, sweep.to], easing: sweep.easing })
|
|
104
|
+
// react-native-web reports the layout in whole pixels: a copy that narrow would wrap a line 193.1 wide, so it takes one more
|
|
105
|
+
const copyWidth = Platform.OS === "web" ? width + 1 : width
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<View onLayout={onLayout} style={containerStyle}>
|
|
109
|
+
<Text {...heading} {...text} style={style}>
|
|
110
|
+
{children}
|
|
111
|
+
</Text>
|
|
112
|
+
{running && width > 0 ? (
|
|
113
|
+
<Animated.View
|
|
114
|
+
pointerEvents="none"
|
|
115
|
+
accessibilityElementsHidden
|
|
116
|
+
importantForAccessibility="no-hide-descendants"
|
|
117
|
+
aria-hidden
|
|
118
|
+
style={[styles.band, { width: sweep.band, height, transform: [{ translateX: x }] }]}
|
|
119
|
+
>
|
|
120
|
+
{Array.from({ length: SLICES }, (_, index) => {
|
|
121
|
+
// The gradient's share of the highlight at the slice's middle: none at the edges, all of it at the center
|
|
122
|
+
const share = 1 - Math.abs((2 * (index + 0.5)) / SLICES - 1)
|
|
123
|
+
return (
|
|
124
|
+
<View key={index} style={[styles.slice, { left: index * slice, width: slice + 0.5, height, opacity: share }]}>
|
|
125
|
+
<Animated.View style={[styles.copy, { left: -index * slice, width: copyWidth, transform: [{ translateX: Animated.multiply(x, -1) }] }]}>
|
|
126
|
+
<Text {...text} numberOfLines={text.numberOfLines} style={[style, { color: highlightColor }]}>
|
|
127
|
+
{children}
|
|
128
|
+
</Text>
|
|
129
|
+
</Animated.View>
|
|
130
|
+
</View>
|
|
131
|
+
)
|
|
132
|
+
})}
|
|
133
|
+
</Animated.View>
|
|
134
|
+
) : null}
|
|
135
|
+
</View>
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const styles = StyleSheet.create({
|
|
140
|
+
// The band and its slices are physical (left), as the web's background position: it sweeps left to right in either direction
|
|
141
|
+
band: { position: "absolute", top: 0, left: 0 },
|
|
142
|
+
slice: { position: "absolute", top: 0, overflow: "hidden" },
|
|
143
|
+
copy: { position: "absolute", top: 0 },
|
|
144
|
+
})
|