@openpeepshq/rn-components 0.15.0 → 0.17.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 (36) hide show
  1. package/package.json +3 -3
  2. package/src/components/conversations/ConversationPreviewCard.tsx +2 -6
  3. package/src/components/custom/navigation/side-menu.test.tsx +212 -0
  4. package/src/components/custom/navigation/side-menu.tsx +3 -8
  5. package/src/components/groups/GroupCard.tsx +3 -6
  6. package/src/components/icons/index.ts +2 -0
  7. package/src/components/jams/JamChatDrawer.test.tsx +113 -41
  8. package/src/components/jams/JamChatDrawer.tsx +23 -20
  9. package/src/components/jams/JamVideoLayout.tsx +2 -2
  10. package/src/components/jams/useLateTrackMediaStream.test.ts +113 -24
  11. package/src/components/jams/useLateTrackMediaStream.ts +86 -24
  12. package/src/components/navigation/nativeRouter.tsx +13 -3
  13. package/src/components/notifications/NotificationHeaderActions.test.tsx +285 -0
  14. package/src/components/notifications/NotificationHeaderActions.tsx +91 -4
  15. package/src/components/notifications/NotificationsList.test.tsx +109 -0
  16. package/src/components/notifications/NotificationsList.tsx +13 -3
  17. package/src/components/notifications/types/Reaction.tsx +6 -2
  18. package/src/components/post/pieces/PostActions.test.tsx +244 -0
  19. package/src/components/post/pieces/PostActions.tsx +74 -49
  20. package/src/components/post/pieces/ReactionPicker.test.tsx +184 -0
  21. package/src/components/post/pieces/ReactionPicker.tsx +58 -0
  22. package/src/components/post/pieces/index.ts +1 -0
  23. package/src/components/post/pieces/modals/ReactionsModal.tsx +1 -1
  24. package/src/components/post/post-form/ResourceForm.tsx +1 -1
  25. package/src/components/profile/EditProfileForm.test.tsx +316 -0
  26. package/src/components/profile/EditProfileForm.tsx +33 -4
  27. package/src/components/ui/dropdown-menu.test.ts +332 -0
  28. package/src/components/ui/dropdown-menu.tsx +108 -19
  29. package/src/components/ui/index.ts +1 -0
  30. package/src/components/ui/unread-badge.test.tsx +111 -0
  31. package/src/components/ui/unread-badge.tsx +43 -0
  32. package/src/pages/Members.test.tsx +117 -0
  33. package/src/pages/Members.tsx +1 -1
  34. package/src/pages/Notifications.tsx +3 -1
  35. package/src/pages/Welcome.test.tsx +166 -0
  36. package/src/pages/Welcome.tsx +50 -4
