Skip to content

Commit

Permalink
feat(WKWebview): [iOS] Add 'allowsBackForwardNavigationGestures' prop…
Browse files Browse the repository at this point in the history
…erty (#97)
  • Loading branch information
bae-unidev authored and Titozzz committed Oct 21, 2018
1 parent d55ce2b commit 7f35344
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This document lays out the current public properties and methods for the React N
- [`url`](Reference.md#url)
- [`html`](Reference.md#html)
- [`hideKeyboardAccessoryView`](Reference.md#hidekeyboardaccessoryview)
- [`allowsBackForwardNavigationGestures`](Reference.md#allowsbackforwardnavigationgestures)

## Methods Index

Expand Down Expand Up @@ -494,6 +495,17 @@ If true, this will hide the keyboard accessory view (< > and Done) when using th
| ------- | -------- | -------- |
| boolean | No | iOS |

---

### `allowsBackForwardNavigationGestures`

If true, this will be able horizontal swipe gestures when using the WKWebView. The default value is `false`.

| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | iOS |


## Methods

### `extraNativeComponentConfig()`
Expand Down
1 change: 1 addition & 0 deletions ios/RNCWKWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
@property (nonatomic, assign) UIEdgeInsets contentInset;
@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
@property (nonatomic, assign) BOOL hideKeyboardAccessoryView;
@property (nonatomic, assign) BOOL allowsBackForwardNavigationGestures;

- (void)postMessage:(NSString *)message;
- (void)injectJavaScript:(NSString *)script;
Expand Down
1 change: 1 addition & 0 deletions ios/RNCWKWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ - (void)didMoveToWindow
_webView.scrollView.scrollEnabled = _scrollEnabled;
_webView.scrollView.bounces = _bounces;
[_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
_webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures;

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
if ([_webView.scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
Expand Down
1 change: 1 addition & 0 deletions ios/RNCWKWebViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)

/**
* Expose methods to enable messaging the webview.
Expand Down
9 changes: 9 additions & 0 deletions js/WebView.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ class WebView extends React.Component<WebViewSharedProps, State> {
'The scalesPageToFit property is not supported when useWebKit = true',
);
}
if (
!this.props.useWebKit &&
this.props.allowsBackForwardNavigationGestures
) {
console.warn(
'The allowsBackForwardNavigationGestures property is not supported when useWebKit = false',
);
}
}

render() {
Expand Down Expand Up @@ -262,6 +270,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
this.props.automaticallyAdjustContentInsets
}
hideKeyboardAccessoryView={this.props.hideKeyboardAccessoryView}
allowsBackForwardNavigationGestures={this.props.allowsBackForwardNavigationGestures}
onLoadingStart={this._onLoadingStart}
onLoadingFinish={this._onLoadingFinish}
onLoadingError={this._onLoadingError}
Expand Down
5 changes: 5 additions & 0 deletions js/WebViewTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ export type IOSWebViewProps = $ReadOnly<{|
* backward compatible.
*/
hideKeyboardAccessoryView?: ?boolean,
/**
* A Boolean value indicating whether horizontal swipe gestures will trigger
* back-forward list navigations.
*/
allowsBackForwardNavigationGestures?: ?boolean,
|}>;

export type AndroidWebViewProps = $ReadOnly<{|
Expand Down

0 comments on commit 7f35344

Please sign in to comment.