5

I have <WebView> that is embedded in a <Card.Content> as I am using react-native-paper. I am trying to have WebView scrollable. The webview shows but not scrollable.

Code I am using:

  <Card theme={{ roundness: 20 }} style={{ margin: 10, height: height*0.8 }} elevation={14}>
     <Card.Content style={{ flex: 1 }}>
        <View style={{ justifyContent: "center", alignItems: "center" }}>
              <WebView
              style={{ width: width * 0.8, height: height * 0.9 }}
              allowsBackForwardNavigationGestures={false}
              source={{ uri: "https://paypal.com"}}
              pullToRefreshEnabled={false}
              javaScriptEnabled
              startInLoadingState
              decelerationRate="normal"
              scalesPageToFit={Platform.OS == "android"?  false : true}
              originWhitelist={['*']}
              domStorageEnabled={true}
              scrollEnabled
              renderError={e => { console.log(e); }}
              />
        </View>
     </Card.Content>
  </Card>

How can I make WebView scrollable?

0x01Brain
  • 798
  • 2
  • 12
  • 28

3 Answers3

8

Just add nestedScrollEnabled=true props i webview component

<ScrollView
    <WebView nestedScrollEnabled source={{uri:'https://www.website.com' }} />
 </ScrollView>
Mustafa Uysal
  • 173
  • 2
  • 5
2

I guess you can try to wrap your WebView inside a ScrollView like this:

export default class App extends Component {
  render() {
    return (
      <ScrollView contentContainerStyle={{ flexGrow: 1 }}>
        <WebView
          source={{
            uri:
              'https://github.com/react-native-community/react-native-webview/issues/22'
          }}
          style={{ height: 100 }}
        />

        <WebView
          source={{ uri: 'https://bbc.co.uk/news' }}
          style={{ height: 100 }}
        />
      </ScrollView>
    );
  }
}

Also, you can use react-native-autoheight-webview

MohamadKh75
  • 2,582
  • 5
  • 28
  • 54
1

I was stuck with this issue.

Problem definition

Webview was inside ScrollView and Webview was taking height greater than ScrollView thats why the ScrollView was stealing the scroll event and I was not able to scroll through the webpage.

Solution

Make Webview fit the Scrollview height. For this we need to use flexGrow in contentContainerStyle

Simple Example
   return (
    <SafeAreaView style={{flex: 1}}>
      <ScrollView
        style={{ width: '100%' }}
        contentContainerStyle={{ flexGrow: 1 }}
      >
        <WebView source={{ uri: contentUrl }} originWhitelist={['*']} />
      </ScrollView>
    </SafeAreaView>
  );

{flex: 1} and { width: '100%' } are important otherwise content will not be visible.

Shiva
  • 11,485
  • 2
  • 67
  • 84