@openpeepshq/rn-components 0.6.9 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/rn-components",
3
- "version": "0.6.9",
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/common": "^0.3.2",
146
- "@openpeepshq/react": "^0.6.3"
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 imagePath = useCachedMediaUri(url);
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 { Image, TouchableOpacity, View } from 'react-native';
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 { Image, Pressable, View } from 'react-native';
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
- <Image
47
- source={{ uri: header }}
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 { Image, Pressable, View } from 'react-native';
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
- <Image
53
- source={{ uri: url }}
53
+ <SvgImage
54
+ uri={url}
54
55
  className="absolute inset-0 w-full h-full"
55
56
  resizeMode="cover"
56
57
  />
@@ -0,0 +1,182 @@
1
+ import React, { useState } from 'react';
2
+ import { View } from 'react-native';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { truncateText } from '@openpeepshq/common';
5
+ import { useJamContext } from '@openpeepshq/react';
6
+ import {
7
+ CircleStopIcon,
8
+ DiscIcon,
9
+ HandIcon,
10
+ InfoIcon,
11
+ LaughIcon,
12
+ MessageSquareTextIcon,
13
+ UsersRoundIcon,
14
+ } from '../icons/index';
15
+ import {
16
+ JamAudioOutputSelector,
17
+ JamCameraSelector,
18
+ JamMicSelector,
19
+ } from './JamDeviceSelectors';
20
+ import { JamReactionMenu } from './JamReactionMenu';
21
+ import { JamToolbarButton, toneIconClass } from './JamToolbarButton';
22
+ import { LeaveCloseButton } from './LeaveCloseButton';
23
+ import { type JamFooterProps } from './JamFooter';
24
+ import { useFooterControls } from './JamFooter';
25
+ import { ThemedText } from '../ui/themed-text';
26
+
27
+ export type JamDesktopFooterProps = JamFooterProps;
28
+
29
+ /**
30
+ * Wide-screen (tablet/desktop) in-room toolbar, mirroring the web JamFooter
31
+ * `md:flex` DesktopFooter (platform/react/src/components/jams/JamFooter.tsx).
32
+ * Rendered by JamParticipantConference in place of the mobile JamFooter when
33
+ * isMediumScreenOrLarger. Screen sharing and background blur are web-only (no
34
+ * React Native equivalents), so they are intentionally omitted.
35
+ */
36
+ export const JamDesktopFooter = ({
37
+ chatOpen,
38
+ onToggleChat,
39
+ peopleOpen,
40
+ onTogglePeople,
41
+ detailsOpen,
42
+ onToggleDetails,
43
+ speakerDeviceId,
44
+ speakerEnabled,
45
+ onSpeakerChange,
46
+ onToggleSpeaker,
47
+ }: JamDesktopFooterProps) => {
48
+ const { t } = useTranslation();
49
+ const { jamEvent } = useJamContext();
50
+ const {
51
+ isModerator,
52
+ isRecording,
53
+ recordingLabel,
54
+ recordingEnabled,
55
+ handRaised,
56
+ busy,
57
+ participantCount,
58
+ waitingRoomCount,
59
+ sendReactionEmoji,
60
+ toggleRecording,
61
+ raiseHand,
62
+ } = useFooterControls();
63
+ const [reactionMenuOpen, setReactionMenuOpen] = useState(false);
64
+
65
+ return (
66
+ <View className="w-full flex-none flex-row items-center justify-between bg-background/75 px-4 py-3">
67
+ <ThemedText className="truncate pr-2">
68
+ {truncateText(jamEvent.name, 40)}
69
+ </ThemedText>
70
+
71
+ <View className="relative flex-row items-center gap-x-4">
72
+ {reactionMenuOpen ? (
73
+ <View className="absolute bottom-12 right-0 z-50">
74
+ <JamReactionMenu
75
+ onSelect={(emoji) => void sendReactionEmoji(emoji)}
76
+ />
77
+ </View>
78
+ ) : null}
79
+
80
+ <JamMicSelector />
81
+ <JamCameraSelector />
82
+ <JamAudioOutputSelector
83
+ speakerDeviceId={speakerDeviceId}
84
+ speakerEnabled={speakerEnabled}
85
+ onSpeakerChange={onSpeakerChange}
86
+ onToggleSpeaker={onToggleSpeaker}
87
+ />
88
+
89
+ {isModerator && recordingEnabled ? (
90
+ <JamToolbarButton
91
+ tone="danger"
92
+ disabled={busy}
93
+ title={recordingLabel}
94
+ action={() => void toggleRecording()}
95
+ >
96
+ {isRecording ? (
97
+ <CircleStopIcon
98
+ size={20}
99
+ className="text-destructive-foreground"
100
+ />
101
+ ) : (
102
+ <DiscIcon size={20} className="text-destructive-foreground" />
103
+ )}
104
+ </JamToolbarButton>
105
+ ) : null}
106
+
107
+ <JamToolbarButton
108
+ title={t('jams.hand.raiseTitle')}
109
+ tone={handRaised ? 'active' : 'default'}
110
+ action={() => void raiseHand()}
111
+ >
112
+ <HandIcon
113
+ size={20}
114
+ className={toneIconClass[handRaised ? 'active' : 'default']}
115
+ />
116
+ </JamToolbarButton>
117
+
118
+ <JamToolbarButton
119
+ title={t('jams.reactions.sendTitle')}
120
+ tone={reactionMenuOpen ? 'active' : 'default'}
121
+ action={() => setReactionMenuOpen((open) => !open)}
122
+ >
123
+ <LaughIcon
124
+ size={20}
125
+ className={toneIconClass[reactionMenuOpen ? 'active' : 'default']}
126
+ />
127
+ </JamToolbarButton>
128
+
129
+ <JamToolbarButton
130
+ title={t('jams.chat.openEveryoneTitle')}
131
+ tone={chatOpen ? 'active' : 'default'}
132
+ action={onToggleChat}
133
+ >
134
+ <MessageSquareTextIcon
135
+ size={20}
136
+ className={toneIconClass[chatOpen ? 'active' : 'default']}
137
+ />
138
+ </JamToolbarButton>
139
+ </View>
140
+
141
+ <View className="relative flex-row items-center gap-x-4">
142
+ <JamToolbarButton
143
+ title={t('jams.mobileMenu.jamDetails')}
144
+ tone={detailsOpen ? 'active' : 'default'}
145
+ action={onToggleDetails}
146
+ >
147
+ <InfoIcon
148
+ size={20}
149
+ className={toneIconClass[detailsOpen ? 'active' : 'default']}
150
+ />
151
+ </JamToolbarButton>
152
+
153
+ <JamToolbarButton
154
+ title={t('jams.participant.showEveryone')}
155
+ tone={peopleOpen ? 'active' : 'default'}
156
+ action={onTogglePeople}
157
+ >
158
+ <View className="relative">
159
+ <UsersRoundIcon
160
+ size={20}
161
+ className={toneIconClass[peopleOpen ? 'active' : 'default']}
162
+ />
163
+ {participantCount > 0 || waitingRoomCount > 0 ? (
164
+ <View className="bg-border-2 absolute -top-1 -right-1 flex h-5 min-w-[20px] items-center justify-center rounded-full px-1 py-0.5">
165
+ <ThemedText className="text-xs text-foreground">
166
+ {participantCount}
167
+ </ThemedText>
168
+ {waitingRoomCount > 0 ? (
169
+ <ThemedText className="text-destructive">
170
+ {' +' + waitingRoomCount}
171
+ </ThemedText>
172
+ ) : null}
173
+ </View>
174
+ ) : null}
175
+ </View>
176
+ </JamToolbarButton>
177
+
178
+ <LeaveCloseButton />
179
+ </View>
180
+ </View>
181
+ );
182
+ };
@@ -39,7 +39,7 @@ export interface JamFooterProps {
39
39
  }
