@oxyhq/bloom 1.13.0 → 1.14.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.
Files changed (114) hide show
  1. package/README.md +1 -1
  2. package/docs/avatar.mdx +46 -5
  3. package/docs/index.mdx +1 -1
  4. package/docs/media-flight.mdx +15 -6
  5. package/docs/tab-bar.mdx +35 -0
  6. package/lib/commonjs/avatar/Avatar.js +24 -8
  7. package/lib/commonjs/avatar/Avatar.js.map +1 -1
  8. package/lib/commonjs/avatar/AvatarRing.js +13 -12
  9. package/lib/commonjs/avatar/AvatarRing.js.map +1 -1
  10. package/lib/commonjs/avatar/index.js +19 -0
  11. package/lib/commonjs/avatar/index.js.map +1 -1
  12. package/lib/commonjs/avatar/resolve-shape.js +43 -0
  13. package/lib/commonjs/avatar/resolve-shape.js.map +1 -0
  14. package/lib/commonjs/avatar/shape-paths.js +174 -0
  15. package/lib/commonjs/avatar/shape-paths.js.map +1 -0
  16. package/lib/commonjs/media-flight/MediaSurface.js +51 -10
  17. package/lib/commonjs/media-flight/MediaSurface.js.map +1 -1
  18. package/lib/commonjs/media-flight/constants.js +32 -7
  19. package/lib/commonjs/media-flight/constants.js.map +1 -1
  20. package/lib/commonjs/tab-bar/TabBarBase.js +87 -13
  21. package/lib/commonjs/tab-bar/TabBarBase.js.map +1 -1
  22. package/lib/commonjs/tab-bar/expo-router/RouterTabBar.js +5 -0
  23. package/lib/commonjs/tab-bar/expo-router/RouterTabBar.js.map +1 -1
  24. package/lib/commonjs/theme/color-scope/ColorScope.js +42 -12
  25. package/lib/commonjs/theme/color-scope/ColorScope.js.map +1 -1
  26. package/lib/commonjs/theme/color-scope/ColorScope.web.js +2 -8
  27. package/lib/commonjs/theme/color-scope/ColorScope.web.js.map +1 -1
  28. package/lib/module/avatar/Avatar.js +24 -8
  29. package/lib/module/avatar/Avatar.js.map +1 -1
  30. package/lib/module/avatar/AvatarRing.js +13 -12
  31. package/lib/module/avatar/AvatarRing.js.map +1 -1
  32. package/lib/module/avatar/index.js +1 -0
  33. package/lib/module/avatar/index.js.map +1 -1
  34. package/lib/module/avatar/resolve-shape.js +40 -0
  35. package/lib/module/avatar/resolve-shape.js.map +1 -0
  36. package/lib/module/avatar/shape-paths.js +170 -0
  37. package/lib/module/avatar/shape-paths.js.map +1 -0
  38. package/lib/module/media-flight/MediaSurface.js +52 -11
  39. package/lib/module/media-flight/MediaSurface.js.map +1 -1
  40. package/lib/module/media-flight/constants.js +31 -6
  41. package/lib/module/media-flight/constants.js.map +1 -1
  42. package/lib/module/tab-bar/TabBarBase.js +89 -15
  43. package/lib/module/tab-bar/TabBarBase.js.map +1 -1
  44. package/lib/module/tab-bar/expo-router/RouterTabBar.js +5 -0
  45. package/lib/module/tab-bar/expo-router/RouterTabBar.js.map +1 -1
  46. package/lib/module/theme/color-scope/ColorScope.js +45 -13
  47. package/lib/module/theme/color-scope/ColorScope.js.map +1 -1
  48. package/lib/module/theme/color-scope/ColorScope.web.js +3 -9
  49. package/lib/module/theme/color-scope/ColorScope.web.js.map +1 -1
  50. package/lib/typescript/commonjs/avatar/Avatar.d.ts.map +1 -1
  51. package/lib/typescript/commonjs/avatar/AvatarRing.d.ts +4 -3
  52. package/lib/typescript/commonjs/avatar/AvatarRing.d.ts.map +1 -1
  53. package/lib/typescript/commonjs/avatar/index.d.ts +3 -1
  54. package/lib/typescript/commonjs/avatar/index.d.ts.map +1 -1
  55. package/lib/typescript/commonjs/avatar/resolve-shape.d.ts +17 -0
  56. package/lib/typescript/commonjs/avatar/resolve-shape.d.ts.map +1 -0
  57. package/lib/typescript/commonjs/avatar/shape-paths.d.ts +27 -0
  58. package/lib/typescript/commonjs/avatar/shape-paths.d.ts.map +1 -0
  59. package/lib/typescript/commonjs/avatar/types.d.ts +30 -3
  60. package/lib/typescript/commonjs/avatar/types.d.ts.map +1 -1
  61. package/lib/typescript/commonjs/media-flight/MediaSurface.d.ts.map +1 -1
  62. package/lib/typescript/commonjs/media-flight/constants.d.ts +30 -6
  63. package/lib/typescript/commonjs/media-flight/constants.d.ts.map +1 -1
  64. package/lib/typescript/commonjs/media-flight/types.d.ts +7 -2
  65. package/lib/typescript/commonjs/media-flight/types.d.ts.map +1 -1
  66. package/lib/typescript/commonjs/tab-bar/TabBarBase.d.ts.map +1 -1
  67. package/lib/typescript/commonjs/tab-bar/expo-router/RouterTabBar.d.ts +5 -0
  68. package/lib/typescript/commonjs/tab-bar/expo-router/RouterTabBar.d.ts.map +1 -1
  69. package/lib/typescript/commonjs/tab-bar/types.d.ts +36 -5
  70. package/lib/typescript/commonjs/tab-bar/types.d.ts.map +1 -1
  71. package/lib/typescript/commonjs/theme/color-scope/ColorScope.d.ts +36 -2
  72. package/lib/typescript/commonjs/theme/color-scope/ColorScope.d.ts.map +1 -1
  73. package/lib/typescript/commonjs/theme/color-scope/ColorScope.web.d.ts +6 -2
  74. package/lib/typescript/commonjs/theme/color-scope/ColorScope.web.d.ts.map +1 -1
  75. package/lib/typescript/module/avatar/Avatar.d.ts.map +1 -1
  76. package/lib/typescript/module/avatar/AvatarRing.d.ts +4 -3
  77. package/lib/typescript/module/avatar/AvatarRing.d.ts.map +1 -1
  78. package/lib/typescript/module/avatar/index.d.ts +3 -1
  79. package/lib/typescript/module/avatar/index.d.ts.map +1 -1
  80. package/lib/typescript/module/avatar/resolve-shape.d.ts +17 -0
  81. package/lib/typescript/module/avatar/resolve-shape.d.ts.map +1 -0
  82. package/lib/typescript/module/avatar/shape-paths.d.ts +27 -0
  83. package/lib/typescript/module/avatar/shape-paths.d.ts.map +1 -0
  84. package/lib/typescript/module/avatar/types.d.ts +30 -3
  85. package/lib/typescript/module/avatar/types.d.ts.map +1 -1
  86. package/lib/typescript/module/media-flight/MediaSurface.d.ts.map +1 -1
  87. package/lib/typescript/module/media-flight/constants.d.ts +30 -6
  88. package/lib/typescript/module/media-flight/constants.d.ts.map +1 -1
  89. package/lib/typescript/module/media-flight/types.d.ts +7 -2
  90. package/lib/typescript/module/media-flight/types.d.ts.map +1 -1
  91. package/lib/typescript/module/tab-bar/TabBarBase.d.ts.map +1 -1
  92. package/lib/typescript/module/tab-bar/expo-router/RouterTabBar.d.ts +5 -0
  93. package/lib/typescript/module/tab-bar/expo-router/RouterTabBar.d.ts.map +1 -1
  94. package/lib/typescript/module/tab-bar/types.d.ts +36 -5
  95. package/lib/typescript/module/tab-bar/types.d.ts.map +1 -1
  96. package/lib/typescript/module/theme/color-scope/ColorScope.d.ts +36 -2
  97. package/lib/typescript/module/theme/color-scope/ColorScope.d.ts.map +1 -1
  98. package/lib/typescript/module/theme/color-scope/ColorScope.web.d.ts +6 -2
  99. package/lib/typescript/module/theme/color-scope/ColorScope.web.d.ts.map +1 -1
  100. package/package.json +1 -1
  101. package/src/avatar/Avatar.tsx +27 -10
  102. package/src/avatar/AvatarRing.tsx +21 -14
  103. package/src/avatar/index.ts +7 -0
  104. package/src/avatar/resolve-shape.ts +33 -0
  105. package/src/avatar/shape-paths.ts +150 -0
  106. package/src/avatar/types.ts +32 -3
  107. package/src/media-flight/MediaSurface.tsx +60 -14
  108. package/src/media-flight/constants.ts +31 -6
  109. package/src/media-flight/types.ts +7 -2
  110. package/src/tab-bar/TabBarBase.tsx +110 -17
  111. package/src/tab-bar/expo-router/RouterTabBar.tsx +5 -0
  112. package/src/tab-bar/types.ts +36 -5
  113. package/src/theme/color-scope/ColorScope.tsx +53 -12
  114. package/src/theme/color-scope/ColorScope.web.tsx +10 -8
