You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Scroll position of ScrollView jumps to WebView when pressed #3014
It looks like the auto-scrolling is a behavior of the React Native ScrollView.
The only thing I imagine could be done from the react-native-webview side would be to set focusable to false... but I think that only makes sense if your WebView content is completely noninteractive? If that is your scenario, you could try hacking/patching in that change to see if it helps.
It looks like the auto-scrolling is a behavior of the React Native ScrollView.
The only thing I imagine could be done from the react-native-webview side would be to set focusable to false... but I think that only makes sense if your WebView content is completely noninteractive? If that is your scenario, you could try hacking/patching in that change to see if it helps.
The focusable={false} on <WebView /> doesn't seem to help with content jump. Tried on the snack I provided above.
focusable={false} on doesn't seem to help with content jump
I'm not sure the focusable property is actually hooked up (in fact I wonder if it's a mistake that WebViewSharedProps extends ViewProps...). I think this would require changing the native Android code.
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
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
This solution is for people who need 2 lines of code right now to provide a temporary but relatively stable fix for this issue without installing forks or diving in to native code.
This solution only works when there are no other focusable elements in your scrollview. This solution is particularly useful when users need to be fully able to focus and interact with various elements inside of the webview.
The solution relies on a ref to the ScrollView, a ref to the WebView and a boolean signifying whether the WebView content was loaded.
// Prevent initial touch jumping ([REDACTED]-78)//#region Here be dragons. Thou art forewarned.useEffect(()=>{webViewRef.current?.requestFocus();scrollViewRef.current?.scrollTo({x: 0,y: 0,animated: false});},[loaded]);//#endregion
Anyway, long story short; Focus the webview before the user does it, and reset the scroll position immediately after. The user shouldn't see this, but since the webview is now focused, the user can interact with it freely without messing up your scrollview. That is, until another element inside your scrollview needs to be focused, in which case this solution is not suitable.
Here are some experiences from native Android developers. Unfortunately, the ScrollView component in React Native does not expose this property, so there isn't much we can do.😥
Due to focus issues, you only need to add one property to the child controls of ScrollView: android:descendantFocusability = "blocksDescendants"
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
This issue is happening again for me on Android 15. It looks fine for older Androids but as soon as I click to web view on Android 15 it scrolls to the top of the screen -> in a same way as described in the video above.
@kubmir I've just tested it for Android 15, on Emulator, using my fork of the library and its Example app (the WEBVIEWINSIDESCROLLVIEW test inside it) — I don't see the problem re-appearing.
Activity
knakandakare commentedon Jun 20, 2023
Same issue here
sanduluca commentedon Jul 12, 2023
I have the same issue.
It was also reported here: #2360 #2057
I also reported this issue in another repo ( here: iou90/react-native-autoheight-webview#259 ) but it seems to be a problem with WebView
Bug description:
Content jumps to top on first time press/click
To Reproduce:
To test on real device
Source (static HTML or url):
https://snack.expo.dev/@sanduluca/webview-content-jump-on-press
To reproduce start from 1
Expected behavior:
No jump when press webview content
Screenshots/Videos:
2023-06-13.14.12.57.mp4
Environment:
TheAlmightyBob commentedon Jul 17, 2023
It looks like the auto-scrolling is a behavior of the React Native ScrollView.
The only thing I imagine could be done from the
react-native-webviewside would be to setfocusabletofalse... but I think that only makes sense if your WebView content is completely noninteractive? If that is your scenario, you could try hacking/patching in that change to see if it helps.sanduluca commentedon Jul 17, 2023
The
focusable={false}on<WebView />doesn't seem to help with content jump. Tried on the snack I provided above.TheAlmightyBob commentedon Jul 17, 2023
I'm not sure the
focusableproperty is actually hooked up (in fact I wonder if it's a mistake thatWebViewSharedPropsextendsViewProps...). I think this would require changing the native Android code.github-actions commentedon Sep 16, 2023
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
steffenkleinle commentedon Sep 18, 2023
Sadly we are still searching for solutions
huanguolin commentedon Sep 27, 2023
same issue here
sh-shamsan commentedon Oct 18, 2023
Same issue here in IOS in version 13.6.2
github-actions commentedon Dec 18, 2023
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
steffenkleinle commentedon Dec 22, 2023
We are still looking for solutions
8 remaining items
steffenkleinle commentedon May 1, 2024
This sadly still happens :/
lvmtam commentedon May 16, 2024
This sadly still happen with me too :/
KubilayMobile commentedon Aug 21, 2024
Still happening
samuel-apps commentedon Sep 12, 2024
This solution is for people who need 2 lines of code right now to provide a temporary but relatively stable fix for this issue without installing forks or diving in to native code.
This solution only works when there are no other focusable elements in your scrollview. This solution is particularly useful when users need to be fully able to focus and interact with various elements inside of the webview.
The solution relies on a
refto theScrollView, arefto theWebViewand abooleansignifying whether theWebViewcontent was loaded.Anyway, long story short; Focus the webview before the user does it, and reset the scroll position immediately after. The user shouldn't see this, but since the webview is now focused, the user can interact with it freely without messing up your scrollview. That is, until another element inside your scrollview needs to be focused, in which case this solution is not suitable.
ashlyWeiting commentedon Sep 13, 2024
I found a temporary, quick, and forceful way to solve the issue.
Add the following content to
node_modules/android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java:However, this will cause input or textarea elements inside the WebView to lose the ability to focus and bring up the keyboard.
So, I forked a project:
https://github.com/ashlyWeiting/react-native-webview
You need to install my forked repo to use this solution:
You can modify it based on your needs to control whether the WebView can be focused or not.
Here’s an example:
If you only need a simple solution where nothing in the WebView can be focused, you can directly set focusEnabled to false:
Although it’s not the best solution, I hope it helps those who urgently need to resolve this issue.
duck123ducker commentedon Sep 27, 2024
Here are some experiences from native Android developers. Unfortunately, the ScrollView component in React Native does not expose this property, so there isn't much we can do.😥
steffenkleinle commentedon Oct 5, 2024
#3575 fixes the issue for us. This fork already includes the fix: https://github.com/birdofpreyru/react-native-webview
github-actions commentedon Dec 5, 2024
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
cguino commentedon Dec 16, 2024
I made a patch based on https://github.com/birdofpreyru/react-native-webview
I did some fixes as the code android did not compile
Also I'm not sure everything is needed ...
react-native-webview+13.12.5.patch
kubmir commentedon Jan 16, 2025
This issue is happening again for me on Android 15. It looks fine for older Androids but as soon as I click to web view on Android 15 it scrolls to the top of the screen -> in a same way as described in the video above.
birdofpreyru commentedon Jan 21, 2025
@kubmir I've just tested it for Android 15, on Emulator, using my fork of the library and its Example app (the
WEBVIEWINSIDESCROLLVIEWtest inside it) — I don't see the problem re-appearing.