feat(WKWebView): add prop `directionalLockEnabled` for iOS (#389)

This commit is contained in:
Jian Wei 2019-03-07 17:27:29 +08:00 committed by Thibault Malbranche
parent 83f13c4ba3
commit 08cc600eb8
8 changed files with 41 additions and 0 deletions

View File

@ -36,6 +36,7 @@ This document lays out the current public properties and methods for the React N
- [`contentInset`](Reference.md#contentinset) - [`contentInset`](Reference.md#contentinset)
- [`dataDetectorTypes`](Reference.md#datadetectortypes) - [`dataDetectorTypes`](Reference.md#datadetectortypes)
- [`scrollEnabled`](Reference.md#scrollenabled) - [`scrollEnabled`](Reference.md#scrollenabled)
- [`directionalLockEnabled`](Reference.md#directionalLockEnabled)
- [`geolocationEnabled`](Reference.md#geolocationenabled) - [`geolocationEnabled`](Reference.md#geolocationenabled)
- [`allowUniversalAccessFromFileURLs`](Reference.md#allowUniversalAccessFromFileURLs) - [`allowUniversalAccessFromFileURLs`](Reference.md#allowUniversalAccessFromFileURLs)
- [`useWebKit`](Reference.md#usewebkit) - [`useWebKit`](Reference.md#usewebkit)
@ -700,6 +701,17 @@ Boolean value that determines whether scrolling is enabled in the `WebView`. The
--- ---
### `directionalLockEnabled`
A Boolean value that determines whether scrolling is disabled in a particular direction.
The default value is `true`.
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | iOS |
---
### `showsHorizontalScrollIndicator` ### `showsHorizontalScrollIndicator`
Boolean value that determines whether a horizontal scroll indicator is shown in the `WebView`. The default value is `true`. Boolean value that determines whether a horizontal scroll indicator is shown in the `WebView`. The default value is `true`.

View File

@ -43,6 +43,7 @@ RCT_REMAP_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, _webView.mediaPlaybackR
RCT_REMAP_VIEW_PROPERTY(dataDetectorTypes, _webView.dataDetectorTypes, UIDataDetectorTypes) RCT_REMAP_VIEW_PROPERTY(dataDetectorTypes, _webView.dataDetectorTypes, UIDataDetectorTypes)
RCT_REMAP_VIEW_PROPERTY(showsHorizontalScrollIndicator, _webView.scrollView.showsHorizontalScrollIndicator, BOOL) RCT_REMAP_VIEW_PROPERTY(showsHorizontalScrollIndicator, _webView.scrollView.showsHorizontalScrollIndicator, BOOL)
RCT_REMAP_VIEW_PROPERTY(showsVerticalScrollIndicator, _webView.scrollView.showsVerticalScrollIndicator, BOOL) RCT_REMAP_VIEW_PROPERTY(showsVerticalScrollIndicator, _webView.scrollView.showsVerticalScrollIndicator, BOOL)
RCT_REMAP_VIEW_PROPERTY(directionalLockEnabled, _webView.scrollView.directionalLockEnabled, BOOL)
RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag) RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag)
{ {

View File

@ -45,6 +45,7 @@
@property (nonatomic, assign) BOOL allowsLinkPreview; @property (nonatomic, assign) BOOL allowsLinkPreview;
@property (nonatomic, assign) BOOL showsHorizontalScrollIndicator; @property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;
@property (nonatomic, assign) BOOL showsVerticalScrollIndicator; @property (nonatomic, assign) BOOL showsVerticalScrollIndicator;
@property (nonatomic, assign) BOOL directionalLockEnabled;
+ (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential; + (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential;
- (void)postMessage:(NSString *)message; - (void)postMessage:(NSString *)message;

View File

@ -51,6 +51,7 @@ static NSURLCredential* clientAuthenticationCredential;
_scrollEnabled = YES; _scrollEnabled = YES;
_showsHorizontalScrollIndicator = YES; _showsHorizontalScrollIndicator = YES;
_showsVerticalScrollIndicator = YES; _showsVerticalScrollIndicator = YES;
_directionalLockEnabled = YES;
_automaticallyAdjustContentInsets = YES; _automaticallyAdjustContentInsets = YES;
_contentInset = UIEdgeInsetsZero; _contentInset = UIEdgeInsetsZero;
} }
@ -135,6 +136,7 @@ static NSURLCredential* clientAuthenticationCredential;
_webView.scrollView.bounces = _bounces; _webView.scrollView.bounces = _bounces;
_webView.scrollView.showsHorizontalScrollIndicator = _showsHorizontalScrollIndicator; _webView.scrollView.showsHorizontalScrollIndicator = _showsHorizontalScrollIndicator;
_webView.scrollView.showsVerticalScrollIndicator = _showsVerticalScrollIndicator; _webView.scrollView.showsVerticalScrollIndicator = _showsVerticalScrollIndicator;
_webView.scrollView.directionalLockEnabled = _directionalLockEnabled;
_webView.allowsLinkPreview = _allowsLinkPreview; _webView.allowsLinkPreview = _allowsLinkPreview;
[_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;
@ -351,6 +353,12 @@ static NSURLCredential* clientAuthenticationCredential;
} }
} }
- (void)setDirectionalLockEnabled:(BOOL)directionalLockEnabled
{
_directionalLockEnabled = directionalLockEnabled;
_webView.scrollView.directionalLockEnabled = directionalLockEnabled;
}
- (void)setShowsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator - (void)setShowsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator
{ {
_showsHorizontalScrollIndicator = showsHorizontalScrollIndicator; _showsHorizontalScrollIndicator = showsHorizontalScrollIndicator;

View File

@ -85,6 +85,10 @@ RCT_CUSTOM_VIEW_PROPERTY(decelerationRate, CGFloat, RNCWKWebView) {
view.decelerationRate = json == nil ? UIScrollViewDecelerationRateNormal : [RCTConvert CGFloat: json]; view.decelerationRate = json == nil ? UIScrollViewDecelerationRateNormal : [RCTConvert CGFloat: json];
} }
RCT_CUSTOM_VIEW_PROPERTY(directionalLockEnabled, BOOL, RNCWKWebView) {
view.directionalLockEnabled = json == nil ? true : [RCTConvert BOOL: json];
}
RCT_CUSTOM_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL, RNCWKWebView) { RCT_CUSTOM_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL, RNCWKWebView) {
view.showsHorizontalScrollIndicator = json == nil ? true : [RCTConvert BOOL: json]; view.showsHorizontalScrollIndicator = json == nil ? true : [RCTConvert BOOL: json];
} }

View File

@ -286,6 +286,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
allowsLinkPreview={this.props.allowsLinkPreview} allowsLinkPreview={this.props.allowsLinkPreview}
showsHorizontalScrollIndicator={this.props.showsHorizontalScrollIndicator} showsHorizontalScrollIndicator={this.props.showsHorizontalScrollIndicator}
showsVerticalScrollIndicator={this.props.showsVerticalScrollIndicator} showsVerticalScrollIndicator={this.props.showsVerticalScrollIndicator}
directionalLockEnabled={this.props.directionalLockEnabled}
{...nativeConfig.props} {...nativeConfig.props}
/> />
); );

View File

@ -253,6 +253,13 @@ export type IOSWebViewProps = $ReadOnly<{|
* @platform ios * @platform ios
*/ */
allowsLinkPreview?: ?boolean, allowsLinkPreview?: ?boolean,
/**
* A Boolean value that determines whether scrolling is disabled in a particular direction.
* The default value is `true`.
* @platform ios
*/
directionalLockEnabled?: ?boolean,
|}>; |}>;
export type AndroidWebViewProps = $ReadOnly<{| export type AndroidWebViewProps = $ReadOnly<{|

7
typings/index.d.ts vendored
View File

@ -151,6 +151,13 @@ export interface IOSWebViewProps {
*/ */
scrollEnabled?: boolean; scrollEnabled?: boolean;
/**
* A Boolean value that determines whether scrolling is disabled in a particular direction.
* The default value is `true`.
* @platform ios
*/
directionalLockEnabled?: boolean;
/** /**
* If the value of this property is true, the scroll view stops on multiples * If the value of this property is true, the scroll view stops on multiples
* of the scroll views bounds when the user scrolls. * of the scroll views bounds when the user scrolls.