@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
|
@@ -10,10 +10,13 @@ import { lastInputKeyboard, spaceToggles } from "../../internal/a11y"
|
|
|
10
10
|
import { textOf } from "../../internal/children"
|
|
11
11
|
import { isRTL, mirrored } from "../../internal/direction"
|
|
12
12
|
import { curves } from "../../internal/motion"
|
|
13
|
+
import { useRipple } from "../../internal/ripple"
|
|
13
14
|
import { RowFrameContext, type RowFrame } from "../../internal/row"
|
|
14
15
|
import { Glass } from "../../internal/Glass"
|
|
15
16
|
import { ACCELERATE_DECELERATE, canTransformGlass, glassOpacity, Overlay, overlayTiming } from "../../internal/Overlay"
|
|
16
|
-
import {
|
|
17
|
+
import { androidGray, androidSelector, barSurface, withAlpha, dangerText } from "../../theme/material"
|
|
18
|
+
import { useAndroidGlass } from "../../internal/BarBackdrop"
|
|
19
|
+
import { BarItemContext } from "../Button/Button"
|
|
17
20
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
18
21
|
import type { Theme } from "../../theme/types"
|
|
19
22
|
import { IconDefaultsProvider } from "../Icon/createIcon"
|
|
@@ -35,6 +38,9 @@ type MenuContextValue = {
|
|
|
35
38
|
anchor: MenuAnchor | null
|
|
36
39
|
/** The List row the trigger stands in. */
|
|
37
40
|
row: MenuRow | null
|
|
41
|
+
/** The trigger stands in a bar (Android's header menu: the bar's glass). */
|
|
42
|
+
header: boolean
|
|
43
|
+
setHeader: (header: boolean) => void
|
|
38
44
|
setTrigger: (node: Measurable | null) => void
|
|
39
45
|
setRowFrame: (frame: RowFrame | null) => void
|
|
40
46
|
/** Measures the trigger again, as it moves while the menu is open. */
|
|
@@ -43,7 +49,7 @@ type MenuContextValue = {
|
|
|
43
49
|
const MenuContext = createContext<MenuContextValue | null>(null)
|
|
44
50
|
|
|
45
51
|
/** Closes the menu once an item is chosen; also used by Select. */
|
|
46
|
-
const SurfaceContext = createContext<{ close: () => void; check: boolean; openSub?: (sub: OpenSub) => void; subOpen?: boolean }>({ close: () => {}, check: false })
|
|
52
|
+
const SurfaceContext = createContext<{ close: () => void; check: boolean; multiple?: boolean; openSub?: (sub: OpenSub) => void; subOpen?: boolean; header?: boolean }>({ close: () => {}, check: false })
|
|
47
53
|
|
|
48
54
|
export type MenuProps = {
|
|
49
55
|
children: ReactNode
|
|
@@ -120,6 +126,7 @@ function MenuRoot({ children, open: openProp, onOpenChange }: MenuProps) {
|
|
|
120
126
|
const open = openProp ?? own
|
|
121
127
|
// A menu opened from outside (the controlled `open`) is placed at its trigger too
|
|
122
128
|
const { anchor, row, place, setTrigger, setRowFrame } = useMenuAnchor(open)
|
|
129
|
+
const [header, setHeader] = useState(false)
|
|
123
130
|
// Listens for the input from the start, so a menu opened from the keyboard knows it (the web)
|
|
124
131
|
useEffect(() => {
|
|
125
132
|
lastInputKeyboard()
|
|
@@ -132,7 +139,7 @@ function MenuRoot({ children, open: openProp, onOpenChange }: MenuProps) {
|
|
|
132
139
|
if (next) place(apply)
|
|
133
140
|
else apply()
|
|
134
141
|
}
|
|
135
|
-
return <MenuContext.Provider value={{ open, setOpen, anchor, row, setTrigger, setRowFrame, place: () => place() }}>{children}</MenuContext.Provider>
|
|
142
|
+
return <MenuContext.Provider value={{ open, setOpen, anchor, row, header, setHeader, setTrigger, setRowFrame, place: () => place() }}>{children}</MenuContext.Provider>
|
|
136
143
|
}
|
|
137
144
|
MenuRoot.displayName = "Menu"
|
|
138
145
|
|
|
@@ -144,13 +151,18 @@ function useMenu(part: string) {
|
|
|
144
151
|
|
|
145
152
|
/** The element that opens the menu: a Button or anything with `onPress`. */
|
|
146
153
|
function MenuTrigger({ children, style }: { children: ReactElement<{ onPress?: (event: GestureResponderEvent) => void }>; style?: StyleProp<ViewStyle> }) {
|
|
147
|
-
const { open, setOpen, setTrigger, setRowFrame, place } = useMenu("Menu.Trigger")
|
|
148
|
-
// A trigger in a List row tells the menu its row
|
|
154
|
+
const { open, setOpen, setTrigger, setRowFrame, setHeader, place } = useMenu("Menu.Trigger")
|
|
155
|
+
// A trigger in a List row tells the menu its row; one in a bar that it is the bar's (Android's header menu)
|
|
149
156
|
const frame = useContext(RowFrameContext)
|
|
157
|
+
const inBar = useContext(BarItemContext) != null
|
|
150
158
|
useLayoutEffect(() => {
|
|
151
159
|
setRowFrame(frame)
|
|
152
160
|
return () => setRowFrame(null)
|
|
153
161
|
}, [frame, setRowFrame])
|
|
162
|
+
useLayoutEffect(() => {
|
|
163
|
+
setHeader(inBar)
|
|
164
|
+
return () => setHeader(false)
|
|
165
|
+
}, [inBar, setHeader])
|
|
154
166
|
const onPress = isValidElement(children) ? children.props.onPress : undefined
|
|
155
167
|
const child = isValidElement(children)
|
|
156
168
|
? cloneElement(children, {
|
|
@@ -184,7 +196,7 @@ export type MenuContentProps = {
|
|
|
184
196
|
function MenuContent(props: MenuContentProps) {
|
|
185
197
|
const menu = useMenu("Menu.Content")
|
|
186
198
|
// A menu whose items say `checked` (true or false) is a set of options: it keeps the checkmark's column, as Select's
|
|
187
|
-
return <MenuSurface {...props} check={hasCheckedItems(props.children)} open={menu.open} anchor={menu.anchor} row={menu.row} onClose={() => menu.setOpen(false)} />
|
|
199
|
+
return <MenuSurface {...props} check={hasCheckedItems(props.children)} open={menu.open} anchor={menu.anchor} row={menu.row} header={menu.header} onClose={() => menu.setOpen(false)} />
|
|
188
200
|
}
|
|
189
201
|
|
|
190
202
|
function hasCheckedItems(children: ReactNode): boolean {
|
|
@@ -199,10 +211,14 @@ type SurfaceProps = MenuContentProps & {
|
|
|
199
211
|
anchor: MenuAnchor | null
|
|
200
212
|
onClose: () => void
|
|
201
213
|
check?: boolean
|
|
214
|
+
/** Select's `multiple`: a press checks or unchecks an option and the menu stays open. */
|
|
215
|
+
multiple?: boolean
|
|
202
216
|
/** The menu opens over its trigger, as Android's popup and the web's phone menu (a dropdown field's list opens under it). @default true */
|
|
203
217
|
cover?: boolean
|
|
204
218
|
/** The List row the menu opens from: on Android the screen dims around it and the popup stands under it. */
|
|
205
219
|
row?: MenuRow | null
|
|
220
|
+
/** Opened from a bar's button: on Android the header menu, in the bar's glass. */
|
|
221
|
+
header?: boolean
|
|
206
222
|
}
|
|
207
223
|
|
|
208
224
|
/** The floating panel of a menu, placed under its anchor (over it when the screen ends first). */
|
|
@@ -212,7 +228,7 @@ export function MenuSurface(props: SurfaceProps) {
|
|
|
212
228
|
}
|
|
213
229
|
|
|
214
230
|
/** iOS 26's pop-up menu: glass, a submenu over the menu at its row while the menu steps back. */
|
|
215
|
-
function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check = false, cover, children, "aria-label": ariaLabel, testID }: SurfaceProps) {
|
|
231
|
+
function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check = false, multiple = false, cover, children, "aria-label": ariaLabel, testID }: SurfaceProps) {
|
|
216
232
|
const theme = useTheme()
|
|
217
233
|
const insets = useSafeAreaInsets()
|
|
218
234
|
const window = useWindowDimensions()
|
|
@@ -279,7 +295,7 @@ function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check =
|
|
|
279
295
|
moveTo(step, 1, true)
|
|
280
296
|
}
|
|
281
297
|
const collapse = () => moveTo(step, 0, false, () => setSub(null))
|
|
282
|
-
const surface = { close: onClose, check, openSub, subOpen: sub != null }
|
|
298
|
+
const surface = { close: onClose, check, multiple, openSub, subOpen: sub != null }
|
|
283
299
|
const content = <SurfaceContext.Provider value={surface}>{children}</SurfaceContext.Provider>
|
|
284
300
|
const subItems = sub != null ? <SurfaceContext.Provider value={{ close: onClose, check: hasCheckedItems(sub.items) }}>{sub.items}</SurfaceContext.Provider> : null
|
|
285
301
|
const scale = !theme.reducedMotion && canTransformGlass
|
|
@@ -547,7 +563,7 @@ function AndroidPage({ children, width, minWidth, maxWidth, maxHeight, onSize, s
|
|
|
547
563
|
* width back, shrinks to 0.95 under a dim of up to 25% black, and the popup's size turns into the submenu's; Back, a
|
|
548
564
|
* drag towards the end or a flick takes it back.
|
|
549
565
|
*/
|
|
550
|
-
function AndroidMenuSurface({ open, anchor, row, onClose, align = "start", width, check = false, cover, children, "aria-label": ariaLabel, testID }: SurfaceProps) {
|
|
566
|
+
function AndroidMenuSurface({ open, anchor, row, header = false, onClose, align = "start", width, check = false, multiple = false, cover, children, "aria-label": ariaLabel, testID }: SurfaceProps) {
|
|
551
567
|
const theme = useTheme()
|
|
552
568
|
const insets = useSafeAreaInsets()
|
|
553
569
|
const window = useWindowDimensions()
|
|
@@ -724,11 +740,11 @@ function AndroidMenuSurface({ open, anchor, row, onClose, align = "start", width
|
|
|
724
740
|
},
|
|
725
741
|
})
|
|
726
742
|
})
|
|
727
|
-
const surface = { close: onClose, check, openSub, subOpen: sub != null }
|
|
743
|
+
const surface = { close: onClose, check, multiple, openSub, subOpen: sub != null, header }
|
|
728
744
|
// The submenu's page: Back, the 8dp band, the items
|
|
729
745
|
const subItems =
|
|
730
746
|
sub != null ? (
|
|
731
|
-
<SurfaceContext.Provider value={{ close: onClose, check: hasCheckedItems(sub.items) }}>
|
|
747
|
+
<SurfaceContext.Provider value={{ close: onClose, check: hasCheckedItems(sub.items), header }}>
|
|
732
748
|
<MenuRow icon={<ArrowLeftLg />} stay={collapse}>
|
|
733
749
|
{sub.backLabel}
|
|
734
750
|
</MenuRow>
|
|
@@ -770,7 +786,16 @@ function AndroidMenuSurface({ open, anchor, row, onClose, align = "start", width
|
|
|
770
786
|
const hidden = sub != null && !web ? { importantForAccessibility: "no-hide-descendants" as const, accessibilityElementsHidden: true } : null
|
|
771
787
|
// The submenu stands at the popup's start edge
|
|
772
788
|
const startEdge = rtl && !swapped ? { right: 0 } : { left: 0 }
|
|
773
|
-
|
|
789
|
+
// A row's menu (and any other) is the popup's card: white, a raised gray at night (the web's --android-card); a
|
|
790
|
+
// header menu the bar's glass, blurred 36 under it on the web
|
|
791
|
+
const glass = useAndroidGlass("bar")
|
|
792
|
+
const card = theme.scheme === "dark" ? theme.color("--gray-300", barSurface(m, theme.scheme)) : barSurface(m, theme.scheme)
|
|
793
|
+
const background = header ? (glass.backgroundColor as string) : card
|
|
794
|
+
const fillLook: ViewStyle = header
|
|
795
|
+
? ({ ...glass, borderRadius: 22, ...(web ? { backdropFilter: "blur(36px)", WebkitBackdropFilter: "blur(36px)" } : null) } as ViewStyle)
|
|
796
|
+
: { backgroundColor: card, borderRadius: 12, boxShadow: theme.scheme === "dark" ? "0 3px 8px rgba(0, 0, 0, 0.4)" : "0 3px 8px rgba(0, 0, 0, 0.14), 0 0 1px rgba(0, 0, 0, 0.12)" }
|
|
797
|
+
// The screen behind it dims: black at 40% (20% at night) around a row's menu and any other, 10% behind a header menu
|
|
798
|
+
const dimAlpha = header ? 0.1 : theme.scheme === "dark" ? 0.2 : 0.4
|
|
774
799
|
// From a List row: the popup's fade (and the dim's) over the first 150ms of its 200, and its growth from 0.95
|
|
775
800
|
const popFade = clock.interpolate({ inputRange: [0, ROW_POP.fade / ROW_POP.scale], outputRange: [0, 1], easing: ACCELERATE_DECELERATE, extrapolate: "clamp" })
|
|
776
801
|
const popScale = clock.interpolate({ inputRange: [0, 1], outputRange: [0.95, 1], easing: ROW_POP.easing })
|
|
@@ -784,7 +809,11 @@ function AndroidMenuSurface({ open, anchor, row, onClose, align = "start", width
|
|
|
784
809
|
const opacity = reduced || !opening ? progress : popping ? popFade : 1
|
|
785
810
|
return (
|
|
786
811
|
<>
|
|
787
|
-
{row ?
|
|
812
|
+
{row ? (
|
|
813
|
+
<RowDim row={row} fade={popIn ? popFade : progress} alpha={dimAlpha} width={window.width} height={window.height} />
|
|
814
|
+
) : (
|
|
815
|
+
<Animated.View pointerEvents="none" style={[StyleSheet.absoluteFill, { backgroundColor: `rgba(0, 0, 0, ${dimAlpha})`, opacity: progress }]} />
|
|
816
|
+
)}
|
|
788
817
|
<Animated.View
|
|
789
818
|
ref={panel as never}
|
|
790
819
|
// The panel takes the focus of a menu opened by a pointer (the web), with no ring of its own
|
|
@@ -804,8 +833,8 @@ function AndroidMenuSurface({ open, anchor, row, onClose, align = "start", width
|
|
|
804
833
|
]}
|
|
805
834
|
>
|
|
806
835
|
{/* The panel's fill and shadow, which fade in as it unrolls; the rows fade in on their own */}
|
|
807
|
-
<Animated.View pointerEvents="none" style={[styles.androidFill, {
|
|
808
|
-
<Animated.View pointerEvents={moving ? "none" : "auto"} style={[styles.android, { width: panelWidth, height: panelHeight }]}>
|
|
836
|
+
<Animated.View pointerEvents="none" style={[styles.androidFill, fillLook, { opacity: unrolling ? reveal([0, 1]) : 1 }]} />
|
|
837
|
+
<Animated.View pointerEvents={moving ? "none" : "auto"} style={[styles.android, header ? styles.androidHeaderPanel : null, { width: panelWidth, height: panelHeight }]}>
|
|
809
838
|
<Animated.View
|
|
810
839
|
ref={mainPage as never}
|
|
811
840
|
{...hidden}
|
|
@@ -825,7 +854,7 @@ function AndroidMenuSurface({ open, anchor, row, onClose, align = "start", width
|
|
|
825
854
|
]}
|
|
826
855
|
>
|
|
827
856
|
<CascadeContext.Provider value={cascade}>
|
|
828
|
-
<AndroidPage width={morphing ? size.width : width} minWidth={minWidth} maxWidth={maxWidth} maxHeight={maxHeight} onSize={(measured) => setSize(sameSize(measured))}>
|
|
857
|
+
<AndroidPage width={morphing ? size.width : width} minWidth={minWidth} maxWidth={maxWidth} maxHeight={maxHeight} onSize={(measured) => setSize(sameSize(measured))} style={header ? styles.androidHeaderPage : undefined}>
|
|
829
858
|
<SurfaceContext.Provider value={surface}>{children}</SurfaceContext.Provider>
|
|
830
859
|
</AndroidPage>
|
|
831
860
|
</CascadeContext.Provider>
|
|
@@ -840,7 +869,7 @@ function AndroidMenuSurface({ open, anchor, row, onClose, align = "start", width
|
|
|
840
869
|
pointerEvents="box-none"
|
|
841
870
|
style={[styles.androidSubPage, startEdge, { width: maxWidth, transform: [{ translateX: swipe.interpolate({ inputRange: [0, 1], outputRange: [span || window.width, 0] }) }] }]}
|
|
842
871
|
>
|
|
843
|
-
<AndroidPage width={width} minWidth={minWidth} maxWidth={maxWidth} maxHeight={maxHeight} onSize={onSubSize} style={{ backgroundColor: background }}>
|
|
872
|
+
<AndroidPage width={width} minWidth={minWidth} maxWidth={maxWidth} maxHeight={maxHeight} onSize={onSubSize} style={[{ backgroundColor: background }, header ? styles.androidHeaderPage : null]}>
|
|
844
873
|
{subItems}
|
|
845
874
|
</AndroidPage>
|
|
846
875
|
</Animated.View>
|
|
@@ -887,7 +916,7 @@ type DomItem = { getAttribute: (name: string) => string | null; focus: (options?
|
|
|
887
916
|
|
|
888
917
|
/** The enabled items of a menu's panel on the web, in their order. */
|
|
889
918
|
function menuItems(node: unknown): DomItem[] {
|
|
890
|
-
const found = (node as { querySelectorAll?: (selector: string) => ArrayLike<DomItem> } | null)?.querySelectorAll?.('[role="menuitem"], [role="menuitemradio"]')
|
|
919
|
+
const found = (node as { querySelectorAll?: (selector: string) => ArrayLike<DomItem> } | null)?.querySelectorAll?.('[role="menuitem"], [role="menuitemradio"], [role="menuitemcheckbox"]')
|
|
891
920
|
return found ? Array.from(found).filter((item) => item.getAttribute("aria-disabled") !== "true") : []
|
|
892
921
|
}
|
|
893
922
|
|
|
@@ -977,32 +1006,39 @@ function MenuRow({ children, icon, description, danger = false, disabled = false
|
|
|
977
1006
|
const surface = useContext(SurfaceContext)
|
|
978
1007
|
const own = useRef<unknown>(null)
|
|
979
1008
|
const node = rowRef ?? own
|
|
1009
|
+
// An item that says `checked` in a menu of options is a radio item (a checkbox item when several can be chosen): the
|
|
1010
|
+
// web names it so, and a phone reads its state
|
|
1011
|
+
const option = surface.check && checked !== undefined && !stay
|
|
980
1012
|
const select = () => {
|
|
981
1013
|
if (disabled) return
|
|
982
1014
|
if (stay) return stay()
|
|
983
1015
|
onSelect?.()
|
|
984
|
-
|
|
1016
|
+
// An option of a multiple choice checks or unchecks itself and the menu stays open
|
|
1017
|
+
if (!(surface.multiple && option)) surface.close()
|
|
985
1018
|
}
|
|
986
|
-
// An item that says `checked` in a menu of options is a radio item: the web names it so, and a phone reads its state
|
|
987
|
-
const option = surface.check && checked !== undefined && !stay
|
|
988
1019
|
const semantics = {
|
|
989
|
-
...(Platform.OS === "web"
|
|
1020
|
+
...(Platform.OS === "web"
|
|
1021
|
+
? { role: (option ? (surface.multiple ? "menuitemcheckbox" : "menuitemradio") : "menuitem") as "menuitem", "aria-checked": option ? !!checked : undefined }
|
|
1022
|
+
: { accessibilityRole: "menuitem" as const }),
|
|
990
1023
|
accessibilityState: { disabled, checked: option ? !!checked : undefined, expanded: opens ? !!expanded : undefined },
|
|
991
1024
|
...(opens ? { "aria-haspopup": "menu" as const, "aria-expanded": !!expanded } : null),
|
|
992
1025
|
// React Native Web's Pressable takes Space only for a button
|
|
993
1026
|
...spaceToggles(select),
|
|
994
1027
|
}
|
|
995
1028
|
const rtl = isRTL()
|
|
1029
|
+
// Android's press: the item's ripple from the touch point in the dialog button selector, clipped to the item and the
|
|
1030
|
+
// popup's corners at the first and the last; the platform's on a device, drawn here on the web
|
|
1031
|
+
const nativeRipple = theme.isAndroid && Platform.OS === "android"
|
|
1032
|
+
const ripple = useRipple(androidSelector(theme.scheme), theme.isAndroid && !nativeRipple, theme.reducedMotion)
|
|
996
1033
|
if (theme.isAndroid) {
|
|
997
|
-
// Android's popup item: 48dp, 18 in, Regular 16 in the text color, a 24dp icon at 18 with the text
|
|
998
|
-
// 13 gray description; red for a destructive item. A chosen option shows the bare check at the
|
|
999
|
-
//
|
|
1000
|
-
//
|
|
1034
|
+
// Android's popup item: 48dp, 18 in, Regular 16 in the text color, a 24dp icon at 18 with the text 20 past it (62
|
|
1035
|
+
// in), a 13 gray description; red for a destructive item. A chosen option shows the bare check at the end, 18
|
|
1036
|
+
// after the text; a row that opens a submenu shows its arrow 8 after the text. Keyboard focus shows as the text
|
|
1037
|
+
// color at 12%
|
|
1001
1038
|
const m = theme.material
|
|
1002
1039
|
const chosen = surface.check && !!checked && !stay
|
|
1003
1040
|
const color = danger ? dangerText(theme) : m.onSurface
|
|
1004
|
-
const
|
|
1005
|
-
const trailCheck = surface.check && !!icon && !opens && !stay
|
|
1041
|
+
const trailCheck = surface.check && !opens && !stay
|
|
1006
1042
|
return (
|
|
1007
1043
|
<CascadeRow>
|
|
1008
1044
|
<Pressable
|
|
@@ -1010,16 +1046,19 @@ function MenuRow({ children, icon, description, danger = false, disabled = false
|
|
|
1010
1046
|
ref={node as never}
|
|
1011
1047
|
disabled={disabled}
|
|
1012
1048
|
onPress={select}
|
|
1049
|
+
onPressIn={nativeRipple ? undefined : ripple.start}
|
|
1050
|
+
onPressOut={nativeRipple ? undefined : ripple.end}
|
|
1051
|
+
android_ripple={nativeRipple ? { color: androidSelector(theme.scheme), foreground: true } : undefined}
|
|
1013
1052
|
testID={testID}
|
|
1014
|
-
// The web's keyboard focus shows as
|
|
1015
|
-
//
|
|
1053
|
+
// The web's keyboard focus shows as a layer (React Native Web passes `focused`), in place of the browser's
|
|
1054
|
+
// square ring, which the popup's round corners would cut
|
|
1016
1055
|
style={(state) => [
|
|
1017
1056
|
styles.androidItem,
|
|
1018
1057
|
{ opacity: disabled ? 0.5 : 1 },
|
|
1019
|
-
|
|
1058
|
+
(state as { focused?: boolean }).focused && focusVisible(node.current) ? { backgroundColor: withAlpha(color, 0.12) } : null,
|
|
1020
1059
|
]}
|
|
1021
1060
|
>
|
|
1022
|
-
{
|
|
1061
|
+
{ripple.layer}
|
|
1023
1062
|
{icon ? (
|
|
1024
1063
|
<View style={[styles.androidIcon, mirrored(rtl && stay != null && !opens)]}>
|
|
1025
1064
|
<IconDefaultsProvider size={24} color={color}>
|
|
@@ -1179,12 +1218,13 @@ MenuSubContent.displayName = "Menu.SubContent"
|
|
|
1179
1218
|
|
|
1180
1219
|
function MenuSeparator() {
|
|
1181
1220
|
const theme = useTheme()
|
|
1182
|
-
|
|
1183
|
-
//
|
|
1221
|
+
const surface = useContext(SurfaceContext)
|
|
1222
|
+
// Android parts a popup's groups with an 8dp band: a light gray (#F5F5F5, #262626 at night) in a row's menu, the text
|
|
1223
|
+
// at 6% in a header menu
|
|
1184
1224
|
if (theme.isAndroid)
|
|
1185
1225
|
return (
|
|
1186
1226
|
<CascadeRow>
|
|
1187
|
-
<View style={[styles.androidSeparator, { backgroundColor: theme.
|
|
1227
|
+
<View style={[styles.androidSeparator, { backgroundColor: androidGray(theme, surface.header ? "menuBand" : "popupGap") }]} />
|
|
1188
1228
|
</CascadeRow>
|
|
1189
1229
|
)
|
|
1190
1230
|
// The phone layer's separator: 1 tall in `--menu-separator-background-color`, `--menu-separator-gutter` around it
|
|
@@ -1261,18 +1301,20 @@ const styles = StyleSheet.create({
|
|
|
1261
1301
|
scroll: { flexGrow: 0 },
|
|
1262
1302
|
// Android's popup: 12dp corners, the items flush with its edges, a soft shadow
|
|
1263
1303
|
android: { borderRadius: 12, overflow: "hidden" },
|
|
1264
|
-
androidFill: { position: "absolute", top: 0, bottom: 0, start: 0, end: 0
|
|
1304
|
+
androidFill: { position: "absolute", top: 0, bottom: 0, start: 0, end: 0 },
|
|
1305
|
+
// A header menu: 22dp corners, 5 above and under its rows
|
|
1306
|
+
androidHeaderPanel: { borderRadius: 22 },
|
|
1307
|
+
androidHeaderPage: { paddingVertical: 5 },
|
|
1265
1308
|
// A page keeps its own size while the popup's changes around it
|
|
1266
1309
|
androidPageBox: { alignSelf: "flex-start", flexShrink: 0 },
|
|
1267
1310
|
androidPage: { flexShrink: 0, flexGrow: 0 },
|
|
1268
1311
|
androidSubPage: { position: "absolute", top: 0, alignItems: "flex-start" },
|
|
1269
1312
|
gone: { opacity: 0 },
|
|
1270
1313
|
androidItem: { minHeight: 48, flexDirection: "row", alignItems: "center", paddingHorizontal: 18, paddingVertical: 6, outlineWidth: 0, outlineStyle: "none" as "solid" },
|
|
1271
|
-
// The 24dp icon at 18, the text
|
|
1272
|
-
androidIcon: { width: 24, marginEnd:
|
|
1273
|
-
//
|
|
1274
|
-
|
|
1275
|
-
androidTrailCheck: { width: 26, marginStart: 8, alignItems: "center" },
|
|
1314
|
+
// The 24dp icon at 18, the text 20 after it (62 in)
|
|
1315
|
+
androidIcon: { width: 24, marginEnd: 20, alignItems: "center" },
|
|
1316
|
+
// A chosen option's check at the end: a 24dp column 18 after the text (the 26 glyph box centered on it)
|
|
1317
|
+
androidTrailCheck: { width: 24, marginStart: 18, alignItems: "center", justifyContent: "center" },
|
|
1276
1318
|
// The submenu arrow: 24dp at the end, the text 8 before it
|
|
1277
1319
|
androidArrow: { width: 24, marginStart: 8, alignItems: "center" },
|
|
1278
1320
|
androidSeparator: { height: 8 },
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { useContext, type ComponentRef } from "react"
|
|
2
|
-
import { View } from "react-native"
|
|
2
|
+
import { StyleSheet, View } from "react-native"
|
|
3
3
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
4
4
|
import CheckMd from "../../icons/plex/CheckMd"
|
|
5
5
|
import ChevronLeftMd from "../../icons/plex/ChevronLeftMd"
|
|
6
6
|
import { mirrored, useRTL } from "../../internal/direction"
|
|
7
|
-
import { BarItemContext, Button, type ButtonProps } from "../Button/Button"
|
|
7
|
+
import { BarItemContext, Button, type BarItemStyle, type ButtonProps } from "../Button/Button"
|
|
8
8
|
import { createIcon } from "../Icon/createIcon"
|
|
9
9
|
import { MaterialArrowBack, MaterialCheckSymbol, MaterialClose } from "../Icon/material"
|
|
10
|
+
import { Text } from "../Text/Text"
|
|
10
11
|
|
|
11
12
|
export type NavigationAction = "back" | "close" | "confirm"
|
|
12
13
|
|
|
@@ -15,6 +16,12 @@ export type NavigationButtonProps = Omit<ButtonProps, "children" | "uniform" | "
|
|
|
15
16
|
action: NavigationAction
|
|
16
17
|
/** @default "Back", "Close" or "Confirm" */
|
|
17
18
|
accessibilityLabel?: string
|
|
19
|
+
/**
|
|
20
|
+
* Android: the short word drawn on confirm's pill (Done, Save, Apply); the pill never draws the `accessibilityLabel`,
|
|
21
|
+
* which stays the button's name. iOS draws no text (confirm is a check circle), so it is unused there, as for back
|
|
22
|
+
* and close. @default "Done"
|
|
23
|
+
*/
|
|
24
|
+
label?: string
|
|
18
25
|
}
|
|
19
26
|
|
|
20
27
|
/** The close glyph of the kit (packages/ui NavigationGlyph), on a 20 grid. */
|
|
@@ -33,11 +40,13 @@ const LABELS: Record<NavigationAction, string> = { back: "Back", close: "Close",
|
|
|
33
40
|
/**
|
|
34
41
|
* Back, close and confirm: on iOS the 44pt circle of a bar, glass for back and close and the accent for confirm (in a
|
|
35
42
|
* Toolbar), with the kit's glyphs at their sizes (`--navigation-button-*`); on Android Material's glyphs (`arrow_back`,
|
|
36
|
-
* `close`, `check`) at 24dp: in a bar back and close take Android's 46dp glass circle
|
|
37
|
-
* outside a bar
|
|
43
|
+
* `close`, `check`) at 24dp: in a bar back and close take Android's 46dp glass circle, outside a bar they are plain icon
|
|
44
|
+
* buttons. Confirm on Android is the glass text pill of a top bar (outside a bar too): a short word, its `label` (Done
|
|
45
|
+
* by default), 15/20 Bold in the text color, 16 in from its ends and cut short past 160; in a bottom bar it keeps the
|
|
46
|
+
* accent circle.
|
|
38
47
|
* Back points the way the screen reads: right to left it turns over.
|
|
39
48
|
*/
|
|
40
|
-
export function NavigationButton({ action, color, variant, mobileMaterial, size = "lg", accessibilityLabel, ...rest }: NavigationButtonProps) {
|
|
49
|
+
export function NavigationButton({ action, color, variant, mobileMaterial, size = "lg", accessibilityLabel, label, ...rest }: NavigationButtonProps) {
|
|
41
50
|
const theme = useTheme()
|
|
42
51
|
const bar = useContext(BarItemContext)
|
|
43
52
|
const confirm = action === "confirm"
|
|
@@ -54,6 +63,20 @@ export function NavigationButton({ action, color, variant, mobileMaterial, size
|
|
|
54
63
|
? CheckMd
|
|
55
64
|
: ChevronLeftMd
|
|
56
65
|
const { ref, rtl } = useRTL<ComponentRef<typeof View>>()
|
|
66
|
+
if (theme.isAndroid && confirm && !bar?.bottom) {
|
|
67
|
+
// The pill draws a short word, never the name; with no name of its own the button is named by its word
|
|
68
|
+
const word = label ?? "Done"
|
|
69
|
+
const name = accessibilityLabel ?? word
|
|
70
|
+
// A neutral ghost Button in a bar stands on the bar's glass, its label dimmed to 38% when disabled
|
|
71
|
+
const pill = (
|
|
72
|
+
<Button {...rest} color={color ?? "primary"} variant={variant ?? "ghost"} mobileMaterial={mobileMaterial} size={size} accessibilityLabel={name}>
|
|
73
|
+
<Text weight="bold" numberOfLines={1} style={styles.androidConfirm}>
|
|
74
|
+
{word}
|
|
75
|
+
</Text>
|
|
76
|
+
</Button>
|
|
77
|
+
)
|
|
78
|
+
return bar ? pill : <BarItemContext.Provider value={ANDROID_BAR_ITEM}>{pill}</BarItemContext.Provider>
|
|
79
|
+
}
|
|
57
80
|
const button = (
|
|
58
81
|
<Button
|
|
59
82
|
{...rest}
|
|
@@ -80,3 +103,10 @@ export function NavigationButton({ action, color, variant, mobileMaterial, size
|
|
|
80
103
|
</BarItemContext.Provider>
|
|
81
104
|
)
|
|
82
105
|
}
|
|
106
|
+
|
|
107
|
+
/** An Android top bar's item, for a confirm outside a bar: the 46dp glass, 16 in from its ends. */
|
|
108
|
+
const ANDROID_BAR_ITEM: BarItemStyle = { height: 46, fontSize: 15, lineHeight: 20, weight: "medium", prominentWeight: "medium", iconSize: 24, gutter: 16 }
|
|
109
|
+
|
|
110
|
+
const styles = StyleSheet.create({
|
|
111
|
+
androidConfirm: { fontSize: 15, lineHeight: 20, maxWidth: 160 },
|
|
112
|
+
})
|
|
@@ -38,6 +38,15 @@ export type OTPInputProps = {
|
|
|
38
38
|
disabled?: boolean
|
|
39
39
|
/** Focuses the first cell on mount. @default false */
|
|
40
40
|
autoFocus?: boolean
|
|
41
|
+
/**
|
|
42
|
+
* Names the code ("Verification code"): the cells' group on the web, and the start of each cell's name on iOS and
|
|
43
|
+
* Android ("Verification code, digit 1 of 6"), where a group is not announced.
|
|
44
|
+
*/
|
|
45
|
+
"aria-label"?: string
|
|
46
|
+
/** The same name as `aria-label`. */
|
|
47
|
+
label?: string
|
|
48
|
+
/** The name of a cell, for another language. @default (index, length) => `Digit ${index + 1}`, with `of ${length}` once the code is named */
|
|
49
|
+
digitLabel?: (index: number, length: number) => string
|
|
41
50
|
/** Applied to the root; each cell's field gets `${testID}-digit-${n}`. */
|
|
42
51
|
testID?: string
|
|
43
52
|
style?: StyleProp<ViewStyle>
|
|
@@ -235,6 +244,9 @@ export function OTPInput({
|
|
|
235
244
|
errorMessage,
|
|
236
245
|
disabled = false,
|
|
237
246
|
autoFocus = false,
|
|
247
|
+
"aria-label": ariaLabel,
|
|
248
|
+
label,
|
|
249
|
+
digitLabel,
|
|
238
250
|
testID,
|
|
239
251
|
style,
|
|
240
252
|
}: OTPInputProps) {
|
|
@@ -388,8 +400,15 @@ export function OTPInput({
|
|
|
388
400
|
Animated.spring(shake, { toValue: 0, velocity: -1000, ...stiffSpring(600, 0.5), useNativeDriver: false }).start()
|
|
389
401
|
}, [failing, shake, theme.isAndroid, theme.reducedMotion])
|
|
390
402
|
|
|
403
|
+
const name = ariaLabel ?? label
|
|
404
|
+
const cellName = (index: number) => {
|
|
405
|
+
const own = digitLabel ? digitLabel(index, length) : name ? `${Platform.OS === "web" ? "Digit" : "digit"} ${index + 1} of ${length}` : `Digit ${index + 1}`
|
|
406
|
+
// The web names the group; a native screen reader hears the code's name on each cell instead
|
|
407
|
+
return name && Platform.OS !== "web" ? `${name}, ${own}` : own
|
|
408
|
+
}
|
|
409
|
+
|
|
391
410
|
return (
|
|
392
|
-
<View style={style} testID={testID}>
|
|
411
|
+
<View style={style} testID={testID} role={name ? "group" : undefined} aria-label={Platform.OS === "web" ? name : undefined}>
|
|
393
412
|
<Animated.View style={[styles.cells, { gap }, theme.isAndroid ? { transform: [{ translateX: shake }] } : null]}>
|
|
394
413
|
{Array.from({ length }, (_, index) => {
|
|
395
414
|
const isGroupGap = grouping ? shouldShowGap(index, grouping) : false
|
|
@@ -416,7 +435,7 @@ export function OTPInput({
|
|
|
416
435
|
autoComplete={index === 0 ? ONE_TIME_CODE : "off"}
|
|
417
436
|
autoCorrect={false}
|
|
418
437
|
spellCheck={false}
|
|
419
|
-
accessibilityLabel={
|
|
438
|
+
accessibilityLabel={cellName(index)}
|
|
420
439
|
aria-invalid={invalid || undefined}
|
|
421
440
|
aria-disabled={disabled || undefined}
|
|
422
441
|
selectionColor={look.caret}
|
|
@@ -26,6 +26,16 @@ export type PageControlProps = {
|
|
|
26
26
|
* turns off scrubbing there. @default "automatic"
|
|
27
27
|
*/
|
|
28
28
|
background?: "automatic" | "prominent" | "minimal"
|
|
29
|
+
/**
|
|
30
|
+
* How the current page shows: `dots`, iOS's and Android's own (the current dot solid); `pill`, the current page a
|
|
31
|
+
* short capsule (two and a half dots wide) among the dots, as many onboarding pagers draw it. @default "dots"
|
|
32
|
+
*/
|
|
33
|
+
indicator?: "dots" | "pill"
|
|
34
|
+
/**
|
|
35
|
+
* `default` draws the dots in the label colors; `onColor` in white for a page of color or a photo behind them (the
|
|
36
|
+
* current white, the rest white at 40%), the capsule a white veil. @default "default"
|
|
37
|
+
*/
|
|
38
|
+
tone?: "default" | "onColor"
|
|
29
39
|
/** @default (index, count) => `Page ${index + 1} of ${count}` */
|
|
30
40
|
valueText?: (index: number, count: number) => string
|
|
31
41
|
/** @default "Pages" */
|
|
@@ -80,7 +90,19 @@ type Press = { startX: number; startIndex: number; scrubbing: boolean; rtl: bool
|
|
|
80
90
|
* page and back as it moves), in a 48dp target, with no capsule at all. For a screen reader it is adjustable: swipe
|
|
81
91
|
* up or down for the next or previous page.
|
|
82
92
|
*/
|
|
83
|
-
export function PageControl({
|
|
93
|
+
export function PageControl({
|
|
94
|
+
count,
|
|
95
|
+
value: valueProp,
|
|
96
|
+
defaultValue = 0,
|
|
97
|
+
onChange,
|
|
98
|
+
background = "automatic",
|
|
99
|
+
indicator = "dots",
|
|
100
|
+
tone = "default",
|
|
101
|
+
valueText = defaultValueText,
|
|
102
|
+
"aria-label": ariaLabel = "Pages",
|
|
103
|
+
testID,
|
|
104
|
+
style,
|
|
105
|
+
}: PageControlProps) {
|
|
84
106
|
const theme = useTheme()
|
|
85
107
|
const [own, setOwn] = useState(defaultValue)
|
|
86
108
|
const current = clampIndex(valueProp ?? own, count)
|
|
@@ -102,17 +124,23 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
|
|
|
102
124
|
const sizes = android ? Array.from({ length: Math.max(0, count) }, (): PageControlDotSize => "full") : pageControlDots(count, current)
|
|
103
125
|
const dotSize = (size: PageControlDotSize) =>
|
|
104
126
|
size === "full" ? dot : android ? (size === "small" ? 4 : 3) : size === "small" ? theme.length("--page-control-dot-size-small", 6) : theme.length("--page-control-dot-size-smaller", 4)
|
|
127
|
+
const pill = indicator === "pill"
|
|
128
|
+
// A pill: the current page two and a half dots wide
|
|
129
|
+
const dotWidth = (size: PageControlDotSize, index: number) => (pill && index === current ? dot * 2.5 : dotSize(size))
|
|
105
130
|
// The center of the current dot, for a tap on either side of it
|
|
106
131
|
let x = padding
|
|
107
132
|
let currentCenter = padding
|
|
108
133
|
sizes.forEach((size, index) => {
|
|
109
134
|
if (size === "hidden") return
|
|
110
|
-
if (index === current) currentCenter = x +
|
|
111
|
-
x +=
|
|
135
|
+
if (index === current) currentCenter = x + dotWidth(size, index) / 2
|
|
136
|
+
x += dotWidth(size, index) + gap
|
|
112
137
|
})
|
|
113
|
-
const
|
|
138
|
+
const onColor = tone === "onColor"
|
|
139
|
+
const on = onColor ? "#FFFFFF" : android ? theme.material.primary : theme.color("--page-control-dot-color-current", theme.colors.text)
|
|
114
140
|
// Android's page dots: #BBBBBB, #555555 in a dark theme
|
|
115
|
-
const off = android ? (theme.scheme === "dark" ? "#555555" : "#BBBBBB") : theme.color("--page-control-dot-color", theme.colors.labelTertiary)
|
|
141
|
+
const off = onColor ? "rgba(255, 255, 255, 0.4)" : android ? (theme.scheme === "dark" ? "#555555" : "#BBBBBB") : theme.color("--page-control-dot-color", theme.colors.labelTertiary)
|
|
142
|
+
// Android's current dot is drawn over the gray ones (it stretches between pages); a pill is a dot of its own
|
|
143
|
+
const worm = android && !pill
|
|
116
144
|
// Android draws no capsule, not even for `prominent`
|
|
117
145
|
const capsuleHeight = theme.length("--page-control-height", 24)
|
|
118
146
|
const target = android ? 48 : theme.length("--page-control-target-size", 44)
|
|
@@ -177,15 +205,15 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
|
|
|
177
205
|
style={[
|
|
178
206
|
styles.capsule,
|
|
179
207
|
{ height: capsuleHeight, paddingHorizontal: padding, gap, borderRadius: capsuleHeight / 2 },
|
|
180
|
-
showBackground ? { backgroundColor: theme.color("--page-control-background") } : null,
|
|
208
|
+
showBackground ? { backgroundColor: onColor ? "rgba(255, 255, 255, 0.2)" : theme.color("--page-control-background") } : null,
|
|
181
209
|
]}
|
|
182
210
|
>
|
|
183
211
|
{sizes.map((size, index) =>
|
|
184
212
|
size === "hidden" ? null : (
|
|
185
|
-
<View key={index} style={{ width:
|
|
213
|
+
<View key={index} style={{ width: dotWidth(size, index), height: dotSize(size), borderRadius: dot / 2, backgroundColor: index === current && !worm ? on : off }} />
|
|
186
214
|
),
|
|
187
215
|
)}
|
|
188
|
-
{
|
|
216
|
+
{worm ? <AndroidCurrent start={currentCenter - dot / 2} color={on} reduced={theme.reducedMotion} /> : null}
|
|
189
217
|
</View>
|
|
190
218
|
</View>
|
|
191
219
|
)
|