@openpeepshq/rn-components 0.13.1 → 0.14.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 (30) hide show
  1. package/README.md +2 -0
  2. package/package.json +3 -3
  3. package/src/components/icons/index.ts +2 -0
  4. package/src/components/jams/JamDeviceSelectors.tsx +2 -2
  5. package/src/components/jams/JamLobby.tsx +5 -3
  6. package/src/components/jams/JamParticipantConference.tsx +6 -1
  7. package/src/components/jams/JamRoomIndicators.test.tsx +80 -4
  8. package/src/components/jams/JamRoomIndicators.tsx +34 -1
  9. package/src/components/jams/JamVideoCall.tsx +5 -5
  10. package/src/components/layout/ContentHeader.tsx +6 -2
  11. package/src/components/layout/HeaderMobile.tsx +48 -22
  12. package/src/components/layout/PlusButton.tsx +1 -7
  13. package/src/components/layout/pageChrome.test.tsx +213 -0
  14. package/src/components/post/pieces/FeedPostStats.tsx +15 -11
  15. package/src/components/post/pieces/PollContent.tsx +1 -1
  16. package/src/components/post/pieces/PostMenu.test.tsx +333 -0
  17. package/src/components/post/pieces/PostMenu.tsx +19 -15
  18. package/src/components/post/post-form/ReplyModal.tsx +1 -1
  19. package/src/components/profile/ProfileCard.test.tsx +16 -1
  20. package/src/components/profile/ProfileCard.tsx +14 -3
  21. package/src/components/resources/ResourceLibrary.tsx +0 -1
  22. package/src/hooks/use-controlled-sheet.test.tsx +140 -0
  23. package/src/hooks/use-controlled-sheet.ts +25 -2
  24. package/src/pages/Explore.tsx +1 -3
  25. package/src/pages/conversations/Info.tsx +1 -1
  26. package/src/pages/conversations/New.tsx +1 -1
  27. package/src/pages/conversations/Show.tsx +21 -29
  28. package/src/pages/posts/Edit.tsx +1 -1
  29. package/src/pages/posts/New.tsx +1 -1
  30. package/src/pages/posts/Reply.tsx +2 -2
@@ -83,13 +83,14 @@ const profile = {
83
83
  bio: longBio,
84
84
  } as unknown as ProfileCardProps['profile'];
85
85
 
86
- const renderCard = () => {
86
+ const renderCard = (props: Partial<ProfileCardProps> = {}) => {
87
87
  let tree: ReturnType<typeof ReactTestRenderer.create>;
88
88
  ReactTestRenderer.act(() => {
89
89
  tree = ReactTestRenderer.create(
90
90
  React.createElement(ProfileCard, {
91
91
  profile,
92
92
  actionType: 'link' as const,
93
+ ...props,
93
94
  })
94
95
  );
95
96
  });
@@ -140,4 +141,18 @@ describe('ProfileCard layout guards (issue #2111)', () => {
140
141
  // Follow/Unfollow action is rendered and not clipped away.
141
142
  expect(tree.root.findByType('FollowUnfollowButton')).toBeDefined();
142
143
  });
144
+
145
+ it('drops the default spacing with unspaced (issue #1971)', () => {
146
+ const spaced = renderCard();
147
+ const spacedRow = spaced.root.findByProps({
148
+ className: 'w-full flex-row items-center justify-between px-4 mb-8',
149
+ });
150
+ expect(spacedRow).toBeDefined();
151
+
152
+ const unspaced = renderCard({ unspaced: true });
153
+ const unspacedRow = unspaced.root.findByProps({
154
+ className: 'w-full flex-row items-center justify-between',
155
+ });
156
+ expect(unspacedRow).toBeDefined();
157
+ });
143
158
  });
@@ -22,6 +22,12 @@ export interface ProfileCardProps {
22
22
  actionType?: 'follow' | 'message' | 'unfollow' | 'link' | 'select';
23
23
  handleSelectProfile?: () => void;
24
24
  rightComponent?: React.ReactNode;
25
+ /**
26
+ * Drop the default bottom margin and horizontal padding for placements
27
+ * that manage their own spacing (e.g. a bordered strip), mirroring web's
28
+ * tight card-to-border spacing.
29
+ */
30
+ unspaced?: boolean;
25
31
  }
