@plexui/react-native 0.2.17 → 0.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
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, StyleSheet, View } from "react-native";
3
+ import { Animated, Easing, Platform, StyleSheet, View } from "react-native";
4
4
  import { Pressable } from "../../internal/Pressable";
5
+ import { CssSlide } from "../../internal/CssSlide";
5
6
  import { childrenOfType, isRenderable, textOf } from "../../internal/children";
6
7
  import { Glass } from "../../internal/Glass";
7
8
  import { curves } from "../../internal/motion";
@@ -118,7 +119,8 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
118
119
  const [width] = useState(() => new Animated.Value(0));
119
120
  const placed = useRef(false);
120
121
  useEffect(() => {
121
- if (selectedX == null || selectedWidth == null)
122
+ // The web's thumb slides in CSS
123
+ if (selectedX == null || selectedWidth == null || Platform.OS === "web")
122
124
  return;
123
125
  if (!placed.current || theme.reducedMotion) {
124
126
  x.setValue(selectedX);
@@ -146,7 +148,9 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
146
148
  };
147
149
  // UISegmentedControl keeps its type at a large text size; a label here grows until it fills its segment
148
150
  const maxScale = look.height / look.lineHeight;
149
- const content = (_jsxs(_Fragment, { children: [selected ? (_jsx(Animated.View, { pointerEvents: "none", style: [styles.thumb, { top: look.gutter, bottom: look.gutter, left: x, width, borderRadius: optionRadius, backgroundColor: look.thumb }] })) : null, options.map((option) => {
151
+ const content = (_jsxs(_Fragment, { children: [selected && Platform.OS === "web" ? (
152
+ // The web slides the thumb in CSS, off the JavaScript thread
153
+ _jsx(CssSlide, { x: selected.x, width: selected.width, side: "left", duration: look.duration, easing: "cubic-bezier(0.25, 0.1, 0.25, 1)", still: theme.reducedMotion, style: [styles.thumb, { top: look.gutter, bottom: look.gutter, borderRadius: optionRadius, backgroundColor: look.thumb }] })) : selected ? (_jsx(Animated.View, { pointerEvents: "none", style: [styles.thumb, { top: look.gutter, bottom: look.gutter, left: x, width, borderRadius: optionRadius, backgroundColor: look.thumb }] })) : null, options.map((option) => {
150
154
  const isSelected = option.value === value;
151
155
  const off = disabled || !!option.disabled;
152
156
  const color = off ? theme.color("--alpha-20") : theme.colors.text;
@@ -204,7 +208,7 @@ function AndroidControl({ options, value, select, keys, disabled, block, equal,
204
208
  const frameWidth = measured ? widths[options[index].value] : undefined;
205
209
  const frame = frameX != null;
206
210
  useEffect(() => {
207
- if (frameX == null || frameWidth == null)
211
+ if (frameX == null || frameWidth == null || Platform.OS === "web")
208
212
  return;
209
213
  if (!placed.current || theme.reducedMotion) {
210
214
  x.setValue(frameX);
@@ -219,7 +223,7 @@ function AndroidControl({ options, value, select, keys, disabled, block, equal,
219
223
  styles.androidRow,
220
224
  { height, borderRadius: height / 2, backgroundColor: barSurface(m, theme.scheme), boxShadow: barShadow(theme.scheme) },
221
225
  block ? styles.stretch : null,
222
- ], children: [frame ? (_jsx(Animated.View, { pointerEvents: "none", style: [styles.androidPill, { height: inner, borderRadius: inner / 2, backgroundColor: withAlpha(m.primary, 0.12), left: x, width }] })) : null, options.map((option) => (_jsx(AndroidSegment, { option: option, selected: option.value === value, off: disabled || !!option.disabled, framed: frame, showBadges: showBadges, badgeColor: badgeColor, height: inner,
226
+ ], children: [frame && Platform.OS === "web" ? (_jsx(CssSlide, { x: frameX, width: frameWidth, side: "left", duration: ANDROID_MOVE.duration, easing: "cubic-bezier(0.23, 1, 0.32, 1)", still: theme.reducedMotion, style: [styles.androidPill, { height: inner, borderRadius: inner / 2, backgroundColor: withAlpha(m.primary, 0.12) }] })) : frame ? (_jsx(Animated.View, { pointerEvents: "none", style: [styles.androidPill, { height: inner, borderRadius: inner / 2, backgroundColor: withAlpha(m.primary, 0.12), left: x, width }] })) : null, options.map((option) => (_jsx(AndroidSegment, { option: option, selected: option.value === value, off: disabled || !!option.disabled, framed: frame, showBadges: showBadges, badgeColor: badgeColor, height: inner,
223
227
  // In a filled row equal segments share the width and the others take their label and share what is left; a
224
228
  // control that hugs its segments gives equal ones the widest one's width
225
229
  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)))] }));
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
3
- import { Animated, Easing, StyleSheet, View } from "react-native";
3
+ import { Animated, Easing, Platform, StyleSheet, View } from "react-native";
4
4
  import { Pressable } from "../../internal/Pressable";
5
+ import { CssSlide } from "../../internal/CssSlide";
5
6
  import { useSafeAreaInsets } from "react-native-safe-area-context";
6
7
  import Search from "../../icons/plex/Search";
7
8
  import { BarBackdrop, SoftBottomEdge, TabBarFade, ANDROID_FADE_ALPHA, ANDROID_FADE_STOPS, glassBarBlur, useAndroidGlass } from "../../internal/BarBackdrop";
@@ -392,6 +393,9 @@ function TabBarRoot({ value: valueProp, defaultValue, onValueChange, search, pro
392
393
  pillShown.current = false;
393
394
  return;
394
395
  }
396
+ // The web's pill slides in CSS
397
+ if (Platform.OS === "web")
398
+ return;
395
399
  // It appears in place (the first frame, back from a minimized bar or the circle's tab), then slides: CSS `ease`
396
400
  // over 300ms, as SegmentedControl's thumb
397
401
  if (!pillShown.current || theme.reducedMotion) {
@@ -437,7 +441,10 @@ function TabBarRoot({ value: valueProp, defaultValue, onValueChange, search, pro
437
441
  { paddingTop: padTop + (accessory ? accessoryHeight + accessoryGap : 0), paddingBottom },
438
442
  physicalPadding(sideLeft, sideRight),
439
443
  style,
440
- ], children: [backdrop, accessory ? (_jsx(Glass, { radius: accessoryHeight / 2, elevation: "raised", style: [styles.accessory, accessoryPlace], children: accessory }, "accessory")) : null, _jsxs(View, { style: [styles.iosRow, { gap: theme.length("--tab-bar-gap", 8), justifyContent: circle || minimized ? "space-between" : "center" }], children: [_jsxs(Glass, { radius: 999, elevation: "raised", style: [styles.capsule, minimized ? { padding: capsulePadding } : { paddingVertical: capsulePadding, paddingHorizontal: theme.length("--tab-bar-capsule-padding-inline", 10) }], children: [pillFrame ? (_jsx(Animated.View, { pointerEvents: "none", style: [
444
+ ], children: [backdrop, accessory ? (_jsx(Glass, { radius: accessoryHeight / 2, elevation: "raised", style: [styles.accessory, accessoryPlace], children: accessory }, "accessory")) : null, _jsxs(View, { style: [styles.iosRow, { gap: theme.length("--tab-bar-gap", 8), justifyContent: circle || minimized ? "space-between" : "center" }], children: [_jsxs(Glass, { radius: 999, elevation: "raised", style: [styles.capsule, minimized ? { padding: capsulePadding } : { paddingVertical: capsulePadding, paddingHorizontal: theme.length("--tab-bar-capsule-padding-inline", 10) }], children: [pillFrame && Platform.OS === "web" ? (
445
+ // The web slides the pill in CSS, off the JavaScript thread, so a screen mounting under the new tab
446
+ // does not stop it
447
+ _jsx(CssSlide, { x: pillLeft, width: pillSpan, side: "start", duration: 300, easing: "cubic-bezier(0.25, 0.1, 0.25, 1)", still: theme.reducedMotion, style: [styles.pill, { top: pillFrame.y, height: pillFrame.height, backgroundColor: theme.color("--tab-bar-item-background-selected") }] })) : pillFrame ? (_jsx(Animated.View, { pointerEvents: "none", style: [
441
448
  styles.pill,
442
449
  { top: pillFrame.y, height: pillFrame.height, start: pillX, width: pillWidth, backgroundColor: theme.color("--tab-bar-item-background-selected") },
443
450
  ] })) : null, visible.map((tab) => (_jsx(Tab, { ...tab, context: context }, tab.value)))] }), circle ? (_jsx(Glass, { radius: circleSize / 2, elevation: "raised", style: { width: circleSize, height: circleSize }, children: _jsx(Tab, { ...circle, context: { ...context, minimized: false }, kind: "circle", hideLabel: true }) })) : null] })] }) }));
@@ -0,0 +1,35 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { View } from "react-native";
3
+ // A fill at the start of a right-to-left row moves the other way: the CSS direction turns the sign of its offset, so
4
+ // a row whose direction changes moves it over at once, as it moves `start`
5
+ const RULE = "[data-plex-slide=start]:dir(rtl){--plex-slide-sign:-1}";
6
+ let ruled = false;
7
+ function addRule() {
8
+ if (ruled)
9
+ return;
10
+ const dom = globalThis;
11
+ const sheet = dom.document?.createElement("style");
12
+ if (sheet == null || dom.document?.head == null)
13
+ return;
14
+ ruled = true;
15
+ sheet.textContent = RULE;
16
+ dom.document.head.appendChild(sheet);
17
+ }
18
+ /**
19
+ * The web's sliding fill (a segmented control's thumb, a tab bar's pill): its place a `translateX` and its width a CSS
20
+ * transition, so the browser runs the slide itself. A slide driven from JavaScript stops for a frame as long as the
21
+ * page's work in it (a screen mounting under the tab it slides to) and then jumps; the compositor keeps the move going.
22
+ * A fill that mounts stands at its place, since a transition starts from a style the browser has already drawn.
23
+ */
24
+ export function CssSlide({ x, width, side, duration, easing, still = false, style }) {
25
+ if (side === "start")
26
+ addRule();
27
+ const time = still ? "0ms" : `${duration}ms`;
28
+ const motion = {
29
+ transform: side === "start" ? `translateX(calc(var(--plex-slide-sign, 1) * ${x}px))` : `translateX(${x}px)`,
30
+ transitionProperty: "transform, width",
31
+ transitionDuration: `${time}, ${time}`,
32
+ transitionTimingFunction: `${easing}, ${easing}`,
33
+ };
34
+ return (_jsx(View, { ...{ dataSet: { plexSlide: side } }, pointerEvents: "none", style: [style, side === "left" ? { left: 0 } : { start: 0 }, { width }, motion] }));
35
+ }
@@ -0,0 +1,22 @@
1
+ import type { StyleProp, ViewStyle } from "react-native";
2
+ type CssSlideProps = {
3
+ /** The offset from the side, in points. */
4
+ x: number;
5
+ width: number;
6
+ /** `left` keeps the screen's left; `start` follows the row's direction (the right in a right-to-left row). */
7
+ side: "left" | "start";
8
+ duration: number;
9
+ /** A CSS timing function: `cubic-bezier(…)`. */
10
+ easing: string;
11
+ /** No slide: the fill moves at once (reduced motion). */
12
+ still?: boolean;
13
+ style?: StyleProp<ViewStyle>;
14
+ };
15
+ /**
16
+ * The web's sliding fill (a segmented control's thumb, a tab bar's pill): its place a `translateX` and its width a CSS
17
+ * transition, so the browser runs the slide itself. A slide driven from JavaScript stops for a frame as long as the
18
+ * page's work in it (a screen mounting under the tab it slides to) and then jumps; the compositor keeps the move going.
19
+ * A fill that mounts stands at its place, since a transition starts from a style the browser has already drawn.
20
+ */
21
+ export declare function CssSlide({ x, width, side, duration, easing, still, style }: CssSlideProps): import("react").JSX.Element;
22
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexui/react-native",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "Plex UI components for React Native and Expo: iOS 26 and Material 3, on the shared @plexui/styles tokens",
5
5
  "license": "MIT",
6
6
  "homepage": "https://plexui.com",
@@ -1,6 +1,7 @@
1
1
  import { createContext, isValidElement, useContext, useEffect, useRef, useState, type ReactElement, type ReactNode } from "react"
2
- import { Animated, Easing, StyleSheet, View, type LayoutChangeEvent, type StyleProp, type ViewStyle } from "react-native"
2
+ import { Animated, Easing, Platform, StyleSheet, View, type LayoutChangeEvent, type StyleProp, type ViewStyle } from "react-native"
3
3
  import { Pressable } from "../../internal/Pressable"
4
+ import { CssSlide } from "../../internal/CssSlide"
4
5
  import { childrenOfType, isRenderable, textOf } from "../../internal/children"
5
6
  import { Glass } from "../../internal/Glass"
6
7
  import { curves } from "../../internal/motion"
@@ -250,7 +251,8 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
250
251
  const [width] = useState(() => new Animated.Value(0))
251
252
  const placed = useRef(false)
252
253
  useEffect(() => {
253
- if (selectedX == null || selectedWidth == null) return
254
+ // The web's thumb slides in CSS
255
+ if (selectedX == null || selectedWidth == null || Platform.OS === "web") return
254
256
  if (!placed.current || theme.reducedMotion) {
255
257
  x.setValue(selectedX)
256
258
  width.setValue(selectedWidth)
@@ -279,7 +281,18 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, show
279
281
  const maxScale = look.height / look.lineHeight
280
282
  const content = (
281
283
  <>
282
- {selected ? (
284
+ {selected && Platform.OS === "web" ? (
285
+ // The web slides the thumb in CSS, off the JavaScript thread
286
+ <CssSlide
287
+ x={selected.x}
288
+ width={selected.width}
289
+ side="left"
290
+ duration={look.duration}
291
+ easing="cubic-bezier(0.25, 0.1, 0.25, 1)"
292
+ still={theme.reducedMotion}
293
+ style={[styles.thumb, { top: look.gutter, bottom: look.gutter, borderRadius: optionRadius, backgroundColor: look.thumb }]}
294
+ />
295
+ ) : selected ? (
283
296
  <Animated.View
284
297
  pointerEvents="none"
285
298
  style={[styles.thumb, { top: look.gutter, bottom: look.gutter, left: x, width, borderRadius: optionRadius, backgroundColor: look.thumb }]}
@@ -395,7 +408,7 @@ function AndroidControl({ options, value, select, keys, disabled, block, equal,
395
408
  const frameWidth = measured ? widths[options[index].value] : undefined
396
409
  const frame = frameX != null
397
410
  useEffect(() => {
398
- if (frameX == null || frameWidth == null) return
411
+ if (frameX == null || frameWidth == null || Platform.OS === "web") return
399
412
  if (!placed.current || theme.reducedMotion) {
400
413
  x.setValue(frameX)
401
414
  width.setValue(frameWidth)
@@ -413,7 +426,17 @@ function AndroidControl({ options, value, select, keys, disabled, block, equal,
413
426
  block ? styles.stretch : null,
414
427
  ]}
415
428
  >
416
- {frame ? (
429
+ {frame && Platform.OS === "web" ? (
430
+ <CssSlide
431
+ x={frameX}
432
+ width={frameWidth!}
433
+ side="left"
434
+ duration={ANDROID_MOVE.duration}
435
+ easing="cubic-bezier(0.23, 1, 0.32, 1)"
436
+ still={theme.reducedMotion}
437
+ style={[styles.androidPill, { height: inner, borderRadius: inner / 2, backgroundColor: withAlpha(m.primary, 0.12) }]}
438
+ />
439
+ ) : frame ? (
417
440
  <Animated.View
418
441
  pointerEvents="none"
419
442
  style={[styles.androidPill, { height: inner, borderRadius: inner / 2, backgroundColor: withAlpha(m.primary, 0.12), left: x, width }]}
@@ -1,6 +1,7 @@
1
1
  import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, type ReactElement, type ReactNode } from "react"
2
- import { Animated, Easing, StyleSheet, View, type LayoutChangeEvent, type NativeScrollEvent, type NativeSyntheticEvent, type StyleProp, type ViewProps, type ViewStyle } from "react-native"
2
+ import { Animated, Easing, Platform, StyleSheet, View, type LayoutChangeEvent, type NativeScrollEvent, type NativeSyntheticEvent, type StyleProp, type ViewProps, type ViewStyle } from "react-native"
3
3
  import { Pressable } from "../../internal/Pressable"
4
+ import { CssSlide } from "../../internal/CssSlide"
4
5
  import { useSafeAreaInsets } from "react-native-safe-area-context"
5
6
  import Search from "../../icons/plex/Search"
6
7
  import { BarBackdrop, SoftBottomEdge, TabBarFade, ANDROID_FADE_ALPHA, ANDROID_FADE_STOPS, glassBarBlur, useAndroidGlass } from "../../internal/BarBackdrop"
@@ -742,6 +743,8 @@ function TabBarRoot({
742
743
  pillShown.current = false
743
744
  return
744
745
  }
746
+ // The web's pill slides in CSS
747
+ if (Platform.OS === "web") return
745
748
  // It appears in place (the first frame, back from a minimized bar or the circle's tab), then slides: CSS `ease`
746
749
  // over 300ms, as SegmentedControl's thumb
747
750
  if (!pillShown.current || theme.reducedMotion) {
@@ -832,7 +835,19 @@ function TabBarRoot({
832
835
  elevation="raised"
833
836
  style={[styles.capsule, minimized ? { padding: capsulePadding } : { paddingVertical: capsulePadding, paddingHorizontal: theme.length("--tab-bar-capsule-padding-inline", 10) }]}
834
837
  >
835
- {pillFrame ? (
838
+ {pillFrame && Platform.OS === "web" ? (
839
+ // The web slides the pill in CSS, off the JavaScript thread, so a screen mounting under the new tab
840
+ // does not stop it
841
+ <CssSlide
842
+ x={pillLeft!}
843
+ width={pillSpan!}
844
+ side="start"
845
+ duration={300}
846
+ easing="cubic-bezier(0.25, 0.1, 0.25, 1)"
847
+ still={theme.reducedMotion}
848
+ style={[styles.pill, { top: pillFrame.y, height: pillFrame.height, backgroundColor: theme.color("--tab-bar-item-background-selected") }]}
849
+ />
850
+ ) : pillFrame ? (
836
851
  <Animated.View
837
852
  pointerEvents="none"
838
853
  style={[
@@ -0,0 +1,54 @@
1
+ import type { StyleProp, ViewStyle } from "react-native"
2
+ import { View } from "react-native"
3
+
4
+ type CssSlideProps = {
5
+ /** The offset from the side, in points. */
6
+ x: number
7
+ width: number
8
+ /** `left` keeps the screen's left; `start` follows the row's direction (the right in a right-to-left row). */
9
+ side: "left" | "start"
10
+ duration: number
11
+ /** A CSS timing function: `cubic-bezier(…)`. */
12
+ easing: string
13
+ /** No slide: the fill moves at once (reduced motion). */
14
+ still?: boolean
15
+ style?: StyleProp<ViewStyle>
16
+ }
17
+
18
+ // A fill at the start of a right-to-left row moves the other way: the CSS direction turns the sign of its offset, so
19
+ // a row whose direction changes moves it over at once, as it moves `start`
20
+ const RULE = "[data-plex-slide=start]:dir(rtl){--plex-slide-sign:-1}"
21
+ let ruled = false
22
+ function addRule() {
23
+ if (ruled) return
24
+ const dom = globalThis as unknown as { document?: { createElement: (tag: string) => { textContent: string }; head?: { appendChild: (node: unknown) => void } } }
25
+ const sheet = dom.document?.createElement("style")
26
+ if (sheet == null || dom.document?.head == null) return
27
+ ruled = true
28
+ sheet.textContent = RULE
29
+ dom.document.head.appendChild(sheet)
30
+ }
31
+
32
+ /**
33
+ * The web's sliding fill (a segmented control's thumb, a tab bar's pill): its place a `translateX` and its width a CSS
34
+ * transition, so the browser runs the slide itself. A slide driven from JavaScript stops for a frame as long as the
35
+ * page's work in it (a screen mounting under the tab it slides to) and then jumps; the compositor keeps the move going.
36
+ * A fill that mounts stands at its place, since a transition starts from a style the browser has already drawn.
37
+ */
38
+ export function CssSlide({ x, width, side, duration, easing, still = false, style }: CssSlideProps) {
39
+ if (side === "start") addRule()
40
+ const time = still ? "0ms" : `${duration}ms`
41
+ const motion = {
42
+ transform: side === "start" ? `translateX(calc(var(--plex-slide-sign, 1) * ${x}px))` : `translateX(${x}px)`,
43
+ transitionProperty: "transform, width",
44
+ transitionDuration: `${time}, ${time}`,
45
+ transitionTimingFunction: `${easing}, ${easing}`,
46
+ } as unknown as ViewStyle
47
+ return (
48
+ <View
49
+ {...({ dataSet: { plexSlide: side } } as object)}
50
+ pointerEvents="none"
51
+ style={[style, side === "left" ? { left: 0 } : { start: 0 }, { width }, motion]}
52
+ />
53
+ )
54
+ }