I have html file with scripts, I need to display it in React native screen so I used react-native-webview, it is working fine in ios debug build but not working in ios production build getting blank screen
This is my html page
<html >
<meta name="viewport" content="width=device-width, initial-scale=1" />
<body onload="loader();">
<script>
window.fwSettings = {
'widget_id': 7300********
};
!function () {
if ("function" != typeof window.FreshworksWidget)
{
var n = function () {
n.q.push(arguments)
};
n.q = [],
window.FreshworksWidget = n } }()
</script>
<script type='text/javascript'
src='https://widget.freshworks.com/widgets/7*********.js' async defer></script>
<script>
function loader() {
FreshworksWidget('hide', 'launcher');
FreshworksWidget('open');
};
</script>
</body>
</html>
I placed this html page in Webview like this
<WebView
source={kbHTML}
javaScriptEnabled={true}
domStorageEnabled={true}
originWhitelist={['*']}
scalesPageToFit={false}
startInLoadingState={true}
automaticallyAdjustContentInsets={false}
containerStyle={{
flex: 1,
width: '100%',
height: '100%'
}}
style={{
flex: 1,
height: height,
width: width,
resizeMode: 'cover',
}}
/>
its working fine in ios debug mode but not working in ios production build.getting blank screen.
react-native-webview: "^11.18.1",
react-native: "0.64.2"
Related
I am implementing the exact same code shown in the material-ui library documentation here
https://mui.com/x/react-data-grid/layout/#flex-layout
I am trying to implement the flex layout,
I just did the exact same steps and the console shows the error all the time:
Sandbox:
https://stackblitz.com/edit/react-8ahs3n?file=src/App.js
Please help, appreciated.
In the documentation example you linked to there is one additional div wrapping what you have in your code: <div style={{ height: 400, width: '100%' }}>. Including that wrapper element (which gives the element an intrinsic height as mentioned in the console warning) gets rid of the console error. Here's a modified version of your stackblitz that does not have the error: https://stackblitz.com/edit/react-m2uoq1?file=src%2FApp.js.
The 400px height in the documentation example can be replaced by whatever height you want -- it just can't be percent-based. If you want the DataGrid to be the full height of the browser, you can use 100vh instead of 100%.
Here's an example:
import * as React from "react";
import { DataGrid } from "#mui/x-data-grid";
import { useDemoData } from "#mui/x-data-grid-generator";
import CssBaseline from "#mui/material/CssBaseline";
export default function FlexLayoutGrid() {
const { data } = useDemoData({
dataSet: "Commodity",
rowLength: 50,
maxColumns: 6
});
return (
<>
<CssBaseline />
<div style={{ height: "100vh", width: "100%" }}>
<div style={{ display: "flex", height: "100%" }}>
<div style={{ flexGrow: 1 }}>
<DataGrid {...data} />
</div>
</div>
</div>
</>
);
}
In my example I included the CssBaseline component in order to get rid of the default 8px margin on the <body> element -- otherwise using 100vh will cause a scroll bar to appear; however the default margin (or a custom margin in your app) can be accounted for in other ways by using calc (e.g. height: "calc(100vh - 16px)").
Use a wrapper component such as Box from Material UI with flex display and height:
<div style={{ height: 400, width: '100%' }}>
<Box style={{
display: "flex",
height:400,
justifyContent: "center",
alignItems: "center"
}}
>
<Datagrid/>
</Box>
</div>
I want to load script tag in my webview react native so below is my script i am receiving form API
const html3 = `<script type="text/javascript" src="https://g.adspeed.net/ad.php?do=js&zid=91679&oid=14755&wd=-1&ht=-1&target=_blank"></script>`
Below is my React native code for webview
return (
<>
<WebView
source={{html3}}
originWhitelist={['*']}
style={{marginTop: 220, height: 150}}
/>
</>
);
but i run above code i am getting blank view any idea how i can solve this ?
You can use iframe and script like below:
const scriptHTML = `<iframe width="100%" height="50%" src="https://www.youtube.com/embed/cqyziA30whE" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
<script>
//your code
</script>`
<WebView
source={{ html: scriptHTML }}
style={{ marginTop: 20 }} />
I have used a contentEditable div inside a webview for some editor functionality in one of my app. The html code seams to work fine and responding to keyboard show and hide action in my android chrome browser but when i tried the same html code with the webview in react-native it won't responds to the keyboard and content hide behind the keyboard.
I have tried scrolling it to the end of the div and auto increase it's height according to content but nothing works.
import React, { Component } from 'react';
import { View, WebView } from 'react-native';
class webviewEditor extends Component{
render() {
return (
<View style={{flex:1}}>
<WebView
source={{
html: `
< head >
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no;" />
<style type="text/css">
html, body {height: 100%;}
body {
margin: 0;
}
#wrap {
height: 100%;
width: 100%;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
}
#editor {
padding: 10px;
}
</style>
</head>
<body>
<div id="wrap">
<div id="editor" contenteditable="true">
</div>
</div></body>
`}}
ref={web => { this.webview = web }}
style={{ flex: 1 }}
scalesPageToFit={false}
scrollEnabled={false}
javaScriptEnabled={true}
automaticallyAdjustContentInsets={false}
/>
</View>
);
}
}
I expect the result to be the webview will scroll to the above of the keyboard just like in the browser but it won't in the app inside webview.
I m using a Webview for rendering some content to a view, to calculate the height of the content I m using a script to get the height of the content, the span tag contains the content.
<html id="htmlContent">
<body>
<span>
...
//content
...
</span>
<script>
document.addEventListener('DOMContentLoaded', function () {
document.title = document.getElementById('htmlContent').offsetHeight;
window.location.hash = 1;
});
</script>
</body>
</html>
And here is the webview component :
const commonHtmlStyle= `font-weight:300; font-family:sans-serif; font-size: 18px; color:rgb(136,136,136); backgroundColor:rgba(0,0,0,0);`;
<WebView style={{ height: this.state.height }}
ref={(ref) => { this.webview = ref; }}
automaticallyAdjustContentInsets={true}
scrollEnabled={false}
javaScriptEnabled={true}
source={{ html: voca.sprintf(commonHtml, commonHtmlStyle, this.state.content) }}
onNavigationStateChange={this.setState({
height: parseInt(navState.title)
})}
/>
So results,
i m seeing blank spaces while running in Android (script returns appox double the height)
and clipped content on iOS (returns height less than the content height).
I tried using other autoHeight webview components like (react-native-webview-autoheight) but still shows nearly same results for both iOS and Android.
I m trying wrap my head around this issue but but not able to solve this any how. Any help would be appreciated.
I can't seem to get my title text to wrap:
I'm using native-base
let SearchPage = (props) => {
const menu = (
<Container>
<Header style={styles.header}>
<Left>
<Button transparent onPress={props.togglePageMenu}>
<Icon name='menu' />
</Button>
</Left>
<Body>
<Title style={styles.title} numberOfLines={2}>Search Products</Title>
</Body>
<Right>
</Right>
</Header>...
styles...:
title: {
flexWrap:'wrap',
flex: 1,
color: '#9E9E9E',
fontWeight: '200',
fontSize: 19
},
header: {
backgroundColor: '#F7F7F7'
},
What am I doing wrong?
I had to stop using <Title> from Native Base and instead use <Text> from Native Base. I guess Title has some behind the scenes styles that prevent it from wrapping.