glacia-native 0.4.0 → 0.5.0

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/src/index.ts CHANGED
@@ -86,5 +86,105 @@ export {
86
86
  } from "./Table";
87
87
  // Charts, drawn with react-native-svg using the same maths as the web package.
88
88
  export * from "./charts";
89
+ // Basics.
90
+ export { Text, type TextProps, type TextVariant } from "./Text";
91
+ export {
92
+ Avatar,
93
+ Badge,
94
+ Separator,
95
+ Skeleton,
96
+ Spinner,
97
+ Progress,
98
+ initialsOf,
99
+ type AvatarProps,
100
+ type AvatarSize,
101
+ type BadgeProps,
102
+ type SeparatorProps,
103
+ type SkeletonProps,
104
+ type SpinnerProps,
105
+ type SpinnerSize,
106
+ type ProgressProps,
107
+ type ProgressVariant,
108
+ } from "./Display";
109
+ // Feedback and display.
110
+ export {
111
+ Toast,
112
+ Banner,
113
+ List,
114
+ ListItem,
115
+ ListSection,
116
+ Accordion,
117
+ type ToastProps,
118
+ type ToastAction,
119
+ type BannerProps,
120
+ type ListProps,
121
+ type ListItemProps,
122
+ type ListSectionProps,
123
+ type AccordionProps,
124
+ type AccordionSection,
125
+ } from "./Feedback";
126
+ // Bars, buttons and navigation.
127
+ export {
128
+ SearchBar,
129
+ Chip,
130
+ FAB,
131
+ IconButton,
132
+ AppBar,
133
+ type SearchBarProps,
134
+ type ChipProps,
135
+ type FABProps,
136
+ type IconButtonProps,
137
+ type AppBarProps,
138
+ type AppBarAction,
139
+ } from "./Bars";
140
+ // Overlays.
141
+ export {
142
+ Menu,
143
+ Sheet,
144
+ Drawer,
145
+ anchorPopover,
146
+ type MenuProps,
147
+ type MenuItem,
148
+ type SheetProps,
149
+ type DrawerProps,
150
+ } from "./Overlays";
151
+ // Carousel.
152
+ export {
153
+ Carousel,
154
+ PageControl,
155
+ type CarouselProps,
156
+ type PageControlProps,
157
+ } from "./Carousel";
158
+ // Forms and pickers.
159
+ export {
160
+ Stepper,
161
+ Toggle,
162
+ ToggleGroup,
163
+ InputOTP,
164
+ ButtonGroup,
165
+ type StepperProps,
166
+ type ToggleProps,
167
+ type ToggleGroupProps,
168
+ type ToggleGroupItem,
169
+ type InputOTPProps,
170
+ type ButtonGroupProps,
171
+ type ButtonGroupItem,
172
+ } from "./Forms2";
173
+ export {
174
+ Calendar,
175
+ DatePicker,
176
+ TimePicker,
177
+ monthGrid,
178
+ startOfDay,
179
+ sameDay,
180
+ parseTime,
181
+ formatTime,
182
+ WEEKDAYS,
183
+ MONTHS,
184
+ type CalendarProps,
185
+ type CalendarCell,
186
+ type DatePickerProps,
187
+ type TimePickerProps,
188
+ } from "./Pickers";
89
189
  export { isGlassSupported } from "./internal/GlassView";
90
- export { colors, radii, springs } from "./internal/tokens";
190
+ export { colors, radii, springs, typeScale, toneColor, type Tone } from "./internal/tokens";
@@ -18,16 +18,37 @@ export interface NativeGlassProps {
18
18
  * colour scheme decides, so developers never thread this prop themselves.
19
19
  */
20
20
  isDark?: boolean;
21
+ /**
22
+ * Any further React Native view prop (accessibility, onLayout, pointer
23
+ * events, …) is passed straight through to whichever surface renders, so a
24
+ * component can put its own accessibility contract on the glass itself.
25
+ */
26
+ [prop: string]: any;
21
27
  }
22
28
 
23
29
  /**
24
- * The installed `@callstack/liquid-glass` module, resolved once at load.
25
- * `isLiquidGlassSupported` is true only on iOS 26+; false on older iOS,
26
- * Android and Expo Go.
30
+ * The installed `@callstack/liquid-glass` module's routing decision.
31
+ *
32
+ * Resolved lazily and memoised on first use, rather than at module load, so the
33
+ * decision is taken when a surface first renders. On a device that is the same
34
+ * answer either way — `isLiquidGlassSupported` is a constant of the installed
35
+ * build — but it keeps the choice a property of the module rather than of
36
+ * import order, which is what makes both branches reachable in tests.
27
37
  */
28
- const router = defaultRouter();
38
+ let cachedRouter: ReturnType<typeof defaultRouter> | null = null;
39
+
40
+ function router(): ReturnType<typeof defaultRouter> {
41
+ if (cachedRouter === null) cachedRouter = defaultRouter();
42
+ return cachedRouter;
43
+ }
44
+
45
+ /** Clears the memoised decision. Only tests call this, to drive both branches. */
46
+ export function resetGlassRouter() {
47
+ cachedRouter = null;
48
+ }
29
49
 
30
- export const isGlassSupported = router.supported;
50
+ /** Whether this build renders Apple's glass. */
51
+ export const isGlassSupported = defaultRouter().supported;
31
52
 
