@openpeepshq/rn-components 0.3.11 → 0.3.12
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/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.tsx +75 -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.12",
|
|
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",
|
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,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
useLayoutEffect,
|
|
5
|
+
useMemo,
|
|
6
|
+
useState,
|
|
7
|
+
type ReactNode,
|
|
8
|
+
} from 'react';
|
|
9
|
+
|
|
10
|
+
export type PlusButtonAction = {
|
|
11
|
+
action: string | (() => Promise<unknown> | unknown);
|
|
12
|
+
title?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type PlusButtonActions =
|
|
16
|
+
| PlusButtonAction
|
|
17
|
+
| PlusButtonAction[]
|
|
18
|
+
| undefined;
|
|
19
|
+
|
|
20
|
+
export type PageHeaderValue = {
|
|
21
|
+
title?: ReactNode;
|
|
22
|
+
actions?: ReactNode;
|
|
23
|
+
onBack?: () => void;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type PageChromeContextValue = {
|
|
27
|
+
header: PageHeaderValue | undefined;
|
|
28
|
+
setHeader: (header: PageHeaderValue | undefined) => void;
|
|
29
|
+
plus: PlusButtonActions;
|
|
30
|
+
setPlus: (plus: PlusButtonActions) => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const PageChromeContext = createContext<PageChromeContextValue | null>(null);
|
|
34
|
+
|
|
35
|
+
export const PageChromeProvider = ({ children }: { children: ReactNode }) => {
|
|
36
|
+
const [header, setHeader] = useState<PageHeaderValue | undefined>();
|
|
37
|
+
const [plus, setPlus] = useState<PlusButtonActions>(undefined);
|
|
38
|
+
const value = useMemo(
|
|
39
|
+
() => ({ header, setHeader, plus, setPlus }),
|
|
40
|
+
[header, plus]
|
|
41
|
+
);
|
|
42
|
+
return (
|
|
43
|
+
<PageChromeContext.Provider value={value}>
|
|
44
|
+
{children}
|
|
45
|
+
</PageChromeContext.Provider>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const usePageChrome = () => {
|
|
50
|
+
const ctx = useContext(PageChromeContext);
|
|
51
|
+
if (!ctx) {
|
|
52
|
+
throw new Error('usePageChrome must be used within RootLayout');
|
|
53
|
+
}
|
|
54
|
+
return ctx;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const useSetPageHeader = (
|
|
58
|
+
title?: ReactNode,
|
|
59
|
+
actions?: ReactNode,
|
|
60
|
+
onBack?: () => void
|
|
61
|
+
) => {
|
|
62
|
+
const { setHeader } = usePageChrome();
|
|
63
|
+
useLayoutEffect(() => {
|
|
64
|
+
setHeader({ title, actions, onBack });
|
|
65
|
+
return () => setHeader(undefined);
|
|
66
|
+
}, [actions, onBack, setHeader, title]);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const useSetPlusButtonActions = (actions: PlusButtonActions) => {
|
|
70
|
+
const { setPlus } = usePageChrome();
|
|
71
|
+
useLayoutEffect(() => {
|
|
72
|
+
setPlus(actions);
|
|
73
|
+
return () => setPlus(undefined);
|
|
74
|
+
}, [actions, setPlus]);
|
|
75
|
+
};
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
ResetPassword,
|
|
13
13
|
} from '../../pages';
|
|
14
14
|
import { AUTH_ROUTES } from './types';
|
|
15
|
-
import {
|
|
15
|
+
import { AuthLayout } from '../layout';
|
|
16
16
|
|
|
17
17
|
const Stack = createNativeStackNavigator<AuthStackParamList>();
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@ export const AuthNavigator = () => {
|
|
|
20
20
|
return (
|
|
21
21
|
<Stack.Navigator
|
|
22
22
|
screenOptions={{ headerShown: false, animation: 'fade' }}
|
|
23
|
-
screenLayout={({ children }) => <
|
|
23
|
+
screenLayout={({ children }) => <AuthLayout>{children}</AuthLayout>}
|
|
24
24
|
>
|
|
25
25
|
<Stack.Screen name={AUTH_ROUTES.WELCOME} component={AuthWelcome} />
|
|
26
26
|
<Stack.Screen name={AUTH_ROUTES.LOGIN} component={Login} />
|
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
} from '../../pages';
|
|
45
45
|
import { MenuWrapper } from './side-menu-wrapper';
|
|
46
46
|
import { SideMenuDrawer } from './side-menu-drawer';
|
|
47
|
+
import { RootLayout } from '../layout';
|
|
47
48
|
|
|
48
49
|
import { MainStackParamList } from './types';
|
|
49
50
|
import { useWindowSize } from '../../hooks/index';
|
|
@@ -52,6 +53,14 @@ import { useOpenpeeps } from '@openpeepshq/react';
|
|
|
52
53
|
|
|
53
54
|
const Stack = createNativeStackNavigator<MainStackParamList>();
|
|
54
55
|
|
|
56
|
+
const NO_ROOT_LAYOUT = new Set([
|
|
57
|
+
'TabNavigator',
|
|
58
|
+
'JamSession',
|
|
59
|
+
'VideoPlayer',
|
|
60
|
+
'About',
|
|
61
|
+
'CodeOfConduct',
|
|
62
|
+
]);
|
|
63
|
+
|
|
55
64
|
export const MainNavigator = () => {
|
|
56
65
|
const { openpeepsApi, queryClient } = useOpenpeeps();
|
|
57
66
|
queryClient.setDefaultOptions({
|
|
@@ -90,7 +99,14 @@ export const MainNavigator = () => {
|
|
|
90
99
|
return (
|
|
91
100
|
<Stack.Navigator
|
|
92
101
|
screenOptions={{ headerShown: false, animation: 'fade' }}
|
|
93
|
-
screenLayout={({ children }) =>
|
|
102
|
+
screenLayout={({ children, route }) => {
|
|
103
|
+
const body = NO_ROOT_LAYOUT.has(route.name) ? (
|
|
104
|
+
children
|
|
105
|
+
) : (
|
|
106
|
+
<RootLayout>{children}</RootLayout>
|
|
107
|
+
);
|
|
108
|
+
return <Wrapper>{body}</Wrapper>;
|
|
109
|
+
}}
|
|
94
110
|
>
|
|
95
111
|
<Stack.Screen name="TabNavigator" component={TabNavigator} />
|
|
96
112
|
<Stack.Screen name="Profile" component={Profile} />
|
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
useServerInfo,
|
|
37
37
|
} from '@openpeepshq/react';
|
|
38
38
|
import { useOpenPeepsTheme } from '../../theme/OpenPeepsThemeProvider';
|
|
39
|
+
import { RootLayout } from '../layout';
|
|
39
40
|
|
|
40
41
|
const Tab = createBottomTabNavigator<TabStackParamList>();
|
|
41
42
|
|
|
@@ -91,6 +92,7 @@ export const TabNavigator = () => {
|
|
|
91
92
|
const display = isMediumScreenOrLarger ? 'none' : 'flex';
|
|
92
93
|
return (
|
|
93
94
|
<Tab.Navigator
|
|
95
|
+
screenLayout={({ children }) => <RootLayout>{children}</RootLayout>}
|
|
94
96
|
screenOptions={({ route }) => ({
|
|
95
97
|
headerShown: false,
|
|
96
98
|
tabBarShowLabel: false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
2
|
import { useTranslation } from 'react-i18next';
|
|
3
3
|
import { useNavigation } from '@react-navigation/native';
|
|
4
4
|
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
@@ -9,8 +9,7 @@ import {
|
|
|
9
9
|
type VisibilityType,
|
|
10
10
|
} from '@openpeepshq/common';
|
|
11
11
|
import { getNewPostStores, useAuthData } from '@openpeepshq/react';
|
|
12
|
-
import {
|
|
13
|
-
import { PlusIcon } from '../icons/index';
|
|
12
|
+
import { useSetPlusButtonActions } from '../layout';
|
|
14
13
|
import { MainStackParamList } from '../navigation/types/index';
|
|
15
14
|
|
|
16
15
|
export interface NewEventButtonProps {
|
|
@@ -19,7 +18,7 @@ export interface NewEventButtonProps {
|
|
|
19
18
|
group?: GroupWithMeta;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
/**
|
|
21
|
+
/** Registers the RootLayout plus button for creating an event. */
|
|
23
22
|
export const NewEventButton = ({
|
|
24
23
|
visibility,
|
|
25
24
|
currentProfile,
|
|
@@ -34,17 +33,25 @@ export const NewEventButton = ({
|
|
|
34
33
|
const canPost =
|
|
35
34
|
!!profile && canCreatePost(authData, 'event', visibility, group);
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
const plusActions = useMemo(
|
|
37
|
+
() =>
|
|
38
|
+
canPost
|
|
39
|
+
? {
|
|
40
|
+
title: t('events.form.title'),
|
|
41
|
+
action: () => {
|
|
42
|
+
const stores = getNewPostStores();
|
|
43
|
+
stores.event = {
|
|
44
|
+
...stores.event,
|
|
45
|
+
visibility,
|
|
46
|
+
groupId: group?.id,
|
|
47
|
+
};
|
|
48
|
+
navigation.navigate('NewEvent');
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
: undefined,
|
|
52
|
+
[canPost, group?.id, navigation, t, visibility]
|
|
49
53
|
);
|
|
54
|
+
|
|
55
|
+
useSetPlusButtonActions(plusActions);
|
|
56
|
+
return null;
|
|
50
57
|
};
|