@oxy.so/bloom 7.10.0 → 7.12.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.
Files changed (59) hide show
  1. package/docs/adoption-matrix.mdx +1 -1
  2. package/docs/button.mdx +9 -1
  3. package/docs/carousel.mdx +37 -1
  4. package/docs/zoomable-media-gallery.mdx +16 -0
  5. package/lib/commonjs/button/Button.js +2 -1
  6. package/lib/commonjs/button/Button.js.map +1 -1
  7. package/lib/commonjs/button/Button.web.js +3 -2
  8. package/lib/commonjs/button/Button.web.js.map +1 -1
  9. package/lib/commonjs/button/shared.js +28 -1
  10. package/lib/commonjs/button/shared.js.map +1 -1
  11. package/lib/commonjs/carousel/Carousel.js +154 -14
  12. package/lib/commonjs/carousel/Carousel.js.map +1 -1
  13. package/lib/commonjs/zoomable-media-gallery/ZoomableMediaGalleryBase.js +59 -15
  14. package/lib/commonjs/zoomable-media-gallery/ZoomableMediaGalleryBase.js.map +1 -1
  15. package/lib/module/button/Button.js +2 -1
  16. package/lib/module/button/Button.js.map +1 -1
  17. package/lib/module/button/Button.web.js +3 -2
  18. package/lib/module/button/Button.web.js.map +1 -1
  19. package/lib/module/button/shared.js +28 -1
  20. package/lib/module/button/shared.js.map +1 -1
  21. package/lib/module/carousel/Carousel.js +155 -15
  22. package/lib/module/carousel/Carousel.js.map +1 -1
  23. package/lib/module/zoomable-media-gallery/ZoomableMediaGalleryBase.js +59 -15
  24. package/lib/module/zoomable-media-gallery/ZoomableMediaGalleryBase.js.map +1 -1
  25. package/lib/typescript/commonjs/button/Button.d.ts.map +1 -1
  26. package/lib/typescript/commonjs/button/Button.web.d.ts.map +1 -1
  27. package/lib/typescript/commonjs/button/shared.d.ts +1 -1
  28. package/lib/typescript/commonjs/button/shared.d.ts.map +1 -1
  29. package/lib/typescript/commonjs/button/types.d.ts +2 -0
  30. package/lib/typescript/commonjs/button/types.d.ts.map +1 -1
  31. package/lib/typescript/commonjs/carousel/Carousel.d.ts +1 -1
  32. package/lib/typescript/commonjs/carousel/Carousel.d.ts.map +1 -1
  33. package/lib/typescript/commonjs/carousel/types.d.ts +9 -1
  34. package/lib/typescript/commonjs/carousel/types.d.ts.map +1 -1
  35. package/lib/typescript/commonjs/zoomable-media-gallery/ZoomableMediaGalleryBase.d.ts.map +1 -1
  36. package/lib/typescript/commonjs/zoomable-media-gallery/types.d.ts +4 -0
  37. package/lib/typescript/commonjs/zoomable-media-gallery/types.d.ts.map +1 -1
  38. package/lib/typescript/module/button/Button.d.ts.map +1 -1
  39. package/lib/typescript/module/button/Button.web.d.ts.map +1 -1
  40. package/lib/typescript/module/button/shared.d.ts +1 -1
  41. package/lib/typescript/module/button/shared.d.ts.map +1 -1
  42. package/lib/typescript/module/button/types.d.ts +2 -0
  43. package/lib/typescript/module/button/types.d.ts.map +1 -1
  44. package/lib/typescript/module/carousel/Carousel.d.ts +1 -1
  45. package/lib/typescript/module/carousel/Carousel.d.ts.map +1 -1
  46. package/lib/typescript/module/carousel/types.d.ts +9 -1
  47. package/lib/typescript/module/carousel/types.d.ts.map +1 -1
  48. package/lib/typescript/module/zoomable-media-gallery/ZoomableMediaGalleryBase.d.ts.map +1 -1
  49. package/lib/typescript/module/zoomable-media-gallery/types.d.ts +4 -0
  50. package/lib/typescript/module/zoomable-media-gallery/types.d.ts.map +1 -1
  51. package/package.json +1 -1
  52. package/src/button/Button.tsx +3 -2
  53. package/src/button/Button.web.tsx +4 -3
  54. package/src/button/shared.ts +20 -0
  55. package/src/button/types.ts +2 -0
  56. package/src/carousel/Carousel.tsx +159 -15
  57. package/src/carousel/types.ts +9 -1
  58. package/src/zoomable-media-gallery/ZoomableMediaGalleryBase.tsx +38 -16
  59. package/src/zoomable-media-gallery/types.ts +4 -0
