@openpeepshq/rn-components 0.16.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.
- package/package.json +3 -3
- package/src/components/conversations/ConversationPreviewCard.tsx +2 -6
- package/src/components/custom/navigation/side-menu.test.tsx +212 -0
- package/src/components/custom/navigation/side-menu.tsx +3 -8
- package/src/components/groups/GroupCard.tsx +3 -6
- package/src/components/jams/JamChatDrawer.test.tsx +113 -41
- package/src/components/jams/JamChatDrawer.tsx +23 -20
- package/src/components/jams/JamVideoLayout.tsx +2 -2
- package/src/components/jams/useLateTrackMediaStream.test.ts +113 -24
- package/src/components/jams/useLateTrackMediaStream.ts +86 -24
- package/src/components/post/post-form/ResourceForm.tsx +1 -1
- package/src/components/profile/EditProfileForm.test.tsx +316 -0
- package/src/components/profile/EditProfileForm.tsx +33 -4
- package/src/components/ui/dropdown-menu.test.ts +332 -0
- package/src/components/ui/dropdown-menu.tsx +108 -19
- package/src/components/ui/index.ts +1 -0
- package/src/components/ui/unread-badge.test.tsx +111 -0
- package/src/components/ui/unread-badge.tsx +43 -0
- package/src/pages/Members.test.tsx +117 -0
- package/src/pages/Members.tsx +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/rn-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "React Native community screens and shared UI (extracted from the Black Ambition app) for the OpenPeeps stack.",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -142,8 +142,8 @@
|
|
|
142
142
|
"timezones-list": "^3.1.0",
|
|
143
143
|
"validator": "^13.15.23",
|
|
144
144
|
"zustand": "^5.0.3",
|
|
145
|
-
"@openpeepshq/common": "^0.
|
|
146
|
-
"@openpeepshq/react": "^0.
|
|
145
|
+
"@openpeepshq/common": "^0.12.0",
|
|
146
|
+
"@openpeepshq/react": "^0.18.0",
|
|
147
147
|
"@openpeepshq/fetch-client": "^0.2.1"
|
|
148
148
|
},
|
|
149
149
|
"devDependencies": {
|
|
@@ -3,13 +3,13 @@ import React, { useCallback, useRef, useState } from 'react';
|
|
|
3
3
|
import { UpdatingDate } from '../custom/date/updating-date';
|
|
4
4
|
import { OpenpeepsMarkdown } from '../markdown/OpenpeepsMarkdown';
|
|
5
5
|
import {
|
|
6
|
-
formatBadgeCount,
|
|
7
6
|
isConversationLeavePost,
|
|
8
7
|
profileName,
|
|
9
8
|
truncateText,
|
|
10
9
|
type PublicPost,
|
|
11
10
|
} from '@openpeepshq/common';
|
|
12
11
|
import { Text } from '../ui/text';
|
|
12
|
+
import { UnreadBadge } from '../ui/unread-badge';
|
|
13
13
|
import { BottomSheetModal } from '@gorhom/bottom-sheet';
|
|
14
14
|
import {
|
|
15
15
|
DropdownMenu,
|
|
@@ -92,11 +92,7 @@ export const ConversationPreviewCard = ({
|
|
|
92
92
|
{truncateText(title, 20)}
|
|
93
93
|
</Text>
|
|
94
94
|
{unreadCount > 0 ? (
|
|
95
|
-
<
|
|
96
|
-
<Text className="text-xs font-semibold text-destructive-foreground">
|
|
97
|
-
{formatBadgeCount(unreadCount)}
|
|
98
|
-
</Text>
|
|
99
|
-
</View>
|
|
95
|
+
<UnreadBadge count={unreadCount} className="shrink-0" />
|
|
100
96
|
) : null}
|
|
101
97
|
</View>
|
|
102
98
|
</View>
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression test for issue #2106 — the side-menu unread badge clipped
|
|
3
|
+
* 3-digit counts and the ∞ glyph in a fixed 20px pill.
|
|
4
|
+
*
|
|
5
|
+
* The fix routes the badge through the shared `UnreadBadge` component, so
|
|
6
|
+
* this suite pins the call-site contract: the Groups row renders the badge
|
|
7
|
+
* when the group unread count is positive, renders nothing at 0, and no
|
|
8
|
+
* inline `size-5` pill markup remains in the menu items.
|
|
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 {
|
|
19
|
+
View: el('View'),
|
|
20
|
+
Text: el('Text'),
|
|
21
|
+
Pressable: el('Pressable'),
|
|
22
|
+
ScrollView: el('ScrollView'),
|
|
23
|
+
TouchableOpacity: el('TouchableOpacity'),
|
|
24
|
+
Linking: { openURL: jest.fn() },
|
|
25
|
+
Platform: { OS: 'android', select: (o: { android: unknown }) => o.android },
|
|
26
|
+
useColorScheme: () => 'light',
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
jest.mock('react-i18next', () => ({
|
|
31
|
+
useTranslation: () => ({
|
|
32
|
+
t: (key: string, opts?: { defaultValue?: string }) =>
|
|
33
|
+
opts?.defaultValue ?? key,
|
|
34
|
+
}),
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
jest.mock('@openpeepshq/common', () => ({
|
|
38
|
+
getTheme: () => ({}),
|
|
39
|
+
// The real UnreadBadge formats its label through this helper.
|
|
40
|
+
formatBadgeCount: require('../../../../../common/src/lib/text')
|
|
41
|
+
.formatBadgeCount,
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
// Mutable so each case can drive the unseen-counts hook; the mock factory
|
|
45
|
+
// reads it lazily per call.
|
|
46
|
+
let mockUnseenData: {
|
|
47
|
+
groups: Record<string, number>;
|
|
48
|
+
direct: Record<string, number>;
|
|
49
|
+
} = { groups: {}, direct: {} };
|
|
50
|
+
|
|
51
|
+
jest.mock('@openpeepshq/react', () => ({
|
|
52
|
+
useOpenpeeps: () => ({
|
|
53
|
+
openpeepsApi: {
|
|
54
|
+
logoutAction: () => jest.fn(),
|
|
55
|
+
useServerInfo: () => ({ data: undefined }),
|
|
56
|
+
useCurrentProfileSettings: () => ({ data: undefined }),
|
|
57
|
+
useUnseenPostCounts: () => ({ data: mockUnseenData }),
|
|
58
|
+
},
|
|
59
|
+
currentProfile: {
|
|
60
|
+
id: 'me',
|
|
61
|
+
handle: 'me@example',
|
|
62
|
+
displayName: 'Me',
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
buildMainNavItems: require('../../../../../react/src/navigation/menuItems')
|
|
66
|
+
.buildMainNavItems,
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
jest.mock('../../../hooks/helper', () => ({
|
|
70
|
+
useWindowSize: () => ({
|
|
71
|
+
windowWidth: 400,
|
|
72
|
+
windowHeight: 800,
|
|
73
|
+
isMediumScreenOrLarger: false,
|
|
74
|
+
}),
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
jest.mock('../../../lib/media-url', () => ({
|
|
78
|
+
toAbsoluteMediaUrl: (u?: string) => u,
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
jest.mock('../../ui/separator', () => ({
|
|
82
|
+
Separator: (props: Record<string, unknown> & { children?: unknown }) =>
|
|
83
|
+
React.createElement('Separator', props, props.children),
|
|
84
|
+
}));
|
|
85
|
+
|
|
86
|
+
jest.mock('../../ui/button', () => ({
|
|
87
|
+
Button: (props: Record<string, unknown> & { children?: unknown }) =>
|
|
88
|
+
React.createElement('Button', props, props.children),
|
|
89
|
+
}));
|
|
90
|
+
|
|
91
|
+
jest.mock('../../ui/svg-image', () => ({
|
|
92
|
+
SvgImage: (props: Record<string, unknown>) =>
|
|
93
|
+
React.createElement('SvgImage', props),
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
jest.mock('../../ui/themed-text', () => ({
|
|
97
|
+
ThemedText: (props: Record<string, unknown> & { children?: unknown }) =>
|
|
98
|
+
React.createElement('ThemedText', props, props.children),
|
|
99
|
+
TextClassContext: {
|
|
100
|
+
Provider: ({ children }: { children?: unknown }) => children,
|
|
101
|
+
},
|
|
102
|
+
}));
|
|
103
|
+
|
|
104
|
+
jest.mock('../../ui/tooltip', () => ({
|
|
105
|
+
Tooltip: ({ children }: { children?: unknown }) => children,
|
|
106
|
+
TooltipTrigger: ({ children }: { children?: unknown }) => children,
|
|
107
|
+
TooltipContent: ({ children }: { children?: unknown }) => children,
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
jest.mock('../../profile/Avatar', () => ({
|
|
111
|
+
ProfileAvatar: (props: Record<string, unknown>) =>
|
|
112
|
+
React.createElement('ProfileAvatar', props),
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
jest.mock(
|
|
116
|
+
'../../icons/index',
|
|
117
|
+
() =>
|
|
118
|
+
new Proxy(
|
|
119
|
+
{},
|
|
120
|
+
{
|
|
121
|
+
get: (_t, name: string) => (props: Record<string, unknown>) =>
|
|
122
|
+
React.createElement(name, props),
|
|
123
|
+
}
|
|
124
|
+
)
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
// The real UnreadBadge is rendered, and its `cn` comes from `lib/utils`,
|
|
128
|
+
// which imports react-native-config (native module, ESM-only) — mock it
|
|
129
|
+
// wholesale with the join helper the components actually use.
|
|
130
|
+
jest.mock('../../../lib/utils', () => ({
|
|
131
|
+
cn: (...parts: Array<string | undefined>) => parts.filter(Boolean).join(' '),
|
|
132
|
+
}));
|
|
133
|
+
|
|
134
|
+
import { SideMenu } from './side-menu';
|
|
135
|
+
|
|
136
|
+
type TreeNode = {
|
|
137
|
+
type: string;
|
|
138
|
+
props?: Record<string, unknown>;
|
|
139
|
+
children?: (string | TreeNode)[];
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const walk = (node: TreeNode): TreeNode[] => [
|
|
143
|
+
node,
|
|
144
|
+
...(node.children ?? [])
|
|
145
|
+
.filter((child): child is TreeNode => typeof child !== 'string')
|
|
146
|
+
.flatMap((child) => walk(child)),
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
const render = (ui: React.ReactNode): TreeNode => {
|
|
150
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
151
|
+
ReactTestRenderer.act(() => {
|
|
152
|
+
tree = ReactTestRenderer.create(ui);
|
|
153
|
+
});
|
|
154
|
+
expect(tree.toJSON()).not.toBeNull();
|
|
155
|
+
return tree.toJSON() as unknown as TreeNode;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const renderSideMenu = (unseen: {
|
|
159
|
+
groups?: Record<string, number>;
|
|
160
|
+
direct?: Record<string, number>;
|
|
161
|
+
}) => {
|
|
162
|
+
mockUnseenData = { groups: {}, direct: {}, ...unseen };
|
|
163
|
+
return render(
|
|
164
|
+
<SideMenu
|
|
165
|
+
handleNavigation={() => {}}
|
|
166
|
+
onNotificationPress={() => {}}
|
|
167
|
+
onProfilePress={() => {}}
|
|
168
|
+
/>
|
|
169
|
+
);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// The real UnreadBadge flattens into a host `View` (function components are
|
|
173
|
+
// elided from the rendered tree), so the badge is detected by its pill
|
|
174
|
+
// classes + geometry, which pins the call site end-to-end.
|
|
175
|
+
const badgeViews = (root: TreeNode): TreeNode[] =>
|
|
176
|
+
walk(root).filter(
|
|
177
|
+
(n) =>
|
|
178
|
+
n.type === 'View' &&
|
|
179
|
+
typeof n.props?.className === 'string' &&
|
|
180
|
+
String(n.props.className).includes('bg-destructive')
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
describe('SideMenu unread badges (#2106)', () => {
|
|
184
|
+
test('Groups row renders the badge when the group count is positive', () => {
|
|
185
|
+
const root = renderSideMenu({ groups: { 'group-1': 3 } });
|
|
186
|
+
const badges = badgeViews(root);
|
|
187
|
+
expect(badges).toHaveLength(1);
|
|
188
|
+
// The label is the real formatBadgeCount output for 3.
|
|
189
|
+
const texts = walk(badges[0]).filter((n) => n.type === 'ThemedText');
|
|
190
|
+
expect(texts).toHaveLength(1);
|
|
191
|
+
expect(texts[0].children).toContain('3');
|
|
192
|
+
// The geometry contract holds through the call site: minWidth, no width.
|
|
193
|
+
const style = badges[0].props!.style as Record<string, unknown>;
|
|
194
|
+
expect(style.minWidth).toBe(20);
|
|
195
|
+
expect(style).not.toHaveProperty('width');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('no badge is rendered when the group count is 0', () => {
|
|
199
|
+
const root = renderSideMenu({});
|
|
200
|
+
expect(badgeViews(root)).toHaveLength(0);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('no inline fixed-size pill markup remains in the menu rows', () => {
|
|
204
|
+
const root = renderSideMenu({ groups: { g: 7 }, direct: { c: 2 } });
|
|
205
|
+
const fixedPills = walk(root).filter((n) => {
|
|
206
|
+
if (n.type !== 'View') return false;
|
|
207
|
+
const cls = n.props?.className;
|
|
208
|
+
return typeof cls === 'string' && cls.includes('size-5');
|
|
209
|
+
});
|
|
210
|
+
expect(fixedPills).toHaveLength(0);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
@@ -29,10 +29,11 @@ import {
|
|
|
29
29
|
LibraryIcon,
|
|
30
30
|
} from '../../icons/index';
|
|
31
31
|
import { ThemedText } from '../../ui/themed-text';
|
|
32
|
+
import { UnreadBadge } from '../../ui/unread-badge';
|
|
32
33
|
import { Tooltip, TooltipContent, TooltipTrigger } from '../../ui/tooltip';
|
|
33
34
|
import { useWindowSize } from '../../../hooks/helper';
|
|
34
35
|
import { toAbsoluteMediaUrl } from '../../../lib/media-url';
|
|
35
|
-
import {
|
|
36
|
+
import { getTheme } from '@openpeepshq/common';
|
|
36
37
|
import { buildMainNavItems, useOpenpeeps } from '@openpeepshq/react';
|
|
37
38
|
import { useTranslation } from 'react-i18next';
|
|
38
39
|
import { ProfileAvatar } from '../../profile/Avatar';
|
|
@@ -238,13 +239,7 @@ export const SideMenu = ({
|
|
|
238
239
|
{t(item.labelKey)}
|
|
239
240
|
</ThemedText>
|
|
240
241
|
</View>
|
|
241
|
-
{
|
|
242
|
-
<View className="bg-destructive size-5 min-w-5 items-center justify-center rounded-full px-1">
|
|
243
|
-
<ThemedText className="text-xs font-semibold text-destructive-foreground">
|
|
244
|
-
{formatBadgeCount(menuUnreadCounts[item.id] ?? 0)}
|
|
245
|
-
</ThemedText>
|
|
246
|
-
</View>
|
|
247
|
-
) : null}
|
|
242
|
+
<UnreadBadge count={menuUnreadCounts[item.id] ?? 0} />
|
|
248
243
|
</View>
|
|
249
244
|
</SideMenuNavButton>
|
|
250
245
|
);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Pressable, View } from 'react-native';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { GroupWithMeta } from '@openpeepshq/common';
|
|
4
4
|
import { useOpenpeeps } from '@openpeepshq/react';
|
|
5
5
|
import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar';
|
|
6
6
|
import { ThemedText } from '../ui/themed-text';
|
|
7
|
+
import { UnreadBadge } from '../ui/unread-badge';
|
|
7
8
|
import { Button } from '../ui/button';
|
|
8
9
|
import { UsersIcon } from '../icons/index';
|
|
9
10
|
import { useTranslation } from 'react-i18next';
|
|
@@ -53,11 +54,7 @@ export const GroupCard = ({
|
|
|
53
54
|
{group.displayName || '-'}
|
|
54
55
|
</ThemedText>
|
|
55
56
|
{unreadCount > 0 ? (
|
|
56
|
-
<
|
|
57
|
-
<ThemedText className="text-xs font-semibold text-destructive-foreground">
|
|
58
|
-
{formatBadgeCount(unreadCount)}
|
|
59
|
-
</ThemedText>
|
|
60
|
-
</View>
|
|
57
|
+
<UnreadBadge count={unreadCount} className="shrink-0" />
|
|
61
58
|
) : null}
|
|
62
59
|
</View>
|
|
63
60
|
<View className="flex-row gap-x-3 mt-2 items-center">
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tests for the JAM chat drawer keyboard handling (issue #1705):
|
|
3
3
|
*
|
|
4
|
-
* - The drawer must present with
|
|
5
|
-
* offset
|
|
6
|
-
*
|
|
4
|
+
* - The drawer must present with a KeyboardAvoidingView on both platforms,
|
|
5
|
+
* both using behavior 'padding' and offset = the safe-area top inset
|
|
6
|
+
* (the KAV's parent screen-Y). The KAV must be enabled on Android too —
|
|
7
|
+
* avoidance is the component's own job, not the host app's
|
|
8
|
+
* windowSoftInputMode (the QA retest on the shipping host found the
|
|
9
|
+
* keyboard still covers the chat when the host does not resize).
|
|
7
10
|
* - It must never crash on hosts that mount no SafeAreaProvider: the
|
|
8
11
|
* react-native-safe-area-context mock below reproduces the 5.8.0
|
|
9
12
|
* semantics (context defaults to null; the hook throws on null) so the
|
|
10
13
|
* drawer's context-based read is what keeps it alive, not a hook mock.
|
|
11
14
|
* - It must re-pin the newest message via the keyboardDidShow listener
|
|
12
|
-
* (the base-sheet.tsx pattern)
|
|
13
|
-
*
|
|
15
|
+
* (the base-sheet.tsx pattern) on both platforms — the KAV reflow lands
|
|
16
|
+
* after the keyboard animation, so the re-pin settles the newest message
|
|
17
|
+
* above the composer; skipped when readOnly (no composer to re-pin).
|
|
14
18
|
*/
|
|
15
19
|
|
|
16
20
|
const React = require('react');
|
|
@@ -33,7 +37,7 @@ jest.mock('react-native-safe-area-context', () => ({
|
|
|
33
37
|
useSafeAreaInsets: throwingUseSafeAreaInsets,
|
|
34
38
|
// The real 5.8.0 provider only exposes the context once native metrics
|
|
35
39
|
// arrive; this stub models the settled state (context set immediately).
|
|
36
|
-
SafeAreaProvider: (props:
|
|
40
|
+
SafeAreaProvider: (props: MockElementProps) =>
|
|
37
41
|
React.createElement(
|
|
38
42
|
'SafeAreaProvider',
|
|
39
43
|
null,
|
|
@@ -45,6 +49,30 @@ jest.mock('react-native-safe-area-context', () => ({
|
|
|
45
49
|
),
|
|
46
50
|
}));
|
|
47
51
|
|
|
52
|
+
// Type-safe stub props: the mocks render through React.createElement with
|
|
53
|
+
// the same prop names the component passes, so a shared interface (instead
|
|
54
|
+
// of Record<string, unknown>) catches prop-name drift at compile time.
|
|
55
|
+
interface MockElementProps {
|
|
56
|
+
children?: React.ReactNode;
|
|
57
|
+
className?: string;
|
|
58
|
+
accessibilityLabel?: string;
|
|
59
|
+
accessibilityRole?: string;
|
|
60
|
+
onPress?: () => void;
|
|
61
|
+
disabled?: boolean;
|
|
62
|
+
editable?: boolean;
|
|
63
|
+
value?: string;
|
|
64
|
+
onChangeText?: (text: string) => void;
|
|
65
|
+
onSubmitEditing?: () => void;
|
|
66
|
+
blurOnSubmit?: boolean;
|
|
67
|
+
numberOfLines?: number;
|
|
68
|
+
placeholder?: string;
|
|
69
|
+
size?: number;
|
|
70
|
+
behavior?: string;
|
|
71
|
+
keyboardVerticalOffset?: number;
|
|
72
|
+
ref?: React.Ref<unknown>;
|
|
73
|
+
[key: string]: unknown;
|
|
74
|
+
}
|
|
75
|
+
|
|
48
76
|
const platformState = { os: 'ios' as 'ios' | 'android' };
|
|
49
77
|
const flatListState = { handles: [] as Array<{ scrollToEnd: jest.Mock }> };
|
|
50
78
|
// Records the Keyboard listeners the drawer subscribes to, so a test can
|
|
@@ -60,14 +88,14 @@ jest.mock('react-native', () => ({
|
|
|
60
88
|
return platformState.os;
|
|
61
89
|
},
|
|
62
90
|
},
|
|
63
|
-
View: (props:
|
|
91
|
+
View: (props: MockElementProps) =>
|
|
64
92
|
React.createElement('View', props, props.children),
|
|
65
|
-
Pressable: (props:
|
|
93
|
+
Pressable: (props: MockElementProps) =>
|
|
66
94
|
React.createElement('Pressable', props, props.children),
|
|
67
|
-
ActivityIndicator: (props:
|
|
95
|
+
ActivityIndicator: (props: MockElementProps) =>
|
|
68
96
|
React.createElement('ActivityIndicator', props),
|
|
69
97
|
FlatList: Object.assign(
|
|
70
|
-
React.forwardRef((props:
|
|
98
|
+
React.forwardRef((props: MockElementProps, ref: unknown) => {
|
|
71
99
|
const handle = { scrollToEnd: jest.fn() };
|
|
72
100
|
flatListState.handles.push(handle);
|
|
73
101
|
React.useImperativeHandle(
|
|
@@ -78,7 +106,7 @@ jest.mock('react-native', () => ({
|
|
|
78
106
|
}),
|
|
79
107
|
{ displayName: 'FlatList' }
|
|
80
108
|
),
|
|
81
|
-
KeyboardAvoidingView: (props:
|
|
109
|
+
KeyboardAvoidingView: (props: MockElementProps) =>
|
|
82
110
|
React.createElement('KeyboardAvoidingView', props, props.children),
|
|
83
111
|
Keyboard: {
|
|
84
112
|
addListener: (type: string, cb: jest.Mock) => {
|
|
@@ -119,27 +147,26 @@ jest.mock('@livekit/react-native', () => ({
|
|
|
119
147
|
jest.mock('@openpeepshq/common', () => ({}));
|
|
120
148
|
|
|
121
149
|
jest.mock('./JamDrawer', () => ({
|
|
122
|
-
JamDrawer: (props:
|
|
150
|
+
JamDrawer: (props: MockElementProps) =>
|
|
123
151
|
React.createElement('JamDrawer', props, props.children),
|
|
124
152
|
}));
|
|
125
153
|
|
|
126
154
|
jest.mock('./JamChatMessage', () => ({
|
|
127
|
-
JamChatMessage: (props:
|
|
155
|
+
JamChatMessage: (props: MockElementProps) =>
|
|
128
156
|
React.createElement('JamChatMessage', props),
|
|
129
157
|
}));
|
|
130
158
|
|
|
131
159
|
jest.mock('../icons/index', () => ({
|
|
132
|
-
SendHorizontalIcon: (props:
|
|
160
|
+
SendHorizontalIcon: (props: MockElementProps) =>
|
|
133
161
|
React.createElement('SendHorizontalIcon', props),
|
|
134
162
|
}));
|
|
135
163
|
|
|
136
164
|
jest.mock('../ui/textarea', () => ({
|
|
137
|
-
Textarea: (props:
|
|
138
|
-
React.createElement('Textarea', props),
|
|
165
|
+
Textarea: (props: MockElementProps) => React.createElement('Textarea', props),
|
|
139
166
|
}));
|
|
140
167
|
|
|
141
168
|
jest.mock('../ui/themed-text', () => ({
|
|
142
|
-
ThemedText: (props:
|
|
169
|
+
ThemedText: (props: MockElementProps) =>
|
|
143
170
|
React.createElement('ThemedText', props, props.children),
|
|
144
171
|
}));
|
|
145
172
|
|
|
@@ -147,16 +174,28 @@ import { JamChatDrawer } from './JamChatDrawer';
|
|
|
147
174
|
|
|
148
175
|
const hostProvider = { value: insets59 };
|
|
149
176
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
177
|
+
// Test-only knobs for renderDrawer, kept apart from the component's props
|
|
178
|
+
// so the helper can never forward one of them into the tree.
|
|
179
|
+
interface RenderDrawerOptions {
|
|
180
|
+
readOnly?: boolean;
|
|
181
|
+
os?: 'ios' | 'android';
|
|
182
|
+
wrapInHostProvider?: boolean;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const renderDrawer = (props: RenderDrawerOptions = {}) => {
|
|
186
|
+
// Tests pass the OS through the helper rather than mutating platformState
|
|
187
|
+
// themselves, so per-test setup stays isolated (afterEach still resets it).
|
|
188
|
+
// Only drawerProps reaches the component element; os and
|
|
189
|
+
// wrapInHostProvider are destructured out, so neither can leak onto
|
|
190
|
+
// JamChatDrawer as a foreign prop.
|
|
191
|
+
const { os = 'ios', wrapInHostProvider = true, ...drawerProps } = props;
|
|
192
|
+
platformState.os = os;
|
|
154
193
|
let tree: ReturnType<typeof ReactTestRenderer.create>;
|
|
155
194
|
ReactTestRenderer.act(() => {
|
|
156
195
|
const drawer = React.createElement(JamChatDrawer, {
|
|
157
196
|
open: true,
|
|
158
197
|
onClose: jest.fn(),
|
|
159
|
-
...
|
|
198
|
+
...drawerProps,
|
|
160
199
|
});
|
|
161
200
|
tree = ReactTestRenderer.create(
|
|
162
201
|
wrapInHostProvider
|
|
@@ -171,6 +210,17 @@ const renderDrawer = (
|
|
|
171
210
|
return tree;
|
|
172
211
|
};
|
|
173
212
|
|
|
213
|
+
// The KAV contract that must hold on every platform/provider variant:
|
|
214
|
+
// 'padding' lift, the safe-area-top offset (the KAV's parent screen-Y), and
|
|
215
|
+
// avoidance not disabled. Call it from each variant test so the contract
|
|
216
|
+
// lives in one place; the test keeps its own comment for the variant's
|
|
217
|
+
// distinguishing assertion.
|
|
218
|
+
const expectKavContract = (kav: { props: MockElementProps }) => {
|
|
219
|
+
expect(kav.props.behavior).toBe('padding');
|
|
220
|
+
expect(kav.props.keyboardVerticalOffset).toBe(59);
|
|
221
|
+
expect(kav.props.enabled).not.toBe(false);
|
|
222
|
+
};
|
|
223
|
+
|
|
174
224
|
describe('JamChatDrawer keyboard handling (issue #1705)', () => {
|
|
175
225
|
afterEach(() => {
|
|
176
226
|
platformState.os = 'ios';
|
|
@@ -190,39 +240,61 @@ describe('JamChatDrawer keyboard handling (issue #1705)', () => {
|
|
|
190
240
|
|
|
191
241
|
it('avoids the keyboard on iOS with the safe-area-top offset', () => {
|
|
192
242
|
const tree = renderDrawer();
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
243
|
+
// The prop is absent (RN defaults enabled to true); the contract pins
|
|
244
|
+
// the axis so a regression that re-gates the KAV to iOS-only fails
|
|
245
|
+
// here, not just on the behavior assertion.
|
|
246
|
+
expectKavContract(tree.root.findByType('KeyboardAvoidingView'));
|
|
197
247
|
});
|
|
198
248
|
|
|
199
|
-
it('
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
// Android
|
|
206
|
-
//
|
|
207
|
-
|
|
249
|
+
it('avoids the keyboard on Android with the padding behavior (host-independent)', () => {
|
|
250
|
+
const tree = renderDrawer({ os: 'android' });
|
|
251
|
+
// Avoidance is the component's own job on Android, not the host app's
|
|
252
|
+
// windowSoftInputMode: 'padding' shrinks the drawer by the measured
|
|
253
|
+
// keyboard overlap, so the newest message and composer stay visible
|
|
254
|
+
// regardless of the host's soft-input mode. The enabled axis is pinned
|
|
255
|
+
// on Android too (in the contract) — without it, a regression that
|
|
256
|
+
// re-adds enabled={isIos} while keeping behavior 'padding' would pass
|
|
257
|
+
// every test here while reintroducing exactly the QA-reported bug (a
|
|
258
|
+
// disabled KAV is a no-op regardless of behavior).
|
|
259
|
+
expectKavContract(tree.root.findByType('KeyboardAvoidingView'));
|
|
260
|
+
// Cross-platform re-pin contract: Android subscribes too, so the newest
|
|
261
|
+
// message settles above the composer after the padding reflow.
|
|
262
|
+
expect(keyboardState.listeners).toHaveLength(1);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('re-pins the newest message on Android when the keyboard shows', () => {
|
|
266
|
+
renderDrawer({ os: 'android' });
|
|
267
|
+
// The Android re-pin is the changed behavior in this fix, so it is
|
|
268
|
+
// asserted behaviorally (listener fired) rather than by subscription
|
|
269
|
+
// count alone — the cross-platform contract is the same as iOS: fire
|
|
270
|
+
// the keyboardDidShow subscriber the way the platform would and the
|
|
271
|
+
// newest message settles above the composer after the padding reflow.
|
|
272
|
+
const didShow = keyboardState.listeners.filter(
|
|
273
|
+
(l) => l.type === 'keyboardDidShow'
|
|
274
|
+
);
|
|
275
|
+
expect(didShow).toHaveLength(1);
|
|
276
|
+
const handle = flatListState.handles[flatListState.handles.length - 1];
|
|
277
|
+
ReactTestRenderer.act(() => {
|
|
278
|
+
didShow[0].cb();
|
|
279
|
+
});
|
|
280
|
+
expect(handle.scrollToEnd).toHaveBeenCalledWith({ animated: true });
|
|
208
281
|
});
|
|
209
282
|
|
|
210
283
|
it('renders without a host SafeAreaProvider instead of throwing', () => {
|
|
211
284
|
// No provider above: the context is null. If the drawer read the hook
|
|
212
285
|
// instead of the context, this render throws (real 5.8.0 semantics).
|
|
213
|
-
const tree = renderDrawer({
|
|
286
|
+
const tree = renderDrawer({ wrapInHostProvider: false });
|
|
214
287
|
expect(throwingUseSafeAreaInsets).not.toHaveBeenCalled();
|
|
215
|
-
// The drawer serves its own provider, so the offset still resolves
|
|
288
|
+
// The drawer serves its own provider, so the offset still resolves —
|
|
289
|
+
// the self-provided provider does not change the avoidance contract.
|
|
216
290
|
expect(tree.root.findByType('SafeAreaProvider')).toBeDefined();
|
|
217
|
-
|
|
218
|
-
expect(kav.props.keyboardVerticalOffset).toBe(59);
|
|
291
|
+
expectKavContract(tree.root.findByType('KeyboardAvoidingView'));
|
|
219
292
|
});
|
|
220
293
|
|
|
221
294
|
it('keeps the host provider authoritative (no nested provider)', () => {
|
|
222
295
|
const tree = renderDrawer();
|
|
223
296
|
expect(tree.root.findAllByType('SafeAreaProvider')).toHaveLength(0);
|
|
224
|
-
|
|
225
|
-
expect(kav.props.keyboardVerticalOffset).toBe(59);
|
|
297
|
+
expectKavContract(tree.root.findByType('KeyboardAvoidingView'));
|
|
226
298
|
});
|
|
227
299
|
|
|
228
300
|
it('re-pins the newest message when the keyboard shows', () => {
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
FlatList,
|
|
5
5
|
Keyboard,
|
|
6
6
|
KeyboardAvoidingView,
|
|
7
|
-
Platform,
|
|
8
7
|
Pressable,
|
|
9
8
|
View,
|
|
10
9
|
} from 'react-native';
|
|
@@ -55,13 +54,14 @@ const JamChatDrawerBody = ({
|
|
|
55
54
|
}: JamChatDrawerProps) => {
|
|
56
55
|
const { t } = useTranslation();
|
|
57
56
|
const participants = useParticipants();
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
57
|
+
// The offset is the screen-Y of the KAV's parent — the JamDrawer root,
|
|
58
|
+
// inside the shell's content area, which the screen's safe-area view pads
|
|
59
|
+
// by insets.top (on both platforms). The KAV measures the keyboard in
|
|
60
|
+
// screen space but its own frame is parent-relative. The title bar and
|
|
61
|
+
// gap-3 are siblings above the KAV in that parent, so they sit inside it
|
|
62
|
+
// and do not shift its screen-Y — correctly excluded from the offset.
|
|
63
|
+
// The body only renders where a provider has settled non-null insets, so
|
|
64
|
+
// the read below is plain.
|
|
65
65
|
const keyboardVerticalOffset = React.useContext(SafeAreaInsetsContext)!.top;
|
|
66
66
|
const {
|
|
67
67
|
messages,
|
|
@@ -85,16 +85,17 @@ const JamChatDrawerBody = ({
|
|
|
85
85
|
return () => clearTimeout(timeout);
|
|
86
86
|
}, [open, messages.length]);
|
|
87
87
|
|
|
88
|
-
// Re-pin the newest message
|
|
89
|
-
// pattern)
|
|
90
|
-
//
|
|
88
|
+
// Re-pin the newest message when the keyboard shows (the base-sheet.tsx
|
|
89
|
+
// pattern). Cross-platform: the KAV's 'padding' reflow lands after the
|
|
90
|
+
// keyboard animation, so the re-pin then settles the newest message above
|
|
91
|
+
// the composer. Skipped when readOnly (no composer to re-pin against).
|
|
91
92
|
useEffect(() => {
|
|
92
|
-
if (!open || readOnly
|
|
93
|
+
if (!open || readOnly) return;
|
|
93
94
|
const sub = Keyboard.addListener('keyboardDidShow', () =>
|
|
94
95
|
listRef.current?.scrollToEnd({ animated: true })
|
|
95
96
|
);
|
|
96
97
|
return () => sub.remove();
|
|
97
|
-
}, [open, readOnly
|
|
98
|
+
}, [open, readOnly]);
|
|
98
99
|
|
|
99
100
|
const handleSendMessage = async () => {
|
|
100
101
|
if (!(await send())) return;
|
|
@@ -107,16 +108,18 @@ const JamChatDrawerBody = ({
|
|
|
107
108
|
|
|
108
109
|
return (
|
|
109
110
|
<JamDrawer title={t('jams.drawer.chatTitle')} onClose={onClose}>
|
|
110
|
-
{/*
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
{/* Keyboard avoidance is the component's own job on both platforms so
|
|
112
|
+
it does not depend on the host app's windowSoftInputMode — the
|
|
113
|
+
shipping host does not resize, and leaving the KAV disabled there
|
|
114
|
+
left the keyboard covering the chat (the QA retest on the shipping
|
|
115
|
+
build found the keyboard still covers the chat).
|
|
116
|
+
'padding' is the validated iOS mechanism; it is host-independent
|
|
117
|
+
and self-correcting (the KAV measures the real overlap, so it adds
|
|
118
|
+
~0 when a host already resizes — no double-shrink). */}
|
|
115
119
|
<KeyboardAvoidingView
|
|
116
120
|
className="flex-1"
|
|
117
|
-
behavior=
|
|
121
|
+
behavior="padding"
|
|
118
122
|
keyboardVerticalOffset={keyboardVerticalOffset}
|
|
119
|
-
enabled={isIos}
|
|
120
123
|
>
|
|
121
124
|
{/* flex-1 is load-bearing here — without it FlatList sizes to
|
|
122
125
|
content and does not fill the remaining KAV space. */}
|