react-native-webview/react-native-webview

MIGRATED: WebView not scrollable when under ScrollView

Closed this issue ยท 36 comments

Migrated from facebook/react-native#20347.

@mehulmpt says:


Environment
React Native Environment Info:
System:
OS: macOS High Sierra 10.13.3
CPU: x64 Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
Memory: 29.76 MB / 8.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 8.1.4 - /usr/local/bin/node
npm: 4.6.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
IDEs:
Android Studio: 3.1 AI-173.4720617
Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
npmPackages:
react: ^16.4.1 => 16.4.1
react-native: ^0.56.0 => 0.56.0
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7
react-native-rename: 2.2.2
Description
WebView component when placed under ScrollView loses its ability to scroll content. However, if scrollEnabled={false} is passed to ScrollView, WebView is scrollable again.

Reproducible Demo
This render function would suffice:

export default class App extends Component {
  render() {
    return (
      <ScrollView contentContainerStyle={{ flexGrow: 1 }}>
        <WebView source={{ uri: 'http://localhost/somepage-with-scrollable-content' }}
                 style={{ height: 300 }}/> {/* this webview is not scrollable now */}
      </ScrollView>)
  }
}

This has also been mentioned in issue #10723 but it was closed without any solution


Is there a chance for this fix any soon?

@vvusts The way the core team handles issues in this repo is we will review them, tag them, get more info, and then ask the community for help fixing them. Then we will review, test, suggest changes, and eventually merge and deploy PRs that fix issues. So it's possible someone else might fix it, but if you want to try, it's much appreciated.

Hey @jamonholmgren @vvusts @mehulmpt @masako-yamada ๐Ÿ‘‹,

I've just tried to reproduce with the provided example and also slightly tweaked it but cannot reproduce on the latest webview:

Here's the code I tried:

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>)
  }
}

Here's a Video of Android & iOS scrolling:

https://imgur.com/a/HGZ1Kye


I'll go ahead and close this issue for now; but if you can provide a repro I'll be happy to open it again.

Thank you

@Salakar I think the provided example is incomplete. The webviews are only not scrollable when the ScrollView itself has a scrollbar.

This only happens on Android. On iOS the webviews are still scrollable.

See this example:

<ScrollView>
    <WebView
        source={{ uri: 'https://github.com/react-native-community/react-native-webview/issues/22' }}
        style={{ height: 200 }}
    />
    <WebView source={{ uri: 'https://bbc.co.uk/news' }} style={{ height: 200 }} />
    <View style={{ height: 200, backgroundColor: 'red' }} />
    <View style={{ height: 200, backgroundColor: 'blue' }} />
    <View style={{ height: 200, backgroundColor: 'green' }} />
</ScrollView>

I can attest to this issue. I have a React Native App which I test with an iPhone XS and a Samsung Galaxy S5 (on Android 6.0 Marshmellow) running Expo. WebViews inside ScrollViews are not scrollable on Android if the scrollEnabled property is set to {true} on the WebView. This not an issue on iOS, only on Android.

I'm also experiencing the same issue, only on Android devices. All good on iOS as @JuanDavidLopez95 mentioned.

reproducible with this example https://snack.expo.io/r1E6viX0N

Note when the height is large enough to exceed the current screen size, the webpage is not scrollable, when the height is small and within the current screen size, the webpage is scrollable.
And it only happens in Android devices

@Salakar There's allso a related stackoverflow discussion and proposed fix
https://stackoverflow.com/questions/13257990/android-webview-inside-scrollview-scrolls-only-scrollview

@masako-yamada already provided the pending PR... #281

@jamonholmgren as above comment, the issue is only happening in Android, I believe this is a bug

ppv94 commented

I am using react-native version 0.56
I am also facing the same issue not able to scroll the webpage in webview (android). it works fine in IOS
how to solve this issue?

This is not related to RN as I am getting the same on 59.10.
I saw this PR: #281
Is there any chance for this to be merged any time soon?

reproducible with this example https://snack.expo.io/r1E6viX0N

Note when the height is large enough to exceed the current screen size, the webpage is not scrollable, when the height is small and within the current screen size, the webpage is scrollable.
And it only happens in Android devices

@Salakar There's allso a related stackoverflow discussion and proposed fix
https://stackoverflow.com/questions/13257990/android-webview-inside-scrollview-scrolls-only-scrollview