@@ -150,6 +150,7 @@ const ButtonWebComponent = forwardRef<View, ButtonProps>(function ButtonWebCompo
150
150
  onPressIn,
151
151
  onPressOut,
152
152
  colors,
153
+ material = 'surface',
153
154
  children,
154
155
  disabled = false,
155
156
  pressed: togglePressed,
@@ -203,7 +204,7 @@ const ButtonWebComponent = forwardRef<View, ButtonProps>(function ButtonWebCompo
203
204
  const resolvedId = id ?? `bloom-btn-${reactId}`;
204
205
 
205
206
  const appearance = appearanceProp ?? 'solid';
206
- useSurfaceRefraction(appearance !== 'plain');
207
+ useSurfaceRefraction(material === 'surface' && appearance !== 'plain');
207
208
  const { size, tone } = useBloomAppearance({ size: sizeProp, tone: toneProp }, { size: 'md', tone: 'accent' });
208
209
  const geometry = resolveButtonGeometry(size, textVariant);
209
210
  const isSquare = iconOnly || (icon != null && children == null);
@@ -214,8 +215,8 @@ const ButtonWebComponent = forwardRef<View, ButtonProps>(function ButtonWebCompo
214
215
  const iconSize = typeof iconSizeProp === 'number' && Number.isFinite(iconSizeProp) && iconSizeProp > 0 ? iconSizeProp : isIconVariant ? ICON_BUTTON_ICON_SIZE[size] : geometry.iconSize;
215
216
 
216
217
  const palette = useMemo(
217
- () => isLink && linkTone != null && toneProp == null ? resolveLinkButtonPalette(theme, linkTone) : resolveButtonPalette(appearance, theme, tone, colors, layer.fill),
218
- [appearance, theme, tone, toneProp, isLink, linkTone, colors, layer.fill],
218
+ () => isLink && linkTone != null && toneProp == null ? resolveLinkButtonPalette(theme, linkTone) : resolveButtonPalette(appearance, theme, tone, colors, layer.fill, material),
219
+ [appearance, theme, tone, toneProp, isLink, linkTone, colors, layer.fill, material],
219
220
  );
220
221
  const underlineMode = resolveButtonUnderline(isLink, underline);
221
222
 
@@ -323,9 +323,29 @@ export function resolveCanonicalButtonPalette(
323
323
  tone: BloomTone = 'accent',
324
324
  colors?: { background: string; foreground: string },
325
325
  neutralFill?: string,
326
+ material: 'surface' | 'flat' = 'surface',
326
327
  ): ButtonPalette {
327
328
  const c = theme.colors;
328
329
  const pair = colors ?? resolveBloomColors(c, tone, appearance);
330
+ if (material === 'flat' && appearance !== 'plain') {
331
+ const semantic = resolveBloomColors(c, tone, appearance);
332
+ const alpha = parseRgba(pair.background)?.a ?? 1;
333
+ const state = (amount: number): ButtonStatePaint => ({
334
+ background: amount === 0 || pair.background === 'transparent' ? pair.background
335
+ : withAlpha(mixColor(pair.background, '#000000', amount), alpha),
336
+ foreground: pair.foreground,
337
+ border: appearance === 'outline' ? semantic.border : TRANSPARENT,
338
+ gradient: null, surface: false,
339
+ });
340
+ return {
341
+ rest: state(0), hover: state(0.04), active: state(0.08),
342
+ disabled: { background: appearance === 'outline' ? TRANSPARENT : c.backgroundSecondary,
343
+ foreground: c.textTertiary, border: appearance === 'outline' ? c.border : TRANSPARENT,
344
+ gradient: null, surface: false },
345
+ disabledOpacity: 1, borderWidth: appearance === 'outline' ? 1 : 0,
346
+ shadow: false, ring: tone === 'support' ? c.secondary : tone === 'action' ? c.tertiary : c.primary,
347
+ };
348
+ }
329
349
  const surface = appearance !== 'plain';
330
350
  const neutral = tone === 'neutral' && !colors;
331
351
  const tint = appearance === 'outline' && !colors
@@ -25,6 +25,8 @@ export interface ButtonProps {
25
25
  /** Keep an embedded action from also activating its parent. Default false. */
26
26
  stopPropagation?: boolean;
27
27
  appearance?: BloomAppearance;
28
+ /** Shared surface paint (default), or a flat semantic fill without sheen, rim or refraction. */
29
+ material?: 'surface' | 'flat';
28
30
  tone?: BloomTone;
29
31
  leading?: ReactNode;
30
32
  trailing?: ReactNode;
@@ -5,6 +5,7 @@ import React, {
5
5
  useCallback,
6
6
  useContext,
7
7
  useEffect,
8
+ useLayoutEffect,
8
9
  useMemo,
9
10
  useRef,
10
11
  useState,
@@ -158,6 +159,7 @@ const CarouselItemComponent = function CarouselItem({
158
159
  const index = useContext(CarouselItemIndexContext);
159
160
  const { messages } = useMessages(CAROUSEL_MESSAGES);
160
161
  const reportOffset = ctx?.reportOffset;
162
+ const itemRef = useRef<View>(null);
161
163
 
162
164
  const onLayout = useCallback(
163
165
  (event: LayoutChangeEvent) => {
@@ -168,9 +170,20 @@ const CarouselItemComponent = function CarouselItem({
168
170
  );
169
171
 
170
172
  const slideWidth = width ?? (ctx && ctx.trackWidth > 0 ? ctx.trackWidth : undefined);
173
+ useLayoutEffect(() => {
174
+ const node: unknown = itemRef.current;
175
+ if (!IS_WEB || typeof HTMLElement === 'undefined' || !(node instanceof HTMLElement)) return;
176
+ // RNW observes sizes, so a keyed slide reordered without resizing might
177
+ // receive no onLayout. Read its new position after that DOM commit too.
178
+ const parent = node.parentElement;
179
+ if (!parent) return;
180
+ const bounds = node.getBoundingClientRect();
181
+ reportOffset?.(index, bounds.left - parent.getBoundingClientRect().left, bounds.width);
182
+ }, [index, reportOffset, slideWidth]);
171
183
 
172
184
  return (
173
185
  <View
186
+ ref={itemRef}
174
187
  {...webDataSet({ bloomCarouselItem: '' })}
175
188
  role="group"
176
189
  {...(IS_WEB ? { 'aria-roledescription': messages.slideRole } : {})}
@@ -308,6 +321,7 @@ const CarouselComponent = function Carousel({
308
321
  align = 'start',
309
322
  gap = 16,
310
323
  inset = 0,
324
+ index,
311
325
  onIndexChange,
312
326
  previousLabel: previousLabelProp,
313
327
  nextLabel: nextLabelProp,
@@ -327,9 +341,17 @@ const CarouselComponent = function Carousel({
327
341
 
328
342
  const slides = Children.toArray(children).filter(isValidElement);
329
343
  const count = slides.length;
344
+ // React's child keys keep measurements attached to slides across insertions,
345
+ // removals and reordering. Do not reuse a removed slide's numeric-index slot.
346
+ const keySignature = JSON.stringify(slides.map(child => child.key));
347
+ const slideKeys = useMemo(() => JSON.parse(keySignature) as string[], [keySignature]);
348
+ const controlledIndex = index === undefined ? undefined
349
+ : Math.min(Math.max(0, count - 1), Math.max(0, Math.trunc(Number.isFinite(index) ? index : 0)));
350
+ const controlledIndexRef = useRef(controlledIndex);
351
+ controlledIndexRef.current = controlledIndex;
330
352
 
331
353
  const scrollRef = useRef<ScrollView>(null);
332
- const offsets = useRef<SlideOffset[]>([]);
354
+ const offsets = useRef(new Map<string, SlideOffset>());
333
355
  const scroll = useRef({ x: 0, contentWidth: 0 });
334
356
  const [trackWidth, setTrackWidth] = useState(0);
335
357
  const [stops, setStops] = useState<Stop[]>([]);
@@ -340,6 +362,33 @@ const CarouselComponent = function Carousel({
340
362
  const onIndexChangeRef = useRef(onIndexChange);
341
363
  onIndexChangeRef.current = onIndexChange;
342
364
  const activeSlideRef = useRef(0);
365
+ const pendingTarget = useRef<number | null>(null);
366
+ const appliedOffset = useRef<number | null>(null);
367
+ const dragging = useRef(false);
368
+ const settleTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
369
+ const [settledRevision, setSettledRevision] = useState(0);
370
+ const lastAppliedSelection = useRef<{ index: number | undefined; keys: string; stops: Stop[] } | null>(null);
371
+ const clearSettleTimer = useCallback(() => {
372
+ if (settleTimer.current !== null) clearTimeout(settleTimer.current);
373
+ settleTimer.current = null;
374
+ }, []);
375
+ useEffect(() => clearSettleTimer, [clearSettleTimer]);
376
+ const scheduleSettled = useCallback(() => {
377
+ clearSettleTimer();
378
+ if (controlledIndexRef.current === undefined || dragging.current) return;
379
+ settleTimer.current = setTimeout(() => {
380
+ settleTimer.current = null;
381
+ const current = controlledIndexRef.current;
382
+ if (current === undefined || dragging.current) return;
383
+ if (activeSlideRef.current !== current) onIndexChangeRef.current?.(activeSlideRef.current);
384
+ // If the owner declined the request, restore its selected slide.
385
+ setSettledRevision(revision => revision + 1);
386
+ }, 150);
387
+ }, [clearSettleTimer]);
388
+ useEffect(() => {
389
+ const current = new Set(slideKeys);
390
+ for (const key of offsets.current.keys()) if (!current.has(key)) offsets.current.delete(key);
391
+ }, [slideKeys]);
343
392
 
344
393
  const targetFor = useCallback(
345
394
  (item: SlideOffset) => {
@@ -357,10 +406,11 @@ const CarouselComponent = function Carousel({
357
406
  * ONE list, so they cannot disagree about where the track can go.
358
407
  */
359
408
  const computeStops = useCallback((): Stop[] | null => {
360
- const all = offsets.current.slice(0, count);
361
- if (all.length !== count || all.some((o) => !o)) return null;
362
- return toStops(all.map(targetFor));
363
- }, [count, targetFor]);
409
+ if (trackWidth <= 0 || scroll.current.contentWidth <= 0) return null;
410
+ const all = slideKeys.map(key => offsets.current.get(key));
411
+ if (all.some(item => !item || item.width <= 0)) return null;
412
+ return toStops((all as SlideOffset[]).map(targetFor));
413
+ }, [slideKeys, targetFor, trackWidth]);
364
414
 
365
415
  const measure = useCallback(() => {
366
416
  const { x, contentWidth } = scroll.current;
@@ -396,22 +446,25 @@ const CarouselComponent = function Carousel({
396
446
  const slide = all[next]?.slide ?? 0;
397
447
  if (slide !== activeSlideRef.current) {
398
448
  activeSlideRef.current = slide;
399
- onIndexChangeRef.current?.(slide);
449
+ if (controlledIndexRef.current === undefined) onIndexChangeRef.current?.(slide);
400
450
  }
401
451
  }, [computeStops, trackWidth]);
402
452
 
403
453
  const recomputeStops = useCallback(() => {
404
454
  const next = computeStops();
405
- if (next) setStops(next);
455
+ if (next) setStops(previous => previous.length === next.length && previous.every((stop, i) =>
456
+ stop.offset === next[i]?.offset && stop.slide === next[i]?.slide) ? previous : next);
406
457
  }, [computeStops]);
407
458
 
408
459
  const reportOffset = useCallback(
409
460
  (index: number, x: number, width: number) => {
410
- offsets.current[index] = { x, width };
461
+ const key = slideKeys[index];
462
+ if (key === undefined) return;
463
+ offsets.current.set(key, { x, width });
411
464
  recomputeStops();
412
465
  measure();
413
466
  },
414
- [measure, recomputeStops],
467
+ [measure, recomputeStops, slideKeys],
415
468
  );
416
469
 
417
470
  useEffect(() => {
@@ -419,14 +472,94 @@ const CarouselComponent = function Carousel({
419
472
  measure();
420
473
  }, [recomputeStops, measure]);
421
474
 
422
- const scrollToStop = (stop: Stop | undefined) => {
423
- if (!stop) return;
475
+ const scrollToOffset = useCallback((offset: number, animated: boolean) => {
424
476
  // Web exposes negative scrollLeft in RTL; Android uses physical x, while
425
477
  // iOS's ScrollView command already converts a logical offset internally.
426
478
  const max = Math.max(0, scroll.current.contentWidth - trackWidth);
427
- const x = !rtl ? stop.offset : IS_WEB ? -stop.offset
428
- : Platform.OS === 'android' ? max - stop.offset : stop.offset;
429
- scrollRef.current?.scrollTo({ x, animated: !reducedMotion });
479
+ const x = !rtl ? offset : IS_WEB ? -offset
480
+ : Platform.OS === 'android' ? max - offset : offset;
481
+ scrollRef.current?.scrollTo({ x, animated });
482
+ }, [rtl, trackWidth]);
483
+
484
+ useLayoutEffect(() => {
485
+ if (controlledIndex === undefined) {
486
+ pendingTarget.current = null;
487
+ appliedOffset.current = null;
488
+ lastAppliedSelection.current = null;
489
+ clearSettleTimer();
490
+ return;
491
+ }
492
+ clearSettleTimer();
493
+ const item = offsets.current.get(slideKeys[controlledIndex]!);
494
+ if (!item || !trackWidth || !scroll.current.contentWidth || !computeStops()) {
495
+ pendingTarget.current = null;
496
+ appliedOffset.current = null;
497
+ if (!slideKeys.length) lastAppliedSelection.current = null;
498
+ return;
499
+ }
500
+ const target = targetFor(item);
501
+ // CSS snapping may retain the same keyed element after a reorder before
502
+ // RNW delivers onScroll. Read the committed DOM position, not that old event.
503
+ const node: unknown = IS_WEB ? scrollRef.current?.getScrollableNode() : null;
504
+ if (typeof HTMLElement !== 'undefined' && node instanceof HTMLElement) {
505
+ scroll.current.x = rtl ? -node.scrollLeft : node.scrollLeft;
506
+ }
507
+ appliedOffset.current = target;
508
+ const previous = lastAppliedSelection.current;
509
+ const changedIndex = previous !== null && previous.keys === keySignature && previous.stops === stops
510
+ && !Object.is(previous.index, index);
511
+ lastAppliedSelection.current = { index, keys: keySignature, stops };
512
+ if (Math.abs(scroll.current.x - target) <= 1) {
513
+ pendingTarget.current = null;
514
+ return;
515
+ }
516
+ pendingTarget.current = target;
517
+ // Initial positioning, resize and list changes are immediate. Only a new
518
+ // selection animates; intermediate scroll events must not rewrite that selection.
519
+ scrollToOffset(target, changedIndex && !reducedMotion);
520
+ }, [index, controlledIndex, keySignature, slideKeys, stops, trackWidth, computeStops, targetFor,
521
+ reducedMotion, scrollToOffset, settledRevision, clearSettleTimer, rtl]);
522
+
523
+ const interruptControlledScroll = useCallback(() => {
524
+ pendingTarget.current = null;
525
+ appliedOffset.current = null;
526
+ clearSettleTimer();
527
+ }, [clearSettleTimer]);
528
+ const beginDrag = useCallback(() => {
529
+ dragging.current = true;
530
+ interruptControlledScroll();
531
+ }, [interruptControlledScroll]);
532
+ const endDrag = useCallback(() => {
533
+ if (!dragging.current) return;
534
+ dragging.current = false;
535
+ scheduleSettled();
536
+ }, [scheduleSettled]);
537
+ useEffect(() => {
538
+ if (!IS_WEB || controlledIndex === undefined) return;
539
+ const node: unknown = scrollRef.current?.getScrollableNode();
540
+ if (typeof HTMLElement === 'undefined' || !(node instanceof HTMLElement)) return;
541
+ // RNW does not emit onScrollBeginDrag. Real input interrupts a requested
542
+ // smooth scroll so its resulting swipe/keyboard position can notify the owner.
543
+ node.addEventListener('pointerdown', beginDrag);
544
+ window.addEventListener('pointerup', endDrag);
545
+ window.addEventListener('pointercancel', endDrag);
546
+ for (const event of ['wheel', 'keydown']) node.addEventListener(event, interruptControlledScroll);
547
+ return () => {
548
+ node.removeEventListener('pointerdown', beginDrag);
549
+ window.removeEventListener('pointerup', endDrag);
550
+ window.removeEventListener('pointercancel', endDrag);
551
+ for (const event of ['wheel', 'keydown']) node.removeEventListener(event, interruptControlledScroll);
552
+ };
553
+ }, [controlledIndex !== undefined, interruptControlledScroll, beginDrag, endDrag]);
554
+
555
+ const scrollToStop = (stop: Stop | undefined) => {
556
+ if (!stop) return;
557
+ if (controlledIndex !== undefined) {
558
+ if (stop.slide !== controlledIndex) onIndexChangeRef.current?.(stop.slide);
559
+ setSettledRevision(revision => revision + 1);
560
+ } else {
561
+ scrollToOffset(stop.offset, !reducedMotion);
562
+ }
430
563
  };
431
564
 
432
565
  /**
@@ -437,7 +570,7 @@ const CarouselComponent = function Carousel({
437
570
  const step = (direction: -1 | 1) => {
438
571
  const all = computeStops();
439
572
  if (!all) return;
440
- const x = scroll.current.x;
573
+ const x = pendingTarget.current ?? scroll.current.x;
441
574
  scrollToStop(
442
575
  direction === 1
443
576
  ? all.find((stop) => stop.offset > x + 1)
@@ -452,6 +585,15 @@ const CarouselComponent = function Carousel({
452
585
  : Platform.OS === 'android' ? max - contentOffset.x : contentOffset.x;
453
586
  scroll.current = { x, contentWidth: contentSize.width };
454
587
  measure();
588
+ if (controlledIndexRef.current === undefined || count === 0 || !computeStops()) return;
589
+ if (pendingTarget.current !== null) {
590
+ if (Math.abs(x - pendingTarget.current) <= 1) pendingTarget.current = null;
591
+ return;
592
+ }
593
+ if (appliedOffset.current !== null && Math.abs(x - appliedOffset.current) <= 1) return;
594
+ // Commit a real swipe only after it settles, preserving momentum and
595
+ // preventing intermediate controlled updates from interrupting the gesture.
596
+ scheduleSettled();
455
597
  };
456
598
 
457
599
  const onContentSizeChange = (width: number) => {
@@ -503,6 +645,8 @@ const CarouselComponent = function Carousel({
503
645
  showsHorizontalScrollIndicator={false}
504
646
  scrollEventThrottle={16}
505
647
  onScroll={onScroll}
648
+ onScrollBeginDrag={beginDrag}
649
+ onScrollEndDrag={endDrag}
506
650
  onContentSizeChange={onContentSizeChange}
507
651
  onLayout={(event) => setTrackWidth(event.nativeEvent.layout.width)}
508
652
  snapToOffsets={IS_WEB ? undefined : snapOffsets}
@@ -32,7 +32,15 @@ export interface CarouselProps {
32
32
  * rests at the inset, not flush. Defaults to `0`.
33
33
  */
34
34
  inset?: number;
35
- /** Called when the slide in view changes. */
35
+ /**
36
+ * Controlled zero-based child index. Out-of-range values clamp to the list;
37
+ * omitted keeps the carousel uncontrolled. Pair with `onIndexChange`.
38
+ */
39
+ index?: number;
40
+ /**
41
+ * Uncontrolled: the slide in view changed. Controlled: arrows/dots or a
42
+ * settled swipe request a child index. Prop-driven scrolls do not echo here.
43
+ */
36
44
  onIndexChange?: (index: number) => void;
37
45
  /** Accessible name of the previous button. Defaults to the localised `'Previous slide'` (in English). */
38
46
  previousLabel?: string;
@@ -1,3 +1,4 @@
1
+ import { BloomThemeContext } from '../theme/BloomThemeProvider';
1
2
  import { useMessages } from '../locale/messages';
2
3
  import { ZOOMABLE_MEDIA_GALLERY_MESSAGES } from './messages';
3
4
  import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
@@ -129,11 +130,11 @@ const webUserSelectNoneStyle = Platform.select({
129
130
  });
130
131
 
131
132
  export function createZoomableMediaGallery(Button: React.ComponentType<ButtonProps>) {
132
- function NavArrow({ direction, onPress, label }: { direction: 'left' | 'right'; onPress: () => void; label: string }) {
133
+ function NavArrow({ direction, onPress, label, pageColors }: { direction: 'left' | 'right'; onPress: () => void; label: string; pageColors?: { background: string; foreground: string } }) {
133
134
  const isLeft = direction === 'left';
134
135
  return <Button onPress={onPress} appearance="outline" tone="neutral" size="lg" iconOnly hitSlop={8}
135
- accessibilityLabel={label}
136
- icon={isLeft ? <RiArrowLeftLine fill="#fff" size="lg" /> : <RiArrowRightLine fill="#fff" size="lg" />}
136
+ accessibilityLabel={label} material={pageColors ? 'flat' : 'surface'} colors={pageColors}
137
+ icon={isLeft ? <RiArrowLeftLine fill={pageColors?.foreground ?? "#fff"} size="lg" /> : <RiArrowRightLine fill={pageColors?.foreground ?? "#fff"} size="lg" />}
137
138
  style={[styles.navArrow, isLeft ? styles.navArrowLeft : styles.navArrowRight]} />;
138
139
  }
139
140
 
@@ -183,8 +184,20 @@ function resolveCornerRadius(cornerRadius: number | 'circle', fit: FittedSize):
183
184
  * `expo-video` is an OPTIONAL peer loaded through `media-flight/expo-video-module`.
184
185
  * Without it a video page degrades to its poster, once, with a dev warning.
185
186
  */
186
- const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, ZoomableMediaGalleryProps>(({ measureThumb, cornerRadius = DEFAULT_CORNER_RADIUS, indicatorVariant = 'dots', videoControls = false, labels: labelsProp }, ref) => {
187
+ const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, ZoomableMediaGalleryProps>(({ appearance = 'overlay', onIndexChange, measureThumb, cornerRadius = DEFAULT_CORNER_RADIUS, indicatorVariant = 'dots', videoControls = false, labels: labelsProp }, ref) => {
187
188
  const { messages } = useMessages(ZOOMABLE_MEDIA_GALLERY_MESSAGES);
189
+ const themeContext = React.useContext(BloomThemeContext);
190
+ if (appearance === 'page' && !themeContext) {
191
+ throw new Error('ZoomableMediaGallery appearance="page" requires a <BloomThemeProvider>');
192
+ }
193
+ // The default overlay can mount closed without a theme provider. Only the
194
+ // opt-in page reads its palette; the default pager's controls keep their own
195
+ // existing provider requirements.
196
+ const pagePalette = appearance === 'page' ? themeContext?.theme.colors : undefined;
197
+ const page = pagePalette != null;
198
+ const pageColors = pagePalette ? { background: pagePalette.backgroundSecondary, foreground: pagePalette.text } : undefined;
199
+ const onIndexChangeRef = useRef(onIndexChange);
200
+ onIndexChangeRef.current = onIndexChange;
188
201
  const labels = useMemo(() => ({ ...messages, ...labelsProp }), [messages, labelsProp]);
189
202
  const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = useWindowDimensions();
190
203
  // The viewer is full-bleed, so its chrome must clear the status bar, the
@@ -295,9 +308,11 @@ const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, Z
295
308
 
296
309
  // Single writer for the current index: updates state (drives indicator + open
297
310
  // image) and the synchronous mirror together, and only when it changes.
298
- const setActiveIndexBoth = useCallback((next: number) => {
311
+ const setActiveIndexBoth = useCallback((next: number, opening = false) => {
312
+ const changed = activeIndexRef.current !== next;
299
313
  activeIndexRef.current = next;
300
314
  setActiveIndex((prev) => (prev === next ? prev : next));
315
+ if (changed || opening) onIndexChangeRef.current?.(next);
301
316
  }, []);
302
317
 
303
318
  // Snap the active media back to its un-zoomed baseline (no animation) and
@@ -375,7 +390,8 @@ const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, Z
375
390
  // every dismiss path (fly-back and fade-out fallback).
376
391
  const finalizeDismiss = useCallback(() => {
377
392
  setIsOpen(false);
378
- dismissingRef.current = false;
393
+ // Keep the dismissal latch until the next open. Throttled web scroll
394
+ // events can arrive after the pager unmounts and must not reset selection.
379
395
  scale.value = 1;
380
396
  translateX.value = 0;
381
397
  translateY.value = 0;
@@ -487,7 +503,7 @@ const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, Z
487
503
  const ratio = knownRatio ?? DEFAULT_ASPECT_RATIO;
488
504
 
489
505
  setItems(nextItems);
490
- setActiveIndexBoth(safeIndex);
506
+ setActiveIndexBoth(safeIndex, true);
491
507
  setOpenRatio(ratio);
492
508
  // Seed every page whose ratio is already known (consumer-provided metadata
493
509
  // or a previously-cached probe) so swiping never hits the same snap — only
@@ -671,6 +687,7 @@ const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, Z
671
687
  // (web, where paging may not fire a reliable momentum-end).
672
688
  const updateIndexFromOffset = useCallback(
673
689
  (offsetX: number) => {
690
+ if (dismissingRef.current || !pagerReady) return;
674
691
  const lastIndex = items.length - 1;
675
692
  if (lastIndex < 0) return;
676
693
  const next = Math.min(Math.max(Math.round(offsetX / SCREEN_WIDTH), 0), lastIndex);
@@ -682,7 +699,7 @@ const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, Z
682
699
  const item = items[next];
683
700
  if (item) ensureRatio(next, posterUri(item));
684
701
  },
685
- [ensureRatio, items, resetZoom, setActiveIndexBoth, SCREEN_WIDTH]
702
+ [ensureRatio, items, pagerReady, resetZoom, setActiveIndexBoth, SCREEN_WIDTH]
686
703
  );
687
704
 
688
705
  // Programmatically page to `index` (arrow buttons, keyboard, thumbnail taps).
@@ -931,6 +948,9 @@ const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, Z
931
948
  onPress={handleDismiss}
932
949
  accessibilityLabel={labels.close}
933
950
  progress={opacity}
951
+ blurIntensity={page ? 0 : undefined}
952
+ dimColor={pagePalette?.background}
953
+ dimOpacity={page ? 1 : undefined}
934
954
  />
935
955
 
936
956
  <GestureDetector gesture={panGesture}>
@@ -1053,8 +1073,8 @@ const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, Z
1053
1073
  style={[styles.indicatorWrap, { bottom: INDICATOR_BOTTOM + insets.bottom }, backdropStyle]}
1054
1074
  pointerEvents="box-none"
1055
1075
  >
1056
- <View style={styles.counterPill} pointerEvents="none">
1057
- <Text style={styles.counterText}>{`${activeIndex + 1} / ${items.length}`}</Text>
1076
+ <View style={[styles.counterPill, pagePalette && { backgroundColor: pagePalette.backgroundSecondary }]} pointerEvents="none">
1077
+ <Text style={[styles.counterText, pagePalette && { color: pagePalette.text }]}>{`${activeIndex + 1} / ${items.length}`}</Text>
1058
1078
  </View>
1059
1079
  {indicatorVariant === 'thumbnails' ? (
1060
1080
  <ScrollView
@@ -1072,6 +1092,7 @@ const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, Z
1072
1092
  style={[
1073
1093
  styles.thumbTile,
1074
1094
  idx === activeIndex ? styles.thumbTileActive : styles.thumbTileInactive,
1095
+ pagePalette && { borderColor: idx === activeIndex ? pagePalette.text : pagePalette.border },
1075
1096
  webPointerStyle,
1076
1097
  ]}
1077
1098
  >
@@ -1087,7 +1108,7 @@ const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, Z
1087
1108
  {items.map((item, idx) => (
1088
1109
  <View
1089
1110
  key={`dot-${mediaKey(item, idx)}`}
1090
- style={[styles.dot, idx === activeIndex ? styles.dotActive : styles.dotInactive]}
1111
+ style={[styles.dot, idx === activeIndex ? styles.dotActive : styles.dotInactive, pagePalette && { backgroundColor: idx === activeIndex ? pagePalette.text : pagePalette.textSecondary }]}
1091
1112
  />
1092
1113
  ))}
1093
1114
  </View>
@@ -1096,11 +1117,11 @@ const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, Z
1096
1117
  )}
1097
1118
 
1098
1119
  {Platform.OS === 'web' && pagerReady && items.length > 1 && activeIndex > 0 && (
1099
- <NavArrow direction="left" label={labels.previous} onPress={() => pageTo(activeIndex - 1)} />
1120
+ <NavArrow pageColors={pageColors} direction="left" label={labels.previous} onPress={() => pageTo(activeIndex - 1)} />
1100
1121
  )}
1101
1122
 
1102
1123
  {Platform.OS === 'web' && pagerReady && items.length > 1 && activeIndex < items.length - 1 && (
1103
- <NavArrow direction="right" label={labels.next} onPress={() => pageTo(activeIndex + 1)} />
1124
+ <NavArrow pageColors={pageColors} direction="right" label={labels.next} onPress={() => pageTo(activeIndex + 1)} />
1104
1125
  )}
1105
1126
 
1106
1127
  {canShare && pagerReady && (
@@ -1110,7 +1131,8 @@ const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, Z
1110
1131
  tone="neutral"
1111
1132
  iconOnly
1112
1133
  accessibilityLabel={labels.share}
1113
- icon={<RiUpload2Line fill="#fff" size="md" />}
1134
+ material={page ? 'flat' : 'surface'} colors={pageColors}
1135
+ icon={<RiUpload2Line fill={pageColors?.foreground ?? "#fff"} size="md" />}
1114
1136
  hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}
1115
1137
  style={[styles.shareButton, { top: CHROME_EDGE + insets.top, right: CHROME_EDGE + insets.right }]}
1116
1138
  />
@@ -1129,8 +1151,8 @@ const ZoomableMediaGalleryInner = React.forwardRef<ZoomableMediaGalleryHandle, Z
1129
1151
  ]}
1130
1152
  pointerEvents="none"
1131
1153
  >
1132
- <View style={styles.altCaptionPill}>
1133
- <Text style={styles.altCaptionText} numberOfLines={4}>{activeAlt}</Text>
1154
+ <View style={[styles.altCaptionPill, pagePalette && { backgroundColor: pagePalette.backgroundSecondary }]}>
1155
+ <Text style={[styles.altCaptionText, pagePalette && { color: pagePalette.text }]} numberOfLines={4}>{activeAlt}</Text>
1134
1156
  </View>
1135
1157
  </Animated.View>
1136
1158
  ) : null}
@@ -89,6 +89,10 @@ export interface ZoomableMediaGalleryLabels {
89
89
  }
90
90
 
91
91
  export interface ZoomableMediaGalleryProps {
92
+ /** Existing dimmed overlay (default), or an opaque page using the current theme. */
93
+ appearance?: 'overlay' | 'page';
94
+ /** Zero-based media index, emitted on opening and once per actual page change. */
95
+ onIndexChange?: (index: number) => void;
92
96
  /** Overrides any of the viewer's names. */
93
97
  labels?: Partial<ZoomableMediaGalleryLabels>;
94
98
  /** Measures any thumbnail by its media subset index, used on dismiss. */