Skip to content

Commit b7d16f8

Browse files
committed
feat(iframe-config): new config option webViewProps
1 parent ee25f4b commit b7d16f8

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

packages/iframe-plugin/src/HTMLIframe.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@ export interface HTMLIframeConfig {
2323
* When the iframe attribute width is wider than the contentWidth, scales
2424
* down the viewport so that it doesn't overflows horizontally.
2525
*
26+
* @remarks Although it looks like the eponymous `WebView` prop, it works
27+
* both on iOS and Android.
28+
*
2629
* @defaultvalue false
2730
*/
28-
scalesPageToFit: boolean;
31+
scalesPageToFit?: boolean;
32+
/**
33+
* Any props you'd like to pass to the `WebView` component.
34+
*
35+
* @remarks
36+
* `source` and `javascriptEnabled` will be ignored and overriden.
37+
*/
38+
webViewProps?: any;
2939
}
3040

3141
/**
@@ -90,8 +100,7 @@ export default function HTMLIframe({
90100
onDOMLinkPress,
91101
style,
92102
source,
93-
testID: 'iframe',
94-
allowsFullscreenVideo: true
103+
testID: 'iframe'
95104
}
96105
});
97106
return React.createElement(WebView, webViewProps);

packages/iframe-plugin/src/extractHtmlIframeProps.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ function normalizeUri(uri: string): string {
1111
return uri.startsWith('//') ? `https:${uri}` : uri;
1212
}
1313

14+
const defaultIframeConfig: HTMLIframeConfig = {
15+
webViewProps: {
16+
allowsFullscreenVideo: true
17+
}
18+
};
19+
1420
/**
1521
* Extract props for the HTMLIframe component from renderer function arguments.
1622
* This function is especially usefull for custom iframe renderers.
@@ -38,8 +44,15 @@ export default function extractHtmlIframeProps(
3844
renderersProps: { iframe: globalIframeConfig }
3945
} = passProps;
4046
const resolvedConfig = {
47+
...defaultIframeConfig,
4148
...globalIframeConfig,
42-
...iframeConfig
49+
...iframeConfig,
50+
webViewProps: {
51+
...defaultWebViewProps,
52+
...defaultIframeConfig.webViewProps,
53+
...globalIframeConfig?.webViewProps,
54+
...iframeConfig?.webViewProps
55+
}
4356
};
4457
const resolvedContentWidth =
4558
typeof contentWidth === 'number'
@@ -92,10 +105,6 @@ export default function extractHtmlIframeProps(
92105
htmlAttribs,
93106
scaleFactor,
94107
style: [restStyle, { width: printWidth, height: printHeight }],
95-
webViewProps: {
96-
...defaultWebViewProps,
97-
...resolvedConfig.webViewProps
98-
},
99108
WebView
100109
};
101110
}

0 commit comments

Comments
 (0)