Skip to content

Commit

Permalink
[RNMobile] Add viewport optional props (#49699)
Browse files Browse the repository at this point in the history
* Add viewport optional props

* Handle unwanted commas

* Clean up regex

* Update packages/components/src/sandbox/index.native.js

Co-authored-by: Carlos Garcia <fluiddot@gmail.com>

---------

Co-authored-by: jhnstn <jhnstn@pm.me>
Co-authored-by: Carlos Garcia <fluiddot@gmail.com>
  • Loading branch information
3 people authored Apr 12, 2023
1 parent b511087 commit 9e00e15
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/components/src/sandbox/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ const Sandbox = forwardRef( function Sandbox(
type,
url,
onWindowEvents = {},
viewportProps = '',
},
ref
) {
Expand Down Expand Up @@ -213,13 +214,19 @@ const Sandbox = forwardRef( function Sandbox(
// we can use this in the future to inject custom styles or scripts.
// Scripts go into the body rather than the head, to support embedded content such as Instagram
// that expect the scripts to be part of the body.

// Avoid comma issues with props.viewportProps.
const addViewportProps = viewportProps
.trim()
.replace( /(^[^,])/, ', $1' );

const htmlDoc = (
<html lang={ lang }>
<head>
<title>{ title }</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1"
content={ `width=device-width, initial-scale=1${ addViewportProps }` }
></meta>
<style dangerouslySetInnerHTML={ { __html: style } } />
{ styles.map( ( rules, i ) => (
Expand Down

0 comments on commit 9e00e15

Please sign in to comment.