2

I need to render some HTML code in my React Native app. But it seems like the WebView can't be set to auto height. Please help me with this problem. This is my code.

<View style={{
                    paddingLeft: 18,
                    paddingRight: 18,
                    paddingTop: 10,
                    paddingBottom: 10,
                }}>
                    <WebView source={{
                        html: HTML
                    }}
                        javaScriptEnabled={true}
                        style={{
                            height: 200,
                            backgroundColor: colors.white,
                            marginTop: 20
                        }} />
                </View>

As you can see here, I need to define a specific value to the height prop. How can I make its height dynamic, based on the inner HTML content height?

Manas Sanas
  • 182
  • 5
  • 17

2 Answers2

3

I will suggest you use the react-native-autoheight-webview which gives you the auto height webview for React Native.

You can check it here - https://www.npmjs.com/package/react-native-autoheight-webview

Dharman
  • 26,923
  • 21
  • 73
  • 125
thelovekesh
  • 1,162
  • 1
  • 7
  • 20
  • 2
    Note: if there is any height problem , change scalesPageToFit={true} to scalesPageToFit={false} – Ken Lee Jun 19 '21 at 08:49
1

I wrap WebView inside a View, and set the height from the View.

<View style={{ height: 200 }}>
  <WebView
    automaticallyAdjustContentInsets={false}
    source={{uri: 'https://player.vimeo.com/video/24156534?title=0&byline=0&portrait=0'}}
  />
</View>

heres where i get the answer pls give him credit... React native: webview height