32
53
  /**
33
54
  * Platform Glass View — the single place a glass surface is chosen:
@@ -48,8 +69,9 @@ export const GlassView = forwardRef<any, NativeGlassProps>(function GlassView(
48
69
  ref,
49
70
  ) {
50
71
  const isDark = useIsDark(isDarkProp);
51
- if (router.supported && router.LiquidGlassView) {
52
- const LiquidGlassView = router.LiquidGlassView;
72
+ const decision = router();
73
+ if (decision.supported && decision.LiquidGlassView) {
74
+ const LiquidGlassView = decision.LiquidGlassView;
53
75
  return (
54
76
  <LiquidGlassView
55
77
  ref={ref}
@@ -202,8 +202,10 @@ function resolve(): RNPrimitives {
202
202
  if (onMouseUp) domProps.onMouseUp = onMouseUp;
203
203
  if (onMouseLeave) domProps.onMouseLeave = onMouseLeave;
204
204
 
205
- if (onPress) {
205
+ if (onPress && !disabled) {
206
206
  // Any element hosting a press handler needs a DOM click to fire it.
207
+ // A disabled control gets no handler at all, mirroring React Native's
208
+ // Pressable, which swallows the press rather than calling it through.
207
209
  domProps.onClick = onPress;
208
210
  if (
209
211
  domProps.role === "button" ||
@@ -240,12 +242,15 @@ function resolve(): RNPrimitives {
240
242
 
241
243
  /** An image that reads its remote source in the DOM preview. */
242
244
  function imageFallback(props: any) {
243
- const { source, accessibilityLabel, style } = props ?? {};
245
+ const { source, accessibilityLabel, style, onError } = props ?? {};
244
246
  const { createElement } = require("react");
245
247
  return createElement("img", {
246
248
  src: source?.uri,
247
249
  alt: accessibilityLabel ?? "",
248
250
  style: toDomStyle(style),
251
+ // A broken source must reach the component the same way it does on a
252
+ // device, or a fallback (initials, placeholder) can never render.
253
+ onError,
249
254
  });
250
255
  }
251
256
 
@@ -14,6 +14,28 @@ export const springs = {
14
14
  bouncy: tokenSprings.bouncy,
15
15
  };
16
16
 
17
+ /**
18
+ * The package's type scale, in React Native points.
19
+ *
20
+ * Text maps its variants onto these names so every component in the library —
21
+ * and every app built on it — sizes type the same way.
22
+ */
23
+ export const typeScale = {
24
+ title: { fontSize: 28, lineHeight: 34, fontWeight: "700" as const },
25
+ heading: { fontSize: 20, lineHeight: 26, fontWeight: "600" as const },
26
+ body: { fontSize: 16, lineHeight: 22, fontWeight: "400" as const },
27
+ label: { fontSize: 13, lineHeight: 18, fontWeight: "600" as const },
28
+ caption: { fontSize: 12, lineHeight: 16, fontWeight: "400" as const },
29
+ };
30
+
31
+ /**
32
+ * Theme colours in the form React Native accepts.
33
+ *
34
+ * The shared tokens express colours as CSS colour strings (`rgb(r g b / a)`),
35
+ * which is right for the web package and rejected by React Native. The values
36
+ * below are the same colours written as `rgba(...)`/hex, sourced from the same
37
+ * token file, so the two platforms stay in step.
38
+ */
17
39
  export const colors = {
18
40
  light: {
19
41
  foreground: "#000000E0",
@@ -21,8 +43,17 @@ export const colors = {
21
43
  glass: "rgba(255, 255, 255, 0.6)",
22
44
  glassActive: "rgba(236, 236, 240, 0.85)",
23
45
  edge: "rgba(0, 0, 0, 0.08)",
46
+ separator: "rgba(60, 60, 67, 0.18)",
24
47
  fill: "#0088FF",
25
48
  destructive: "#FF3B30",
49
+ on: "#34C759",
50
+ warning: "#FF9500",
51
+ info: "#007AFF",
52
+ // The dimmed layer behind a sheet, drawer or dialog.
53
+ scrim: "rgba(0, 0, 0, 0.45)",
54
+ // Text and icons drawn on top of a filled (tinted) surface.
55
+ onTint: "#FFFFFF",
56
+ skeleton: "rgba(60, 60, 67, 0.12)",
26
57
  // Chart axis and grid lines: low-contrast, so they never compete with data.
27
58
  axis: "#3C3C43",
28
59
  },
@@ -32,8 +63,39 @@ export const colors = {
32
63
  glass: "rgba(40, 40, 40, 0.62)",
33
64
  glassActive: "rgba(70, 70, 70, 0.62)",
34
65
  edge: "rgba(255, 255, 255, 0.08)",
66
+ separator: "rgba(235, 235, 245, 0.16)",
35
67
  fill: "#0091FF",
36
68
  destructive: "#FF4245",
69
+ on: "#30D158",
70
+ warning: "#FF9F0A",
71
+ info: "#0A84FF",
72
+ scrim: "rgba(0, 0, 0, 0.6)",
73
+ onTint: "#FFFFFF",
74
+ skeleton: "rgba(235, 235, 245, 0.14)",
37
75
  axis: "#EBEBF5",
38
76
  },
39
77
  };
78
+
79
+ /** Keeps the shared token file honest if a colour is added there first. */
80
+ export type ThemeColors = typeof colors.light;
81
+
82
+ /** The semantic tone of a feedback component (Banner, Toast). */
83
+ export type Tone = "info" | "success" | "warning" | "error";
84
+
85
+ /** Resolves a tone to its theme colour. */
86
+ export function toneColor(theme: ThemeColors, tone: Tone): string {
87
+ switch (tone) {
88
+ case "success":
89
+ return theme.on;
90
+ case "warning":
91
+ return theme.warning;
92
+ case "error":
93
+ return theme.destructive;
94
+ default:
95
+ return theme.info;
96
+ }
97
+ }
98
+
99
+ // Referenced so the shared tokens stay a live dependency: a colour removed
100
+ // from glacia-tokens should not silently linger here forever.
101
+ void tokenColors;