feat(WKWebview): [ios] Add 'pagingEnabled' property to the iOS WKWebview (#165)

This commit is contained in:
wiscat 2018-11-22 15:58:07 +03:00 committed by Thibault Malbranche
parent f79b7133c1
commit 4870e1f06a
7 changed files with 34 additions and 3 deletions

View File

@ -46,6 +46,7 @@ This document lays out the current public properties and methods for the React N
- [`allowsBackForwardNavigationGestures`](Reference.md#allowsbackforwardnavigationgestures) - [`allowsBackForwardNavigationGestures`](Reference.md#allowsbackforwardnavigationgestures)
- [`allowFileAccess`](Reference.md#allowFileAccess) - [`allowFileAccess`](Reference.md#allowFileAccess)
- [`saveFormDataDisabled`](Reference.md#saveFormDataDisabled) - [`saveFormDataDisabled`](Reference.md#saveFormDataDisabled)
- [`pagingEnabled`](Reference.md#pagingEnabled)
## Methods Index ## Methods Index
@ -517,6 +518,16 @@ Sets whether the WebView should disable saving form data. The default value is `
| ------- | -------- | -------- | | ------- | -------- | -------- |
| boolean | No | Android | | boolean | No | Android |
---
### `pagingEnabled`
If the value of this property is true, the scroll view stops on multiples of the scroll views bounds when the user scrolls. The default value is false.
| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | iOS |
## Methods ## Methods
### `extraNativeComponentConfig()` ### `extraNativeComponentConfig()`

View File

@ -26,6 +26,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
@property (nonatomic, assign) BOOL messagingEnabled; @property (nonatomic, assign) BOOL messagingEnabled;
@property (nonatomic, copy) NSString *injectedJavaScript; @property (nonatomic, copy) NSString *injectedJavaScript;
@property (nonatomic, assign) BOOL scrollEnabled; @property (nonatomic, assign) BOOL scrollEnabled;
@property (nonatomic, assign) BOOL pagingEnabled;
@property (nonatomic, assign) CGFloat decelerationRate; @property (nonatomic, assign) CGFloat decelerationRate;
@property (nonatomic, assign) BOOL allowsInlineMediaPlayback; @property (nonatomic, assign) BOOL allowsInlineMediaPlayback;
@property (nonatomic, assign) BOOL bounces; @property (nonatomic, assign) BOOL bounces;

View File

@ -70,7 +70,7 @@ static NSString *const MessageHanderName = @"ReactNative";
_automaticallyAdjustContentInsets = YES; _automaticallyAdjustContentInsets = YES;
_contentInset = UIEdgeInsetsZero; _contentInset = UIEdgeInsetsZero;
} }
// Workaround for a keyboard dismissal bug present in iOS 12 // Workaround for a keyboard dismissal bug present in iOS 12
// https://openradar.appspot.com/radar?id=5018321736957952 // https://openradar.appspot.com/radar?id=5018321736957952
if (@available(iOS 12.0, *)) { if (@available(iOS 12.0, *)) {
@ -111,6 +111,7 @@ static NSString *const MessageHanderName = @"ReactNative";
_webView.UIDelegate = self; _webView.UIDelegate = self;
_webView.navigationDelegate = self; _webView.navigationDelegate = self;
_webView.scrollView.scrollEnabled = _scrollEnabled; _webView.scrollView.scrollEnabled = _scrollEnabled;
_webView.scrollView.pagingEnabled = _pagingEnabled;
_webView.scrollView.bounces = _bounces; _webView.scrollView.bounces = _bounces;
[_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil]; [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
_webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures; _webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures;
@ -137,7 +138,7 @@ static NSString *const MessageHanderName = @"ReactNative";
[_webView removeFromSuperview]; [_webView removeFromSuperview];
_webView = nil; _webView = nil;
} }
[super removeFromSuperview]; [super removeFromSuperview];
} }
@ -146,7 +147,7 @@ static NSString *const MessageHanderName = @"ReactNative";
keyboardTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(keyboardDisplacementFix) userInfo:nil repeats:false]; keyboardTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(keyboardDisplacementFix) userInfo:nil repeats:false];
[[NSRunLoop mainRunLoop] addTimer:keyboardTimer forMode:NSRunLoopCommonModes]; [[NSRunLoop mainRunLoop] addTimer:keyboardTimer forMode:NSRunLoopCommonModes];
} }
-(void)keyboardWillShow -(void)keyboardWillShow
{ {
if (keyboardTimer != nil) { if (keyboardTimer != nil) {

View File

@ -45,6 +45,7 @@ RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL) RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL) RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL) RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString) RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
/** /**

View File

@ -269,6 +269,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
injectedJavaScript={this.props.injectedJavaScript} injectedJavaScript={this.props.injectedJavaScript}
bounces={this.props.bounces} bounces={this.props.bounces}
scrollEnabled={this.props.scrollEnabled} scrollEnabled={this.props.scrollEnabled}
pagingEnabled={this.props.pagingEnabled}
decelerationRate={decelerationRate} decelerationRate={decelerationRate}
contentInset={this.props.contentInset} contentInset={this.props.contentInset}
automaticallyAdjustContentInsets={ automaticallyAdjustContentInsets={

View File

@ -168,6 +168,14 @@ export type IOSWebViewProps = $ReadOnly<{|
*/ */
scrollEnabled?: ?boolean, scrollEnabled?: ?boolean,
/**
* If the value of this property is true, the scroll view stops on multiples
* of the scroll views bounds when the user scrolls.
* The default value is false.
* @platform ios
*/
pagingEnabled?: ?boolean,
/** /**
* The amount by which the web view content is inset from the edges of * The amount by which the web view content is inset from the edges of
* the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}. * the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.

8
typings/index.d.ts vendored
View File

@ -145,6 +145,14 @@ export interface IOSWebViewProps {
*/ */
scrollEnabled?: boolean; scrollEnabled?: boolean;
/**
* If the value of this property is true, the scroll view stops on multiples
* of the scroll views bounds when the user scrolls.
* The default value is false.
* @platform ios
*/
pagingEnabled?: boolean,
/** /**
* The amount by which the web view content is inset from the edges of * The amount by which the web view content is inset from the edges of
* the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}. * the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.