@openpeepshq/rn-components 0.6.3 → 0.6.5
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 -2
- package/src/components/layout/PlusButton.tsx +6 -0
- package/src/components/markdown/extensions/html.tsx +23 -15
- package/src/components/ui/button.tsx +8 -2
- package/src/theme/OpenPeepsThemeProvider.tsx +23 -5
- package/src/theme/defaults.ts +1 -0
- package/src/theme/types.ts +1 -0
- package/src/theme/utils.ts +9 -0
- package/tailwind.config.js +5 -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.5",
|
|
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",
|
|
@@ -133,6 +133,7 @@
|
|
|
133
133
|
"react-native-uuid": "^2.0.3",
|
|
134
134
|
"react-native-video": "^6.19.2",
|
|
135
135
|
"react-native-voip-push-notification": "^3.3.2",
|
|
136
|
+
"react-native-webview": "^14.0.1",
|
|
136
137
|
"react-native-worklets": "^0.8.1",
|
|
137
138
|
"tailwind-merge": "^3.0.1",
|
|
138
139
|
"tailwindcss": "^3.4.17",
|
|
@@ -141,7 +142,7 @@
|
|
|
141
142
|
"timezones-list": "^3.1.0",
|
|
142
143
|
"validator": "^13.15.23",
|
|
143
144
|
"zustand": "^5.0.3",
|
|
144
|
-
"@openpeepshq/common": "^0.3.
|
|
145
|
+
"@openpeepshq/common": "^0.3.2",
|
|
145
146
|
"@openpeepshq/react": "^0.6.1"
|
|
146
147
|
},
|
|
147
148
|
"devDependencies": {
|
|
@@ -3,6 +3,11 @@ import { Pressable } from 'react-native';
|
|
|
3
3
|
import { PlusIcon } from '../icons/index';
|
|
4
4
|
import { usePageChrome } from './pageChrome';
|
|
5
5
|
|
|
6
|
+
// PlusButton is always fully round — it doesn't use the theme's buttonRadius
|
|
7
|
+
// setting (which is for regular buttons). On web, circular elements have a
|
|
8
|
+
// separate theme token; on RN we use a static 9999px (same as rounded-full).
|
|
9
|
+
const PLUS_BUTTON_RADIUS = 9999;
|
|
10
|
+
|
|
6
11
|
export const PlusButton = () => {
|
|
7
12
|
const { plus } = usePageChrome();
|
|
8
13
|
if (!plus || Array.isArray(plus)) return null;
|
|
@@ -20,6 +25,7 @@ export const PlusButton = () => {
|
|
|
20
25
|
accessibilityRole="button"
|
|
21
26
|
accessibilityLabel={plus.title || 'New'}
|
|
22
27
|
onPress={onPress}
|
|
28
|
+
style={{ borderRadius: PLUS_BUTTON_RADIUS }}
|
|
23
29
|
className="bg-primary absolute bottom-10 right-6 z-20 size-16 items-center justify-center rounded-button"
|
|
24
30
|
>
|
|
25
31
|
<Icon size={24} className="text-primary-foreground" />
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
3
|
+
import { WebView } from 'react-native-webview';
|
|
3
4
|
import type { RenderFunction } from 'react-native-markdown-display';
|
|
4
5
|
import {
|
|
5
6
|
extractIframeSrcs,
|
|
@@ -10,7 +11,7 @@ const TAG_RE = /<\/?([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>/g;
|
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Renderer for markdown-it `html_inline` tokens.
|
|
13
|
-
* Extracts iframes (rendered as
|
|
14
|
+
* Extracts iframes (rendered as inline WebViews) and strips other HTML.
|
|
14
15
|
*/
|
|
15
16
|
export const htmlInlineRenderer =
|
|
16
17
|
(onIframePress: (url: string) => void): RenderFunction =>
|
|
@@ -35,20 +36,27 @@ const renderHtmlContent = (
|
|
|
35
36
|
raw: string,
|
|
36
37
|
onIframePress: (url: string) => void
|
|
37
38
|
): React.ReactElement | null => {
|
|
38
|
-
// Iframes:
|
|
39
|
+
// Iframes: render as inline WebViews so embedded content (YouTube, etc.)
|
|
40
|
+
// is visible without leaving the app.
|
|
39
41
|
const iframes = extractIframeSrcs(raw);
|
|
40
42
|
if (iframes.length > 0) {
|
|
41
43
|
return (
|
|
42
44
|
<View style={styles.iframeContainer} key={raw.slice(0, 40)}>
|
|
43
45
|
{iframes.map((src, i) => (
|
|
44
46
|
<View key={`${i}-${src.slice(0, 20)}`} style={styles.iframeRow}>
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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)}>
|
|
52
60
|
{src}
|
|
53
61
|
</Text>
|
|
54
62
|
</View>
|
|
@@ -80,15 +88,15 @@ const renderHtmlContent = (
|
|
|
80
88
|
const styles = StyleSheet.create({
|
|
81
89
|
iframeContainer: { marginVertical: 8 },
|
|
82
90
|
iframeRow: { flexDirection: 'column', alignItems: 'flex-start' },
|
|
83
|
-
iframeLink: {
|
|
84
|
-
color: '#007AFF',
|
|
85
|
-
textDecorationLine: 'underline',
|
|
86
|
-
fontSize: 14,
|
|
87
|
-
},
|
|
88
91
|
iframeUrl: {
|
|
89
92
|
color: '#666',
|
|
90
93
|
fontSize: 12,
|
|
91
94
|
marginTop: 4,
|
|
92
95
|
},
|
|
96
|
+
webview: {
|
|
97
|
+
width: '100%',
|
|
98
|
+
aspectRatio: 16 / 9,
|
|
99
|
+
borderRadius: 8,
|
|
100
|
+
},
|
|
93
101
|
text: { fontSize: 16, lineHeight: 24 },
|
|
94
102
|
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { cva, type VariantProps } from 'class-variance-authority';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { Pressable } from 'react-native';
|
|
3
|
+
import { Pressable, type StyleProp, type ViewStyle } from 'react-native';
|
|
4
4
|
import { TextClassContext } from './themed-text';
|
|
5
5
|
import { cn } from '../../lib/utils';
|
|
6
|
+
import { useThemeBorderRadius } from '../../theme/OpenPeepsThemeProvider';
|
|
6
7
|
|
|
7
8
|
const buttonVariants = cva(
|
|
8
9
|
'group flex items-center justify-center rounded-button web:ring-offset-background web:transition-colors web:focus-visible:outline-none web:focus-visible:ring-2 web:focus-visible:ring-ring web:focus-visible:ring-offset-2',
|
|
@@ -65,7 +66,11 @@ type ButtonProps = React.ComponentPropsWithoutRef<typeof Pressable> &
|
|
|
65
66
|
const Button = React.forwardRef<
|
|
66
67
|
React.ElementRef<typeof Pressable>,
|
|
67
68
|
ButtonProps
|
|
68
|
-
>(({ className, variant, size, ...props }, ref) => {
|
|
69
|
+
>(({ className, variant, size, style, ...props }, ref) => {
|
|
70
|
+
// NativeWind v4 doesn't resolve CSS variables for borderRadius, so
|
|
71
|
+
// apply the theme button radius via inline style as a fallback.
|
|
72
|
+
const borderRadius = useThemeBorderRadius();
|
|
73
|
+
|
|
69
74
|
return (
|
|
70
75
|
<TextClassContext.Provider
|
|
71
76
|
value={cn(
|
|
@@ -80,6 +85,7 @@ const Button = React.forwardRef<
|
|
|
80
85
|
)}
|
|
81
86
|
ref={ref}
|
|
82
87
|
role="button"
|
|
88
|
+
style={cn({ borderRadius }, style) as StyleProp<ViewStyle>}
|
|
83
89
|
{...props}
|
|
84
90
|
/>
|
|
85
91
|
</TextClassContext.Provider>
|
|
@@ -4,7 +4,7 @@ import { colorScheme } from 'nativewind';
|
|
|
4
4
|
import { useOpenpeeps } from '@openpeepshq/react';
|
|
5
5
|
import { OpenPeepsTheme } from './types';
|
|
6
6
|
import { defaultTheme } from './defaults';
|
|
7
|
-
import { buildTheme, getThemeVars } from './utils';
|
|
7
|
+
import { buildTheme, getThemeVars, parseDimension } from './utils';
|
|
8
8
|
import { CommunityConfig, getTheme } from '@openpeepshq/common';
|
|
9
9
|
|
|
10
10
|
const OpenPeepsThemeContext = createContext<OpenPeepsTheme>(defaultTheme);
|
|
@@ -36,10 +36,20 @@ export const OpenPeepsThemeProvider = ({
|
|
|
36
36
|
|
|
37
37
|
const theme = useMemo(
|
|
38
38
|
() =>
|
|
39
|
-
buildTheme(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
buildTheme(
|
|
40
|
+
resolvedTheme.dark,
|
|
41
|
+
resolvedTheme.primaryHex,
|
|
42
|
+
resolvedTheme.buttonRadius,
|
|
43
|
+
() => {
|
|
44
|
+
refetchProfileSettings();
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
[
|
|
48
|
+
refetchProfileSettings,
|
|
49
|
+
resolvedTheme.dark,
|
|
50
|
+
resolvedTheme.primaryHex,
|
|
51
|
+
resolvedTheme.buttonRadius,
|
|
52
|
+
]
|
|
43
53
|
);
|
|
44
54
|
|
|
45
55
|
const themeVars = useMemo(
|
|
@@ -78,3 +88,11 @@ export const useOpenPeepsTheme = () => {
|
|
|
78
88
|
}
|
|
79
89
|
return context;
|
|
80
90
|
};
|
|
91
|
+
|
|
92
|
+
/** Returns the theme button border-radius as a React Native numeric value.
|
|
93
|
+
* NativeWind v4 does not resolve CSS variables for borderRadius, so
|
|
94
|
+
* components must apply this via inline style instead of `rounded-button`. */
|
|
95
|
+
export const useThemeBorderRadius = (): number => {
|
|
96
|
+
const { buttonRadius } = useOpenPeepsTheme();
|
|
97
|
+
return parseDimension(buttonRadius);
|
|
98
|
+
};
|
package/src/theme/defaults.ts
CHANGED
package/src/theme/types.ts
CHANGED
package/src/theme/utils.ts
CHANGED
|
@@ -36,9 +36,17 @@ export const getThemeVars = (
|
|
|
36
36
|
'--theme-rounded-container': radii?.radius || '0.5rem',
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
+
/** Parse a CSS dimension string (e.g. '9999px', '8px') into a React Native
|
|
40
|
+
* numeric pixel value. Returns 0 when the string can't be parsed. */
|
|
41
|
+
export const parseDimension = (value: string): number => {
|
|
42
|
+
const num = parseFloat(value);
|
|
43
|
+
return isNaN(num) ? 0 : num;
|
|
44
|
+
};
|
|
45
|
+
|
|
39
46
|
export const buildTheme = (
|
|
40
47
|
isDark: boolean,
|
|
41
48
|
primaryColor: string | undefined,
|
|
49
|
+
buttonRadius: string | undefined,
|
|
42
50
|
refresh: () => void | Promise<void>
|
|
43
51
|
) => {
|
|
44
52
|
const colors = mapColors(isDark);
|
|
@@ -48,6 +56,7 @@ export const buildTheme = (
|
|
|
48
56
|
...colors,
|
|
49
57
|
primary: primaryColor || colors.primary,
|
|
50
58
|
},
|
|
59
|
+
buttonRadius: buttonRadius || '9999px',
|
|
51
60
|
refresh,
|
|
52
61
|
};
|
|
53
62
|
};
|
package/tailwind.config.js
CHANGED
|
@@ -66,7 +66,11 @@ export default {
|
|
|
66
66
|
hairline: hairlineWidth(),
|
|
67
67
|
},
|
|
68
68
|
borderRadius: {
|
|
69
|
-
|
|
69
|
+
// NativeWind v4 does not resolve CSS variables for borderRadius
|
|
70
|
+
// (only for colors via processColor). Components apply the theme
|
|
71
|
+
// button radius via inline style (see useThemeBorderRadius).
|
|
72
|
+
// Static fallback ensures non-square buttons as a safety net.
|
|
73
|
+
button: '9999px',
|
|
70
74
|
lg: 'var(--theme-rounded-container, 0.5rem)',
|
|
71
75
|
md: 'calc(var(--theme-rounded-container, 0.5rem) - 2px)',
|
|
72
76
|
sm: 'calc(var(--theme-rounded-container, 0.5rem) - 4px)',
|