@masako-yamada already provided the pending PR... #281

reproducible with this example https://snack.expo.io/r1E6viX0N

Note when the height is large enough to exceed the current screen size, the webpage is not scrollable, when the height is small and within the current screen size, the webpage is scrollable.
And it only happens in Android devices

@Salakar There's allso a related stackoverflow discussion and proposed fix
https://stackoverflow.com/questions/13257990/android-webview-inside-scrollview-scrolls-only-scrollview

@masako-yamada already provided the pending PR... #281

we don't want to edit something about the native, so can ur team test and merge the fix into master.

I have tested this PR #281 and it solves the issue of nesting the webview inside a scrollview, but there is no traction on this ticket? It would be great if some attention could be made to this.

@Titozzz (I saw you as the top contributor) as the comment above, do you mind to take a look on PR #281 ?

Hello ๐Ÿ‘‹, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

i still experience this issue..

same here, the PR is reverted, so this issue is not resolved yet

I applied change from this PR and it work fine. But this PR is not part of npm package.

Any workaround except for manually merging the PR changes?

Hi, I am similarly facing this issue, kindly let me know if and how you all managed to make it work finally? thanks

jkga commented

I faced a similar issue when trying to put an overflowing WebView inside ScrollView. If I just put a normal WebView, ScrollView will work as intended but the height of WebView will become fixed and some of the contents are hidden. So what I did is I created a custom component autoheight WebView to make everything visible.

https://gist.github.com/jkga/4ee1c366d46a3eba9045f88c58d3bc37

@jkga That's clever, I like it.

This should be re-opened, I'm still having this issue on the latest versions.

jsamr commented

@jkga and @jamonholmgren, it's (almost) a feature of @formidable-webview/webshell. The addition to your gist is that the height will update each time the content layout change, such as with screen orientation changes, or if the layout is affected by asynchronous script after DOM is mounted. To that regard, it's a little more accurate!

For a complete guide, see: https://formidable-webview.github.io/webshell/docs/autoheight

I see similar issue. This issue should be reopened. @jamonholmgren

When the page is not long enough to be scrolled, the webview is scrollable. However once the page becomes longer and it needs to be scrolled, the webview scroll is difficutl. Seems it is the scroll/swipe/drag gesture is capatured by scrollview but not the webview.

I managed to get it working in a non-ideal manner in my project, as I was using a webview inside https://github.com/jeremybarbet/react-native-modalize. Disabling pan gestures with panGestureEnabled={false} fixed the WebView scrolling. Hopefully this helps somebody.

          <WebView
            scrollEnabled={true}
            style={{height: Dimensions.get('window').height-70, width: Dimensions.get('window').width, flex: 1}}
            automaticallyAdjustContentInsets={false}
           />

This code has solved my issues. The screen height of your phone must be smaller than the webview so it can scroll. Thank you :)

https://stackoverflow.com/a/51513193

this is a solution for me

workaround would be to set scrollEnabled to false (somehow conditionally) on ScrollView during usage of WebView, then it works fine

I fixed this issue

<ScrollView contentContainerStyle={{ flexGrow: 1 }} >
<WebView
style ={{flex:1,height:Dimensions.get('screen').height}}
/>

Solved it by following one of the the answers in this SO - link

I just added nestedScrollEnabled=true just like from a normal nested ScrollView
<ScrollView> <WebView nestedScrollEnabled source={{uri:'https://www.website.com' }} /> </ScrollView>

Hello, this link has expired

@haohongyang1 Were you referring to my link? Link is still working but here it is again. https://stackoverflow.com/questions/63568982/how-to-make-webview-scrollable-in-react-native-webview

The solution is basically the same as the one I mentioned on my previous comment which is by adding the nestedScrollEnabled in the nested WebView.

Anyone still looking for, @Leorenzo 's way is helped me:

     <WebView
        source={{ uri: uriWithQueryParams }}
        allowFileAccessFromFileURLs={true}
        domStorageEnabled={true}
        allowFileAccess={true}
        allowUniversalAccessFromFileURLs={true}
        originWhitelist={['*']}
        onShouldStartLoadWithRequest={() => true}
        scrollEnabled={true}
        nestedScrollEnabled
        style={{
          backgroundColor: COLORS.grey900,
        }}
      />