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?
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.
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.
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.
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).
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..
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/?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With