@openpeepshq/rn-components 0.6.10 → 0.6.11
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/cached-image.tsx +14 -1
- package/src/components/custom/navigation/side-menu.tsx +3 -8
- package/src/components/form/HeaderAvatarInput.tsx +4 -3
- package/src/components/form/ImageInput.tsx +4 -3
- package/src/components/layout/AuthLayout.tsx +10 -11
- package/src/components/layout/HeaderMobile.tsx +11 -16
- package/src/components/markdown/extensions/html.test.tsx +172 -0
- package/src/components/markdown/extensions/html.tsx +33 -19
- package/src/components/navigation/side-menu-wrapper.tsx +9 -6
- package/src/components/post/CompactReplyParent.tsx +3 -2
- package/src/components/profile/ProfileHeader.tsx +4 -3
- package/src/components/ui/avatar.tsx +14 -1
- package/src/components/ui/index.ts +1 -0
- package/src/components/ui/svg-image.tsx +89 -0
- package/src/utils/media-cache.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/rn-components",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.11",
|
|
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/
|
|
146
|
-
"@openpeepshq/
|
|
145
|
+
"@openpeepshq/react": "^0.6.3",
|
|
146
|
+
"@openpeepshq/common": "^0.3.2"
|
|
147
147
|
},
|
|
148
148
|
"devDependencies": {
|
|
149
149
|
"@babel/core": "^7.26.7",
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Image, ImageProps, ActivityIndicator, View } from 'react-native';
|
|
3
|
+
import { isSvgUrl } from '@openpeepshq/react';
|
|
3
4
|
import { useCachedMediaUri } from '../../../hooks/use-cached-media-uri';
|
|
5
|
+
import { SvgImage } from '../../ui/svg-image';
|
|
4
6
|
|
|
5
7
|
interface CachedImageProps extends Omit<ImageProps, 'source'> {
|
|
6
8
|
url: string;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
export const CachedImage: React.FC<CachedImageProps> = ({ url, ...props }) => {
|
|
10
|
-
const
|
|
12
|
+
const svg = isSvgUrl(url);
|
|
13
|
+
const imagePath = useCachedMediaUri(svg ? null : url);
|
|
14
|
+
|
|
15
|
+
if (svg) {
|
|
16
|
+
return (
|
|
17
|
+
<SvgImage
|
|
18
|
+
uri={url}
|
|
19
|
+
className={props.className}
|
|
20
|
+
resizeMode={props.resizeMode}
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
11
24
|
|
|
12
25
|
if (!imagePath) {
|
|
13
26
|
return (
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ScrollView, useColorScheme } from 'react-native';
|
|
3
3
|
import { Separator } from '../../ui/separator';
|
|
4
|
-
import {
|
|
4
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
5
5
|
import { Button } from '../../ui/button';
|
|
6
|
+
import { SvgImage } from '../../ui/svg-image';
|
|
6
7
|
import {
|
|
7
8
|
BellIcon,
|
|
8
9
|
BookCheckIcon,
|
|
@@ -112,13 +113,7 @@ export const SideMenu = ({
|
|
|
112
113
|
<View className="sm:w-56 md:w-80 bg-background flex-1">
|
|
113
114
|
<TouchableOpacity onPress={onProfilePress} className="mt-12 mb-6 px-4">
|
|
114
115
|
<View className="w-full flex-row items-center justify-between">
|
|
115
|
-
{logoUri
|
|
116
|
-
<Image
|
|
117
|
-
source={{ uri: logoUri }}
|
|
118
|
-
className="-mt-2 h-12 w-48"
|
|
119
|
-
resizeMode="contain"
|
|
120
|
-
/>
|
|
121
|
-
) : null}
|
|
116
|
+
<SvgImage uri={logoUri} className="-mt-2 h-12 w-48" />
|
|
122
117
|
{!isMediumScreenOrLarger && (
|
|
123
118
|
<View className="md:hidden">
|
|
124
119
|
<Button onPress={close} variant={'outline'} size={'icon'}>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useRef } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Pressable, View } from 'react-native';
|
|
3
3
|
import { BottomSheetModal } from '@gorhom/bottom-sheet';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
import { MediaAttachment } from '@openpeepshq/common';
|
|
@@ -7,6 +7,7 @@ import { ImagePickerSheet } from '../custom/modals/media/index';
|
|
|
7
7
|
import { CameraIcon, XIcon } from '../icons/index';
|
|
8
8
|
import { Avatar, AvatarImage } from '../ui/avatar';
|
|
9
9
|
import { ThemedText } from '../ui/themed-text';
|
|
10
|
+
import { SvgImage } from '../ui/svg-image';
|
|
10
11
|
import { bottomSheetPresent } from '../../lib/bottom-sheet-ref';
|
|
11
12
|
|
|
12
13
|
export interface HeaderAvatarInputProps {
|
|
@@ -43,8 +44,8 @@ export const HeaderAvatarInput = ({
|
|
|
43
44
|
className="w-full aspect-[3/1] rounded-md overflow-hidden bg-muted items-center justify-center"
|
|
44
45
|
>
|
|
45
46
|
{header ? (
|
|
46
|
-
<
|
|
47
|
-
|
|
47
|
+
<SvgImage
|
|
48
|
+
uri={header}
|
|
48
49
|
className="absolute inset-0 w-full h-full"
|
|
49
50
|
resizeMode="cover"
|
|
50
51
|
/>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React, { useRef } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Pressable, View } from 'react-native';
|
|
3
3
|
import { BottomSheetModal } from '@gorhom/bottom-sheet';
|
|
4
4
|
import type { MediaAttachment } from '@openpeepshq/common';
|
|
5
5
|
import { ImagePickerSheet } from '../custom/modals/media/index';
|
|
6
6
|
import { CameraIcon, XIcon } from '../icons/index';
|
|
7
7
|
import { ThemedText } from '../ui/themed-text';
|
|
8
|
+
import { SvgImage } from '../ui/svg-image';
|
|
8
9
|
import { bottomSheetPresent } from '../../lib/bottom-sheet-ref';
|
|
9
10
|
import { cn } from '../../lib/utils';
|
|
10
11
|
|
|
@@ -49,8 +50,8 @@ export const ImageInput = ({
|
|
|
49
50
|
)}
|
|
50
51
|
>
|
|
51
52
|
{url ? (
|
|
52
|
-
<
|
|
53
|
-
|
|
53
|
+
<SvgImage
|
|
54
|
+
uri={url}
|
|
54
55
|
className="absolute inset-0 w-full h-full"
|
|
55
56
|
resizeMode="cover"
|
|
56
57
|
/>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { type ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Pressable, View } from 'react-native';
|
|
3
3
|
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
import { getTheme } from '@openpeepshq/common';
|
|
@@ -9,6 +9,7 @@ import { BASE_URL, isProduction } from '../../lib/constants';
|
|
|
9
9
|
import { toAbsoluteMediaUrl } from '../../lib/media-url';
|
|
10
10
|
import { ProfileAvatar } from '../profile/Avatar';
|
|
11
11
|
import { ThemedText } from '../ui/themed-text';
|
|
12
|
+
import { SvgImage } from '../ui/svg-image';
|
|
12
13
|
|
|
13
14
|
export interface AuthLayoutProps {
|
|
14
15
|
children?: ReactNode;
|
|
@@ -34,11 +35,7 @@ const Logo = ({ uri }: { uri?: string }) => {
|
|
|
34
35
|
hitSlop={24}
|
|
35
36
|
className="absolute left-2 top-16 z-10 h-[26px] w-[206px] max-w-fit"
|
|
36
37
|
>
|
|
37
|
-
<
|
|
38
|
-
source={{ uri }}
|
|
39
|
-
className="h-[26px] w-[206px] max-w-fit"
|
|
40
|
-
resizeMode="contain"
|
|
41
|
-
/>
|
|
38
|
+
<SvgImage uri={uri} className="h-[26px] w-[206px] max-w-fit" />
|
|
42
39
|
</Pressable>
|
|
43
40
|
);
|
|
44
41
|
};
|
|
@@ -88,12 +85,14 @@ const AuthImage = ({ children }: { children?: ReactNode }) => {
|
|
|
88
85
|
|
|
89
86
|
if (authBackgroundUri && !isLoading) {
|
|
90
87
|
return (
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
<View className="w-full flex-1 justify-end">
|
|
89
|
+
<SvgImage
|
|
90
|
+
uri={authBackgroundUri}
|
|
91
|
+
className="absolute inset-0"
|
|
92
|
+
resizeMode="stretch"
|
|
93
|
+
/>
|
|
95
94
|
{content}
|
|
96
|
-
</
|
|
95
|
+
</View>
|
|
97
96
|
);
|
|
98
97
|
}
|
|
99
98
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import {
|
|
3
|
-
Image,
|
|
4
|
-
ImageBackground,
|
|
5
3
|
Platform,
|
|
6
4
|
StatusBar,
|
|
7
5
|
StyleSheet,
|
|
@@ -20,6 +18,7 @@ import { getTheme } from '@openpeepshq/common';
|
|
|
20
18
|
import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar';
|
|
21
19
|
import { Button } from '../ui/button';
|
|
22
20
|
import { ThemedText } from '../ui/themed-text';
|
|
21
|
+
import { SvgImage } from '../ui/svg-image';
|
|
23
22
|
import { MessageSquareTextIcon, UserIcon } from '../icons/index';
|
|
24
23
|
import type { MainStackParamList } from '../navigation/types/index';
|
|
25
24
|
|
|
@@ -47,12 +46,14 @@ export const HeaderMobile = () => {
|
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
return (
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
<View style={styles.header} className="px-4 pb-3">
|
|
50
|
+
{backgroundUri ? (
|
|
51
|
+
<SvgImage
|
|
52
|
+
uri={backgroundUri}
|
|
53
|
+
className="absolute inset-0"
|
|
54
|
+
resizeMode="cover"
|
|
55
|
+
/>
|
|
56
|
+
) : null}
|
|
56
57
|
<SafeAreaView edges={['top']}>
|
|
57
58
|
{!isProduction && (
|
|
58
59
|
<View className="mb-2 w-full rounded-lg bg-white/50 p-2">
|
|
@@ -78,13 +79,7 @@ export const HeaderMobile = () => {
|
|
|
78
79
|
)}
|
|
79
80
|
</Avatar>
|
|
80
81
|
</Button>
|
|
81
|
-
{logoUri
|
|
82
|
-
<Image
|
|
83
|
-
source={{ uri: logoUri }}
|
|
84
|
-
resizeMode="contain"
|
|
85
|
-
className="h-[64px] w-[216px]"
|
|
86
|
-
/>
|
|
87
|
-
) : null}
|
|
82
|
+
<SvgImage uri={logoUri} className="h-[64px] w-[216px]" />
|
|
88
83
|
<Button
|
|
89
84
|
variant="outline"
|
|
90
85
|
size="icon"
|
|
@@ -100,7 +95,7 @@ export const HeaderMobile = () => {
|
|
|
100
95
|
</Button>
|
|
101
96
|
</View>
|
|
102
97
|
</SafeAreaView>
|
|
103
|
-
</
|
|
98
|
+
</View>
|
|
104
99
|
);
|
|
105
100
|
};
|
|
106
101
|
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for iframe WebView navigation interception.
|
|
3
|
+
*
|
|
4
|
+
* Regression guard for the bug where ANY url change inside an embedded
|
|
5
|
+
* iframe (e.g. YouTube updating query params when play is tapped) was
|
|
6
|
+
* treated as a cross-origin navigation and opened the system browser.
|
|
7
|
+
*
|
|
8
|
+
* The fix compares origins (via isExternalLink) instead of the full URL,
|
|
9
|
+
* so same-origin navigations stay in the WebView and only genuinely
|
|
10
|
+
* external clicks are intercepted.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const React = require('react');
|
|
14
|
+
const ReactTestRenderer = require('react-test-renderer');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React & RN are not available in the node test environment, so we provide
|
|
18
|
+
* minimal stand-ins for the primitives that html.tsx touches.
|
|
19
|
+
*/
|
|
20
|
+
jest.mock('react-native', () => {
|
|
21
|
+
const View = ({ children }: { children?: unknown }) =>
|
|
22
|
+
React.createElement('View', null, children);
|
|
23
|
+
const Text = ({ children }: { children?: unknown }) =>
|
|
24
|
+
React.createElement('Text', null, children);
|
|
25
|
+
const StyleSheet = { create: (s: unknown) => s };
|
|
26
|
+
return { View, Text, StyleSheet };
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The built common package ships ESM which Jest's node transform doesn't
|
|
31
|
+
* cover. Mock the two helpers html.tsx needs with the real implementations
|
|
32
|
+
* (mirrored from markdownHelpers.ts) so the integration test is accurate.
|
|
33
|
+
*/
|
|
34
|
+
jest.mock('@openpeepshq/common/lib', () => {
|
|
35
|
+
const IFRAME_SRC_RE =
|
|
36
|
+
/<iframe\b[^>]*?\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)')[^>]*>/gi;
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
extractIframeSrcs: (html: string): string[] => {
|
|
40
|
+
const srcs: string[] = [];
|
|
41
|
+
let match: RegExpExecArray | null;
|
|
42
|
+
while ((match = IFRAME_SRC_RE.exec(html)) !== null) {
|
|
43
|
+
srcs.push(match[1] ?? match[2] ?? '');
|
|
44
|
+
}
|
|
45
|
+
return srcs;
|
|
46
|
+
},
|
|
47
|
+
isExternalLink: (href: string, origin?: string): boolean => {
|
|
48
|
+
if (!href || /^(mailto:|tel:|#)/.test(href)) return false;
|
|
49
|
+
if (href.startsWith('/') && !href.startsWith('//')) return false;
|
|
50
|
+
if (!origin) return !href.startsWith('/');
|
|
51
|
+
try {
|
|
52
|
+
return new URL(href, origin).origin !== origin;
|
|
53
|
+
} catch {
|
|
54
|
+
return !href.startsWith('/');
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
MARKDOWN_HTML_ALLOWED_TAGS: [
|
|
58
|
+
'a',
|
|
59
|
+
'b',
|
|
60
|
+
'blockquote',
|
|
61
|
+
'br',
|
|
62
|
+
'code',
|
|
63
|
+
'em',
|
|
64
|
+
'hr',
|
|
65
|
+
'img',
|
|
66
|
+
'iframe',
|
|
67
|
+
'li',
|
|
68
|
+
'ol',
|
|
69
|
+
'p',
|
|
70
|
+
'pre',
|
|
71
|
+
'strong',
|
|
72
|
+
'ul',
|
|
73
|
+
'video',
|
|
74
|
+
'source',
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
jest.mock('react-native-webview', () => {
|
|
80
|
+
const { View } = require('react-native');
|
|
81
|
+
class WebView extends React.Component {
|
|
82
|
+
render() {
|
|
83
|
+
return React.createElement(View, { testID: 'webview-mock' });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
WebView.navigation = { whitelist: [], blacklist: [] };
|
|
87
|
+
return { WebView };
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const { WebView } = require('react-native-webview');
|
|
91
|
+
const { htmlInlineRenderer } = require('./html');
|
|
92
|
+
|
|
93
|
+
const YOUTUBE_EMBED = 'https://www.youtube.com/embed/dQw4w9WgXcQ';
|
|
94
|
+
|
|
95
|
+
const renderWithNode = (onIframePress: jest.Mock, iframeHtml: string) => {
|
|
96
|
+
const fn = htmlInlineRenderer(onIframePress);
|
|
97
|
+
// RenderFunction signature: (node, childrenList, ...rest)
|
|
98
|
+
const node = { content: iframeHtml };
|
|
99
|
+
const element = fn(node, [], {});
|
|
100
|
+
let tree: ReturnType<typeof ReactTestRenderer.create>;
|
|
101
|
+
ReactTestRenderer.act(() => {
|
|
102
|
+
tree = ReactTestRenderer.create(
|
|
103
|
+
React.createElement(React.Fragment, null, element)
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
return tree;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
describe('htmlInlineRenderer iframe navigation guard', () => {
|
|
110
|
+
it('allows same-origin navigations and does not open the browser', () => {
|
|
111
|
+
const onIframePress = jest.fn();
|
|
112
|
+
const tree = renderWithNode(
|
|
113
|
+
onIframePress,
|
|
114
|
+
`<iframe src="${YOUTUBE_EMBED}"></iframe>`
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const webView = tree.root.findByType(WebView);
|
|
118
|
+
const handler = webView.props.onShouldStartLoadWithRequest;
|
|
119
|
+
expect(handler).toBeDefined();
|
|
120
|
+
|
|
121
|
+
const sameOriginUrls = [
|
|
122
|
+
`${YOUTUBE_EMBED}?autoplay=1`,
|
|
123
|
+
`${YOUTUBE_EMBED}?autoplay=1&start=30`,
|
|
124
|
+
'https://www.youtube.com/embed/another_video',
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
for (const url of sameOriginUrls) {
|
|
128
|
+
const result = handler({ url });
|
|
129
|
+
expect(result).toBe(true);
|
|
130
|
+
expect(onIframePress).not.toHaveBeenCalled();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
tree.unmount();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('intercepts cross-origin navigations and opens them in the browser', () => {
|
|
137
|
+
const onIframePress = jest.fn();
|
|
138
|
+
const tree = renderWithNode(
|
|
139
|
+
onIframePress,
|
|
140
|
+
`<iframe src="${YOUTUBE_EMBED}"></iframe>`
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const webView = tree.root.findByType(WebView);
|
|
144
|
+
const handler = webView.props.onShouldStartLoadWithRequest;
|
|
145
|
+
|
|
146
|
+
const result = handler({ url: 'https://twitter.com/home' });
|
|
147
|
+
|
|
148
|
+
expect(result).toBe(false);
|
|
149
|
+
expect(onIframePress).toHaveBeenCalledWith('https://twitter.com/home');
|
|
150
|
+
|
|
151
|
+
tree.unmount();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('allows all navigations when the embed src origin cannot be determined', () => {
|
|
155
|
+
const onIframePress = jest.fn();
|
|
156
|
+
const tree = renderWithNode(
|
|
157
|
+
onIframePress,
|
|
158
|
+
'<iframe src="not-a-valid-url"></iframe>'
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const webView = tree.root.findByType(WebView);
|
|
162
|
+
const handler = webView.props.onShouldStartLoadWithRequest;
|
|
163
|
+
|
|
164
|
+
const result = handler({ url: 'https://twitter.com/home' });
|
|
165
|
+
|
|
166
|
+
// Can't determine embed origin — be permissive, don't intercept.
|
|
167
|
+
expect(result).toBe(true);
|
|
168
|
+
expect(onIframePress).not.toHaveBeenCalled();
|
|
169
|
+
|
|
170
|
+
tree.unmount();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -4,6 +4,7 @@ import { WebView } from 'react-native-webview';
|
|
|
4
4
|
import type { RenderFunction } from 'react-native-markdown-display';
|
|
5
5
|
import {
|
|
6
6
|
extractIframeSrcs,
|
|
7
|
+
isExternalLink,
|
|
7
8
|
MARKDOWN_HTML_ALLOWED_TAGS,
|
|
8
9
|
} from '@openpeepshq/common/lib';
|
|
9
10
|
|
|
@@ -42,25 +43,38 @@ const renderHtmlContent = (
|
|
|
42
43
|
if (iframes.length > 0) {
|
|
43
44
|
return (
|
|
44
45
|
<View style={styles.iframeContainer} key={raw.slice(0, 40)}>
|
|
45
|
-
{iframes.map((src, i) =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
46
|
+
{iframes.map((src, i) => {
|
|
47
|
+
// Compute the embed origin once so we can distinguish
|
|
48
|
+
// same-origin navigations (allow) from cross-origin (intercept).
|
|
49
|
+
let embedOrigin: string | undefined;
|
|
50
|
+
try {
|
|
51
|
+
embedOrigin = new URL(src).origin;
|
|
52
|
+
} catch {
|
|
53
|
+
embedOrigin = undefined;
|
|
54
|
+
}
|
|
55
|
+
return (
|
|
56
|
+
<View key={`${i}-${src.slice(0, 20)}`} style={styles.iframeRow}>
|
|
57
|
+
<WebView
|
|
58
|
+
source={{ uri: src }}
|
|
59
|
+
style={styles.webview}
|
|
60
|
+
scrollEnabled={false}
|
|
61
|
+
onShouldStartLoadWithRequest={(nav) => {
|
|
62
|
+
// Allow same-origin navigations (e.g., YouTube updating
|
|
63
|
+
// query params when play is tapped). Only intercept
|
|
64
|
+
// cross-origin navigations and open them in the browser.
|
|
65
|
+
if (embedOrigin && isExternalLink(nav.url, embedOrigin)) {
|
|
66
|
+
onIframePress(nav.url);
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}}
|
|
71
|
+
/>
|
|
72
|
+
<Text style={styles.iframeUrl} onPress={() => onIframePress(src)}>
|
|
73
|
+
{src}
|
|
74
|
+
</Text>
|
|
75
|
+
</View>
|
|
76
|
+
);
|
|
77
|
+
})}
|
|
64
78
|
</View>
|
|
65
79
|
);
|
|
66
80
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useOpenpeeps } from '@openpeepshq/react';
|
|
3
|
-
import {
|
|
3
|
+
import { View } from 'react-native';
|
|
4
4
|
import { SideMenu } from '../custom/navigation/side-menu';
|
|
5
|
+
import { SvgImage } from '../ui/svg-image';
|
|
5
6
|
import { useNavigation } from '@react-navigation/native';
|
|
6
7
|
import { MainStackParamList } from './types';
|
|
7
8
|
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
@@ -62,12 +63,14 @@ export const MenuWrapper = ({ children }: { children: React.ReactNode }) => {
|
|
|
62
63
|
|
|
63
64
|
if (resolvedBackgroundUri && !isLoading) {
|
|
64
65
|
return (
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
<View className="w-screen h-screen flex justify-center items-center">
|
|
67
|
+
<SvgImage
|
|
68
|
+
uri={resolvedBackgroundUri}
|
|
69
|
+
className="absolute inset-0"
|
|
70
|
+
resizeMode="stretch"
|
|
71
|
+
/>
|
|
69
72
|
{content}
|
|
70
|
-
</
|
|
73
|
+
</View>
|
|
71
74
|
);
|
|
72
75
|
}
|
|
73
76
|
|
|
@@ -11,13 +11,14 @@ import {
|
|
|
11
11
|
import { useNavigation } from '@react-navigation/native';
|
|
12
12
|
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
13
13
|
import React from 'react';
|
|
14
|
-
import {
|
|
14
|
+
import { Pressable, View } from 'react-native';
|
|
15
15
|
import { useTranslation } from 'react-i18next';
|
|
16
16
|
import { ProfileAvatar } from '../profile/index';
|
|
17
17
|
import { CalendarIcon, PaperclipIcon, PlayIcon } from '../icons/index';
|
|
18
18
|
import { MainStackParamList } from '../navigation/types/index';
|
|
19
19
|
import { ThemedText } from '../ui/themed-text';
|
|
20
20
|
import { ThemedView } from '../ui/themed-view';
|
|
21
|
+
import { SvgImage } from '../ui/svg-image';
|
|
21
22
|
|
|
22
23
|
type CompactPost = Pick<
|
|
23
24
|
PublicReplyPost,
|
|
@@ -56,7 +57,7 @@ const CompactThumb = ({
|
|
|
56
57
|
extra?: number;
|
|
57
58
|
}) => (
|
|
58
59
|
<View className="bg-surface relative size-16 shrink-0 overflow-hidden rounded-md">
|
|
59
|
-
<
|
|
60
|
+
<SvgImage uri={src} className="size-full" resizeMode="cover" />
|
|
60
61
|
{video ? (
|
|
61
62
|
<View className="absolute inset-0 items-center justify-center bg-black/40">
|
|
62
63
|
<PlayIcon className="size-5 text-white" />
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Linking, Pressable, View } from 'react-native';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import type { PublicProfile } from '@openpeepshq/common/types';
|
|
5
5
|
import { truncateText } from '@openpeepshq/common/lib';
|
|
@@ -7,6 +7,7 @@ import { profileFieldLink } from '@openpeepshq/react';
|
|
|
7
7
|
import { MapPinIcon } from '../icons/index';
|
|
8
8
|
import { PostMarkdown } from '../post/Markdown';
|
|
9
9
|
import { ThemedText } from '../ui/themed-text';
|
|
10
|
+
import { SvgImage } from '../ui/svg-image';
|
|
10
11
|
import { ProfileAvatar } from './Avatar';
|
|
11
12
|
import { ProfilePageAction } from './ProfilePageAction';
|
|
12
13
|
import { ProfileStats } from './ProfileStats';
|
|
@@ -26,8 +27,8 @@ export const ProfileHeader = ({
|
|
|
26
27
|
<View className="relative mb-8">
|
|
27
28
|
<View className="relative aspect-[3/1] w-full bg-surface-2">
|
|
28
29
|
{profile.header ? (
|
|
29
|
-
<
|
|
30
|
-
|
|
30
|
+
<SvgImage
|
|
31
|
+
uri={profile.header}
|
|
31
32
|
className="h-full w-full"
|
|
32
33
|
resizeMode="cover"
|
|
33
34
|
/>
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as AvatarPrimitive from '@rn-primitives/avatar';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import type { ImageSourcePropType, ImageURISource } from 'react-native';
|
|
4
|
+
import { isSvgUrl } from '@openpeepshq/react';
|
|
4
5
|
import { useCachedMediaUri } from '../../hooks/use-cached-media-uri';
|
|
6
|
+
import { SvgImage } from './svg-image';
|
|
5
7
|
import { cn } from '../../lib/utils';
|
|
6
8
|
|
|
7
9
|
const remoteUriFromSource = (
|
|
@@ -39,7 +41,8 @@ const AvatarImage = React.forwardRef<
|
|
|
39
41
|
const remoteUri = remoteUriFromSource(
|
|
40
42
|
source as ImageSourcePropType | undefined
|
|
41
43
|
);
|
|
42
|
-
const
|
|
44
|
+
const svg = remoteUri ? isSvgUrl(remoteUri) : false;
|
|
45
|
+
const cachedUri = useCachedMediaUri(svg ? null : remoteUri);
|
|
43
46
|
const resolvedSource =
|
|
44
47
|
remoteUri &&
|
|
45
48
|
cachedUri &&
|
|
@@ -49,6 +52,16 @@ const AvatarImage = React.forwardRef<
|
|
|
49
52
|
? { ...(source as ImageURISource), uri: cachedUri }
|
|
50
53
|
: source;
|
|
51
54
|
|
|
55
|
+
if (svg) {
|
|
56
|
+
return (
|
|
57
|
+
<SvgImage
|
|
58
|
+
uri={remoteUri}
|
|
59
|
+
className={cn('aspect-square h-full w-full', className)}
|
|
60
|
+
resizeMode="cover"
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
return (
|
|
53
66
|
<AvatarPrimitiveImage
|
|
54
67
|
ref={ref}
|
|
@@ -29,6 +29,7 @@ export { ThemedText, TextClassContext } from './themed-text';
|
|
|
29
29
|
export { ThemedView, ViewClassContext } from './themed-view';
|
|
30
30
|
export * from './tooltip';
|
|
31
31
|
export * from './skeleton';
|
|
32
|
+
export * from './svg-image';
|
|
32
33
|
export * from './switch';
|
|
33
34
|
export * from './tabs';
|
|
34
35
|
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { Image, View, type ImageResizeMode } from 'react-native';
|
|
3
|
+
import RNFS from 'react-native-fs';
|
|
4
|
+
import { SvgXml } from 'react-native-svg';
|
|
5
|
+
import { isSvgUrl } from '@openpeepshq/react';
|
|
6
|
+
import { useCachedMediaUri } from '../../hooks/use-cached-media-uri';
|
|
7
|
+
|
|
8
|
+
// RN Image cannot decode SVG, so .svg media renders via react-native-svg.
|
|
9
|
+
// The bytes flow through the shared on-disk media cache — the same avatars
|
|
10
|
+
// and logos repeat everywhere, so each URL is fetched only once.
|
|
11
|
+
//
|
|
12
|
+
// resizeMode maps to preserveAspectRatio exactly as web encodes it via the
|
|
13
|
+
// #svgView fragment (see svgCoverSrc in @openpeepshq/react).
|
|
14
|
+
const preserveAspectRatioFor: Record<string, string> = {
|
|
15
|
+
cover: 'xMidYMid slice',
|
|
16
|
+
contain: 'xMidYMid meet',
|
|
17
|
+
stretch: 'none',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
interface SvgImageProps {
|
|
21
|
+
uri?: string | null;
|
|
22
|
+
className?: string;
|
|
23
|
+
resizeMode?: ImageResizeMode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const SvgImage = ({
|
|
27
|
+
uri,
|
|
28
|
+
className,
|
|
29
|
+
resizeMode = 'contain',
|
|
30
|
+
}: SvgImageProps) => {
|
|
31
|
+
// Fragments (#svgView etc.) are web-only hints; strip before fetching.
|
|
32
|
+
const src = uri?.split('#')[0];
|
|
33
|
+
const svg = !!src && isSvgUrl(src);
|
|
34
|
+
const localPath = useCachedMediaUri(svg ? src : null);
|
|
35
|
+
const [xml, setXml] = useState<string | null>(null);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!svg) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
setXml(null);
|
|
42
|
+
if (!localPath?.startsWith('file://')) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
let cancelled = false;
|
|
46
|
+
void RNFS.readFile(localPath, 'utf8')
|
|
47
|
+
.then((text) => {
|
|
48
|
+
if (!cancelled) {
|
|
49
|
+
setXml(text);
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
.catch(() => {
|
|
53
|
+
if (!cancelled) {
|
|
54
|
+
setXml(null);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return () => {
|
|
58
|
+
cancelled = true;
|
|
59
|
+
};
|
|
60
|
+
}, [svg, localPath]);
|
|
61
|
+
|
|
62
|
+
if (!src) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (!svg) {
|
|
66
|
+
return (
|
|
67
|
+
<Image
|
|
68
|
+
source={{ uri: src }}
|
|
69
|
+
className={className}
|
|
70
|
+
resizeMode={resizeMode}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
if (!xml) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return (
|
|
78
|
+
<View className={className}>
|
|
79
|
+
<SvgXml
|
|
80
|
+
xml={xml}
|
|
81
|
+
width="100%"
|
|
82
|
+
height="100%"
|
|
83
|
+
preserveAspectRatio={
|
|
84
|
+
preserveAspectRatioFor[resizeMode] ?? 'xMidYMid meet'
|
|
85
|
+
}
|
|
86
|
+
/>
|
|
87
|
+
</View>
|
|
88
|
+
);
|
|
89
|
+
};
|
package/src/utils/media-cache.ts
CHANGED
|
@@ -69,7 +69,7 @@ export const getProperFileExtension = (
|
|
|
69
69
|
const extension = url?.split('.').pop()?.toLowerCase() || '';
|
|
70
70
|
|
|
71
71
|
const supportedFormats = {
|
|
72
|
-
image: ['jpg', 'jpeg', 'png', 'gif', 'webp'],
|
|
72
|
+
image: ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'],
|
|
73
73
|
video: ['mp4', 'm4v', 'mov', 'webm'],
|
|
74
74
|
audio: ['mp3', 'wav', 'ogg', 'm4a', 'aac'],
|
|
75
75
|
};
|