@@ -0,0 +1,332 @@
1
+ /**
2
+ * Placement math for the shared `DropdownMenuContent` (issue #1858 — "Edit
3
+ * Post is not accessible when your post is on the bottom of a thread").
4
+ *
5
+ * Before this fix `DropdownMenuContent` only clamped the *horizontal* position
6
+ * and placed the menu at a raw `top:` below the trigger with no viewport clamp
7
+ * and no flip. A trigger near the bottom edge opened the menu below the
8
+ * viewport, so the bottom items (Edit / Delete / …) were unreachable.
9
+ *
10
+ * `computeMenuPlacement` is the extracted, pure placement helper: it flips a
11
+ * `side="bottom"` menu to `top` when there is less room below than above
12
+ * (Radix-style collision handling from the trigger position), never flips an
13
+ * explicit `side="top"` back down, and caps the menu at the viewport space on
14
+ * its chosen side (`maxHeight`) so an overlong menu scrolls instead of leaving
15
+ * the screen. These tests pin that contract.
16
+ *
17
+ * The helper is pure, so the suite only needs the module to *load*; the
18
+ * react-native / portal / themed-view imports are stubbed (node jest env, no
19
+ * native modules) and the render tests follow this file's own stub-host
20
+ * convention — stub host elements that forward `style`/`className` so the
21
+ * placed menu's `maxHeight` and flip are readable on the rendered tree.
22
+ */
23
+ import ReactTestRenderer from 'react-test-renderer';
24
+ import {
25
+ DropdownContext,
26
+ DropdownMenuContent,
27
+ computeMenuPlacement,
28
+ type MenuTriggerLayout,
29
+ } from './dropdown-menu';
30
+
31
+ const React = require('react');
32
+
33
+ // React 19 act() requires the act environment flag, or it warns on every act().
34
+ (
35
+ globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
36
+ ).IS_REACT_ACT_ENVIRONMENT = true;
37
+
38
+ jest.mock('react-native', () => {
39
+ // Forward every prop (including `style` / `className`) onto the host element
40
+ // so the render tests can read the placed menu's `maxHeight`, `top`/`bottom`,
41
+ // `left` and `width` on the rendered tree.
42
+ const host = (tag: string) => {
43
+ const C = (props: Record<string, unknown>) =>
44
+ React.createElement(tag, props, props.children);
45
+ return C;
46
+ };
47
+ return {
48
+ Dimensions: { get: () => ({ width: 375, height: 812 }) },
49
+ Pressable: host('Pressable'),
50
+ ScrollView: host('ScrollView'),
51
+ StyleSheet: {
52
+ create: (s: Record<string, unknown>) => s,
53
+ absoluteFill: {
54
+ position: 'absolute',
55
+ top: 0,
56
+ left: 0,
57
+ right: 0,
58
+ bottom: 0,
59
+ },
60
+ },
61
+ Text: host('Text'),
62
+ View: host('View'),
63
+ };
64
+ });
65
+ jest.mock('@rn-primitives/portal', () => ({
66
+ Portal: (props: { children?: unknown }) =>
67
+ React.createElement('Portal', null, props.children),
68
+ }));
69
+ jest.mock('./themed-view', () => ({
70
+ ThemedView: (props: Record<string, unknown>) =>
71
+ React.createElement(
72
+ 'ThemedView',
73
+ {
74
+ className: `bg-background ${String(props.className ?? '')}`,
75
+ style: props.style,
76
+ },
77
+ props.children
78
+ ),
79
+ }));
80
+
81
+ // iPhone 11 window (the issue's device).
82
+ const SCREEN = { screenHeight: 812, screenWidth: 375 };
83
+ const MENU_WIDTH = 200;
84
+
85
+ const at = (
86
+ triggerLayout: MenuTriggerLayout,
87
+ extra: Record<string, unknown> = {}
88
+ ) =>
89
+ computeMenuPlacement({
90
+ triggerLayout,
91
+ screenHeight: SCREEN.screenHeight,
92
+ screenWidth: SCREEN.screenWidth,
93
+ ...extra,
94
+ });
95
+
96
+ test('1. trigger near the bottom flips to `top` (the #1858 repro)', () => {
97
+ const p = at({ x: 100, y: 750, width: 40, height: 40 });
98
+ // spaceBelow = 812 - 750 - 40 - 4 - 8 = 10; spaceAbove = 750 - 4 - 8 = 738.
99
+ expect(p.effectiveSide).toBe('top');
100
+ expect(p.bottom).toBe(812 - 750 + 4); // 66
101
+ expect(p.top).toBeUndefined();
102
+ expect(p.maxHeight).toBe(738);
103
+ });
104
+
105
+ test('2. trigger near the top stays `bottom`, clamped to the space below', () => {
106
+ const p = at({ x: 100, y: 50, width: 40, height: 40 });
107
+ // spaceBelow = 812 - 50 - 40 - 4 - 8 = 710; spaceAbove = 50 - 4 - 8 = 38.
108
+ expect(p.effectiveSide).toBe('bottom');
109
+ expect(p.top).toBe(50 + 40 + 4); // 94
110
+ expect(p.bottom).toBeUndefined();
111
+ expect(p.maxHeight).toBe(710);
112
+ });
113
+
114
+ test('3. explicit `side="top"` is never flipped back down (and floors at the min height)', () => {
115
+ // Near the top edge: the "more room" heuristic would pick `bottom`
116
+ // (spaceBelow 710 > spaceAbove 38), but an explicit drop-up must stay up.
117
+ const p = at({ x: 100, y: 50, width: 40, height: 40 }, { side: 'top' });
118
+ expect(p.effectiveSide).toBe('top');
119
+ expect(p.bottom).toBe(812 - 50 + 4); // 766
120
+ expect(p.top).toBeUndefined();
121
+ // spaceAbove (38) is below the two-item floor, so maxHeight is the min.
122
+ expect(p.maxHeight).toBe(120);
123
+ });
124
+
125
+ test('4. mid-screen trigger with more room below does not flip', () => {
126
+ const p = at({ x: 100, y: 300, width: 40, height: 40 });
127
+ // spaceBelow = 460 >= spaceAbove = 288 → stays `bottom`.
128
+ expect(p.effectiveSide).toBe('bottom');
129
+ expect(p.top).toBe(300 + 40 + 4); // 344
130
+ expect(p.maxHeight).toBe(460);
131
+ });
132
+
133
+ test('5. exactly-tied space (spaceBelow === spaceAbove) stays `bottom`', () => {
134
+ // spaceBelow = 812 - y - 40 - 4 - 8 = 760 - y; spaceAbove = y - 4 - 8 = y - 12.
135
+ // 760 - y === y - 12 → y = 386, where both spaces are exactly 374.
136
+ // The `>=` tie-break keeps `bottom` (the pre-fix behavior for mid-screen
137
+ // menus); a future `>` change would flip such menus and this test would fail.
138
+ const p = at({ x: 100, y: 386, width: 40, height: 40 });
139
+ expect(p.effectiveSide).toBe('bottom');
140
+ expect(p.top).toBe(386 + 40 + 4); // 430
141
+ expect(p.bottom).toBeUndefined();
142
+ expect(p.maxHeight).toBe(374);
143
+ });
144
+
145
+ test('6. horizontal clamping is unchanged for each align mode', () => {
146
+ // end-aligned trigger near the right edge clamps to screenWidth - width - margin.
147
+ const end = at({ x: 320, y: 400, width: 50, height: 40 });
148
+ expect(end.left).toBe(SCREEN.screenWidth - MENU_WIDTH - 8); // 167
149
+
150
+ // start-aligned trigger at the left edge clamps to the margin.
151
+ const start = at({ x: 0, y: 300, width: 50, height: 40 }, { align: 'start' });
152
+ expect(start.left).toBe(8);
153
+
154
+ // center-aligned trigger in the middle is not clamped.
155
+ const center = at(
156
+ { x: 112.5, y: 300, width: 50, height: 40 },
157
+ { align: 'center' }
158
+ );
159
+ expect(center.left).toBe(37.5);
160
+ });
161
+
162
+ test('7. sideOffset and margin are respected on the chosen side', () => {
163
+ const base = at({ x: 100, y: 300, width: 40, height: 40 });
164
+ const offset = at(
165
+ { x: 100, y: 300, width: 40, height: 40 },
166
+ { sideOffset: 16 }
167
+ );
168
+ // A larger sideOffset pushes the menu down and shrinks the space it may use.
169
+ expect(offset.top).toBe(base.top! + 12);
170
+ expect(offset.maxHeight).toBe(base.maxHeight - 12);
171
+
172
+ // A larger margin widens the left-edge clamp (start-aligned at x=0).
173
+ const wideMargin = at(
174
+ { x: 0, y: 300, width: 50, height: 40 },
175
+ {
176
+ align: 'start',
177
+ margin: 20,
178
+ }
179
+ );
180
+ expect(wideMargin.left).toBe(20);
181
+ });
182
+
183
+ // ---------------------------------------------------------------------------
184
+ // Width assumption + component-level wiring (render tests).
185
+ // ---------------------------------------------------------------------------
186
+
187
+ type TreeNode = {
188
+ type: string;
189
+ props?: Record<string, unknown>;
190
+ children?: (string | TreeNode)[];
191
+ };
192
+
193
+ const walk = (node: TreeNode): TreeNode[] => [
194
+ node,
195
+ ...(node.children ?? [])
196
+ .filter((child): child is TreeNode => typeof child !== 'string')
197
+ .flatMap((child) => walk(child)),
198
+ ];
199
+
200
+ const findByType = (node: TreeNode, type: string): TreeNode => {
201
+ const found = walk(node).find((n) => n.type === type);
202
+ if (!found) throw new Error(`No ${type} node in rendered tree`);
203
+ return found;
204
+ };
205
+
206
+ /** Flattens a style prop (array or object; RN style arrays hold `false` slots). */
207
+ const flattenedStyle = (style: unknown): Record<string, number | string> =>
208
+ (Array.isArray(style) ? style : [style]).reduce(
209
+ (acc: Record<string, number | string>, s: unknown) =>
210
+ s && typeof s === 'object' ? { ...acc, ...s } : acc,
211
+ {}
212
+ );
213
+
214
+ // The base `styles.content` object always contributes these layout/visual props
215
+ // to the content view. The placement spread must add ONLY `left` / `top|bottom`
216
+ // / `maxHeight` / `width` on top of them — nothing else (this is what pins
217
+ // that the `effectiveSide` diagnostic no longer leaks into the view style).
218
+ const CONTENT_BASE_KEYS = [
219
+ 'position',
220
+ 'borderRadius',
221
+ 'borderWidth',
222
+ 'overflow',
223
+ 'paddingVertical',
224
+ 'shadowColor',
225
+ 'shadowOffset',
226
+ 'shadowOpacity',
227
+ 'shadowRadius',
228
+ 'elevation',
229
+ 'zIndex',
230
+ ].sort();
231
+
232
+ /**
233
+ * Renders an open `DropdownMenuContent` with a fixed trigger layout,
234
+ * following this file's stub-host convention (host elements forward `style`
235
+ * / `className` so the placement is readable on the rendered tree).
236
+ */
237
+ const renderContent = (
238
+ triggerLayout: MenuTriggerLayout,
239
+ contentProps: Record<string, unknown> = {}
240
+ ): TreeNode => {
241
+ let tree!: ReactTestRenderer.ReactTestRenderer;
242
+ ReactTestRenderer.act(() => {
243
+ tree = ReactTestRenderer.create(
244
+ React.createElement(
245
+ DropdownContext.Provider,
246
+ {
247
+ value: {
248
+ open: true,
249
+ setOpen: () => {},
250
+ triggerLayout,
251
+ setTriggerLayout: () => {},
252
+ portalName: 'test-portal',
253
+ },
254
+ },
255
+ React.createElement(DropdownMenuContent, contentProps, 'Menu item')
256
+ )
257
+ );
258
+ });
259
+ expect(tree.toJSON()).not.toBeNull();
260
+ return tree.toJSON() as unknown as TreeNode;
261
+ };
262
+
263
+ test('8. a wider call-site width (w-56) is assumed, not enforced, by the clamp', () => {
264
+ // `DropdownMenuContent` renders at a fixed `width: MENU_WIDTH` (200) and the
265
+ // helper clamps `left` against that same 200px width. Live call sites style
266
+ // the content wider — `JamToolbarButton` passes `className="w-56"` (224px) —
267
+ // but the fixed inline width wins (RN inline styles override tailwind
268
+ // classes), so 200px is the real rendered width. Pin that assumption here so
269
+ // the width mismatch cannot silently regress the fix for #1858.
270
+ const trigger: MenuTriggerLayout = { x: 335, y: 400, width: 40, height: 40 };
271
+
272
+ // The rendered width is the fixed MENU_WIDTH, never the wider call-site width.
273
+ const root = renderContent(trigger, { className: 'w-56' });
274
+ const content = flattenedStyle(findByType(root, 'ThemedView').props!.style);
275
+ expect(content.width).toBe(MENU_WIDTH);
276
+
277
+ // ...so clamping at the right edge keeps the (w-56-styled) menu on screen:
278
+ const p = computeMenuPlacement({
279
+ triggerLayout: trigger,
280
+ screenHeight: SCREEN.screenHeight,
281
+ screenWidth: SCREEN.screenWidth,
282
+ menuWidth: MENU_WIDTH,
283
+ });
284
+ // left = min(335 + 40 - 200, 375 - 200 - 8) = 167.
285
+ expect(p.left + MENU_WIDTH).toBe(SCREEN.screenWidth - 8);
286
+ // A genuine 224px menu at that `left` would overflow the edge by 16px —
287
+ // the fixed width is what keeps it inside.
288
+ expect(p.left + 224).toBe(SCREEN.screenWidth + 16);
289
+ });
290
+
291
+ test('9. the component flips a bottom-edge trigger to `top` and caps it (#1858 wiring)', () => {
292
+ // spaceBelow = 812 - 750 - 40 - 4 - 8 = 10 < spaceAbove = 750 - 4 - 8 = 738
293
+ // → the menu flips above the trigger and is capped at the room above.
294
+ const root = renderContent({ x: 100, y: 750, width: 40, height: 40 });
295
+ const content = flattenedStyle(findByType(root, 'ThemedView').props!.style);
296
+ expect(content.bottom).toBe(66);
297
+ expect(content.top).toBeUndefined();
298
+ expect(content.maxHeight).toBe(738);
299
+ // The content view carries only the base content props plus the four
300
+ // placement layout props: the `effectiveSide` diagnostic from the
301
+ // placement helper must not leak into the style.
302
+ expect(Object.keys(content).sort()).toEqual(
303
+ [...CONTENT_BASE_KEYS, 'bottom', 'left', 'maxHeight', 'width'].sort()
304
+ );
305
+ // The scroll container inherits the same cap, so an overlong menu scrolls
306
+ // instead of leaving the viewport unreachable, and does not stretch empty
307
+ // space (flexGrow: 0 keeps the menu at its natural height when short).
308
+ const scroll = findByType(root, 'ScrollView');
309
+ const scrollStyle = flattenedStyle(scroll.props!.style);
310
+ expect(scrollStyle.maxHeight).toBe(738);
311
+ expect(flattenedStyle(scroll.props!.contentContainerStyle)).toEqual({
312
+ flexGrow: 0,
313
+ });
314
+ });
315
+
316
+ test('10. a top-edge trigger keeps `bottom`; the ScrollView is capped to the clamp', () => {
317
+ // spaceBelow = 812 - 50 - 40 - 4 - 8 = 710 >= spaceAbove = 50 - 4 - 8 = 38
318
+ // → stays below the trigger; the scroll container is capped at the space.
319
+ const root = renderContent({ x: 100, y: 50, width: 40, height: 40 });
320
+ const content = flattenedStyle(findByType(root, 'ThemedView').props!.style);
321
+ expect(content.top).toBe(94);
322
+ expect(content.bottom).toBeUndefined();
323
+ expect(Object.keys(content).sort()).toEqual(
324
+ [...CONTENT_BASE_KEYS, 'left', 'maxHeight', 'top', 'width'].sort()
325
+ );
326
+ const scroll = findByType(root, 'ScrollView');
327
+ const scrollStyle = flattenedStyle(scroll.props!.style);
328
+ expect(scrollStyle.maxHeight).toBe(710);
329
+ expect(flattenedStyle(scroll.props!.contentContainerStyle)).toEqual({
330
+ flexGrow: 0,
331
+ });
332
+ });
@@ -2,6 +2,7 @@ import * as React from 'react';
2
2
  import {
3
3
  Dimensions,
4
4
  Pressable,
5
+ ScrollView,
5
6
  type StyleProp,
6
7
  StyleSheet,
7
8
  Text,
@@ -37,6 +38,90 @@ export type DropdownMenuRef = {
37
38
  close: () => void;
38
39
  };
39
40
 
41
+ export type MenuTriggerLayout = {
42
+ x: number;
43
+ y: number;
44
+ width: number;
45
+ height: number;
46
+ };
47
+
48
+ const MENU_MARGIN = 8;
49
+ /** Never clamp the menu below two or so items — a taller menu scrolls. */
50
+ const MIN_MENU_HEIGHT = 120;
51
+ const MENU_WIDTH = 200;
52
+
53
+ export interface MenuPlacementInput {
54
+ triggerLayout: MenuTriggerLayout;
55
+ screenHeight: number;
56
+ screenWidth: number;
57
+ menuWidth?: number;
58
+ sideOffset?: number;
59
+ side?: 'top' | 'bottom';
60
+ align?: 'start' | 'end' | 'center';
61
+ margin?: number;
62
+ }
63
+
64
+ export interface MenuPlacement {
65
+ left: number;
66
+ top?: number;
67
+ bottom?: number;
68
+ maxHeight: number;
69
+ effectiveSide: 'top' | 'bottom';
70
+ }
71
+
72
+ /**
73
+ * Computes the absolute placement of a `DropdownMenuContent` for a trigger.
74
+ *
75
+ * A menu that would open below the trigger flips above it when there is less
76
+ * room below than above (Radix-style collision handling, computed from the
77
+ * trigger position — no content measurement). An explicit `side="top"` is
78
+ * never flipped back down. The menu is capped at the viewport space on its
79
+ * chosen side (`maxHeight`) so an overlong menu scrolls instead of leaving
80
+ * the viewport unreachable.
81
+ */
82
+ export function computeMenuPlacement({
83
+ triggerLayout,
84
+ screenHeight,
85
+ screenWidth,
86
+ menuWidth = MENU_WIDTH,
87
+ sideOffset = 4,
88
+ side = 'bottom',
89
+ align = 'end',
90
+ margin = MENU_MARGIN,
91
+ }: MenuPlacementInput): MenuPlacement {
92
+ let left: number;
93
+ if (align === 'end') {
94
+ left = triggerLayout.x + triggerLayout.width - menuWidth;
95
+ } else if (align === 'start') {
96
+ left = triggerLayout.x;
97
+ } else {
98
+ left = triggerLayout.x + triggerLayout.width / 2 - menuWidth / 2;
99
+ }
100
+ left = Math.max(margin, Math.min(left, screenWidth - menuWidth - margin));
101
+
102
+ const spaceBelow =
103
+ screenHeight - triggerLayout.y - triggerLayout.height - sideOffset - margin;
104
+ const spaceAbove = triggerLayout.y - sideOffset - margin;
105
+
106
+ const effectiveSide: 'top' | 'bottom' =
107
+ side === 'top' || spaceBelow >= spaceAbove ? side : 'top';
108
+
109
+ if (effectiveSide === 'top') {
110
+ return {
111
+ left,
112
+ bottom: screenHeight - triggerLayout.y + sideOffset,
113
+ maxHeight: Math.max(spaceAbove, MIN_MENU_HEIGHT),
114
+ effectiveSide: 'top',
115
+ };
116
+ }
117
+ return {
118
+ left,
119
+ top: triggerLayout.y + triggerLayout.height + sideOffset,
120
+ maxHeight: Math.max(spaceBelow, MIN_MENU_HEIGHT),
121
+ effectiveSide: 'bottom',
122
+ };
123
+ }
124
+
40
125
  const DropdownMenu = React.forwardRef<
41
126
  DropdownMenuRef,
42
127
  {
@@ -102,6 +187,11 @@ const DropdownMenuTrigger = ({
102
187
  const { setOpen, open, setTriggerLayout } = React.useContext(DropdownContext);
103
188
  const ref = React.useRef<View>(null);
104
189
 
190
+ // The trigger must be re-measured on *every* open. Placement is computed
191
+ // from the trigger's window position (see computeMenuPlacement), and that
192
+ // position changes whenever the trigger scrolls. Caching the last
193
+ // measurement would leave a menu placed at the stale trigger location, so
194
+ // always take a fresh measureInWindow here.
105
195
  const handlePress = React.useCallback(() => {
106
196
  ref.current?.measureInWindow((x, y, width, height) => {
107
197
  setTriggerLayout({ x, y, width, height });
@@ -145,25 +235,17 @@ const DropdownMenuContent = ({
145
235
  React.useContext(DropdownContext);
146
236
  const { width: screenWidth, height: screenHeight } = Dimensions.get('window');
147
237
 
148
- const menuWidth = 200;
149
-
150
238
  if (!open || !triggerLayout) return null;
151
239
 
152
- let left: number;
153
- if (align === 'end') {
154
- left = triggerLayout.x + triggerLayout.width - menuWidth;
155
- } else if (align === 'start') {
156
- left = triggerLayout.x;
157
- } else {
158
- left = triggerLayout.x + triggerLayout.width / 2 - menuWidth / 2;
159
- }
160
- left = Math.max(8, Math.min(left, screenWidth - menuWidth - 8));
161
- const vertical =
162
- side === 'top'
163
- ? { bottom: screenHeight - triggerLayout.y + sideOffset }
164
- : { top: triggerLayout.y + triggerLayout.height + sideOffset };
165
-
166
- if (!triggerLayout && !open) return null;
240
+ const { effectiveSide: _effectiveSide, ...placementStyle } =
241
+ computeMenuPlacement({
242
+ triggerLayout,
243
+ screenHeight,
244
+ screenWidth,
245
+ sideOffset,
246
+ align,
247
+ side,
248
+ });
167
249
 
168
250
  return (
169
251
  <Portal name={portalName}>
@@ -177,11 +259,16 @@ const DropdownMenuContent = ({
177
259
  className={`p-4 ${className}`}
178
260
  style={[
179
261
  styles.content,
180
- { ...vertical, left, width: menuWidth },
262
+ { ...placementStyle, width: MENU_WIDTH },
181
263
  !open && styles.hidden,
182
264
  ]}
183
265
  >
184
- {children}
266
+ <ScrollView
267
+ style={{ maxHeight: placementStyle.maxHeight }}
268
+ contentContainerStyle={{ flexGrow: 0 }}
269
+ >
270
+ {children}
271
+ </ScrollView>
185
272
  </ThemedView>
186
273
  </Portal>
187
274
  );
@@ -298,6 +385,7 @@ const styles = StyleSheet.create({
298
385
  position: 'absolute',
299
386
  borderRadius: 8,
300
387
  borderWidth: 1,
388
+ overflow: 'hidden',
301
389
  shadowColor: '#000',
302
390
  shadowOffset: { width: 0, height: 4 },
303
391
  shadowOpacity: 0.12,
@@ -332,6 +420,7 @@ const styles = StyleSheet.create({
332
420
  });
333
421
 
334
422
  export {
423
+ DropdownContext,
335
424
  DropdownMenu,
336
425
  DropdownMenuCheckboxItem,
337
426
  DropdownMenuContent,
@@ -32,6 +32,7 @@ export * from './skeleton';
32
32
  export * from './svg-image';
33
33
  export * from './switch';
34
34
  export * from './tabs';
35
+ export * from './unread-badge';
35
36
 
36
37
  // @rn-primitives select — renamed to avoid clashing with custom/common/select
37
38
  export {
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Tests for the shared unread-count pill (issue #2106 — badge clips
3
+ * 3-digit counts and the ∞ glyph in a fixed 20px RN pill).
4
+ *
5
+ * Pins the geometry contract the fix relies on: the pill grows via native
6
+ * `minWidth` (no fixed `width`), the label is single-line, and the label
7
+ * string comes from the real `formatBadgeCount` (∞ past 99) so the
8
+ * regression the issue reports cannot come back silently.
9
+ */
10
+ const React = require('react');
11
+ const ReactTestRenderer = require('react-test-renderer');
12
+
13
+ jest.mock('react-native', () => {
14
+ const el =
15
+ (tag: string) =>
16
+ (props: Record<string, unknown> & { children?: unknown }) =>
17
+ React.createElement(tag, props, props.children);
18
+ return { View: el('View'), Text: el('Text') };
19
+ });
20
+
21
+ jest.mock('./themed-text', () => ({
22
+ ThemedText: (props: Record<string, unknown> & { children?: unknown }) =>
23
+ React.createElement('ThemedText', props, props.children),
24
+ TextClassContext: {
25
+ Provider: ({ children }: { children?: unknown }) => children,
26
+ },
27
+ }));
28
+
29
+ jest.mock('../../lib/utils', () => ({
30
+ cn: (...parts: Array<string | undefined>) => parts.filter(Boolean).join(' '),
31
+ }));
32
+
33
+ // The jest moduleNameMapper pins the `@openpeepshq/common` root to a single
34
+ // module that does not export `formatBadgeCount` — load the real source
35
+ // directly, since the ∞-past-99 threshold is exactly what this issue pins.
36
+ jest.mock('@openpeepshq/common', () => ({
37
+ formatBadgeCount: require('../../../../common/src/lib/text').formatBadgeCount,
38
+ }));
39
+
40
+ import { UnreadBadge } from './unread-badge';
41
+
42
+ type TreeNode = {
43
+ type: string;
44
+ props?: Record<string, unknown>;
45
+ children?: (string | TreeNode)[];
46
+ };
47
+
48
+ const walk = (node: TreeNode): TreeNode[] => [
49
+ node,
50
+ ...(node.children ?? [])
51
+ .filter((child): child is TreeNode => typeof child !== 'string')
52
+ .flatMap((child) => walk(child)),
53
+ ];
54
+
55
+ const render = (ui: React.ReactNode): TreeNode | null => {
56
+ let tree!: ReactTestRenderer.ReactTestRenderer;
57
+ ReactTestRenderer.act(() => {
58
+ tree = ReactTestRenderer.create(ui);
59
+ });
60
+ return tree.toJSON() as unknown as TreeNode | null;
61
+ };
62
+
63
+ describe('UnreadBadge', () => {
64
+ test('renders the count up to 99', () => {
65
+ const root = render(<UnreadBadge count={99} />);
66
+ expect(root).not.toBeNull();
67
+ const texts = walk(root!).filter((n) => n.type === 'ThemedText');
68
+ expect(texts).toHaveLength(1);
69
+ expect(texts[0].children).toContain('99');
70
+ });
71
+
72
+ test.each([100, 102, 9999])('renders ∞ for count %i', (count) => {
73
+ const root = render(<UnreadBadge count={count} />);
74
+ expect(root).not.toBeNull();
75
+ const texts = walk(root!).filter((n) => n.type === 'ThemedText');
76
+ expect(texts).toHaveLength(1);
77
+ expect(texts[0].children).toContain('∞');
78
+ });
79
+
80
+ test.each([0, -5])('renders nothing for count %i', (count) => {
81
+ const root = render(<UnreadBadge count={count} />);
82
+ expect(root).toBeNull();
83
+ });
84
+
85
+ test('pill grows via minWidth and never carries a fixed width', () => {
86
+ const root = render(<UnreadBadge count={100} />);
87
+ expect(root).not.toBeNull();
88
+ // The pill is the root View here (single node with a style prop).
89
+ const pill = walk(root!).find((n) => n.type === 'View' && n.props?.style);
90
+ expect(pill).toBeDefined();
91
+ const style = pill!.props!.style as Record<string, unknown>;
92
+ expect(style.minWidth).toBe(20);
93
+ expect(style.height).toBe(20);
94
+ expect(style).not.toHaveProperty('width');
95
+ expect(String(pill!.props!.className)).toContain('bg-destructive');
96
+ expect(String(pill!.props!.className)).toContain('rounded-full');
97
+ });
98
+
99
+ test('label is single-line and passes through extra className', () => {
100
+ const root = render(<UnreadBadge count={5} className="shrink-0" />);
101
+ expect(root).not.toBeNull();
102
+ const label = walk(root!).find((n) => n.type === 'ThemedText');
103
+ expect(label).toBeDefined();
104
+ expect(label!.props?.numberOfLines).toBe(1);
105
+ expect(String(label!.props?.className)).toContain(
106
+ 'text-destructive-foreground'
107
+ );
108
+ const pill = walk(root!).find((n) => n.type === 'View' && n.props?.style);
109
+ expect(String(pill!.props!.className)).toContain('shrink-0');
110
+ });
111
+ });
@@ -0,0 +1,43 @@
1
+ import * as React from 'react';
2
+ import { View } from 'react-native';
3
+ import { formatBadgeCount } from '@openpeepshq/common';
4
+ import { cn } from '../../lib/utils';
5
+ import { ThemedText } from './themed-text';
6
+
7
+ /**
8
+ * Shared unread-count pill for every RN badge (side menu, group cards,
9
+ * conversation cards).
10
+ *
11
+ * The geometry is native `minWidth`/`height` on purpose: NativeWind's
12
+ * `size-5` compiles to a fixed 20px width, and on native a fixed width is not
13
+ * overridden by `min-w-5` (unlike web, where `min-width` participates in flex
14
+ * layout). A fixed width is exactly what clipped 3-digit counts and the `∞`
15
+ * glyph in issue #2106 — the pill must be allowed to grow.
16
+ */
17
+ export const UnreadBadge = ({
18
+ count,
19
+ className,
20
+ }: {
21
+ count: number;
22
+ className?: string;
23
+ }) => {
24
+ if (count <= 0) {
25
+ return null;
26
+ }
27
+ return (
28
+ <View
29
+ className={cn(
30
+ 'bg-destructive items-center justify-center rounded-full px-1',
31
+ className
32
+ )}
33
+ style={{ height: 20, minWidth: 20 }}
34
+ >
35
+ <ThemedText
36
+ className="text-xs font-semibold text-destructive-foreground"
37
+ numberOfLines={1}
38
+ >
39
+ {formatBadgeCount(count)}
40
+ </ThemedText>
41
+ </View>
42
+ );
43
+ };