Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how could I swipe the page from left to right in order to go back in a webview?

Tags:

react-native

In a web view,I want to swipe the page from left to right in order to go back,just like what safari did. what should I do?

like image 406
tangjingxin Avatar asked Feb 25 '16 11:02

tangjingxin


1 Answers

TL/DR: Currently, you'll need a third party package for that. Use the react-native-wkwebview-reborn package and set the allowsBackForwardNavigationGestures prop to true. Example:

WebView.ios.js:

import React from 'react';
import WKWebView from 'react-native-wkwebview-reborn';

export default (props) => <WKWebView allowsBackForwardNavigationGestures {...props} />

WebView.js

import { WebView } from 'react-native';

export default WebView;

It's a drop-in replacement, so you won't need to change much code.


Why:

The WebView component from React Native uses UIWebView under the hood, which is not recommended by Apple anymore:

wkwebview

It has worse performance and does not support a lot of features, like 3D Touch and swipe back gesture.

Join this discussion so react native updates their core component.

like image 134
Bruno Lemos Avatar answered Oct 30 '22 07:10

Bruno Lemos