Skip to content

Commit a7ef8c3

Browse files
authored
Pressable Table + Html Webview (47) (#692)
* Added ability to press Table Rows and Cells * SImplified passing of html to webview to ease integration into draftbit
1 parent 561a806 commit a7ef8c3

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

example/src/WebViewExample.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ const WebViewExample = () => (
1414
/>
1515
</Section>
1616
<Section title="With custom HTML">
17-
<WebView
18-
style={style.webView}
19-
source={{
20-
html: "<div> Hello! </div>",
21-
}}
22-
/>
17+
<WebView style={style.webView} html="<div> Hello! </div>" />
2318
</Section>
2419
</Container>
2520
);

packages/core/src/components/Table/TableCell.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
TableProps,
66
TableStyleContext,
77
} from "./TableCommon";
8+
import Pressable from "../Pressable";
89

910
export interface Props extends TableProps {
11+
onPress?: () => void;
1012
style?: StyleProp<ViewStyle>;
1113
}
1214

@@ -21,6 +23,7 @@ const TableCell: React.FC<React.PropsWithChildren<Props>> = ({
2123
cellVerticalPadding,
2224
cellHorizontalPadding,
2325
children,
26+
onPress,
2427
style,
2528
}) => {
2629
const parentContextValue = React.useContext(TableStyleContext);
@@ -34,8 +37,11 @@ const TableCell: React.FC<React.PropsWithChildren<Props>> = ({
3437
drawStartBorder,
3538
drawEndBorder,
3639
});
40+
41+
const ContainerComponent = onPress ? Pressable : View;
3742
return (
38-
<View
43+
<ContainerComponent
44+
onPress={onPress}
3945
style={[
4046
styles.cellContainer,
4147
borderViewStyle,
@@ -49,7 +55,7 @@ const TableCell: React.FC<React.PropsWithChildren<Props>> = ({
4955
]}
5056
>
5157
{children}
52-
</View>
58+
</ContainerComponent>
5359
);
5460
};
5561

packages/core/src/components/Table/TableRow.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import {
88
} from "./TableCommon";
99
import { Theme } from "../../styles/DefaultTheme";
1010
import { withTheme } from "../../theming";
11+
import Pressable from "../Pressable";
1112

1213
export interface Props extends TableProps {
14+
onPress?: () => void;
1315
isTableHeader?: boolean;
1416
style?: StyleProp<ViewStyle>;
1517
theme: Theme;
@@ -27,6 +29,7 @@ const TableRow: React.FC<React.PropsWithChildren<Props>> = ({
2729
cellHorizontalPadding,
2830
isTableHeader = false,
2931
children,
32+
onPress,
3033
style,
3134
theme,
3235
}) => {
@@ -52,9 +55,12 @@ const TableRow: React.FC<React.PropsWithChildren<Props>> = ({
5255
drawStartBorder,
5356
drawEndBorder,
5457
});
58+
59+
const ContainerComponent = onPress ? Pressable : View;
5560
return (
5661
<TableStyleContext.Provider value={contextValue}>
57-
<View
62+
<ContainerComponent
63+
onPress={onPress}
5864
style={[
5965
borderViewStyle,
6066
isTableHeader ? { backgroundColor: theme.colors.primary } : {},
@@ -63,7 +69,7 @@ const TableRow: React.FC<React.PropsWithChildren<Props>> = ({
6369
]}
6470
>
6571
{children}
66-
</View>
72+
</ContainerComponent>
6773
</TableStyleContext.Provider>
6874
);
6975
};

packages/native/src/components/WebView.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const injectFirst = `
3939
`;
4040

4141
interface WebViewProps {
42-
source: WebViewSourceUri | WebViewSourceHtml;
42+
source?: WebViewSourceUri | WebViewSourceHtml;
43+
html?: string;
4344
style?: ViewStyle;
4445
optimizeVideoChat?: boolean;
4546
// Advancted Builder Config Props
@@ -80,7 +81,7 @@ interface WebViewProps {
8081
}
8182

8283
const NativeWebView = React.forwardRef<any, WebViewProps>(
83-
({ source, style, optimizeVideoChat, ...otherWebViewProps }, ref) => {
84+
({ source, html, style, optimizeVideoChat, ...otherWebViewProps }, ref) => {
8485
const [height, setHeight] = useState(0);
8586

8687
const [cameraPermissions, setCameraPermissions] =
@@ -149,6 +150,12 @@ const NativeWebView = React.forwardRef<any, WebViewProps>(
149150
}
150151
};
151152

153+
if (!source && !html) {
154+
throw new Error(
155+
"'source' or 'html' props need to be provided to render WebView"
156+
);
157+
}
158+
152159
const selectComponent = () => {
153160
if (
154161
!optimizeVideoChat ||
@@ -157,7 +164,7 @@ const NativeWebView = React.forwardRef<any, WebViewProps>(
157164
return (
158165
<WebView
159166
ref={ref}
160-
source={source}
167+
source={source || { html: html!! }}
161168
style={{ ...style, width: getFinalWidth() }}
162169
injectedJavaScript={injectFirst}
163170
onMessage={onMessage}

0 commit comments

Comments
 (0)