@openpeepshq/rn-components 0.3.11 → 0.3.13
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 -10
- package/src/components/custom/common/index.ts +0 -1
- package/src/components/custom/index.ts +0 -1
- package/src/components/index.ts +1 -0
- package/src/components/jams/CreateNewJam.tsx +11 -10
- package/src/components/layout/AuthLayout.tsx +120 -0
- package/src/components/layout/ContentHeader.tsx +62 -0
- package/src/components/layout/HeaderActionButton.tsx +23 -0
- package/src/components/layout/HeaderMobile.tsx +96 -0
- package/src/components/layout/PlusButton.tsx +26 -0
- package/src/components/layout/RootLayout.tsx +30 -0
- package/src/components/layout/index.ts +13 -0
- package/src/components/layout/pageChrome.test.tsx +147 -0
- package/src/components/layout/pageChrome.tsx +110 -0
- package/src/components/navigation/auth-navigator.tsx +2 -2
- package/src/components/navigation/main-navigator.tsx +17 -1
- package/src/components/navigation/tab-navigator.tsx +2 -0
- package/src/components/post/NewEventButton.tsx +23 -16
- package/src/components/post/NewNoteButton.tsx +15 -13
- package/src/pages/About.tsx +3 -5
- package/src/pages/CodeOfConduct.tsx +7 -7
- package/src/pages/Explore.tsx +87 -127
- package/src/pages/Members.tsx +31 -39
- package/src/pages/Notifications.tsx +6 -13
- package/src/pages/PostDetail.tsx +12 -16
- package/src/pages/Profile.tsx +3 -2
- package/src/pages/Tags.tsx +74 -16
- package/src/pages/Welcome.tsx +3 -8
- package/src/pages/articles/Edit.tsx +18 -15
- package/src/pages/articles/Index.tsx +11 -21
- package/src/pages/articles/New.tsx +18 -15
- package/src/pages/conversations/Index.tsx +44 -68
- package/src/pages/conversations/Info.tsx +6 -5
- package/src/pages/conversations/New.tsx +14 -13
- package/src/pages/conversations/NewDraft.tsx +5 -5
- package/src/pages/conversations/Show.tsx +16 -20
- package/src/pages/events/Edit.tsx +14 -13
- package/src/pages/events/Index.tsx +28 -32
- package/src/pages/events/My.tsx +7 -7
- package/src/pages/events/New.tsx +14 -13
- package/src/pages/feeds/Bookmarks.tsx +3 -9
- package/src/pages/feeds/Local.tsx +3 -10
- package/src/pages/feeds/My.tsx +3 -9
- package/src/pages/groups/Edit.tsx +6 -7
- package/src/pages/groups/EditInfo.tsx +20 -17
- package/src/pages/groups/EditRoles.tsx +18 -19
- package/src/pages/groups/Index.tsx +82 -119
- package/src/pages/groups/Info.tsx +22 -23
- package/src/pages/groups/Members.tsx +9 -8
- package/src/pages/groups/New.tsx +18 -15
- package/src/pages/groups/Show.tsx +6 -5
- package/src/pages/jams/Index.tsx +8 -26
- package/src/pages/jams/New.tsx +14 -11
- package/src/pages/posts/Edit.tsx +20 -17
- package/src/pages/posts/New.tsx +30 -29
- package/src/pages/posts/Reply.tsx +20 -16
- package/src/pages/profile/Followers.tsx +9 -10
- package/src/pages/profile/Following.tsx +9 -10
- package/src/pages/settings/AccessTokens.tsx +6 -5
- package/src/pages/settings/Account.tsx +13 -12
- package/src/pages/settings/Blocked.tsx +5 -5
- package/src/pages/settings/Feed.tsx +13 -12
- package/src/pages/settings/Index.tsx +4 -24
- package/src/pages/settings/Language.tsx +36 -37
- package/src/pages/settings/NotificationPreferences.tsx +10 -12
- package/src/pages/settings/Notifications.tsx +10 -9
- package/src/pages/settings/PublicProfile.tsx +6 -6
- package/src/pages/settings/PushEnabledDevices.tsx +10 -9
- package/src/pages/settings/Theme.tsx +13 -12
- package/src/pages/settings/Timezone.tsx +27 -28
- package/src/components/custom/common/plus-fab.tsx +0 -23
- package/src/components/custom/headers/generic-header.tsx +0 -103
- package/src/components/custom/headers/index.ts +0 -2
- package/src/components/custom/headers/tab-screens-header.tsx +0 -206
- package/src/components/navigation/auth-wrapper.tsx +0 -107
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/rn-components",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.13",
|
|
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",
|
|
@@ -140,8 +140,8 @@
|
|
|
140
140
|
"timezones-list": "^3.1.0",
|
|
141
141
|
"validator": "^13.15.23",
|
|
142
142
|
"zustand": "^5.0.3",
|
|
143
|
-
"@openpeepshq/
|
|
144
|
-
"@openpeepshq/
|
|
143
|
+
"@openpeepshq/common": "^0.2.0",
|
|
144
|
+
"@openpeepshq/react": "^0.3.3"
|
|
145
145
|
},
|
|
146
146
|
"devDependencies": {
|
|
147
147
|
"@babel/core": "^7.26.7",
|
|
@@ -182,13 +182,6 @@
|
|
|
182
182
|
"turbo": "^1.10.7",
|
|
183
183
|
"typescript": "~5.8.3"
|
|
184
184
|
},
|
|
185
|
-
"jest": {
|
|
186
|
-
"preset": "react-native",
|
|
187
|
-
"modulePathIgnorePatterns": [
|
|
188
|
-
"<rootDir>/example/node_modules",
|
|
189
|
-
"<rootDir>/lib/"
|
|
190
|
-
]
|
|
191
|
-
},
|
|
192
185
|
"commitlint": {
|
|
193
186
|
"extends": [
|
|
194
187
|
"@commitlint/config-conventional"
|
package/src/components/index.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
2
|
import { useTranslation } from 'react-i18next';
|
|
3
|
-
import {
|
|
4
|
-
import { PhoneCallIcon } from '../icons/index';
|
|
3
|
+
import { useSetPlusButtonActions } from '../layout';
|
|
5
4
|
import { useCreateNewJam } from './CreateNewJamContext';
|
|
6
5
|
|
|
7
6
|
export const CreateNewJam = () => {
|
|
8
7
|
const { t } = useTranslation();
|
|
9
8
|
const { openCreateJam } = useCreateNewJam();
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
</PlusFab>
|
|
10
|
+
const plusActions = useMemo(
|
|
11
|
+
() => ({
|
|
12
|
+
title: t('jams.create.title'),
|
|
13
|
+
action: openCreateJam,
|
|
14
|
+
}),
|
|
15
|
+
[openCreateJam, t]
|
|
18
16
|
);
|
|
17
|
+
|
|
18
|
+
useSetPlusButtonActions(plusActions);
|
|
19
|
+
return null;
|
|
19
20
|
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import { Image, ImageBackground, View } from 'react-native';
|
|
3
|
+
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
|
|
4
|
+
import { getTheme } from '@openpeepshq/common';
|
|
5
|
+
import { useOpenpeeps } from '@openpeepshq/react';
|
|
6
|
+
import { useWindowSize } from '../../hooks/index';
|
|
7
|
+
import { BASE_URL, isProduction } from '../../lib/constants';
|
|
8
|
+
import { toAbsoluteMediaUrl } from '../../lib/media-url';
|
|
9
|
+
import { ThemedText } from '../ui/themed-text';
|
|
10
|
+
|
|
11
|
+
export interface AuthLayoutProps {
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
description?: ReactNode;
|
|
14
|
+
noRedirect?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const DevBanner = () =>
|
|
18
|
+
!isProduction ? (
|
|
19
|
+
<View className="absolute top-64 z-10 ml-8 mr-8 w-auto rounded-lg bg-white/80 p-4">
|
|
20
|
+
<ThemedText className="text-center text-destructive">
|
|
21
|
+
Test Backend ({BASE_URL})
|
|
22
|
+
</ThemedText>
|
|
23
|
+
</View>
|
|
24
|
+
) : null;
|
|
25
|
+
|
|
26
|
+
const Logo = ({ uri }: { uri?: string }) => {
|
|
27
|
+
if (!uri) return null;
|
|
28
|
+
return (
|
|
29
|
+
<Image
|
|
30
|
+
source={{ uri }}
|
|
31
|
+
className="absolute left-2 top-16 z-10 h-[26px] w-[206px] max-w-fit"
|
|
32
|
+
resizeMode="contain"
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const AuthImage = ({ children }: { children?: ReactNode }) => {
|
|
38
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
39
|
+
const { data: serverInfo, isLoading } = openpeepsApi.useServerInfo();
|
|
40
|
+
const resolvedTheme = serverInfo
|
|
41
|
+
? getTheme(serverInfo.communityConfig)
|
|
42
|
+
: undefined;
|
|
43
|
+
const authBackgroundUri = toAbsoluteMediaUrl(resolvedTheme?.backgroundAuth);
|
|
44
|
+
const resolvedLogoUri = toAbsoluteMediaUrl(resolvedTheme?.logoSmall);
|
|
45
|
+
|
|
46
|
+
const content = (
|
|
47
|
+
<>
|
|
48
|
+
<Logo uri={resolvedLogoUri} />
|
|
49
|
+
<DevBanner />
|
|
50
|
+
{children}
|
|
51
|
+
</>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (authBackgroundUri && !isLoading) {
|
|
55
|
+
return (
|
|
56
|
+
<ImageBackground
|
|
57
|
+
source={{ uri: authBackgroundUri }}
|
|
58
|
+
className="w-full flex-1 justify-end"
|
|
59
|
+
>
|
|
60
|
+
{content}
|
|
61
|
+
</ImageBackground>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<View className="bg-background w-full flex-1 justify-end">{content}</View>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const NarrowAuthLayout = ({
|
|
71
|
+
children,
|
|
72
|
+
description,
|
|
73
|
+
}: {
|
|
74
|
+
children?: ReactNode;
|
|
75
|
+
description?: ReactNode;
|
|
76
|
+
}) => (
|
|
77
|
+
<AuthImage>
|
|
78
|
+
<View className="bg-background w-full min-h-[400px] px-2 pb-10 pt-4">
|
|
79
|
+
{description}
|
|
80
|
+
{children}
|
|
81
|
+
</View>
|
|
82
|
+
</AuthImage>
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const WideAuthLayout = ({
|
|
86
|
+
children,
|
|
87
|
+
description,
|
|
88
|
+
}: {
|
|
89
|
+
children?: ReactNode;
|
|
90
|
+
description?: ReactNode;
|
|
91
|
+
}) => (
|
|
92
|
+
<View className="flex flex-1 flex-row">
|
|
93
|
+
<View className="flex-1">
|
|
94
|
+
<AuthImage />
|
|
95
|
+
</View>
|
|
96
|
+
<View className="flex flex-1 justify-center p-6">
|
|
97
|
+
{description}
|
|
98
|
+
{children}
|
|
99
|
+
</View>
|
|
100
|
+
</View>
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
export const AuthLayout = ({ children, description }: AuthLayoutProps) => {
|
|
104
|
+
const { isMediumScreenOrLarger } = useWindowSize();
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<KeyboardAwareScrollView
|
|
108
|
+
contentContainerClassName="grow"
|
|
109
|
+
className="bg-background flex w-full"
|
|
110
|
+
>
|
|
111
|
+
{isMediumScreenOrLarger ? (
|
|
112
|
+
<WideAuthLayout description={description}>{children}</WideAuthLayout>
|
|
113
|
+
) : (
|
|
114
|
+
<NarrowAuthLayout description={description}>
|
|
115
|
+
{children}
|
|
116
|
+
</NarrowAuthLayout>
|
|
117
|
+
)}
|
|
118
|
+
</KeyboardAwareScrollView>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Pressable, View } from 'react-native';
|
|
3
|
+
import { useNavigation, useRoute } from '@react-navigation/native';
|
|
4
|
+
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
5
|
+
import { useCurrentProfile } from '@openpeepshq/react';
|
|
6
|
+
import { goToParentOrBack } from '../navigation/parent-back';
|
|
7
|
+
import type { MainStackParamList } from '../navigation/types';
|
|
8
|
+
import { ChevronLeftIcon } from '../icons/index';
|
|
9
|
+
import { ThemedText } from '../ui/themed-text';
|
|
10
|
+
import { usePageChrome } from './pageChrome';
|
|
11
|
+
|
|
12
|
+
export const ContentHeader = () => {
|
|
13
|
+
const { header } = usePageChrome();
|
|
14
|
+
const navigation =
|
|
15
|
+
useNavigation<NativeStackNavigationProp<MainStackParamList>>();
|
|
16
|
+
const route = useRoute();
|
|
17
|
+
const me = useCurrentProfile();
|
|
18
|
+
|
|
19
|
+
const title = header?.title;
|
|
20
|
+
const titleIsString = typeof title === 'string';
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<View className="border-border flex-row items-center justify-between border-b px-4 py-2">
|
|
24
|
+
<View className="min-w-0 flex-1 flex-row items-center gap-2">
|
|
25
|
+
<Pressable
|
|
26
|
+
accessibilityRole="button"
|
|
27
|
+
accessibilityLabel="Back"
|
|
28
|
+
onPress={() => {
|
|
29
|
+
if (header?.onBack) {
|
|
30
|
+
header.onBack();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
goToParentOrBack({
|
|
34
|
+
navigation,
|
|
35
|
+
routeName: route.name,
|
|
36
|
+
params: route.params as Record<string, unknown> | undefined,
|
|
37
|
+
profileHandle: me?.handle,
|
|
38
|
+
});
|
|
39
|
+
}}
|
|
40
|
+
className="items-center justify-center p-2"
|
|
41
|
+
>
|
|
42
|
+
<ChevronLeftIcon size={28} className="text-foreground" />
|
|
43
|
+
</Pressable>
|
|
44
|
+
{titleIsString ? (
|
|
45
|
+
<ThemedText
|
|
46
|
+
className="min-w-0 flex-1 text-xl font-semibold"
|
|
47
|
+
numberOfLines={1}
|
|
48
|
+
>
|
|
49
|
+
{title}
|
|
50
|
+
</ThemedText>
|
|
51
|
+
) : (
|
|
52
|
+
title
|
|
53
|
+
)}
|
|
54
|
+
</View>
|
|
55
|
+
{header?.actions ? (
|
|
56
|
+
<View className="ml-2 shrink-0 flex-row items-center">
|
|
57
|
+
{header.actions}
|
|
58
|
+
</View>
|
|
59
|
+
) : null}
|
|
60
|
+
</View>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ActivityIndicator } from 'react-native';
|
|
3
|
+
import { Button } from '../ui/button';
|
|
4
|
+
import { ThemedText } from '../ui/themed-text';
|
|
5
|
+
|
|
6
|
+
export const HeaderActionButton = ({
|
|
7
|
+
title,
|
|
8
|
+
onPress,
|
|
9
|
+
disabled,
|
|
10
|
+
loading,
|
|
11
|
+
}: {
|
|
12
|
+
title: string;
|
|
13
|
+
onPress: () => void;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
loading?: boolean;
|
|
16
|
+
}) => (
|
|
17
|
+
<Button disabled={disabled} onPress={onPress}>
|
|
18
|
+
{loading ? <ActivityIndicator size="small" /> : null}
|
|
19
|
+
<ThemedText className="text-primary-foreground text-base font-semibold">
|
|
20
|
+
{title}
|
|
21
|
+
</ThemedText>
|
|
22
|
+
</Button>
|
|
23
|
+
);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Image,
|
|
4
|
+
ImageBackground,
|
|
5
|
+
Platform,
|
|
6
|
+
StatusBar,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
View,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
11
|
+
import { useNavigation } from '@react-navigation/native';
|
|
12
|
+
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
13
|
+
import { useOpenpeeps } from '@openpeepshq/react';
|
|
14
|
+
import { useDrawer } from '../../contexts/drawer-context';
|
|
15
|
+
import { useWindowSize } from '../../hooks/index';
|
|
16
|
+
import { BASE_URL, isProduction } from '../../lib/constants';
|
|
17
|
+
import { useAppImagesStore } from '../../stores/useAppImagesStore';
|
|
18
|
+
import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar';
|
|
19
|
+
import { Button } from '../ui/button';
|
|
20
|
+
import { ThemedText } from '../ui/themed-text';
|
|
21
|
+
import { MessageSquareTextIcon, UserIcon } from '../icons/index';
|
|
22
|
+
import type { MainStackParamList } from '../navigation/types/index';
|
|
23
|
+
|
|
24
|
+
export const HeaderMobile = () => {
|
|
25
|
+
const { openDrawer } = useDrawer();
|
|
26
|
+
const { isMediumScreenOrLarger } = useWindowSize();
|
|
27
|
+
const { currentProfile } = useOpenpeeps();
|
|
28
|
+
const navigation =
|
|
29
|
+
useNavigation<NativeStackNavigationProp<MainStackParamList>>();
|
|
30
|
+
const { background, logoSmall } = useAppImagesStore();
|
|
31
|
+
|
|
32
|
+
if (isMediumScreenOrLarger) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<ImageBackground
|
|
38
|
+
resizeMode="cover"
|
|
39
|
+
source={{ uri: background! }}
|
|
40
|
+
style={styles.header}
|
|
41
|
+
className="px-4 pb-3"
|
|
42
|
+
>
|
|
43
|
+
<SafeAreaView edges={['top']}>
|
|
44
|
+
{!isProduction && (
|
|
45
|
+
<View className="mb-2 w-full rounded-lg bg-white/50 p-2">
|
|
46
|
+
<ThemedText className="text-center text-destructive">
|
|
47
|
+
Test Backend ({BASE_URL})
|
|
48
|
+
</ThemedText>
|
|
49
|
+
</View>
|
|
50
|
+
)}
|
|
51
|
+
<View className="flex-row items-center justify-between">
|
|
52
|
+
<Button
|
|
53
|
+
variant="outline"
|
|
54
|
+
size="icon"
|
|
55
|
+
onPress={openDrawer}
|
|
56
|
+
className="native:px-0 active:bg-none rounded-full bg-black"
|
|
57
|
+
>
|
|
58
|
+
<Avatar alt={(currentProfile?.displayName as string) || 'Profile'}>
|
|
59
|
+
{currentProfile?.avatar ? (
|
|
60
|
+
<AvatarImage source={{ uri: currentProfile.avatar }} />
|
|
61
|
+
) : (
|
|
62
|
+
<AvatarFallback className="-bottom-2 -right-2 h-6 w-6 bg-black">
|
|
63
|
+
<UserIcon size={20} className="text-muted-foreground" />
|
|
64
|
+
</AvatarFallback>
|
|
65
|
+
)}
|
|
66
|
+
</Avatar>
|
|
67
|
+
</Button>
|
|
68
|
+
<Image
|
|
69
|
+
source={{ uri: logoSmall! }}
|
|
70
|
+
resizeMode="contain"
|
|
71
|
+
className="h-[64px] w-[216px]"
|
|
72
|
+
/>
|
|
73
|
+
<Button
|
|
74
|
+
variant="outline"
|
|
75
|
+
size="icon"
|
|
76
|
+
onPress={() =>
|
|
77
|
+
navigation.navigate('TabNavigator', { screen: 'Messages' })
|
|
78
|
+
}
|
|
79
|
+
accessibilityLabel="Messages"
|
|
80
|
+
>
|
|
81
|
+
<MessageSquareTextIcon
|
|
82
|
+
className="text-muted-foreground"
|
|
83
|
+
size={18}
|
|
84
|
+
/>
|
|
85
|
+
</Button>
|
|
86
|
+
</View>
|
|
87
|
+
</SafeAreaView>
|
|
88
|
+
</ImageBackground>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const styles = StyleSheet.create({
|
|
93
|
+
header: {
|
|
94
|
+
paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight : 0,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Pressable } from 'react-native';
|
|
3
|
+
import { PlusIcon } from '../icons/index';
|
|
4
|
+
import { usePageChrome } from './pageChrome';
|
|
5
|
+
|
|
6
|
+
export const PlusButton = () => {
|
|
7
|
+
const { plus } = usePageChrome();
|
|
8
|
+
if (!plus || Array.isArray(plus)) return null;
|
|
9
|
+
|
|
10
|
+
const onPress = () => {
|
|
11
|
+
if (typeof plus.action === 'function') {
|
|
12
|
+
void plus.action();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<Pressable
|
|
18
|
+
accessibilityRole="button"
|
|
19
|
+
accessibilityLabel={plus.title || 'New'}
|
|
20
|
+
onPress={onPress}
|
|
21
|
+
className="bg-foreground absolute bottom-10 right-6 z-20 size-16 items-center justify-center rounded-full"
|
|
22
|
+
>
|
|
23
|
+
<PlusIcon size={24} className="text-background" />
|
|
24
|
+
</Pressable>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { ThemedView } from '../ui/themed-view';
|
|
4
|
+
import { ContentHeader } from './ContentHeader';
|
|
5
|
+
import { HeaderMobile } from './HeaderMobile';
|
|
6
|
+
import { PageChromeProvider } from './pageChrome';
|
|
7
|
+
import { PlusButton } from './PlusButton';
|
|
8
|
+
|
|
9
|
+
export const RootLayout = ({ children }: { children: ReactNode }) => (
|
|
10
|
+
<PageChromeProvider>
|
|
11
|
+
<ThemedView className="flex-1">
|
|
12
|
+
<HeaderMobile />
|
|
13
|
+
<ContentHeader />
|
|
14
|
+
<View className="min-h-0 flex-1">{children}</View>
|
|
15
|
+
<PlusButton />
|
|
16
|
+
</ThemedView>
|
|
17
|
+
</PageChromeProvider>
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const withRootLayout = <P extends object>(
|
|
21
|
+
Screen: React.ComponentType<P>
|
|
22
|
+
) => {
|
|
23
|
+
const Wrapped = (props: P) => (
|
|
24
|
+
<RootLayout>
|
|
25
|
+
<Screen {...props} />
|
|
26
|
+
</RootLayout>
|
|
27
|
+
);
|
|
28
|
+
Wrapped.displayName = `withRootLayout(${Screen.displayName ?? Screen.name})`;
|
|
29
|
+
return Wrapped;
|
|
30
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { HeaderActionButton } from './HeaderActionButton';
|
|
2
|
+
export { AuthLayout } from './AuthLayout';
|
|
3
|
+
export type { AuthLayoutProps } from './AuthLayout';
|
|
4
|
+
export { ContentHeader } from './ContentHeader';
|
|
5
|
+
export { HeaderMobile } from './HeaderMobile';
|
|
6
|
+
export {
|
|
7
|
+
PageChromeProvider,
|
|
8
|
+
usePageChrome,
|
|
9
|
+
useSetPageHeader,
|
|
10
|
+
useSetPlusButtonActions,
|
|
11
|
+
} from './pageChrome';
|
|
12
|
+
export { PlusButton } from './PlusButton';
|
|
13
|
+
export { RootLayout, withRootLayout } from './RootLayout';
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression tests for the page-chrome infinite update loop
|
|
3
|
+
* ("Maximum update depth exceeded") that crashed Groups, Jams and Explore
|
|
4
|
+
* (and any other page that registers header or plus actions with fresh,
|
|
5
|
+
* non-memoized values) in @openpeepshq/rn-components 0.3.12.
|
|
6
|
+
*
|
|
7
|
+
* Root cause: useSetPageHeader / useSetPlusButtonActions read their
|
|
8
|
+
* setters from the same context whose value changes whenever the header
|
|
9
|
+
* or plus state changes. A screen that registers a fresh element or
|
|
10
|
+
* object therefore re-renders on every chrome update, re-runs its layout
|
|
11
|
+
* effect and calls setState again.
|
|
12
|
+
*/
|
|
13
|
+
import { type ReactNode } from 'react';
|
|
14
|
+
import ReactTestRenderer from 'react-test-renderer';
|
|
15
|
+
import {
|
|
16
|
+
PageChromeProvider,
|
|
17
|
+
usePageChrome,
|
|
18
|
+
useSetPageHeader,
|
|
19
|
+
useSetPlusButtonActions,
|
|
20
|
+
} from './pageChrome';
|
|
21
|
+
|
|
22
|
+
const MAX_RENDER_GUARD = 20;
|
|
23
|
+
|
|
24
|
+
const Text = ({ children }: { children?: ReactNode }) => (
|
|
25
|
+
<text>{children}</text>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const View = ({ children }: { children?: ReactNode }) => (
|
|
29
|
+
<view>{children}</view>
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const render = (ui: ReactNode) => {
|
|
33
|
+
const element = <PageChromeProvider>{ui}</PageChromeProvider>;
|
|
34
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
35
|
+
ReactTestRenderer.act(() => {
|
|
36
|
+
tree = ReactTestRenderer.create(element);
|
|
37
|
+
});
|
|
38
|
+
return tree;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const UnstableHeaderScreen = ({ onRender }: { onRender: () => void }) => {
|
|
42
|
+
onRender();
|
|
43
|
+
useSetPageHeader(
|
|
44
|
+
'Jams',
|
|
45
|
+
<View>
|
|
46
|
+
<Text>actions</Text>
|
|
47
|
+
</View>
|
|
48
|
+
);
|
|
49
|
+
return <Text>screen</Text>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const UnstablePlusScreen = ({ onRender }: { onRender: () => void }) => {
|
|
53
|
+
onRender();
|
|
54
|
+
useSetPageHeader('Groups');
|
|
55
|
+
useSetPlusButtonActions({ title: 'New group', action: () => {} });
|
|
56
|
+
return <Text>screen</Text>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const StableScreen = () => {
|
|
60
|
+
useSetPageHeader('Feed');
|
|
61
|
+
return <Text>screen</Text>;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const ChromeProbe = ({
|
|
65
|
+
onChrome,
|
|
66
|
+
}: {
|
|
67
|
+
onChrome: (title?: string, plusTitle?: string) => void;
|
|
68
|
+
}) => {
|
|
69
|
+
const { header, plus } = usePageChrome();
|
|
70
|
+
const plusTitle = Array.isArray(plus) ? plus[0]?.title : plus?.title;
|
|
71
|
+
onChrome(
|
|
72
|
+
typeof header?.title === 'string' ? header.title : undefined,
|
|
73
|
+
plusTitle
|
|
74
|
+
);
|
|
75
|
+
return null;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
test('unstable header actions do not loop (jams/explore)', () => {
|
|
79
|
+
let renders = 0;
|
|
80
|
+
const tree = render(
|
|
81
|
+
<UnstableHeaderScreen
|
|
82
|
+
onRender={() => {
|
|
83
|
+
renders += 1;
|
|
84
|
+
if (renders > MAX_RENDER_GUARD) {
|
|
85
|
+
throw new Error('Maximum update depth exceeded');
|
|
86
|
+
}
|
|
87
|
+
}}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
expect(renders).toBeLessThanOrEqual(MAX_RENDER_GUARD);
|
|
91
|
+
expect(JSON.stringify(tree.toJSON())).toContain('screen');
|
|
92
|
+
tree.unmount();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('unstable plus actions do not loop (groups)', () => {
|
|
96
|
+
let renders = 0;
|
|
97
|
+
const tree = render(
|
|
98
|
+
<UnstablePlusScreen
|
|
99
|
+
onRender={() => {
|
|
100
|
+
renders += 1;
|
|
101
|
+
if (renders > MAX_RENDER_GUARD) {
|
|
102
|
+
throw new Error('Maximum update depth exceeded');
|
|
103
|
+
}
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
expect(renders).toBeLessThanOrEqual(MAX_RENDER_GUARD);
|
|
108
|
+
expect(JSON.stringify(tree.toJSON())).toContain('screen');
|
|
109
|
+
tree.unmount();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('stable title-only header still works', () => {
|
|
113
|
+
const tree = render(<StableScreen />);
|
|
114
|
+
expect(JSON.stringify(tree.toJSON())).toContain('screen');
|
|
115
|
+
tree.unmount();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('display chrome still sees registered header and plus', () => {
|
|
119
|
+
let title: string | undefined;
|
|
120
|
+
let plusTitle: string | undefined;
|
|
121
|
+
const tree = render(
|
|
122
|
+
<View>
|
|
123
|
+
<UnstablePlusScreen onRender={() => {}} />
|
|
124
|
+
<ChromeProbe
|
|
125
|
+
onChrome={(nextTitle, nextPlusTitle) => {
|
|
126
|
+
title = nextTitle;
|
|
127
|
+
plusTitle = nextPlusTitle;
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
130
|
+
</View>
|
|
131
|
+
);
|
|
132
|
+
expect(title).toBe('Groups');
|
|
133
|
+
expect(plusTitle).toBe('New group');
|
|
134
|
+
tree.unmount();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('page chrome hooks throw outside RootLayout', () => {
|
|
138
|
+
const Bare = () => {
|
|
139
|
+
useSetPageHeader('Feed');
|
|
140
|
+
return null;
|
|
141
|
+
};
|
|
142
|
+
expect(() => {
|
|
143
|
+
ReactTestRenderer.act(() => {
|
|
144
|
+
ReactTestRenderer.create(<Bare />);
|
|
145
|
+
});
|
|
146
|
+
}).toThrow('Page chrome hooks must be used within RootLayout');
|
|
147
|
+
});
|