40
40
 
41
41
  /** Native wrapper: `Alert` confirm + toasts. */
42
- const useFooterControls = () => {
42
+ export const useFooterControls = () => {
43
43
  const { t } = useTranslation();
44
44
  const room = useRoomContext();
45
45
  const participants = useParticipants();
@@ -14,10 +14,12 @@ import {
14
14
  useJamContext,
15
15
  useJamLocalSettings,
16
16
  } from '@openpeepshq/react';
17
+ import { useWindowSize } from '../../hooks/index';
17
18
  import { ThemedText } from '../ui/themed-text';
18
19
  import { JamChatDrawer } from './JamChatDrawer';
19
20
  import { JamDetailsDrawer } from './JamDetailsDrawer';
20
- import { JamFooter } from './JamFooter';
21
+ import { JamDesktopFooter } from './JamDesktopFooter';
22
+ import { JamFooter, type JamFooterProps } from './JamFooter';
21
23
  import { JamPeopleDrawer } from './JamPeopleDrawer';
22
24
  import { JamNetworkQuality, JamRecordingIndicator } from './JamRoomIndicators';
23
25
  import { JamVideoLayout } from './JamVideoLayout';
@@ -27,6 +29,7 @@ type Drawer = 'chat' | 'people' | 'details' | null;
27
29
  const JamParticipantConferenceInner = () => {
28
30
  const room = useRoomContext();
29
31
  const { jamEvent } = useJamContext();
32
+ const { isMediumScreenOrLarger } = useWindowSize();
30
33
  const [drawer, setDrawer] = useState<Drawer>(null);
31
34
  const [settings, updateSettings] = useJamLocalSettings();
32
35
  const remoteParticipants = useRemoteParticipants();
@@ -70,6 +73,20 @@ const JamParticipantConferenceInner = () => {
70
73
  const toggleDrawer = (next: Exclude<Drawer, null>) =>
71
74
  setDrawer((current) => (current === next ? null : next));
72
75
 
76
+ const footerProps: JamFooterProps = {
77
+ chatOpen: drawer === 'chat',
78
+ onToggleChat: () => toggleDrawer('chat'),
79
+ peopleOpen: drawer === 'people',
80
+ onTogglePeople: () => toggleDrawer('people'),
81
+ detailsOpen: drawer === 'details',
82
+ onToggleDetails: () => toggleDrawer('details'),
83
+ speakerDeviceId: settings.speakerDeviceId,
84
+ speakerEnabled: settings.speakerEnabled,
85
+ onSpeakerChange: (speakerDeviceId) => updateSettings({ speakerDeviceId }),
86
+ onToggleSpeaker: () =>
87
+ updateSettings({ speakerEnabled: !settings.speakerEnabled }),
88
+ };
89
+
73
90
  return (
74
91
  <View className="relative flex-1 overflow-hidden bg-background">
75
92
  <JamNetworkQuality />
@@ -103,22 +120,11 @@ const JamParticipantConferenceInner = () => {
103
120
  />
104
121
  </View>
105
122
  <View className="w-full shrink-0 bg-background">
106
- <JamFooter
107
- chatOpen={drawer === 'chat'}
108
- onToggleChat={() => toggleDrawer('chat')}
109
- peopleOpen={drawer === 'people'}
110
- onTogglePeople={() => toggleDrawer('people')}
111
- detailsOpen={drawer === 'details'}
112
- onToggleDetails={() => toggleDrawer('details')}
113
- speakerDeviceId={settings.speakerDeviceId}
114
- speakerEnabled={settings.speakerEnabled}
115
- onSpeakerChange={(speakerDeviceId) =>
116
- updateSettings({ speakerDeviceId })
117
- }
118
- onToggleSpeaker={() =>
119
- updateSettings({ speakerEnabled: !settings.speakerEnabled })
120
- }
121
- />
123
+ {isMediumScreenOrLarger ? (
124
+ <JamDesktopFooter {...footerProps} />
125
+ ) : (
126
+ <JamFooter {...footerProps} />
127
+ )}
122
128
  </View>
123
129
  </View>
124
130
  );
@@ -1,5 +1,5 @@
1
1
  import React, { type ReactNode } from 'react';
2
- import { Image, ImageBackground, Pressable, View } from 'react-native';
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
- <Image
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
- <ImageBackground
92
- source={{ uri: authBackgroundUri }}
93
- className="w-full flex-1 justify-end"
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
- </ImageBackground>
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
- <ImageBackground
51
- resizeMode="cover"
52
- source={backgroundUri ? { uri: backgroundUri } : undefined}
53
- style={styles.header}
54
- className="px-4 pb-3"
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
- </ImageBackground>
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
- <View key={`${i}-${src.slice(0, 20)}`} style={styles.iframeRow}>
47
- <WebView
48
- source={{ uri: src }}
49
- style={styles.webview}
50
- scrollEnabled={false}
51
- onNavigationStateChange={(nav) => {
52
- // Intercept navigations away from the original embed URL
53
- // and open them in the system browser instead.
54
- if (nav.url !== src) {
55
- onIframePress(nav.url);
56
- }
57
- }}
58
- />
59
- <Text style={styles.iframeUrl} onPress={() => onIframePress(src)}>
60
- {src}
61
- </Text>
62
- </View>
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 { ImageBackground, View } from 'react-native';
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
- <ImageBackground
66
- source={{ uri: resolvedBackgroundUri }}
67
- className="w-screen h-screen flex justify-center items-center"
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
- </ImageBackground>
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 { Image, Pressable, View } from 'react-native';
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
- <Image source={{ uri: src }} className="size-full" resizeMode="cover" />
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 { Image, Linking, Pressable, View } from 'react-native';
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
- <Image
30
- source={{ uri: profile.header }}
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 cachedUri = useCachedMediaUri(remoteUri);
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
+ };
@@ -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
  };