@@ -10,8 +10,8 @@ import { Z_INDEX } from '../styles/z-index';
10
10
  import { useAvatarPlaceholder } from './context';
11
11
  import { LiveBadge } from './LiveBadge';
12
12
  import { AvatarRing, getRingOuterSize } from './AvatarRing';
13
- import { SQUIRCLE_PATH } from './squircle-path';
14
- import type { AvatarProps, AvatarRingConfig } from './types';
13
+ import { resolveAvatarShape } from './resolve-shape';
14
+ import type { AvatarProps, AvatarRingConfig, AvatarShapePath } from './types';
15
15
 
16
16
  // Google Contacts-inspired palette used to pick a deterministic background
17
17
  // color for name-based placeholder avatars.
@@ -45,10 +45,19 @@ import DEFAULT_AVATAR_IMAGE from './default-avatar';
45
45
 
46
46
  let clipIdCounter = 0;
47
47
 
48
- function SquircleImage({
48
+ /**
49
+ * Renders the avatar image clipped to an arbitrary outline.
50
+ *
51
+ * The path and the SVG viewport share one coordinate space, so a 0–1 squircle
52
+ * and a 0–100 named shape both work without rewriting their numbers: the
53
+ * viewport is declared at the path's own scale and the whole thing is drawn at
54
+ * `size` pixels.
55
+ */
56
+ function ClippedImage({
49
57
  uri,
50
58
  fallbackSource,
51
59
  size,
60
+ shape,
52
61
  fallbackColor,
53
62
  placeholderIcon,
54
63
  name,
@@ -57,6 +66,7 @@ function SquircleImage({
57
66
  uri?: string;
58
67
  fallbackSource?: AvatarProps['fallbackSource'];
59
68
  size: number;
69
+ shape: AvatarShapePath;
60
70
  fallbackColor: string;
61
71
  placeholderIcon?: React.ReactNode;
62
72
  name?: string;
@@ -71,6 +81,8 @@ function SquircleImage({
71
81
  );
72
82
  }
73
83
 
84
+ const span = shape.viewBox ?? 1;
85
+
74
86
  return (
75
87
  <>
76
88
  {/* Hidden RN Image for error detection on remote URIs */}
@@ -81,16 +93,16 @@ function SquircleImage({
81
93
  onError={onError}
82
94
  />
83
95
  )}
84
- <Svg width={size} height={size} viewBox="0 0 1 1">
96
+ <Svg width={size} height={size} viewBox={`0 0 ${span} ${span}`}>
85
97
  <Defs>
86
98
  <ClipPath id={clipId}>
87
- <Path d={SQUIRCLE_PATH} />
99
+ <Path d={shape.d} />
88
100
  </ClipPath>
89
101
  </Defs>
90
102
  <SvgImage
91
103
  href={href}
92
- width={1}
93
- height={1}
104
+ width={span}
105
+ height={span}
94
106
  preserveAspectRatio="xMidYMid slice"
95
107
  clipPath={`url(#${clipId})`}
96
108
  />
@@ -183,6 +195,10 @@ const AvatarComponent: React.FC<AvatarProps> = ({
183
195
  const theme = useTheme();
184
196
  const placeholderConfig = useAvatarPlaceholder();
185
197
  const radius = size / 2;
198
+ // `null` means "a circle", which is drawn with borderRadius and never reaches
199
+ // the SVG renderer. Memoised so an inline `shape={{ d: … }}` object literal
200
+ // does not produce a new clip descriptor on every render.
201
+ const clipShape = useMemo(() => resolveAvatarShape(shape), [shape]);
186
202
  const hasName = typeof name === 'string' && name.trim().length > 0;
187
203
  // Priority: explicit placeholderColor > deterministic color from name > theme default.
188
204
  const fallbackColor =
@@ -265,7 +281,7 @@ const AvatarComponent: React.FC<AvatarProps> = ({
265
281
  const ringElement = resolvedRing ? (
266
282
  <AvatarRing
267
283
  size={size}
268
- shape={shape}
284
+ shape={clipShape}
269
285
  colors={resolvedRing.colors}
270
286
  width={ringWidth}
271
287
  gap={ringGap}
@@ -278,11 +294,12 @@ const AvatarComponent: React.FC<AvatarProps> = ({
278
294
  // fills the container exactly.
279
295
  const avatarBox = (
280
296
  <View style={[styles.avatarBox, { width: size, height: size }]}>
281
- {shape === 'squircle' ? (
282
- <SquircleImage
297
+ {clipShape ? (
298
+ <ClippedImage
283
299
  uri={effectiveUri}
284
300
  fallbackSource={fallbackSource}
285
301
  size={size}
302
+ shape={clipShape}
286
303
  fallbackColor={fallbackColor}
287
304
  placeholderIcon={resolvedPlaceholderIcon}
288
305
  name={name}
@@ -3,8 +3,8 @@ import { View, StyleSheet } from 'react-native';
3
3
  import Svg, { Circle, Defs, LinearGradient, Path, Stop } from 'react-native-svg';
4
4
 
5
5
  import { Z_INDEX } from '../styles/z-index';
6
- import { SQUIRCLE_PATH } from './squircle-path';
7
- import type { AvatarRingGradientDirection, AvatarShape } from './types';
6
+ import type { ResolvedAvatarShape } from './resolve-shape';
7
+ import type { AvatarRingGradientDirection } from './types';
8
8
 
9
9
  // Module counter for unique gradient element ids — mirrors the `clipIdCounter`
10
10
  // pattern in `Avatar.tsx`. Deterministic (no `Math.random()`) so ids are stable
@@ -25,8 +25,8 @@ export function getRingOuterSize(size: number, width: number, gap: number): numb
25
25
  interface AvatarRingProps {
26
26
  /** Avatar diameter in px (the inner content size, before any gap). */
27
27
  size: number;
28
- /** Matches the avatar shape. */
29
- shape: AvatarShape;
28
+ /** The avatar's resolved outline, or `null` for a circle. */
29
+ shape: ResolvedAvatarShape;
30
30
  /** Solid ring: one color. Gradient ring: 2+ colors. */
31
31
  colors: string | string[];
32
32
  /** Ring stroke width in px. */
@@ -79,10 +79,10 @@ const AvatarRingComponent: React.FC<AvatarRingProps> = ({
79
79
  // box; drawn as a plain border it is a full circle → radius `outer / 2`.
80
80
  const ringRadius = outer / 2;
81
81
 
82
- // SVG is only needed for gradients (both shapes) and for the squircle
83
- // outline. A solid circle ring is a plain bordered View — cheaper, and it
84
- // keeps the common case off the SVG renderer entirely.
85
- const needsSvg = wantsGradient || shape === 'squircle';
82
+ // SVG is only needed for gradients and for non-circular outlines. A solid
83
+ // circle ring is a plain bordered View — cheaper, and it keeps the common
84
+ // case off the SVG renderer entirely.
85
+ const needsSvg = wantsGradient || shape !== null;
86
86
 
87
87
  if (!needsSvg) {
88
88
  return (
@@ -127,15 +127,22 @@ const AvatarRingComponent: React.FC<AvatarRingProps> = ({
127
127
  { zIndex: gap > 0 ? Z_INDEX.base : Z_INDEX.raised },
128
128
  ];
129
129
 
130
- if (shape === 'squircle') {
131
- // The path lives in 0–1 space, so the stroke width is expressed in the same
132
- // units; center-stroking it and letting the viewport clip the outer half
133
- // yields a ~`width`-px band on the inner edge of the outer box.
130
+ if (shape !== null) {
131
+ // The path lives in its own square space, so the stroke width has to be
132
+ // expressed in those units too: one unit is `outer / span` px. Center-
133
+ // stroking and letting the viewport clip the outer half yields a
134
+ // ~`width`-px band on the inner edge of the outer box, hence the doubling.
135
+ const span = shape.viewBox ?? 1;
134
136
  return (
135
137
  <View pointerEvents="none" style={overlayStyle}>
136
- <Svg width={outer} height={outer} viewBox="0 0 1 1">
138
+ <Svg width={outer} height={outer} viewBox={`0 0 ${span} ${span}`}>
137
139
  {gradientDefs}
138
- <Path d={SQUIRCLE_PATH} fill="none" stroke={stroke} strokeWidth={(width / outer) * 2} />
140
+ <Path
141
+ d={shape.d}
142
+ fill="none"
143
+ stroke={stroke}
144
+ strokeWidth={(width / outer) * 2 * span}
145
+ />
139
146
  </Svg>
140
147
  </View>
141
148
  );
@@ -4,7 +4,14 @@ export type { AvatarPlaceholderConfig } from './context';
4
4
  export type {
5
5
  AvatarProps,
6
6
  AvatarShape,
7
+ AvatarShapePath,
7
8
  AvatarRingConfig,
8
9
  AvatarRingGradientDirection,
9
10
  } from './types';
10
11
  export { defaultAvatarSource } from './default-avatar';
12
+ export {
13
+ AVATAR_SHAPE_PATHS,
14
+ AVATAR_SHAPE_LABELS,
15
+ NAMED_SHAPE_VIEW_BOX,
16
+ } from './shape-paths';
17
+ export type { AvatarShapeName } from './shape-paths';
@@ -0,0 +1,33 @@
1
+ import { SQUIRCLE_PATH } from './squircle-path';
2
+ import { AVATAR_SHAPE_PATHS, NAMED_SHAPE_VIEW_BOX } from './shape-paths';
3
+ import type { AvatarShape, AvatarShapePath } from './types';
4
+
5
+ /**
6
+ * A shape reduced to what the renderers need: either nothing (a circle, drawn
7
+ * with `borderRadius` and no SVG at all) or one outline plus the size of the
8
+ * square space it is drawn in.
9
+ */
10
+ export type ResolvedAvatarShape = AvatarShapePath | null;
11
+
12
+ /**
13
+ * Turns the public `shape` prop into an outline.
14
+ *
15
+ * Returns `null` for a circle so callers can keep the cheap `borderRadius`
16
+ * path — the common case never touches `react-native-svg`. An unknown string
17
+ * also returns `null`: a shape name that does not resolve should degrade to a
18
+ * plain circular avatar, never to a blank hole where a face should be.
19
+ */
20
+ export function resolveAvatarShape(shape: AvatarShape | AvatarShapePath | undefined): ResolvedAvatarShape {
21
+ if (!shape || shape === 'circle') return null;
22
+
23
+ if (typeof shape !== 'string') {
24
+ return { d: shape.d, viewBox: shape.viewBox ?? 1 };
25
+ }
26
+
27
+ if (shape === 'squircle') {
28
+ return { d: SQUIRCLE_PATH, viewBox: 1 };
29
+ }
30
+
31
+ const named = AVATAR_SHAPE_PATHS[shape];
32
+ return named ? { d: named, viewBox: NAMED_SHAPE_VIEW_BOX } : null;
33
+ }
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Named avatar outlines.
3
+ *
4
+ * Each entry is an SVG path drawn in a 100×100 square coordinate space, scaled
5
+ * at render time to the avatar's pixel size. That space is declared once in
6
+ * {@link NAMED_SHAPE_VIEW_BOX} rather than baked into the numbers, so the paths
7
+ * can be read and edited at human-friendly magnitudes. The built-in squircle
8
+ * lives in `squircle-path.ts` and uses a 0–1 space; both are supported because
9
+ * {@link AvatarShapePath} carries its own `viewBox`.
10
+ *
11
+ * `circle` is deliberately absent: a circular avatar is rendered with
12
+ * `borderRadius` and never reaches the SVG renderer.
13
+ */
14
+
15
+ /** Side length of the coordinate space every path below is drawn in. */
16
+ export const NAMED_SHAPE_VIEW_BOX = 100;
17
+
18
+ export type AvatarShapeName =
19
+ | 'square' | 'slanted' | 'arch' | 'semicircle'
20
+ | 'oval' | 'pill' | 'triangle' | 'arrow' | 'fan'
21
+ | 'diamond' | 'clamshell' | 'pentagon' | 'gem' | 'very-sunny'
22
+ | 'sunny' | '4-sided-cookie' | '6-sided-cookie' | '7-sided-cookie'
23
+ | '9-sided-cookie' | '12-sided-cookie' | '4-leaf-clover'
24
+ | '8-leaf-clover' | 'burst' | 'soft-burst' | 'boom' | 'soft-boom'
25
+ | 'flower' | 'puffy' | 'puffy-diamond' | 'ghost-ish'
26
+ | 'pixel-circle' | 'pixel-triangle' | 'bun' | 'heart';
27
+
28
+ export const AVATAR_SHAPE_PATHS: Record<AvatarShapeName, string> = {
29
+ // --- Basic ---
30
+ square:
31
+ 'M12 0H88Q100 0 100 12V88Q100 100 88 100H12Q0 100 0 88V12Q0 0 12 0Z',
32
+ slanted:
33
+ 'M22 0H88Q100 0 100 12V78Q100 100 78 100H12Q0 100 0 88V22Q0 0 22 0Z',
34
+ arch:
35
+ 'M50 0Q100 0 100 50V88Q100 100 88 100H12Q0 100 0 88V50Q0 0 50 0Z',
36
+ semicircle:
37
+ 'M0 50A50 50 0 0 1 100 50V88Q100 100 88 100H12Q0 100 0 88Z',
38
+
39
+ // --- Organic ---
40
+ oval:
41
+ 'M50 2C78 2 96 22 96 50S78 98 50 98S4 78 4 50S22 2 50 2Z',
42
+ pill:
43
+ 'M34 4H66Q96 4 96 34V66Q96 96 66 96H34Q4 96 4 66V34Q4 4 34 4Z',
44
+ triangle:
45
+ 'M50 5L95 90Q97 95 92 95H8Q3 95 5 90Z',
46
+ arrow:
47
+ 'M50 0L100 45Q100 52 94 52H68V92Q68 100 58 100H42Q32 100 32 92V52H6Q0 52 0 45Z',
48
+ fan:
49
+ 'M50 8Q90 8 96 48Q100 78 70 96Q50 108 30 96Q0 78 4 48Q10 8 50 8Z',
50
+
51
+ // --- Geometric ---
52
+ diamond:
53
+ 'M50 2L96 50L50 98L4 50Z',
54
+ clamshell:
55
+ 'M10 20Q10 4 26 4H74Q90 4 90 20V60Q90 96 50 96Q10 96 10 60Z',
56
+ pentagon:
57
+ 'M50 2L97 36L79 96H21L3 36Z',
58
+ gem:
59
+ 'M30 4H70L98 36L50 98L2 36Z',
60
+
61
+ // --- Sunny/Cookie ---
62
+ 'very-sunny':
63
+ 'M50 0L58 20L78 6L72 28L96 22L82 42L100 50L82 58L96 78L72 72L78 94L58 80L50 100L42 80L22 94L28 72L4 78L18 58L0 50L18 42L4 22L28 28L22 6L42 20Z',
64
+ sunny:
65
+ 'M50 4L60 24L80 10L74 32L98 28L84 48L100 50L84 52L98 72L74 68L80 90L60 76L50 96L40 76L20 90L26 68L2 72L16 52L0 50L16 48L2 28L26 32L20 10L40 24Z',
66
+ '4-sided-cookie':
67
+ 'M50 2Q76 22 76 50Q76 78 50 98Q24 78 24 50Q24 22 50 2Z',
68
+ '6-sided-cookie':
69
+ 'M50 2Q72 10 82 30Q92 52 80 74Q66 96 44 96Q22 96 10 74Q-2 52 10 30Q22 10 50 2Z',
70
+ '7-sided-cookie':
71
+ 'M50 2Q70 6 84 22Q96 40 94 62Q90 82 74 94Q56 102 38 96Q20 88 10 70Q2 50 8 32Q18 10 50 2Z',
72
+ '9-sided-cookie':
73
+ 'M50 2Q64 4 76 14Q86 26 92 42Q94 58 88 72Q78 86 64 94Q50 98 36 94Q22 86 12 72Q6 58 8 42Q14 26 24 14Q36 4 50 2Z',
74
+ '12-sided-cookie':
75
+ 'M50 2L62 6L74 14L84 26L90 40L92 54L88 68L80 80L68 88L54 92L40 90L28 84L18 72L10 58L8 44L12 30L20 18L32 10L44 4Z',
76
+
77
+ // --- Nature ---
78
+ '4-leaf-clover':
79
+ 'M50 4Q70 4 70 26Q96 26 96 50Q96 74 70 74Q70 96 50 96Q30 96 30 74Q4 74 4 50Q4 26 30 26Q30 4 50 4Z',
80
+ '8-leaf-clover':
81
+ 'M50 2Q60 16 72 8Q84 16 80 30Q96 32 92 46Q100 60 86 66Q92 80 78 84Q76 98 60 92Q52 100 42 92Q28 98 24 84Q10 80 16 66Q2 60 10 46Q6 32 22 30Q18 16 30 8Q42 16 50 2Z',
82
+ burst:
83
+ 'M50 0L56 30L80 6L62 34L100 26L70 44L100 50L70 56L100 74L62 66L80 94L56 70L50 100L44 70L20 94L38 66L0 74L30 56L0 50L30 44L0 26L38 34L20 6L44 30Z',
84
+ 'soft-burst':
85
+ 'M50 4L58 28L78 8L66 32L96 24L76 44L98 50L76 56L96 76L66 68L78 92L58 72L50 96L42 72L22 92L34 68L4 76L24 56L2 50L24 44L4 24L34 32L22 8L42 28Z',
86
+ boom:
87
+ 'M50 0L54 18L62 2L60 20L76 6L68 24L88 14L76 30L98 24L82 38L100 38L86 46L100 50L86 54L100 62L82 62L98 76L76 70L88 86L68 76L76 94L60 80L62 98L54 82L50 100L46 82L38 98L40 80L24 94L32 76L12 86L24 70L2 76L18 62L0 62L14 54L0 50L14 46L0 38L18 38L2 24L24 30L12 14L32 24L24 6L40 20L38 2L46 18Z',
88
+ 'soft-boom':
89
+ 'M50 4L56 22L68 6L64 26L82 14L74 32L94 24L82 40L100 36L86 48L100 50L86 52L100 64L82 60L94 76L74 68L82 86L64 74L68 94L56 78L50 96L44 78L32 94L36 74L18 86L26 68L6 76L18 60L0 64L14 52L0 50L14 48L0 36L18 40L6 24L26 32L18 14L36 26L32 6L44 22Z',
90
+ flower:
91
+ 'M50 4Q62 18 72 10Q82 18 76 32Q90 30 88 44Q98 50 88 56Q90 70 76 68Q82 82 72 90Q62 82 50 96Q38 82 28 90Q18 82 24 68Q10 70 12 56Q2 50 12 44Q10 30 24 32Q18 18 28 10Q38 18 50 4Z',
92
+ puffy:
93
+ 'M34 6Q50-4 66 6Q84 6 90 22Q104 34 96 50Q104 66 90 78Q84 94 66 94Q50 104 34 94Q16 94 10 78Q-4 66 4 50Q-4 34 10 22Q16 6 34 6Z',
94
+ 'puffy-diamond':
95
+ 'M50 2Q66 10 72 4Q86 12 84 28Q98 32 94 48Q100 64 86 70Q88 86 72 88Q62 98 48 94Q34 100 26 86Q12 88 8 72Q-2 62 6 48Q0 32 16 28Q14 12 28 4Q38 10 50 2Z',
96
+
97
+ // --- Fun ---
98
+ 'ghost-ish':
99
+ 'M20 96V40Q20 4 50 4Q80 4 80 40V96L70 86L60 96L50 86L40 96L30 86Z',
100
+ 'pixel-circle':
101
+ 'M30 4H70V4H86V14H96V30H100V70H96V86H86V96H70V100H30V96H14V86H4V70H0V30H4V14H14V4H30Z',
102
+ 'pixel-triangle':
103
+ 'M42 4H58V18H70V32H82V46H94V60H100V100H0V60H6V46H18V32H30V18H42Z',
104
+ bun:
105
+ 'M12 54Q-4 24 20 8Q44-6 68 8Q92 22 94 50Q96 72 76 88Q56 100 36 96Q14 90 12 54Z',
106
+ heart:
107
+ 'M50 90C25 70 2 55 2 32Q2 10 24 6Q40 2 50 18Q60 2 76 6Q98 10 98 32Q98 55 75 70Z',
108
+ };
109
+
110
+ /**
111
+ * Display labels for the named shapes, in the order a picker should show them.
112
+ * Exported so consumers building a shape picker do not re-derive the order (or
113
+ * the capitalisation) themselves.
114
+ */
115
+ export const AVATAR_SHAPE_LABELS: { name: AvatarShapeName; label: string }[] = [
116
+ { name: 'square', label: 'Square' },
117
+ { name: 'slanted', label: 'Slanted' },
118
+ { name: 'arch', label: 'Arch' },
119
+ { name: 'semicircle', label: 'Semicircle' },
120
+ { name: 'oval', label: 'Oval' },
121
+ { name: 'pill', label: 'Pill' },
122
+ { name: 'triangle', label: 'Triangle' },
123
+ { name: 'arrow', label: 'Arrow' },
124
+ { name: 'fan', label: 'Fan' },
125
+ { name: 'diamond', label: 'Diamond' },
126
+ { name: 'clamshell', label: 'Clamshell' },
127
+ { name: 'pentagon', label: 'Pentagon' },
128
+ { name: 'gem', label: 'Gem' },
129
+ { name: 'very-sunny', label: 'Very Sunny' },
130
+ { name: 'sunny', label: 'Sunny' },
131
+ { name: '4-sided-cookie', label: '4-Sided Cookie' },
132
+ { name: '6-sided-cookie', label: '6-Sided Cookie' },
133
+ { name: '7-sided-cookie', label: '7-Sided Cookie' },
134
+ { name: '9-sided-cookie', label: '9-Sided Cookie' },
135
+ { name: '12-sided-cookie', label: '12-Sided Cookie' },
136
+ { name: '4-leaf-clover', label: '4-Leaf Clover' },
137
+ { name: '8-leaf-clover', label: '8-Leaf Clover' },
138
+ { name: 'burst', label: 'Burst' },
139
+ { name: 'soft-burst', label: 'Soft Burst' },
140
+ { name: 'boom', label: 'Boom' },
141
+ { name: 'soft-boom', label: 'Soft Boom' },
142
+ { name: 'flower', label: 'Flower' },
143
+ { name: 'puffy', label: 'Puffy' },
144
+ { name: 'puffy-diamond', label: 'Puffy Diamond' },
145
+ { name: 'ghost-ish', label: 'Ghost-ish' },
146
+ { name: 'pixel-circle', label: 'Pixel Circle' },
147
+ { name: 'pixel-triangle', label: 'Pixel Triangle' },
148
+ { name: 'bun', label: 'Bun' },
149
+ { name: 'heart', label: 'Heart' },
150
+ ];
@@ -3,7 +3,30 @@ import type { ImageSourcePropType, StyleProp, ViewStyle, ImageStyle } from 'reac
3
3
  // Referenced by the `variant` prop docs below.
4
4
  import type { ImageResolver } from '../image-resolver/context';
5
5
 
6
- export type AvatarShape = 'circle' | 'squircle';
6
+ import type { AvatarShapeName } from './shape-paths';
7
+
8
+ /**
9
+ * Built-in avatar outlines: the two originals plus the named registry in
10
+ * `shape-paths.ts`. Any of these can be passed as a plain string.
11
+ */
12
+ export type AvatarShape = 'circle' | 'squircle' | AvatarShapeName;
13
+
14
+ /**
15
+ * A caller-supplied outline, for shapes that are not in the built-in registry.
16
+ *
17
+ * The path is clipped against the avatar box, so it should fill its coordinate
18
+ * space edge to edge; anything outside is cut off rather than scaled to fit.
19
+ */
20
+ export interface AvatarShapePath {
21
+ /** SVG path data (the `d` attribute) describing a closed outline. */
22
+ d: string;
23
+ /**
24
+ * Side length of the square coordinate space `d` is drawn in — 100 for a
25
+ * path written over a 0–100 grid, 1 for one written over a 0–1 grid.
26
+ * Defaults to 1.
27
+ */
28
+ viewBox?: number;
29
+ }
7
30
 
8
31
  /** Gradient sweep direction for a multi-color {@link AvatarRingConfig}. */
9
32
  export type AvatarRingGradientDirection = 'diagonal' | 'horizontal' | 'vertical';
@@ -45,8 +68,14 @@ export interface AvatarProps {
45
68
  verified?: boolean;
46
69
  /** Custom verified badge icon (rendered at bottom-right) */
47
70
  verifiedIcon?: ReactNode;
48
- /** Shape of the avatar (defaults to 'circle'). 'squircle' requires react-native-svg. */
49
- shape?: AvatarShape;
71
+ /**
72
+ * Shape of the avatar (defaults to `'circle'`). Accepts a built-in name —
73
+ * `'squircle'`, `'heart'`, `'pentagon'`, … see {@link AvatarShapeName} — or an
74
+ * {@link AvatarShapePath} with your own outline. Everything except `'circle'`
75
+ * clips through `react-native-svg`; a name that does not resolve falls back to
76
+ * a circle.
77
+ */
78
+ shape?: AvatarShape | AvatarShapePath;
50
79
  /** Container style */
51
80
  style?: StyleProp<ViewStyle>;
52
81
  /** Image style (circle shape only) */
@@ -25,7 +25,7 @@ import {
25
25
  import { Image } from 'expo-image';
26
26
  import Animated from 'react-native-reanimated';
27
27
 
28
- import { SLOT_IDENTITY_CHURN_LIMIT } from './constants';
28
+ import { SLOT_IDENTITY_CHURN_LIMIT, SLOT_IDENTITY_CHURN_WINDOW_MS } from './constants';
29
29
  import { handOffFlight } from './store';
30
30
  import type { MediaSurfaceContent, MediaVideoSlot } from './types';
31
31
  import {
@@ -149,17 +149,61 @@ export const MediaSurface = memo(function MediaSurface({
149
149
  // supports.
150
150
  const [mountedSurfaceType] = useState(surfaceType);
151
151
 
152
- // A slot rebuilt on every render republishes this surface to the layer on
153
- // every render, which nothing at runtime reports the picture is correct and
154
- // the app is doing work in proportion to how often its rows re-render. The
155
- // counter lives in an effect rather than in render: a render-phase ref write
156
- // makes the React Compiler bail on the whole component.
157
- const slotChurn = useRef(0);
152
+ // A slot rebuilt on every render re-renders this surface and on web
153
+ // republishes the shared node every time the row it lives in renders, which
154
+ // nothing at runtime reports: the picture is correct and the app is just
155
+ // doing work in proportion to its render count.
156
+ //
157
+ // What is counted is a RUN of consecutive commits that each carried a new
158
+ // slot, NOT how many times the slot has ever changed. The lifetime count
159
+ // cannot tell the defect from a correctly memoised slot: Bloom's own
160
+ // documented example lists `isWatched` in its deps, so its identity changes
161
+ // once per activation of a long-lived surface, and any such consumer reaches
162
+ // any fixed lifetime total eventually. It would then be told to do the thing
163
+ // it is already doing, with no way to make the warning stop — which is worse
164
+ // than not warning, because the advice is unsatisfiable. A slot rebuilt per
165
+ // render is different in kind: it is new on EVERY commit, including the ones
166
+ // where nothing it reads changed.
167
+ //
168
+ // The run must also be FAST, and that second condition is what covers the
169
+ // consumer who memoised everything else too. With `content` and the rest
170
+ // stable, `memo` skips the renders where only the parent changed, so this
171
+ // component commits ONLY when the slot changes — every commit carries a new
172
+ // slot and the run never breaks, even though there is nothing to fix and no
173
+ // cost to pay. Rate is what tells them apart, and it is what the warning was
174
+ // ever about: a slot rebuilt per render churns as fast as its row renders,
175
+ // while one rebuilt when its state changes moves at the speed of a finger.
176
+ //
177
+ // All three refs are written from effects rather than in render: a
178
+ // render-phase ref write makes the React Compiler bail on the whole
179
+ // component. The first effect fires only when the identity changed, and the
180
+ // second — declared after it, and with no dependency array, so it runs on
181
+ // every commit — is what reads that mark and either extends the run or
182
+ // clears it.
183
+ const slotChangedInCommit = useRef(false);
184
+ const slotChurnRun = useRef(0);
185
+ const slotChurnRunStartedAt = useRef(0);
158
186
  useEffect(() => {
159
- if (renderVideo === undefined) return;
160
- slotChurn.current += 1;
161
- if (slotChurn.current === SLOT_IDENTITY_CHURN_LIMIT) warnSlotNotMemoised();
187
+ slotChangedInCommit.current = true;
162
188
  }, [renderVideo]);
189
+ useEffect(() => {
190
+ if (renderVideo === undefined || !slotChangedInCommit.current) {
191
+ slotChurnRun.current = 0;
192
+ return;
193
+ }
194
+ slotChangedInCommit.current = false;
195
+ const now = Date.now();
196
+ if (
197
+ slotChurnRun.current === 0 ||
198
+ now - slotChurnRunStartedAt.current > SLOT_IDENTITY_CHURN_WINDOW_MS
199
+ ) {
200
+ slotChurnRun.current = 1;
201
+ slotChurnRunStartedAt.current = now;
202
+ return;
203
+ }
204
+ slotChurnRun.current += 1;
205
+ if (slotChurnRun.current === SLOT_IDENTITY_CHURN_LIMIT) warnSlotNotMemoised();
206
+ });
163
207
 
164
208
  // Both arms report the same fact — "there is a picture here now" — because the
165
209
  // destination of a flight can be either, and a caller should not have to know
@@ -252,10 +296,12 @@ function warnSlotNotMemoised(): void {
252
296
  hasWarnedAboutSlotChurn = true;
253
297
  // eslint-disable-next-line no-console
254
298
  console.warn(
255
- `[Bloom] A \`renderVideo\` slot changed identity ${SLOT_IDENTITY_CHURN_LIMIT} times. ` +
256
- 'It is part of what a media host publishes to the flight layer and is compared by ' +
257
- 'identity, so a slot rebuilt on every render republishes the surface on every render. ' +
258
- 'Wrap it in `useCallback` with the props it actually reads.',
299
+ `[Bloom] A \`renderVideo\` slot was a NEW function on ${SLOT_IDENTITY_CHURN_LIMIT} ` +
300
+ 'consecutive renders, including ones where nothing it reads changed. The slot is ' +
301
+ 'compared by identity on web it is part of what a media host publishes to the ' +
302
+ 'flight layer so one rebuilt per render re-renders the surface per render. Wrap ' +
303
+ 'it in `useCallback` with the props it actually reads. A slot that changes when ' +
304
+ 'those props change is fine and does not reach this.',
259
305
  );
260
306
  }
261
307
 
@@ -32,16 +32,41 @@ export const SURFACE_MOUNT_TIMEOUT_MS = 250;
32
32
  */
33
33
 
34
34
  /**
35
- * How many times a video slot may change identity before Bloom says so.
35
+ * How many CONSECUTIVE renders a video slot may arrive new on before Bloom says
36
+ * so.
36
37
  *
37
- * `renderVideo` is part of what a host publishes to the layer and is compared
38
- * by identity, so an unmemoised slot republishes on every render of the row it
39
- * lives in silently, and only under load. Five is well past any legitimate
40
- * cause (a mute toggle, a fit change) and far below the churn of a slot rebuilt
41
- * per render in a scrolling feed.
38
+ * `renderVideo` is compared by identity and on web it is part of what a host
39
+ * publishes to the layer — so an unmemoised slot re-renders the surface on
40
+ * every render of the row it lives in, silently and only under load.
41
+ *
42
+ * Consecutive, never a lifetime total. A correctly memoised slot changes
43
+ * identity whenever the state it reads changes (`isWatched` on a reel slide,
44
+ * say), so ANY fixed lifetime total is reached eventually by a consumer with
45
+ * nothing to fix — and the warning's own advice, `useCallback` over the props
46
+ * the slot reads, is what such a consumer already wrote. Five in a row is
47
+ * unreachable that way: it takes five commits where nothing the slot reads
48
+ * changed and the slot was rebuilt anyway.
42
49
  */
43
50
  export const SLOT_IDENTITY_CHURN_LIMIT = 5;
44
51
 
52
+ /**
53
+ * How long a run of {@link SLOT_IDENTITY_CHURN_LIMIT} new slots may take and
54
+ * still be reported (ms).
55
+ *
56
+ * "Consecutive" alone is not enough for the consumer who memoised the surface's
57
+ * other props as well: `memo` then skips every render where only the parent
58
+ * changed, so the surface commits ONLY when the slot changes and the run never
59
+ * breaks — with nothing to fix and, because the renders were skipped, no cost
60
+ * paid either.
61
+ *
62
+ * Rate is what separates them, and it is what the warning was always about. A
63
+ * slot rebuilt per render changes as fast as its row renders, which in a
64
+ * scrolling feed is five times in a fraction of a frame budget. A slot rebuilt
65
+ * when the state it reads changes moves at the speed of a finger, and half a
66
+ * second is far too short for five activations of ONE surface.
67
+ */
68
+ export const SLOT_IDENTITY_CHURN_WINDOW_MS = 500;
69
+
45
70
  /**
46
71
  * How far a media element may sit from the box it is supposed to fill, in px,
47
72
  * before Bloom says so.
@@ -276,9 +276,14 @@ export interface MediaVideoSlotProps<P extends VideoPlayerLike = VideoPlayerLike
276
276
  * So the consumer may build the element instead, with Bloom deciding only what
277
277
  * it has to: which player, and a style that fills the box.
278
278
  *
279
- * MEMOISE IT (`useCallback`). The slot is part of what a host publishes to the
280
- * layer, compared by identity — a new function every render republishes every
279
+ * MEMOISE IT (`useCallback`), over the state the element actually reads. The
280
+ * slot is compared by identity — and on web it is part of what a host publishes
281
+ * to the layer — so a new function every render re-renders the surface every
281
282
  * render. Correct either way, wasteful if you skip it.
283
+ *
284
+ * It is expected to change when that state does; only a slot rebuilt on renders
285
+ * where nothing it reads changed is the mistake, and that is the only one Bloom
286
+ * warns about.
282
287
  */
283
288
  export type MediaVideoSlot<P extends VideoPlayerLike = VideoPlayerLike> = (
284
289
  props: MediaVideoSlotProps<P>,