26
32
 
27
33
  export const ProfileCard = ({
@@ -32,6 +38,7 @@ export const ProfileCard = ({
32
38
  actionType = 'link',
33
39
  handleSelectProfile,
34
40
  rightComponent,
41
+ unspaced = false,
35
42
  }: ProfileCardProps) => {
36
43
  const navigation =
37
44
  useNavigation<NativeStackNavigationProp<MainStackParamList>>();
@@ -59,9 +66,13 @@ export const ProfileCard = ({
59
66
 
60
67
  return (
61
68
  <View
62
- className={`w-full flex-row items-center justify-between px-4 ${
63
- actionType === 'select' ? 'mb-1 py-1' : 'mb-8'
64
- }`}
69
+ className={
70
+ unspaced
71
+ ? 'w-full flex-row items-center justify-between'
72
+ : `w-full flex-row items-center justify-between px-4 ${
73
+ actionType === 'select' ? 'mb-1 py-1' : 'mb-8'
74
+ }`
75
+ }
65
76
  >
66
77
  <TouchableWithoutFeedback onPress={onPress}>
67
78
  <View className="flex flex-row items-center gap-x-2 min-w-0 flex-1">
@@ -358,7 +358,6 @@ export const ResourceLibrary = ({ groupId }: ResourceLibraryProps) => {
358
358
  {library.posts.length > 0 ? (
359
359
  <ThemedText className="text-xs text-muted-foreground">
360
360
  {t('resources.library.resourceCount', {
361
- defaultValue: 'Showing {{count}} resources',
362
361
  count: library.posts.length,
363
362
  })}
364
363
  </ThemedText>
@@ -0,0 +1,140 @@
1
+ /**
2
+ * useControlledSheet regression coverage (issue #2110 round 5).
3
+ *
4
+ * Pins the guard the round-4 review asked to protect: an open with a
5
+ * never-attached sheet ref (missing <BottomSheetModalProvider>, or a sheet
6
+ * that unmounted before the effect ran) must fail loudly — console.error plus
7
+ * exactly one console.warn — instead of silently dropping the present.
8
+ *
9
+ * Node jest env (no native modules): the bottom-sheet ref module is mocked so
10
+ * present/dismiss are observable spies; the component never mounts a real
11
+ * BottomSheetModal, it only holds (or deliberately drops) the ref.
12
+ */
13
+ import { createElement, type ReactNode } from 'react';
14
+ import ReactTestRenderer from 'react-test-renderer';
15
+
16
+ // React 19 act() requires the act environment flag, or it warns on every act().
17
+ (
18
+ globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
19
+ ).IS_REACT_ACT_ENVIRONMENT = true;
20
+
21
+ // --- bottom sheet: drive the attached instance like the real lib does -------
22
+ const presentSpy = jest.fn();
23
+ const dismissSpy = jest.fn();
24
+ jest.mock('../lib/bottom-sheet-ref', () => ({
25
+ bottomSheetPresent: (ref: { current: unknown } | null) =>
26
+ presentSpy(ref?.current),
27
+ bottomSheetDismiss: (ref: { current: unknown } | null) =>
28
+ dismissSpy(ref?.current),
29
+ }));
30
+
31
+ import { useControlledSheet } from './use-controlled-sheet';
32
+
33
+ // Stands in for the BottomSheetModal instance a real <BottomSheetModal ref>
34
+ // would attach to the hook's ref. The hook's present/dismiss path requires
35
+ // ref.current to be non-null (the detached-ref guard is what tests #2/#3 probe).
36
+ const FAKE_SHEET = { present: jest.fn(), dismiss: jest.fn() };
37
+
38
+ // Drives the hook and, when `attach` is true, simulates the sheet mounting by
39
+ // attaching the fake instance to the ref (as a real BottomSheetModal would).
40
+ const FakeSheet = ({
41
+ open,
42
+ attach = true,
43
+ }: {
44
+ open: boolean;
45
+ attach?: boolean;
46
+ }) => {
47
+ const ref = useControlledSheet(open);
48
+ if (attach) {
49
+ ref.current = FAKE_SHEET;
50
+ }
51
+ return null;
52
+ };
53
+
54
+ // Same hook, but the ref is never handed to a sheet: ref.current stays null,
55
+ // which is the detached-ref / missing-provider case the guard must catch.
56
+ const DetachedSheet = ({ open }: { open: boolean }) => {
57
+ useControlledSheet(open);
58
+ return null;
59
+ };
60
+
61
+ const render = (element: ReactNode): ReactTestRenderer.ReactTestRenderer => {
62
+ let renderer!: ReactTestRenderer.ReactTestRenderer;
63
+ ReactTestRenderer.act(() => {
64
+ renderer = ReactTestRenderer.create(element);
65
+ });
66
+ return renderer;
67
+ };
68
+
69
+ describe('useControlledSheet', () => {
70
+ let errorSpy: jest.SpyInstance;
71
+ let warnSpy: jest.SpyInstance;
72
+
73
+ // React's own deprecation/act warnings also route through console.error, so
74
+ // count only this hook's messages rather than raw call counts.
75
+ const noSheetErrors = () =>
76
+ errorSpy.mock.calls.filter((c) =>
77
+ String(c[0]).includes('no bottom sheet instance')
78
+ ).length;
79
+ const noSheetWarns = () =>
80
+ warnSpy.mock.calls.filter((c) =>
81
+ String(c[0]).includes('no sheet instance on first open')
82
+ ).length;
83
+
84
+ beforeEach(() => {
85
+ presentSpy.mockClear();
86
+ dismissSpy.mockClear();
87
+ errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
88
+ warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
89
+ });
90
+
91
+ afterEach(() => {
92
+ errorSpy.mockRestore();
93
+ warnSpy.mockRestore();
94
+ });
95
+
96
+ it('presents when open and the sheet ref is attached', () => {
97
+ const renderer = render(createElement(FakeSheet, { open: true }));
98
+ expect(presentSpy).toHaveBeenCalledTimes(1);
99
+ expect(presentSpy).toHaveBeenCalledWith(FAKE_SHEET);
100
+ expect(noSheetErrors()).toBe(0);
101
+ expect(noSheetWarns()).toBe(0);
102
+ ReactTestRenderer.act(() => renderer.unmount());
103
+ });
104
+
105
+ it('dismisses when open goes false', () => {
106
+ const renderer = render(createElement(FakeSheet, { open: true }));
107
+ expect(presentSpy).toHaveBeenCalledTimes(1);
108
+ expect(dismissSpy).not.toHaveBeenCalled();
109
+ ReactTestRenderer.act(() => {
110
+ renderer.update(createElement(FakeSheet, { open: false }));
111
+ });
112
+ expect(dismissSpy).toHaveBeenCalledTimes(1);
113
+ expect(dismissSpy).toHaveBeenCalledWith(FAKE_SHEET);
114
+ expect(noSheetErrors()).toBe(0);
115
+ });
116
+
117
+ it('errors on a detached ref and warns exactly once per hook instance', () => {
118
+ const renderer = render(createElement(DetachedSheet, { open: false }));
119
+ expect(presentSpy).not.toHaveBeenCalled();
120
+ expect(noSheetErrors()).toBe(0);
121
+ expect(noSheetWarns()).toBe(0);
122
+
123
+ // First open with a never-attached ref: loud error + one provider warning.
124
+ ReactTestRenderer.act(() => {
125
+ renderer.update(createElement(DetachedSheet, { open: true }));
126
+ });
127
+ expect(noSheetErrors()).toBe(1);
128
+ expect(noSheetWarns()).toBe(1);
129
+
130
+ // Re-open after a dismiss must not re-spam the provider warning.
131
+ ReactTestRenderer.act(() => {
132
+ renderer.update(createElement(DetachedSheet, { open: false }));
133
+ });
134
+ ReactTestRenderer.act(() => {
135
+ renderer.update(createElement(DetachedSheet, { open: true }));
136
+ });
137
+ expect(noSheetErrors()).toBe(2);
138
+ expect(noSheetWarns()).toBe(1);
139
+ });
140
+ });
@@ -8,9 +8,32 @@ import {
8
8
  /** Drives an imperative bottom sheet from web-style `open`/`onClose` props. */
9
9
  export const useControlledSheet = (open: boolean) => {
10
10
  const ref = useRef<BottomSheetModal>(null);
11
+ // Fired once per hook instance so a missing provider can't spam on every
12
+ // open attempt.
13
+ const warnedMissingProvider = useRef(false);
11
14
  useEffect(() => {
12
- if (open) bottomSheetPresent(ref);
13
- else bottomSheetDismiss(ref);
15
+ if (open) {
16
+ if (!ref.current) {
17
+ // The sheet instance never attached: the modal subtree either failed
18
+ // to mount or unmounted before this effect ran.
19
+ console.error(
20
+ 'useControlledSheet: no bottom sheet instance to present — the ' +
21
+ 'sheet never mounted.'
22
+ );
23
+ if (!warnedMissingProvider.current) {
24
+ warnedMissingProvider.current = true;
25
+ console.warn(
26
+ 'useControlledSheet: no sheet instance on first open. If this ' +
27
+ 'happens for every sheet, the app root is missing ' +
28
+ '<BottomSheetModalProvider> from @gorhom/bottom-sheet.'
29
+ );
30
+ }
31
+ return;
32
+ }
33
+ bottomSheetPresent(ref);
34
+ } else {
35
+ bottomSheetDismiss(ref);
36
+ }
14
37
  }, [open]);
15
38
  return ref;
16
39
  };
@@ -64,9 +64,7 @@ export const Explore: React.FC<ExploreScreenProps> = ({ navigation }) => {
64
64
  <View className="max-w-[200px] flex-row items-center">
65
65
  <Input
66
66
  className="flex-1"
67
- placeholder={t('explore.searchPlaceholder', {
68
- defaultValue: 'Search',
69
- })}
67
+ placeholder={t('explore.searchPlaceholder')}
70
68
  value={searchQuery}
71
69
  onChangeText={setSearchQuery}
72
70
  />
@@ -35,7 +35,7 @@ export const ConversationInfo = ({ route }: ConversationInfoProps) => {
35
35
  const navigation =
36
36
  useNavigation<NativeStackNavigationProp<MainStackParamList>>();
37
37
 
38
- useSetPageHeader(t('conversations.info'));
38
+ useSetPageHeader(t('conversations.info.title'));
39
39
 
40
40
  return (
41
41
  <ThemedView className="flex-1">
@@ -46,7 +46,7 @@ export const NewConversation = ({
46
46
  }, [currentProfile, allProfiles, searchQuery]);
47
47
 
48
48
  useSetPageHeader(
49
- t('conversations.selectMembers', { defaultValue: 'Select Members' }),
49
+ t('conversations.selectMembers'),
50
50
  <HeaderActionButton
51
51
  title={t('common.next', { defaultValue: 'Next' })}
52
52
  onPress={() => navigation.navigate('DraftMessage')}
@@ -43,31 +43,7 @@ import {
43
43
  DirectMessageSearch,
44
44
  MessageInThread,
45
45
  } from '../../components/conversations/index';
46
-
47
- /**
48
- * Shows handle + bio for a 1:1 conversation participant, without a
49
- * duplicate avatar (the header already renders it).
50
- */
51
- const ConversationParticipantDetail = ({
52
- profile,
53
- }: {
54
- profile: import('@openpeepshq/common').Profile;
55
- }) => {
56
- const truncate = (text: string | null | undefined, max: number) =>
57
- !text ? '' : text.length > max ? text.slice(0, max) + '…' : text;
58
- return (
59
- <View className="gap-y-1 p-3">
60
- <ThemedText className="text-muted-foreground text-xs">
61
- @{profile.handle}
62
- </ThemedText>
63
- {profile.bio ? (
64
- <ThemedText className="text-sm">
65
- {truncate(profile.bio, 100)}
66
- </ThemedText>
67
- ) : null}
68
- </View>
69
- );
70
- };
46
+ import { ProfileCard } from '../../components/profile/index';
71
47
 
72
48
  const isMessageId = (value: string | undefined): value is string =>
73
49
  !!value &&
@@ -122,6 +98,9 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
122
98
  participants.length > 0
123
99
  ? participants.map((p) => p.displayName || `@${p.handle}`).join(', ')
124
100
  : t('conversations.title', { defaultValue: 'Conversation' });
101
+ const openParticipantsLabel = t('conversations.participants.openList', {
102
+ defaultValue: 'View participants',
103
+ });
125
104
 
126
105
  const resetForm = useCallback(() => {
127
106
  setContent('');
@@ -210,6 +189,9 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
210
189
  : t('conversations.search.toggle', {
211
190
  defaultValue: 'Search this conversation',
212
191
  });
192
+ const infoLabel = t('conversations.info.title', {
193
+ defaultValue: 'Conversation info',
194
+ });
213
195
 
214
196
  useSetPageHeader(
215
197
  isLoading ? undefined : (
@@ -237,6 +219,8 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
237
219
  </TouchableOpacity>
238
220
  <TouchableOpacity
239
221
  onPress={() => navigation.navigate('ConversationInfo', { id })}
222
+ accessibilityRole="button"
223
+ accessibilityLabel={infoLabel}
240
224
  className="rounded-md p-1.5"
241
225
  >
242
226
  <InfoIcon size={18} className="text-foreground" />
@@ -257,13 +241,19 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
257
241
  <ThemedView className="flex-1">
258
242
  <View className="flex-1">
259
243
  {/* Section under the page header showing the participants,
260
- mirroring the web conversation Show page. */}
261
- <View className="border-b border-border">
244
+ mirroring the web conversation Show page (ProfileCard for 1:1). */}
245
+ <View className="border-b border-border p-4">
262
246
  {participants.length === 1 && participants[0] ? (
263
- <ConversationParticipantDetail profile={participants[0]} />
247
+ <ProfileCard
248
+ profile={participants[0]}
249
+ showAction={false}
250
+ unspaced
251
+ />
264
252
  ) : multipleParticipants ? (
265
253
  <TouchableOpacity
266
254
  onPress={() => setParticipantsOpen(true)}
255
+ accessibilityRole="button"
256
+ accessibilityLabel={openParticipantsLabel}
267
257
  className="w-full flex-row items-center gap-2 p-3"
268
258
  >
269
259
  <View className="flex-row -space-x-2 shrink-0">
@@ -289,7 +279,9 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
289
279
  <KeyboardAvoidingView
290
280
  className="flex-1"
291
281
  behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
292
- keyboardVerticalOffset={Platform.OS === 'ios' ? 90 : 0}
282
+ // iOS: total chrome above the composer (app bar row + h-16
283
+ // content header); re-measure when the shell chrome changes.
284
+ keyboardVerticalOffset={Platform.OS === 'ios' ? 74 : 0}
293
285
  >
294
286
  {searchOpen ? (
295
287
  <View nativeID="conversation-message-search">
@@ -127,7 +127,7 @@ export const EditPost = ({ route, navigation }: PostProps) => {
127
127
  isPosting
128
128
  ? t('posts.edit.loading')
129
129
  : attachmentsProcessing
130
- ? t('posts.create.processing', 'Processing…')
130
+ ? t('form.upload.processing')
131
131
  : t('posts.edit.submit')
132
132
  }
133
133
  onPress={() => void handlePostUpdate()}
@@ -273,7 +273,7 @@ export const NewPost = ({ route, navigation }: PostProps) => {
273
273
  isPosting
274
274
  ? t('posts.create.loading')
275
275
  : attachmentsProcessing
276
- ? t('posts.create.processing', 'Processing…')
276
+ ? t('form.upload.processing')
277
277
  : t('posts.create.submit')
278
278
  }
279
279
  onPress={() => void handlePostCreation()}
@@ -246,13 +246,13 @@ export const ReplyPost = ({ route, navigation }: PostProps) => {
246
246
  }, [t]);
247
247
 
248
248
  useSetPageHeader(
249
- t('posts.reply.title', { defaultValue: 'Reply' }),
249
+ t('posts.replyModal.title'),
250
250
  <HeaderActionButton
251
251
  title={
252
252
  isPosting
253
253
  ? t('posts.create.loading')
254
254
  : attachmentsProcessing
255
- ? t('posts.create.processing', 'Processing…')
255
+ ? t('form.upload.processing')
256
256
  : t('posts.create.submit')
257
257
  }
258
258
  onPress={() => void handlePostCreation()}