React Native Android WebView's PanResponder not working
I have a webview inside one of the screens of tab navigator. There are elements inside the webview which the user could swipe horizontally to show more information. The problem I have is that whenever the user tries to swipe horizontally inside the webview, the tab navigator detects the swipe instead and this results in the tab changing. This only happens on Android devices but not iOS devices.
To solve this issue, I am trying to set PanResponder inside the webview but it's not working. The related methods are not even called because the console logs are not printed when I am dragging my finger across the webview. Below is my code for the webview:
import React, Component from 'react';
import WebView, View, PanResponder from 'react-native';
class CustomWebPage extends Component
componentWillMount()
this.gesture = PanResponder.create(
onPanResponderTerminationRequest: () => false,
onStartShouldSetPanResponder: (evt, gestureState) => true,
onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
onMoveShouldSetPanResponder: (evt, gestureState) => true,
onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
onPanResponderGrant: (evt, gestureState) =>
console.log('onPanResponderGrant');
,
onPanResponderMove: (evt, gestureState) =>
console.log('onPanResponderMove: ', evt, ', ', gestureState);
,
onPanResponderTerminate: (evt, gestureState) =>
console.log('onPanResponderTerminate: ', evt, ', ', gestureState);
,
onPanResponderRelease: (evt, gestureState) =>
console.log('onPanResponderRelease: ', evt, ', ', gestureState);
,
);
render()
return (
<WebView
source= uri: 'https://www.google.com.sg/'
style= flex: 1
...this.gesture.panHandlers
/>
);
export default CustomWebPage;
javascript react-native
add a comment |
I have a webview inside one of the screens of tab navigator. There are elements inside the webview which the user could swipe horizontally to show more information. The problem I have is that whenever the user tries to swipe horizontally inside the webview, the tab navigator detects the swipe instead and this results in the tab changing. This only happens on Android devices but not iOS devices.
To solve this issue, I am trying to set PanResponder inside the webview but it's not working. The related methods are not even called because the console logs are not printed when I am dragging my finger across the webview. Below is my code for the webview:
import React, Component from 'react';
import WebView, View, PanResponder from 'react-native';
class CustomWebPage extends Component
componentWillMount()
this.gesture = PanResponder.create(
onPanResponderTerminationRequest: () => false,
onStartShouldSetPanResponder: (evt, gestureState) => true,
onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
onMoveShouldSetPanResponder: (evt, gestureState) => true,
onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
onPanResponderGrant: (evt, gestureState) =>
console.log('onPanResponderGrant');
,
onPanResponderMove: (evt, gestureState) =>
console.log('onPanResponderMove: ', evt, ', ', gestureState);
,
onPanResponderTerminate: (evt, gestureState) =>
console.log('onPanResponderTerminate: ', evt, ', ', gestureState);
,
onPanResponderRelease: (evt, gestureState) =>
console.log('onPanResponderRelease: ', evt, ', ', gestureState);
,
);
render()
return (
<WebView
source= uri: 'https://www.google.com.sg/'
style= flex: 1
...this.gesture.panHandlers
/>
);
export default CustomWebPage;
javascript react-native
did u manage to solve this?
– WantIt
Jun 24 '18 at 0:44
No, I wasn't able to solve it. In the end, I disabled tab navigator's "swipe to change tab" function so that I can scroll horizontally inside webview
– karansky
Jun 28 '18 at 10:11
1
You can wrap yourWebView
in aView
. Attach the panHandlers to the View.<View ...this.gesture.panHandlers><WebView /></View>
– Dan
Jul 12 '18 at 16:44
add a comment |
I have a webview inside one of the screens of tab navigator. There are elements inside the webview which the user could swipe horizontally to show more information. The problem I have is that whenever the user tries to swipe horizontally inside the webview, the tab navigator detects the swipe instead and this results in the tab changing. This only happens on Android devices but not iOS devices.
To solve this issue, I am trying to set PanResponder inside the webview but it's not working. The related methods are not even called because the console logs are not printed when I am dragging my finger across the webview. Below is my code for the webview:
import React, Component from 'react';
import WebView, View, PanResponder from 'react-native';
class CustomWebPage extends Component
componentWillMount()
this.gesture = PanResponder.create(
onPanResponderTerminationRequest: () => false,
onStartShouldSetPanResponder: (evt, gestureState) => true,
onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
onMoveShouldSetPanResponder: (evt, gestureState) => true,
onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
onPanResponderGrant: (evt, gestureState) =>
console.log('onPanResponderGrant');
,
onPanResponderMove: (evt, gestureState) =>
console.log('onPanResponderMove: ', evt, ', ', gestureState);
,
onPanResponderTerminate: (evt, gestureState) =>
console.log('onPanResponderTerminate: ', evt, ', ', gestureState);
,
onPanResponderRelease: (evt, gestureState) =>
console.log('onPanResponderRelease: ', evt, ', ', gestureState);
,
);
render()
return (
<WebView
source= uri: 'https://www.google.com.sg/'
style= flex: 1
...this.gesture.panHandlers
/>
);
export default CustomWebPage;
javascript react-native
I have a webview inside one of the screens of tab navigator. There are elements inside the webview which the user could swipe horizontally to show more information. The problem I have is that whenever the user tries to swipe horizontally inside the webview, the tab navigator detects the swipe instead and this results in the tab changing. This only happens on Android devices but not iOS devices.
To solve this issue, I am trying to set PanResponder inside the webview but it's not working. The related methods are not even called because the console logs are not printed when I am dragging my finger across the webview. Below is my code for the webview:
import React, Component from 'react';
import WebView, View, PanResponder from 'react-native';
class CustomWebPage extends Component
componentWillMount()
this.gesture = PanResponder.create(
onPanResponderTerminationRequest: () => false,
onStartShouldSetPanResponder: (evt, gestureState) => true,
onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
onMoveShouldSetPanResponder: (evt, gestureState) => true,
onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
onPanResponderGrant: (evt, gestureState) =>
console.log('onPanResponderGrant');
,
onPanResponderMove: (evt, gestureState) =>
console.log('onPanResponderMove: ', evt, ', ', gestureState);
,
onPanResponderTerminate: (evt, gestureState) =>
console.log('onPanResponderTerminate: ', evt, ', ', gestureState);
,
onPanResponderRelease: (evt, gestureState) =>
console.log('onPanResponderRelease: ', evt, ', ', gestureState);
,
);
render()
return (
<WebView
source= uri: 'https://www.google.com.sg/'
style= flex: 1
...this.gesture.panHandlers
/>
);
export default CustomWebPage;
javascript react-native
javascript react-native
asked Apr 6 '18 at 9:25
karanskykaransky
358317
358317
did u manage to solve this?
– WantIt
Jun 24 '18 at 0:44
No, I wasn't able to solve it. In the end, I disabled tab navigator's "swipe to change tab" function so that I can scroll horizontally inside webview
– karansky
Jun 28 '18 at 10:11
1
You can wrap yourWebView
in aView
. Attach the panHandlers to the View.<View ...this.gesture.panHandlers><WebView /></View>
– Dan
Jul 12 '18 at 16:44
add a comment |
did u manage to solve this?
– WantIt
Jun 24 '18 at 0:44
No, I wasn't able to solve it. In the end, I disabled tab navigator's "swipe to change tab" function so that I can scroll horizontally inside webview
– karansky
Jun 28 '18 at 10:11
1
You can wrap yourWebView
in aView
. Attach the panHandlers to the View.<View ...this.gesture.panHandlers><WebView /></View>
– Dan
Jul 12 '18 at 16:44
did u manage to solve this?
– WantIt
Jun 24 '18 at 0:44
did u manage to solve this?
– WantIt
Jun 24 '18 at 0:44
No, I wasn't able to solve it. In the end, I disabled tab navigator's "swipe to change tab" function so that I can scroll horizontally inside webview
– karansky
Jun 28 '18 at 10:11
No, I wasn't able to solve it. In the end, I disabled tab navigator's "swipe to change tab" function so that I can scroll horizontally inside webview
– karansky
Jun 28 '18 at 10:11
1
1
You can wrap your
WebView
in a View
. Attach the panHandlers to the View. <View ...this.gesture.panHandlers><WebView /></View>
– Dan
Jul 12 '18 at 16:44
You can wrap your
WebView
in a View
. Attach the panHandlers to the View. <View ...this.gesture.panHandlers><WebView /></View>
– Dan
Jul 12 '18 at 16:44
add a comment |
1 Answer
1
active
oldest
votes
Replace componentWillMount() with constructor()
so here,
constructor(props) {
super(props)
// Here your PanResponder related codes
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49689548%2freact-native-android-webviews-panresponder-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Replace componentWillMount() with constructor()
so here,
constructor(props) {
super(props)
// Here your PanResponder related codes
add a comment |
Replace componentWillMount() with constructor()
so here,
constructor(props) {
super(props)
// Here your PanResponder related codes
add a comment |
Replace componentWillMount() with constructor()
so here,
constructor(props) {
super(props)
// Here your PanResponder related codes
Replace componentWillMount() with constructor()
so here,
constructor(props) {
super(props)
// Here your PanResponder related codes
answered Nov 13 '18 at 16:13
Syed Sadrul Ullah SahadSyed Sadrul Ullah Sahad
438312
438312
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49689548%2freact-native-android-webviews-panresponder-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
did u manage to solve this?
– WantIt
Jun 24 '18 at 0:44
No, I wasn't able to solve it. In the end, I disabled tab navigator's "swipe to change tab" function so that I can scroll horizontally inside webview
– karansky
Jun 28 '18 at 10:11
1
You can wrap your
WebView
in aView
. Attach the panHandlers to the View.<View ...this.gesture.panHandlers><WebView /></View>
– Dan
Jul 12 '18 at 16:44