Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native - How do I scroll a Webview inside scrollview for android?

Tags:

I want to use WebView inside ScrollView for my react native app. But if I do so, I am not able to scroll my webview, unless I disable the scroll on scrollview. However, I need the scroll in both scrollview as well as webview. Any suggestions or solutions on how to accomplish this?

like image 935
Garvita C Avatar asked May 04 '17 11:05

Garvita C


People also ask

Can scroll in ScrollView React Native?

ScrollViews can be configured to allow paging through views using swiping gestures by using the pagingEnabled props. Swiping horizontally between views can also be implemented on Android using the ViewPager component. On iOS a ScrollView with a single item can be used to allow the user to zoom content.

Why ScrollView is not scrolling in React Native?

To fix ScrollView Not scrolling with React Native, we wrap the content of the ScrollView with the ScrollView. to wrap ScrollView around the Text components that we render inside. Anything inside the ScrollView will scroll. As a result, we should see text inside and we can scroll up and down.

How do I scroll to a specific element in React Native?

To scroll to the specific item first we will make a blank array to store the X and Y coordinates of the item. const [dataSourceCords, setDataSourceCords] = useState([]); 2. While rendering the item we will store the X and Y location of the item in the array.

How do I scroll horizontal ScrollView in React Native?

In the ScrollView, we can scroll the components in both direction vertically and horizontally. By default, the ScrollView container scrolls its components and views in vertical. To scroll its components in horizontal, it uses the props horizontal: true (default, horizontal: false).


2 Answers

I am also searching for this issue on the internet for the last 2-3 days and I have got an awesome solution for this ...

npm install --save react-native-webview-autoheight

After installing this with no issues

import MyWebView from "react-native-webview-autoheight";

<ScrollView style={{ flex: 1, backgroundColor: "white" }}>
  <View
    style={{ flex: 1, flexDirection: "column", backgroundColor: "white" }}
    pointerEvents={"none"}
  >
    <Text>Hi I am at top</Text>
    <MyWebView
      //sets the activity indicator before loading content
      startInLoadingState={true}
      source={{
        uri:
          "https://stackoverflow.com/questions/43781301/react-native-how-do-i-scroll-a-webview-inside-scrollview-for-android"
      }}
    />
    <Text>Hi I am at bottom</Text>
  </View>
</ScrollView>

it works perfectly for me..

like image 151
Tijo Thomas Avatar answered Sep 21 '22 06:09

Tijo Thomas


I fix bug scroll Webview inside ScrollView. I override func onTouchEvent if not only Webview catch event onTouch call requestDisallowInterceptTouchEvent(true);.

You can try my repo https://github.com/thepday12/react-native-webview

  • package.json

    "react-native-webview": "https://github.com/thepday12/react-native-webview",

  • Using

    import WebView from 'react-native-webview';

  • Source from https://github.com/react-native-community/react-native-webview/?

like image 40
Thép Tô Kim Avatar answered Sep 20 '22 06:09

Thép Tô Kim