glacia-native 0.5.0 → 0.5.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/lib/module/Bars.js +95 -2
- package/lib/module/Display.js +78 -1
- package/lib/module/Feedback.js +221 -7
- package/lib/module/Forms2.js +228 -1
- package/lib/module/Message.js +88 -0
- package/lib/module/Overlays.js +173 -11
- package/lib/module/SegmentedControl.js +5 -1
- package/lib/module/Slider.js +6 -1
- package/lib/module/Switch.js +4 -1
- package/lib/module/TabBar.js +5 -1
- package/lib/module/ai.js +8 -3
- package/lib/module/index.js +23 -2
- package/lib/module/internal/GlassContainer.js +54 -0
- package/lib/module/internal/GlassView.js +8 -0
- package/lib/module/internal/a11y.js +94 -0
- package/lib/module/internal/fallback.js +19 -8
- package/lib/module/internal/glass-routing.js +7 -0
- package/lib/module/internal/haptics.js +54 -0
- package/lib/module/internal/motion.js +10 -1
- package/lib/module/internal/primitives.js +69 -4
- package/lib/module/internal/tokens.js +47 -1
- package/lib/typescript/Bars.d.ts +67 -0
- package/lib/typescript/Display.d.ts +59 -0
- package/lib/typescript/Feedback.d.ts +58 -0
- package/lib/typescript/Forms2.d.ts +81 -0
- package/lib/typescript/Message.d.ts +71 -0
- package/lib/typescript/Overlays.d.ts +41 -0
- package/lib/typescript/SegmentedControl.d.ts +2 -0
- package/lib/typescript/Slider.d.ts +2 -0
- package/lib/typescript/Switch.d.ts +2 -0
- package/lib/typescript/TabBar.d.ts +2 -0
- package/lib/typescript/index.d.ts +8 -6
- package/lib/typescript/internal/GlassContainer.d.ts +37 -0
- package/lib/typescript/internal/GlassView.d.ts +8 -0
- package/lib/typescript/internal/a11y.d.ts +19 -0
- package/lib/typescript/internal/fallback.d.ts +5 -0
- package/lib/typescript/internal/glass-routing.d.ts +10 -0
- package/lib/typescript/internal/haptics.d.ts +7 -0
- package/lib/typescript/internal/motion.d.ts +4 -0
- package/lib/typescript/internal/primitives.d.ts +21 -0
- package/lib/typescript/internal/tokens.d.ts +53 -0
- package/package.json +2 -2
- package/src/Bars.tsx +227 -0
- package/src/Display.tsx +229 -1
- package/src/Feedback.tsx +412 -22
- package/src/Forms2.tsx +407 -1
- package/src/Message.tsx +219 -0
- package/src/Overlays.tsx +244 -33
- package/src/SegmentedControl.tsx +6 -0
- package/src/Slider.tsx +7 -0
- package/src/Switch.tsx +5 -0
- package/src/TabBar.tsx +6 -0
- package/src/ai.tsx +9 -3
- package/src/index.ts +42 -1
- package/src/internal/GlassContainer.tsx +82 -0
- package/src/internal/GlassView.tsx +8 -0
- package/src/internal/a11y.ts +105 -0
- package/src/internal/fallback.tsx +19 -2
- package/src/internal/glass-routing.ts +17 -0
- package/src/internal/haptics.ts +59 -0
- package/src/internal/motion.ts +10 -1
- package/src/internal/primitives.ts +80 -4
- package/src/internal/tokens.ts +48 -0
package/lib/module/Forms2.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ButtonGroup = exports.InputOTP = exports.ToggleGroup = exports.Toggle = exports.Stepper = void 0;
|
|
3
|
+
exports.Combobox = exports.ColorPicker = exports.DEFAULT_PALETTE = exports.ButtonGroup = exports.InputOTP = exports.ToggleGroup = exports.Toggle = exports.Stepper = void 0;
|
|
4
|
+
exports.hexToRgb = hexToRgb;
|
|
5
|
+
exports.hueGradientColors = hueGradientColors;
|
|
6
|
+
exports.rgbToHex = rgbToHex;
|
|
4
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
8
|
const react_1 = require("react");
|
|
6
9
|
const Glass_1 = require("./Glass");
|
|
@@ -225,3 +228,227 @@ exports.ButtonGroup = (0, react_1.forwardRef)(function ButtonGroup({ items, size
|
|
|
225
228
|
}, children: (0, jsx_runtime_1.jsx)(RNText, { numberOfLines: 1, style: { fontSize: size === "sm" ? 13 : 14, fontWeight: "500", color: theme.foreground }, children: item.label }) }) }, `${item.label}-${index}`));
|
|
226
229
|
}) }));
|
|
227
230
|
});
|
|
231
|
+
/**
|
|
232
|
+
* A colour picker built from Glacia's own parts — no native widget.
|
|
233
|
+
*
|
|
234
|
+
* The palette is a grid of swatches from the caller's colours; the custom row
|
|
235
|
+
* is a hue track drawn as an SVG gradient (the resolver's shapes, so it works
|
|
236
|
+
* wherever the charts work) driven by the same Slider mechanics as the rest of
|
|
237
|
+
* the library: a drag along the track picks a hue, and a second track saturates
|
|
238
|
+
* it. The value is a hex string.
|
|
239
|
+
*
|
|
240
|
+
* The default palette is a small set of iOS-conventional colours, in case a
|
|
241
|
+
* caller wants a picker with no colour knowledge of its own.
|
|
242
|
+
*/
|
|
243
|
+
exports.DEFAULT_PALETTE = tokens_1.palette.default;
|
|
244
|
+
/** Parses a hex colour into its red, green and blue channels. */
|
|
245
|
+
function hexToRgb(hex) {
|
|
246
|
+
const match = /^#?([0-9a-f]{6})$/i.exec(hex.trim());
|
|
247
|
+
if (!match)
|
|
248
|
+
return null;
|
|
249
|
+
const raw = match[1];
|
|
250
|
+
return {
|
|
251
|
+
r: parseInt(raw.slice(0, 2), 16),
|
|
252
|
+
g: parseInt(raw.slice(2, 4), 16),
|
|
253
|
+
b: parseInt(raw.slice(4, 6), 16),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/** Builds a hue gradient's colours, sweeping red → orange → … → red. */
|
|
257
|
+
function hueGradientColors() {
|
|
258
|
+
const stops = 12;
|
|
259
|
+
return Array.from({ length: stops }, (_u, i) => {
|
|
260
|
+
const angle = (i / stops) * 360;
|
|
261
|
+
const c = hslToRgb(angle, 1, 0.5);
|
|
262
|
+
return `#${c.r.toString(16).padStart(2, "0")}${c.g.toString(16).padStart(2, "0")}${c.b.toString(16).padStart(2, "0")}`;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
/** Converts an HSL triple (h 0–360, s/l 0–1) to an RGB hex string. */
|
|
266
|
+
function hslToRgb(h, s, l) {
|
|
267
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
268
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
269
|
+
const m = l - c / 2;
|
|
270
|
+
let r = 0, g = 0, b = 0;
|
|
271
|
+
if (h < 60) {
|
|
272
|
+
r = c;
|
|
273
|
+
g = x;
|
|
274
|
+
}
|
|
275
|
+
else if (h < 120) {
|
|
276
|
+
r = x;
|
|
277
|
+
g = c;
|
|
278
|
+
}
|
|
279
|
+
else if (h < 180) {
|
|
280
|
+
g = c;
|
|
281
|
+
b = x;
|
|
282
|
+
}
|
|
283
|
+
else if (h < 240) {
|
|
284
|
+
g = x;
|
|
285
|
+
b = c;
|
|
286
|
+
}
|
|
287
|
+
else if (h < 300) {
|
|
288
|
+
r = x;
|
|
289
|
+
b = c;
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
r = c;
|
|
293
|
+
b = x;
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
r: Math.round((r + m) * 255),
|
|
297
|
+
g: Math.round((g + m) * 255),
|
|
298
|
+
b: Math.round((b + m) * 255),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/** Converts an RGB triple to a hex string. */
|
|
302
|
+
function rgbToHex(r, g, b) {
|
|
303
|
+
const clamp = (n) => Math.max(0, Math.min(255, Math.round(n)));
|
|
304
|
+
return `#${clamp(r).toString(16).padStart(2, "0")}${clamp(g).toString(16).padStart(2, "0")}${clamp(b).toString(16).padStart(2, "0")}`;
|
|
305
|
+
}
|
|
306
|
+
exports.ColorPicker = (0, react_1.forwardRef)(function ColorPicker({ colors: palette, value, defaultValue, onChange, size = "md", columns = 6, allowCustom = true, disabled = false, accessibilityLabel = "Color", style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
307
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
308
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
309
|
+
const { View, Pressable, Text: RNText, PanResponder, Svg, Rect, Defs, LinearGradient, Stop } = (0, primitives_1.primitives)();
|
|
310
|
+
const swatches = palette && palette.length > 0 ? palette : exports.DEFAULT_PALETTE;
|
|
311
|
+
const [internalValue, setInternalValue] = (0, react_1.useState)(defaultValue ?? swatches[0] ?? tokens_1.palette.fallback);
|
|
312
|
+
const activeColor = value !== undefined ? value : internalValue;
|
|
313
|
+
const setColor = (next) => {
|
|
314
|
+
if (disabled)
|
|
315
|
+
return;
|
|
316
|
+
if (value === undefined)
|
|
317
|
+
setInternalValue(next);
|
|
318
|
+
onChange?.(next);
|
|
319
|
+
};
|
|
320
|
+
// The custom row's two tracks: hue on the top, saturation on the bottom.
|
|
321
|
+
// Both are driven by PanResponder like the library's Slider — a press or a
|
|
322
|
+
// drag along a track reports the colour at that position.
|
|
323
|
+
const trackRef = (0, react_1.useRef)(0);
|
|
324
|
+
const swatchSize = tokens_1.controlSizes.swatch[size];
|
|
325
|
+
const hueColor = (h) => {
|
|
326
|
+
const c = hslToRgb(h, 1, 0.5);
|
|
327
|
+
return rgbToHex(c.r, c.g, c.b);
|
|
328
|
+
};
|
|
329
|
+
const colorAtFraction = (fraction, hue) => {
|
|
330
|
+
const sat = Math.max(0, Math.min(1, fraction));
|
|
331
|
+
const c = hslToRgb(hue, sat, 0.5);
|
|
332
|
+
return rgbToHex(c.r, c.g, c.b);
|
|
333
|
+
};
|
|
334
|
+
const hue = hexToRgb(activeColor) ? hueOf(activeColor) : 0;
|
|
335
|
+
const hueResponder = makeTrackResponder((fraction) => {
|
|
336
|
+
setColor(hueColor(fraction * 360));
|
|
337
|
+
}, PanResponder, trackRef);
|
|
338
|
+
const satResponder = makeTrackResponder((fraction) => {
|
|
339
|
+
setColor(colorAtFraction(fraction, hue));
|
|
340
|
+
}, PanResponder, trackRef);
|
|
341
|
+
const hueGradient = hueGradientColors();
|
|
342
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, accessibilityRole: "adjustable", accessibilityLabel: accessibilityLabel, accessibilityValue: { text: activeColor }, style: { gap: 12, opacity: disabled ? 0.38 : 1, ...style }, ...props, children: [(0, jsx_runtime_1.jsx)(View, { style: { flexDirection: "row", flexWrap: "wrap", gap: 8 }, children: swatches.map((swatch, index) => {
|
|
343
|
+
const selected = swatch.toLowerCase() === activeColor.toLowerCase();
|
|
344
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: `${swatch} color`, accessibilityState: { selected }, disabled: disabled, onPress: () => setColor(swatch), style: {
|
|
345
|
+
width: swatchSize,
|
|
346
|
+
height: swatchSize,
|
|
347
|
+
borderRadius: swatchSize / 2,
|
|
348
|
+
backgroundColor: swatch,
|
|
349
|
+
borderWidth: selected ? 2 : 0.5,
|
|
350
|
+
borderColor: selected ? theme.fill : theme.separator,
|
|
351
|
+
} }, `${swatch}-${index}`));
|
|
352
|
+
}) }), allowCustom ? ((0, jsx_runtime_1.jsxs)(View, { style: { gap: 8 }, children: [(0, jsx_runtime_1.jsx)(View, { style: { height: tokens_1.controlSizes.picker.track, borderRadius: tokens_1.radii.md, overflow: "hidden" }, ...(hueResponder ? hueResponder.panHandlers : {}), children: (0, jsx_runtime_1.jsxs)(Svg, { width: "100%", height: "100%", children: [(0, jsx_runtime_1.jsx)(Defs, { children: (0, jsx_runtime_1.jsx)(LinearGradient, { id: "hueGradient", x1: "0", y1: "0", x2: "1", y2: "0", children: hueGradient.map((color, i) => ((0, jsx_runtime_1.jsx)(Stop, { offset: i / (hueGradient.length - 1), stopColor: color }, i))) }) }), (0, jsx_runtime_1.jsx)(Rect, { x: "0", y: "0", width: "100%", height: "100%", fill: "url(#hueGradient)" })] }) }), (0, jsx_runtime_1.jsx)(View, { style: { height: tokens_1.controlSizes.picker.track, borderRadius: tokens_1.radii.md, overflow: "hidden" }, ...(satResponder ? satResponder.panHandlers : {}), children: (0, jsx_runtime_1.jsxs)(Svg, { width: "100%", height: "100%", children: [(0, jsx_runtime_1.jsx)(Defs, { children: (0, jsx_runtime_1.jsxs)(LinearGradient, { id: "satGradient", x1: "0", y1: "0", x2: "1", y2: "0", children: [(0, jsx_runtime_1.jsx)(Stop, { offset: "0", stopColor: theme.neutralTop }), (0, jsx_runtime_1.jsx)(Stop, { offset: "1", stopColor: hueColor(hue) })] }) }), (0, jsx_runtime_1.jsx)(Rect, { x: "0", y: "0", width: "100%", height: "100%", fill: "url(#satGradient)" })] }) }), (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 12, color: theme.muted }, children: activeColor })] })) : null] }));
|
|
353
|
+
});
|
|
354
|
+
/** The hue (0–360) of a hex colour. */
|
|
355
|
+
function hueOf(hex) {
|
|
356
|
+
const rgb = hexToRgb(hex);
|
|
357
|
+
if (!rgb)
|
|
358
|
+
return 0;
|
|
359
|
+
const { r, g, b } = rgb;
|
|
360
|
+
const max = Math.max(r, g, b) / 255;
|
|
361
|
+
const min = Math.min(r, g, b) / 255;
|
|
362
|
+
const delta = max - min;
|
|
363
|
+
if (delta === 0)
|
|
364
|
+
return 0;
|
|
365
|
+
let h = 0;
|
|
366
|
+
if (max === r / 255)
|
|
367
|
+
h = ((g / 255 - b / 255) / delta) % 6;
|
|
368
|
+
else if (max === g / 255)
|
|
369
|
+
h = (b / 255 - r / 255) / delta + 2;
|
|
370
|
+
else
|
|
371
|
+
h = (r / 255 - g / 255) / delta + 4;
|
|
372
|
+
const degrees = h * 60;
|
|
373
|
+
return degrees < 0 ? degrees + 360 : degrees;
|
|
374
|
+
}
|
|
375
|
+
/** Builds a PanResponder that reports the fraction (0–1) across a track. */
|
|
376
|
+
function makeTrackResponder(onFraction, PanResponder, trackRef) {
|
|
377
|
+
if (!PanResponder?.create)
|
|
378
|
+
return null;
|
|
379
|
+
return PanResponder.create({
|
|
380
|
+
onStartShouldSetPanResponder: () => true,
|
|
381
|
+
onMoveShouldSetPanResponder: () => true,
|
|
382
|
+
onPanResponderGrant: (event) => {
|
|
383
|
+
const fraction = fractionAt(event, 100);
|
|
384
|
+
if (fraction !== null)
|
|
385
|
+
onFraction(fraction);
|
|
386
|
+
},
|
|
387
|
+
onPanResponderMove: (event) => {
|
|
388
|
+
const fraction = fractionAt(event, 100);
|
|
389
|
+
if (fraction !== null)
|
|
390
|
+
onFraction(fraction);
|
|
391
|
+
},
|
|
392
|
+
onPanResponderTerminationRequest: () => false,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
/** The fraction of the track under a touch, from the touch's X. */
|
|
396
|
+
function fractionAt(event, fallbackWidth) {
|
|
397
|
+
const x = event?.nativeEvent?.locationX;
|
|
398
|
+
const width = event?.nativeEvent?.layoutMeasurement?.width ?? fallbackWidth;
|
|
399
|
+
if (typeof x !== "number" || typeof width !== "number" || width <= 0)
|
|
400
|
+
return null;
|
|
401
|
+
return Math.max(0, Math.min(1, x / width));
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* A type-to-search select.
|
|
405
|
+
*
|
|
406
|
+
* The Input patterns (real TextInput, themed placeholder, `value`/`defaultValue`)
|
|
407
|
+
* open a Menu-style glass dropdown whose list filters as the user types — every
|
|
408
|
+
* keystroke re-filters the options, so the visible set genuinely shrinks, never
|
|
409
|
+
* a list that stays put and pretends to search.
|
|
410
|
+
*
|
|
411
|
+
* The filter is a case-insensitive substring match on label and description. An
|
|
412
|
+
* empty result shows an explicit empty row, so the user sees a search that found
|
|
413
|
+
* nothing rather than a list that silently went blank. The dropdown stays open
|
|
414
|
+
* until an option is picked or the field loses focus.
|
|
415
|
+
*/
|
|
416
|
+
exports.Combobox = (0, react_1.forwardRef)(function Combobox({ options, value, defaultValue, onChange, label, placeholder = "Search…", disabled = false, onEmpty, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
417
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
418
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
419
|
+
const { View, TextInput, Text: RNText, Pressable } = (0, primitives_1.primitives)();
|
|
420
|
+
const [internalValue, setInternalValue] = (0, react_1.useState)(defaultValue ?? "");
|
|
421
|
+
const [query, setQuery] = (0, react_1.useState)("");
|
|
422
|
+
const selected = value !== undefined ? value : internalValue;
|
|
423
|
+
const selectedLabel = (options ?? []).find((option) => option.value === selected)?.label ?? "";
|
|
424
|
+
const setValue = (next) => {
|
|
425
|
+
if (disabled)
|
|
426
|
+
return;
|
|
427
|
+
if (value === undefined)
|
|
428
|
+
setInternalValue(next);
|
|
429
|
+
onChange?.(next);
|
|
430
|
+
};
|
|
431
|
+
// Filter as the user types.
|
|
432
|
+
// An option list that has not loaded yet is empty, not a crash: a combobox
|
|
433
|
+
// is frequently rendered before its options arrive.
|
|
434
|
+
const available = options ?? [];
|
|
435
|
+
const needle = query.trim().toLowerCase();
|
|
436
|
+
const matches = needle.length === 0
|
|
437
|
+
? available
|
|
438
|
+
: available.filter((option) => option.label.toLowerCase().includes(needle) ||
|
|
439
|
+
(option.description ?? "").toLowerCase().includes(needle));
|
|
440
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, style: { ...style }, children: [(0, jsx_runtime_1.jsx)(TextInput, { value: query, onChangeText: (text) => setQuery(text), placeholder: placeholder, accessibilityLabel: label ?? placeholder, accessibilityState: { disabled }, editable: !disabled, style: {
|
|
441
|
+
borderRadius: tokens_1.radii.md,
|
|
442
|
+
paddingHorizontal: 12,
|
|
443
|
+
paddingVertical: 8,
|
|
444
|
+
fontSize: 16,
|
|
445
|
+
color: theme.foreground,
|
|
446
|
+
backgroundColor: disabled ? theme.muted : theme.fieldWash,
|
|
447
|
+
} }), query.length > 0 ? ((0, jsx_runtime_1.jsx)(View, { style: { marginTop: 6, borderRadius: tokens_1.radii.md, overflow: "hidden", backgroundColor: disabled ? theme.muted : theme.glass }, children: matches.length === 0 ? ((0, jsx_runtime_1.jsx)(View, { style: { paddingHorizontal: 12, paddingVertical: 10 }, children: (0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 14, color: theme.muted }, children: "No matches" }) })) : (matches.map((option, index) => {
|
|
448
|
+
const isSelected = option.value === selected;
|
|
449
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: option.label, accessibilityState: { selected: isSelected }, onPress: () => {
|
|
450
|
+
setValue(option.value);
|
|
451
|
+
setQuery("");
|
|
452
|
+
}, style: { flexDirection: "row", alignItems: "center", paddingHorizontal: 12, paddingVertical: 10, backgroundColor: isSelected ? theme.glassActive : "transparent" }, children: (0, jsx_runtime_1.jsxs)(View, { style: { flex: 1 }, children: [(0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 15, color: theme.foreground }, children: option.label }), option.description ? ((0, jsx_runtime_1.jsx)(RNText, { style: { fontSize: 12, color: theme.muted }, numberOfLines: 1, children: option.description })) : null] }) }, `${option.value}-${index}`));
|
|
453
|
+
})) })) : null] }));
|
|
454
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Message = exports.MessageAttachment = exports.MessageBubble = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const Display_1 = require("./Display");
|
|
7
|
+
const tokens_1 = require("./internal/tokens");
|
|
8
|
+
const primitives_1 = require("./internal/primitives");
|
|
9
|
+
const motion_1 = require("./internal/motion");
|
|
10
|
+
/**
|
|
11
|
+
* One message's bubble.
|
|
12
|
+
*
|
|
13
|
+
* Both directions are flat tints, not glass: a chat transcript is a long
|
|
14
|
+
* scrolling list, and glass under every line would stack translucent surfaces
|
|
15
|
+
* over each other and over the conversation behind them. The glass in a chat
|
|
16
|
+
* belongs to the composer, which floats over the transcript — so
|
|
17
|
+
* `NativeAIInput` is glass and the bubbles are not.
|
|
18
|
+
*
|
|
19
|
+
* Incoming messages take the theme's wash; outgoing take `glassActive`, the
|
|
20
|
+
* same tint the library uses for any selected surface, so a transcript reads
|
|
21
|
+
* consistently with the rest of Glacia.
|
|
22
|
+
*/
|
|
23
|
+
exports.MessageBubble = (0, react_1.forwardRef)(function MessageBubble({ outgoing = false, children, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
24
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
25
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
26
|
+
const { View } = (0, primitives_1.primitives)();
|
|
27
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, style: {
|
|
28
|
+
alignSelf: outgoing ? "flex-end" : "flex-start",
|
|
29
|
+
maxWidth: "82%",
|
|
30
|
+
paddingHorizontal: 12,
|
|
31
|
+
paddingVertical: 8,
|
|
32
|
+
borderRadius: tokens_1.radii.lg,
|
|
33
|
+
backgroundColor: outgoing ? theme.glassActive : theme.wash,
|
|
34
|
+
...style,
|
|
35
|
+
}, ...props, children: children }));
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* A file chip for a message.
|
|
39
|
+
*
|
|
40
|
+
* A flat, bordered chip rather than a glass one, for the same reason the
|
|
41
|
+
* bubbles are flat: it sits inside a bubble or beside one, and glass inside
|
|
42
|
+
* glass is never allowed. The size is a caller-formatted string — byte
|
|
43
|
+
* formatting belongs to the app's locale, not to a component library.
|
|
44
|
+
*/
|
|
45
|
+
exports.MessageAttachment = (0, react_1.forwardRef)(function MessageAttachment({ name, size, icon, onPress, disabled = false, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
46
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
47
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
48
|
+
const { View, Text, Pressable } = (0, primitives_1.primitives)();
|
|
49
|
+
const body = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [icon ? (0, jsx_runtime_1.jsx)(View, { style: { marginRight: 8 }, children: icon }) : null, (0, jsx_runtime_1.jsxs)(View, { style: { flexShrink: 1 }, children: [(0, jsx_runtime_1.jsx)(Text, { numberOfLines: 1, style: { fontSize: 14, color: theme.foreground }, children: name }), size ? ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 11, color: theme.muted }, children: size })) : null] })] }));
|
|
50
|
+
const chipStyle = {
|
|
51
|
+
flexDirection: "row",
|
|
52
|
+
alignItems: "center",
|
|
53
|
+
paddingHorizontal: 10,
|
|
54
|
+
paddingVertical: 7,
|
|
55
|
+
borderRadius: tokens_1.radii.md,
|
|
56
|
+
backgroundColor: theme.wash,
|
|
57
|
+
borderWidth: 0.5,
|
|
58
|
+
borderColor: theme.separator,
|
|
59
|
+
opacity: disabled ? 0.38 : 1,
|
|
60
|
+
...style,
|
|
61
|
+
};
|
|
62
|
+
if (!onPress) {
|
|
63
|
+
return ((0, jsx_runtime_1.jsx)(View, { ref: ref, testID: testID, accessibilityRole: "text", accessibilityLabel: size ? `${name}, ${size}` : name, style: chipStyle, ...props, children: body }));
|
|
64
|
+
}
|
|
65
|
+
return ((0, jsx_runtime_1.jsx)(Pressable, { ref: ref, testID: testID, accessibilityRole: "button", accessibilityLabel: size ? `${name}, ${size}` : name, accessibilityState: { disabled }, disabled: disabled, onPress: onPress, style: chipStyle, ...props, children: body }));
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* A whole message: who sent it, when, and what they said.
|
|
69
|
+
*
|
|
70
|
+
* The row every chat screen builds by hand — an avatar, a name and time line,
|
|
71
|
+
* and the content under it. Grouping it means the alignment, spacing and
|
|
72
|
+
* accessibility grouping are decided once: the row is announced as a single
|
|
73
|
+
* message (name, time, content) rather than as three unrelated pieces of text.
|
|
74
|
+
*/
|
|
75
|
+
exports.Message = (0, react_1.forwardRef)(function Message({ name, time, avatar = false, outgoing = false, children, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
76
|
+
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
77
|
+
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
78
|
+
const { View, Text } = (0, primitives_1.primitives)();
|
|
79
|
+
const meta = [name, time].filter(Boolean).join(", ");
|
|
80
|
+
return ((0, jsx_runtime_1.jsxs)(View, { ref: ref, testID: testID, accessibilityRole: "text", accessibilityLabel: meta || undefined, style: {
|
|
81
|
+
flexDirection: outgoing ? "row-reverse" : "row",
|
|
82
|
+
alignItems: "flex-end",
|
|
83
|
+
gap: 8,
|
|
84
|
+
paddingHorizontal: 4,
|
|
85
|
+
paddingVertical: 4,
|
|
86
|
+
...style,
|
|
87
|
+
}, ...props, children: [avatar ? ((0, jsx_runtime_1.jsx)(Display_1.Avatar, { name: name ?? "", size: "sm", isDark: isDark })) : null, (0, jsx_runtime_1.jsxs)(View, { style: { flexShrink: 1, alignItems: outgoing ? "flex-end" : "flex-start", gap: 2 }, children: [name || time ? ((0, jsx_runtime_1.jsxs)(View, { style: { flexDirection: "row", alignItems: "center", gap: 6 }, children: [name ? ((0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 12, fontWeight: "600", color: theme.foreground }, children: name })) : null, time ? (0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 11, color: theme.muted }, children: time }) : null] })) : null, children] })] }));
|
|
88
|
+
});
|
package/lib/module/Overlays.js
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Drawer = exports.Sheet = exports.Menu = void 0;
|
|
4
4
|
exports.anchorPopover = anchorPopover;
|
|
5
|
+
exports.resolveSnapPoint = resolveSnapPoint;
|
|
6
|
+
exports.nearestSnapPoint = nearestSnapPoint;
|
|
5
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
8
|
const react_1 = require("react");
|
|
7
9
|
const Glass_1 = require("./Glass");
|
|
8
10
|
const tokens_1 = require("./internal/tokens");
|
|
9
11
|
const primitives_1 = require("./internal/primitives");
|
|
10
12
|
const motion_1 = require("./internal/motion");
|
|
13
|
+
const haptics_1 = require("./internal/haptics");
|
|
11
14
|
/**
|
|
12
15
|
* Registers Android's hardware back while an overlay is open.
|
|
13
16
|
*
|
|
@@ -85,10 +88,38 @@ function AnimatedScale({ scale, children }) {
|
|
|
85
88
|
* specialisation of this shape; Sheet is for arbitrary content — a form, a
|
|
86
89
|
* calendar, a detail panel.
|
|
87
90
|
*/
|
|
88
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Turns a snap point into a pixel height.
|
|
93
|
+
*
|
|
94
|
+
* A number under 1 is a fraction of the window; anything else is points. The
|
|
95
|
+
* result is clamped so a sheet can never be taller than the space it has.
|
|
96
|
+
*/
|
|
97
|
+
function resolveSnapPoint(point, windowHeight) {
|
|
98
|
+
const height = point > 0 && point < 1 ? point * windowHeight : point;
|
|
99
|
+
return Math.max(0, Math.min(height, windowHeight));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Picks the snap point nearest to where the user let go.
|
|
103
|
+
*
|
|
104
|
+
* `height` is how tall the sheet currently is. Ties go to the smaller sheet,
|
|
105
|
+
* so a small flick does not jump the panel to full height.
|
|
106
|
+
*/
|
|
107
|
+
function nearestSnapPoint(heights, height) {
|
|
108
|
+
let best = 0;
|
|
109
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
110
|
+
heights.forEach((candidate, index) => {
|
|
111
|
+
const distance = Math.abs(candidate - height);
|
|
112
|
+
if (distance < bestDistance) {
|
|
113
|
+
bestDistance = distance;
|
|
114
|
+
best = index;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return best;
|
|
118
|
+
}
|
|
119
|
+
exports.Sheet = (0, react_1.forwardRef)(function Sheet({ open: openProp, defaultOpen = false, onOpenChange, title, children, footer, dismissOnBackdropPress = true, showHandle = true, snapPoints, initialSnapIndex = 0, snapIndex: snapIndexProp, onSnapIndexChange, dismissOnSnapToBottom = false, draggable = true, haptics = true, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
89
120
|
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
90
121
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
91
|
-
const { View, Text: RNText, Pressable, Modal } = (0, primitives_1.primitives)();
|
|
122
|
+
const { View, Text: RNText, Pressable, Modal, PanResponder, useWindowDimensions } = (0, primitives_1.primitives)();
|
|
92
123
|
const [internalOpen, setInternalOpen] = (0, react_1.useState)(defaultOpen);
|
|
93
124
|
const open = openProp !== undefined ? openProp : internalOpen;
|
|
94
125
|
const setOpen = (0, react_1.useCallback)((next) => {
|
|
@@ -98,17 +129,109 @@ exports.Sheet = (0, react_1.forwardRef)(function Sheet({ open: openProp, default
|
|
|
98
129
|
}, [openProp, onOpenChange]);
|
|
99
130
|
const dismiss = (0, react_1.useCallback)(() => setOpen(false), [setOpen]);
|
|
100
131
|
useBackDismiss(open, dismiss);
|
|
101
|
-
//
|
|
132
|
+
// Snap points in pixels, smallest first so index 0 is the shortest sheet.
|
|
133
|
+
const windowHeight = useWindowDimensions?.().height ?? 800;
|
|
134
|
+
const heights = (0, react_1.useMemo)(() => {
|
|
135
|
+
if (!snapPoints || snapPoints.length === 0)
|
|
136
|
+
return [];
|
|
137
|
+
return snapPoints.map((point) => resolveSnapPoint(point, windowHeight)).sort((a, b) => a - b);
|
|
138
|
+
}, [snapPoints, windowHeight]);
|
|
139
|
+
const [internalSnap, setInternalSnap] = (0, react_1.useState)(initialSnapIndex);
|
|
140
|
+
const snapIndex = snapIndexProp !== undefined ? snapIndexProp : internalSnap;
|
|
141
|
+
const activeHeight = heights.length > 0 ? heights[Math.min(snapIndex, heights.length - 1)] : null;
|
|
142
|
+
// Drag offset in pixels: 0 is resting at the active snap point, positive is
|
|
143
|
+
// dragged down. It resets to 0 after a release, because the settle either
|
|
144
|
+
// changes the snap index or dismisses.
|
|
145
|
+
const dragRef = (0, react_1.useRef)(0);
|
|
146
|
+
const [drag, setDrag] = (0, react_1.useState)(0);
|
|
102
147
|
const { value: rise, animated } = (0, motion_1.useSpring)(open ? 1 : 0, "gentle");
|
|
103
|
-
const
|
|
104
|
-
|
|
148
|
+
const slideIn = animated ? rise.interpolate({ inputRange: [0, 1], outputRange: [420, 0] }) : 0;
|
|
149
|
+
const heightsRef = (0, react_1.useRef)(heights);
|
|
150
|
+
heightsRef.current = heights;
|
|
151
|
+
const activeHeightRef = (0, react_1.useRef)(activeHeight);
|
|
152
|
+
activeHeightRef.current = activeHeight;
|
|
153
|
+
const snapIndexRef = (0, react_1.useRef)(snapIndex);
|
|
154
|
+
snapIndexRef.current = snapIndex;
|
|
155
|
+
const goToSnap = (0, react_1.useCallback)((index) => {
|
|
156
|
+
if (snapIndexProp === undefined)
|
|
157
|
+
setInternalSnap(index);
|
|
158
|
+
onSnapIndexChange?.(index);
|
|
159
|
+
if (haptics)
|
|
160
|
+
(0, haptics_1.hapticSelection)();
|
|
161
|
+
}, [snapIndexProp, onSnapIndexChange, haptics]);
|
|
162
|
+
/**
|
|
163
|
+
* The release decision.
|
|
164
|
+
*
|
|
165
|
+
* Below the lowest snap point the sheet dismisses when allowed, otherwise it
|
|
166
|
+
* snaps back; anywhere else it settles at the nearest point, with a fast
|
|
167
|
+
* downward flick counting as a step towards the smaller sheet.
|
|
168
|
+
*/
|
|
169
|
+
const release = (0, react_1.useCallback)((dy, vy) => {
|
|
170
|
+
const list = heightsRef.current;
|
|
171
|
+
const current = list[snapIndexRef.current] ?? activeHeightRef.current ?? 0;
|
|
172
|
+
const restingAfterDrag = current - dy;
|
|
173
|
+
if (list.length === 0) {
|
|
174
|
+
// No snap points: a decisive downward drag dismisses.
|
|
175
|
+
if (dy > 120 || vy > 0.8)
|
|
176
|
+
dismiss();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const lowest = list[0];
|
|
180
|
+
const belowLowest = restingAfterDrag < lowest - 40;
|
|
181
|
+
if (belowLowest && dismissOnSnapToBottom) {
|
|
182
|
+
dismiss();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
// A fast flick moves one step in its direction before distance decides.
|
|
186
|
+
let index = nearestSnapPoint(list, restingAfterDrag);
|
|
187
|
+
if (vy > 0.5)
|
|
188
|
+
index = Math.max(0, Math.min(index, snapIndexRef.current - 1));
|
|
189
|
+
if (vy < -0.5)
|
|
190
|
+
index = Math.max(index, Math.min(snapIndexRef.current + 1, list.length - 1));
|
|
191
|
+
if (index !== snapIndexRef.current)
|
|
192
|
+
goToSnap(index);
|
|
193
|
+
}, [dismiss, dismissOnSnapToBottom, goToSnap]);
|
|
194
|
+
const panResponder = (0, react_1.useMemo)(() => {
|
|
195
|
+
if (!draggable || !PanResponder?.create)
|
|
196
|
+
return null;
|
|
197
|
+
return PanResponder.create({
|
|
198
|
+
// Vertical drags belong to the sheet; horizontal ones are left alone.
|
|
199
|
+
onStartShouldSetPanResponder: () => false,
|
|
200
|
+
onMoveShouldSetPanResponder: (_event, gesture) => Math.abs(gesture.dy) > Math.abs(gesture.dx) && Math.abs(gesture.dy) > 6,
|
|
201
|
+
onPanResponderGrant: () => {
|
|
202
|
+
dragRef.current = 0;
|
|
203
|
+
},
|
|
204
|
+
onPanResponderMove: (_event, gesture) => {
|
|
205
|
+
// Dragging up past the tallest point has nowhere to go; clamp at 0.
|
|
206
|
+
const next = Math.max(-40, gesture.dy);
|
|
207
|
+
dragRef.current = next;
|
|
208
|
+
setDrag(next);
|
|
209
|
+
},
|
|
210
|
+
onPanResponderRelease: (_event, gesture) => {
|
|
211
|
+
release(gesture.dy, gesture.vy);
|
|
212
|
+
dragRef.current = 0;
|
|
213
|
+
setDrag(0);
|
|
214
|
+
},
|
|
215
|
+
onPanResponderTerminate: () => {
|
|
216
|
+
dragRef.current = 0;
|
|
217
|
+
setDrag(0);
|
|
218
|
+
},
|
|
219
|
+
onPanResponderTerminationRequest: () => false,
|
|
220
|
+
});
|
|
221
|
+
}, [draggable, PanResponder, release]);
|
|
222
|
+
// Reduce Motion is honoured by useSpring: when it is on, `animated` is false
|
|
223
|
+
// and the panel is already in position, so the sheet opens and snaps without
|
|
224
|
+
// a transition.
|
|
225
|
+
const translateY = drag !== 0 ? drag : animated ? slideIn : 0;
|
|
226
|
+
const panel = ((0, jsx_runtime_1.jsx)(SheetPanel, { title: title, footer: footer, showHandle: showHandle, isDark: isDark, testID: testID, style: style, height: activeHeight, children: children }));
|
|
227
|
+
return ((0, jsx_runtime_1.jsx)(Modal, { visible: open, transparent: true, animationType: "fade", onRequestClose: dismiss, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Close sheet", onPress: dismissOnBackdropPress ? dismiss : undefined, style: { flex: 1, justifyContent: "flex-end", backgroundColor: theme.scrim }, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "none", onPress: () => { }, style: { width: "100%" }, ...(panResponder ? panResponder.panHandlers : {}), children: animated || drag !== 0 ? ((0, jsx_runtime_1.jsx)(SheetRise, { translateY: translateY, children: panel })) : (panel) }) }) }));
|
|
105
228
|
});
|
|
106
229
|
function SheetRise({ translateY, children }) {
|
|
107
230
|
const { Animated } = (0, primitives_1.primitives)();
|
|
108
231
|
return (0, jsx_runtime_1.jsx)(Animated.View, { style: { transform: [{ translateY }] }, children: children });
|
|
109
232
|
}
|
|
110
233
|
/** The panel itself: a glass surface with a handle, a title and a footer. */
|
|
111
|
-
function SheetPanel({ title, footer, showHandle, isDark, testID, style, children, }) {
|
|
234
|
+
function SheetPanel({ title, footer, showHandle, isDark, testID, style, height, children, }) {
|
|
112
235
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
113
236
|
const { View, Text: RNText } = (0, primitives_1.primitives)();
|
|
114
237
|
return ((0, jsx_runtime_1.jsxs)(Glass_1.Glass, { effect: "regular", isDark: isDark, testID: testID, style: {
|
|
@@ -117,7 +240,8 @@ function SheetPanel({ title, footer, showHandle, isDark, testID, style, children
|
|
|
117
240
|
borderBottomLeftRadius: 0,
|
|
118
241
|
borderBottomRightRadius: 0,
|
|
119
242
|
paddingBottom: 20,
|
|
120
|
-
|
|
243
|
+
// A snap point fixes the height; without one the panel is natural.
|
|
244
|
+
...(height != null ? { height } : { maxHeight: 560 }),
|
|
121
245
|
...style,
|
|
122
246
|
}, children: [showHandle ? ((0, jsx_runtime_1.jsx)(View, { style: { alignItems: "center", paddingTop: 8, paddingBottom: 4 }, children: (0, jsx_runtime_1.jsx)(View, { accessibilityElementsHidden: true,
|
|
123
247
|
// A capsule: the radius is half the handle's own height.
|
|
@@ -129,11 +253,16 @@ function SheetPanel({ title, footer, showHandle, isDark, testID, style, children
|
|
|
129
253
|
* The same overlay discipline as Sheet — scrim, spring slide, Android back —
|
|
130
254
|
* but anchored to a side edge, with a square panel that runs the full height.
|
|
131
255
|
* The caller supplies the content, typically a List.
|
|
256
|
+
*
|
|
257
|
+
* Dragging the panel towards its own edge follows the finger; releasing past
|
|
258
|
+
* the halfway point, or with enough outward velocity, closes it, and a drag
|
|
259
|
+
* that stays inside springs it back open. Reduce Motion is honoured: with it
|
|
260
|
+
* on, the drawer appears and disappears without sliding.
|
|
132
261
|
*/
|
|
133
|
-
exports.Drawer = (0, react_1.forwardRef)(function Drawer({ open: openProp, defaultOpen = false, onOpenChange, side = "left", width = 280, children, dismissOnBackdropPress = true, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
262
|
+
exports.Drawer = (0, react_1.forwardRef)(function Drawer({ open: openProp, defaultOpen = false, onOpenChange, side = "left", width = 280, children, dismissOnBackdropPress = true, draggable = true, haptics = true, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
134
263
|
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
135
264
|
const theme = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
136
|
-
const { View, Pressable, Modal } = (0, primitives_1.primitives)();
|
|
265
|
+
const { View, Pressable, Modal, PanResponder } = (0, primitives_1.primitives)();
|
|
137
266
|
const [internalOpen, setInternalOpen] = (0, react_1.useState)(defaultOpen);
|
|
138
267
|
const open = openProp !== undefined ? openProp : internalOpen;
|
|
139
268
|
const setOpen = (0, react_1.useCallback)((next) => {
|
|
@@ -145,9 +274,42 @@ exports.Drawer = (0, react_1.forwardRef)(function Drawer({ open: openProp, defau
|
|
|
145
274
|
useBackDismiss(open, dismiss);
|
|
146
275
|
const { value: slide, animated } = (0, motion_1.useSpring)(open ? 1 : 0, "gentle");
|
|
147
276
|
// Slide in from off-screen: negative from the left, positive from the right.
|
|
148
|
-
const
|
|
277
|
+
const slideIn = animated
|
|
149
278
|
? slide.interpolate({ inputRange: [0, 1], outputRange: [side === "left" ? -width : width, 0] })
|
|
150
279
|
: 0;
|
|
280
|
+
// The drag is measured in the drawer's own closing direction, so a drag
|
|
281
|
+
// towards the anchored edge is always positive whichever side it is on.
|
|
282
|
+
const [drag, setDrag] = (0, react_1.useState)(0);
|
|
283
|
+
const panResponder = (0, react_1.useMemo)(() => {
|
|
284
|
+
if (!draggable || !PanResponder?.create)
|
|
285
|
+
return null;
|
|
286
|
+
const outward = side === "left" ? -1 : 1;
|
|
287
|
+
return PanResponder.create({
|
|
288
|
+
onStartShouldSetPanResponder: () => false,
|
|
289
|
+
onMoveShouldSetPanResponder: (_event, gesture) =>
|
|
290
|
+
// Only a horizontal drag towards the edge is ours; the other way has
|
|
291
|
+
// nowhere to go and should not fight content inside the panel.
|
|
292
|
+
Math.abs(gesture.dx) > Math.abs(gesture.dy) && gesture.dx * outward > 6,
|
|
293
|
+
onPanResponderMove: (_event, gesture) => {
|
|
294
|
+
setDrag(Math.max(0, gesture.dx * outward));
|
|
295
|
+
},
|
|
296
|
+
onPanResponderRelease: (_event, gesture) => {
|
|
297
|
+
const travelled = Math.max(0, gesture.dx * outward);
|
|
298
|
+
const thrown = gesture.vx * outward > 0.4;
|
|
299
|
+
setDrag(0);
|
|
300
|
+
if (travelled > width / 2 || thrown) {
|
|
301
|
+
if (haptics)
|
|
302
|
+
(0, haptics_1.hapticSelection)();
|
|
303
|
+
dismiss();
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
onPanResponderTerminate: () => setDrag(0),
|
|
307
|
+
onPanResponderTerminationRequest: () => false,
|
|
308
|
+
});
|
|
309
|
+
// `dismiss` is stable; the gesture only needs rebuilding when its shape
|
|
310
|
+
// (side or width) changes.
|
|
311
|
+
}, [draggable, PanResponder, side, width, haptics, dismiss]);
|
|
312
|
+
const translateX = drag !== 0 ? (side === "left" ? -drag : drag) : animated ? slideIn : 0;
|
|
151
313
|
const panel = ((0, jsx_runtime_1.jsx)(Glass_1.Glass, { effect: "regular", isDark: isDark, testID: testID, style: {
|
|
152
314
|
width,
|
|
153
315
|
height: "100%",
|
|
@@ -158,7 +320,7 @@ exports.Drawer = (0, react_1.forwardRef)(function Drawer({ open: openProp, defau
|
|
|
158
320
|
return ((0, jsx_runtime_1.jsx)(Modal, { visible: open, transparent: true, animationType: "fade", onRequestClose: dismiss, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "button", accessibilityLabel: "Close drawer", onPress: dismissOnBackdropPress ? dismiss : undefined, style: { flex: 1, backgroundColor: theme.scrim }, children: (0, jsx_runtime_1.jsx)(View, { style: {
|
|
159
321
|
flex: 1,
|
|
160
322
|
alignItems: side === "left" ? "flex-start" : "flex-end",
|
|
161
|
-
}, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "none", onPress: () => { }, style: { height: "100%" }, children: animated ? (0, jsx_runtime_1.jsx)(DrawerSlide, { translateX: translateX, children: panel }) : panel }) }) }) }));
|
|
323
|
+
}, children: (0, jsx_runtime_1.jsx)(Pressable, { accessibilityRole: "none", onPress: () => { }, style: { height: "100%" }, ...(panResponder ? panResponder.panHandlers : {}), children: animated || drag !== 0 ? (0, jsx_runtime_1.jsx)(DrawerSlide, { translateX: translateX, children: panel }) : panel }) }) }) }));
|
|
162
324
|
});
|
|
163
325
|
function DrawerSlide({ translateX, children }) {
|
|
164
326
|
const { Animated } = (0, primitives_1.primitives)();
|
|
@@ -7,6 +7,7 @@ const Glass_1 = require("./Glass");
|
|
|
7
7
|
const tokens_1 = require("./internal/tokens");
|
|
8
8
|
const primitives_1 = require("./internal/primitives");
|
|
9
9
|
const motion_1 = require("./internal/motion");
|
|
10
|
+
const haptics_1 = require("./internal/haptics");
|
|
10
11
|
const SEGMENT_HEIGHT = 30;
|
|
11
12
|
/**
|
|
12
13
|
* A row of mutually exclusive segments on one glass container.
|
|
@@ -15,7 +16,7 @@ const SEGMENT_HEIGHT = 30;
|
|
|
15
16
|
* The pill's colours come from the theme tokens, so it reads correctly in both
|
|
16
17
|
* light and dark instead of assuming a white-on-light palette.
|
|
17
18
|
*/
|
|
18
|
-
exports.SegmentedControl = (0, react_1.forwardRef)(function SegmentedControl({ values, selectedIndex: selectedProp, defaultIndex = 0, onValueChange, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
19
|
+
exports.SegmentedControl = (0, react_1.forwardRef)(function SegmentedControl({ values, selectedIndex: selectedProp, defaultIndex = 0, onValueChange, haptics = true, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
19
20
|
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
20
21
|
const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
21
22
|
const { View, Text, Pressable, Animated } = (0, primitives_1.primitives)();
|
|
@@ -26,6 +27,9 @@ exports.SegmentedControl = (0, react_1.forwardRef)(function SegmentedControl({ v
|
|
|
26
27
|
// the first segment, values.length - 1 the last.
|
|
27
28
|
const { value: slide, animated } = (0, motion_1.useSpring)(safeIndex, "snappy");
|
|
28
29
|
const handleSelect = (index) => {
|
|
30
|
+
// Only a change ticks: re-pressing the current segment is not a selection.
|
|
31
|
+
if (haptics && index !== safeIndex)
|
|
32
|
+
(0, haptics_1.hapticSelection)();
|
|
29
33
|
if (selectedProp === undefined)
|
|
30
34
|
setInternalIndex(index);
|
|
31
35
|
const val = values[index];
|
package/lib/module/Slider.js
CHANGED
|
@@ -8,6 +8,7 @@ const Glass_1 = require("./Glass");
|
|
|
8
8
|
const tokens_1 = require("./internal/tokens");
|
|
9
9
|
const primitives_2 = require("./internal/primitives");
|
|
10
10
|
const motion_1 = require("./internal/motion");
|
|
11
|
+
const haptics_1 = require("./internal/haptics");
|
|
11
12
|
const TRACK_HEIGHT = 8;
|
|
12
13
|
const THUMB = 22;
|
|
13
14
|
const CONTAINER_HEIGHT = 40;
|
|
@@ -32,7 +33,7 @@ function quantize(value, min, max, step) {
|
|
|
32
33
|
* sliders are not used, so the control looks and behaves the same on every
|
|
33
34
|
* platform; only the glass material changes.
|
|
34
35
|
*/
|
|
35
|
-
exports.Slider = (0, react_1.forwardRef)(function Slider({ value: valueProp, defaultValue = 50, min = 0, max = 100, step = 1, onValueChange, disabled = false, accessibilityLabel, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
36
|
+
exports.Slider = (0, react_1.forwardRef)(function Slider({ value: valueProp, defaultValue = 50, min = 0, max = 100, step = 1, onValueChange, disabled = false, haptics = true, accessibilityLabel, style, isDark: isDarkProp, testID, ...props }, ref) {
|
|
36
37
|
const isDark = (0, motion_1.useIsDark)(isDarkProp);
|
|
37
38
|
const themeColors = isDark ? tokens_1.colors.dark : tokens_1.colors.light;
|
|
38
39
|
const { View, Pressable, PanResponder } = (0, primitives_2.primitives)();
|
|
@@ -55,8 +56,12 @@ exports.Slider = (0, react_1.forwardRef)(function Slider({ value: valueProp, def
|
|
|
55
56
|
return quantize(min + ratio * (max - min), min, max, step);
|
|
56
57
|
}, [max, min, step]);
|
|
57
58
|
const report = (next) => {
|
|
59
|
+
// Only a real step change ticks: a drag that stays inside one step is not
|
|
60
|
+
// a selection, and reporting the same value twice must not buzz twice.
|
|
58
61
|
if (next === valueRef.current)
|
|
59
62
|
return;
|
|
63
|
+
if (haptics)
|
|
64
|
+
(0, haptics_1.hapticSelection)();
|
|
60
65
|
valueRef.current = next;
|
|
61
66
|
if (valueProp === undefined)
|
|
62
67
|
setInternalValue(next);
|