Browse Source

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

Jian Wei 5 years ago
parent
commit
08cc600eb8

+ 12
- 0
docs/Reference.md View File

36
 - [`contentInset`](Reference.md#contentinset)
36
 - [`contentInset`](Reference.md#contentinset)
37
 - [`dataDetectorTypes`](Reference.md#datadetectortypes)
37
 - [`dataDetectorTypes`](Reference.md#datadetectortypes)
38
 - [`scrollEnabled`](Reference.md#scrollenabled)
38
 - [`scrollEnabled`](Reference.md#scrollenabled)
39
+- [`directionalLockEnabled`](Reference.md#directionalLockEnabled)
39
 - [`geolocationEnabled`](Reference.md#geolocationenabled)
40
 - [`geolocationEnabled`](Reference.md#geolocationenabled)
40
 - [`allowUniversalAccessFromFileURLs`](Reference.md#allowUniversalAccessFromFileURLs)
41
 - [`allowUniversalAccessFromFileURLs`](Reference.md#allowUniversalAccessFromFileURLs)
41
 - [`useWebKit`](Reference.md#usewebkit)
42
 - [`useWebKit`](Reference.md#usewebkit)
700
 
701
 
701
 ---
702
 ---
702
 
703
 
704
+### `directionalLockEnabled`
705
+
706
+A Boolean value that determines whether scrolling is disabled in a particular direction.
707
+The default value is `true`.
708
+
709
+| Type | Required | Platform |
710
+| ---- | -------- | -------- |
711
+| bool | No       | iOS      |
712
+
713
+---
714
+
703
 ### `showsHorizontalScrollIndicator`
715
 ### `showsHorizontalScrollIndicator`
704
 
716
 
705
 Boolean value that determines whether a horizontal scroll indicator is shown in the `WebView`. The default value is `true`.
717
 Boolean value that determines whether a horizontal scroll indicator is shown in the `WebView`. The default value is `true`.

+ 1
- 0
ios/RNCUIWebViewManager.m View File

43
 RCT_REMAP_VIEW_PROPERTY(dataDetectorTypes, _webView.dataDetectorTypes, UIDataDetectorTypes)
43
 RCT_REMAP_VIEW_PROPERTY(dataDetectorTypes, _webView.dataDetectorTypes, UIDataDetectorTypes)
44
 RCT_REMAP_VIEW_PROPERTY(showsHorizontalScrollIndicator, _webView.scrollView.showsHorizontalScrollIndicator, BOOL)
44
 RCT_REMAP_VIEW_PROPERTY(showsHorizontalScrollIndicator, _webView.scrollView.showsHorizontalScrollIndicator, BOOL)
45
 RCT_REMAP_VIEW_PROPERTY(showsVerticalScrollIndicator, _webView.scrollView.showsVerticalScrollIndicator, BOOL)
45
 RCT_REMAP_VIEW_PROPERTY(showsVerticalScrollIndicator, _webView.scrollView.showsVerticalScrollIndicator, BOOL)
46
+RCT_REMAP_VIEW_PROPERTY(directionalLockEnabled, _webView.scrollView.directionalLockEnabled, BOOL)
46
 
47
 
47
 RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag)
48
 RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag)
48
 {
49
 {

+ 1
- 0
ios/RNCWKWebView.h View File

45
 @property (nonatomic, assign) BOOL allowsLinkPreview;
45
 @property (nonatomic, assign) BOOL allowsLinkPreview;
46
 @property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;
46
 @property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;
47
 @property (nonatomic, assign) BOOL showsVerticalScrollIndicator;
47
 @property (nonatomic, assign) BOOL showsVerticalScrollIndicator;
48
+@property (nonatomic, assign) BOOL directionalLockEnabled;
48
 
49
 
49
 + (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential;
50
 + (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential;
50
 - (void)postMessage:(NSString *)message;
51
 - (void)postMessage:(NSString *)message;

+ 8
- 0
ios/RNCWKWebView.m View File

51
     _scrollEnabled = YES;
51
     _scrollEnabled = YES;
52
     _showsHorizontalScrollIndicator = YES;
52
     _showsHorizontalScrollIndicator = YES;
53
     _showsVerticalScrollIndicator = YES;
53
     _showsVerticalScrollIndicator = YES;
54
+    _directionalLockEnabled = YES;
54
     _automaticallyAdjustContentInsets = YES;
55
     _automaticallyAdjustContentInsets = YES;
55
     _contentInset = UIEdgeInsetsZero;
56
     _contentInset = UIEdgeInsetsZero;
56
   }
57
   }
135
     _webView.scrollView.bounces = _bounces;
136
     _webView.scrollView.bounces = _bounces;
136
     _webView.scrollView.showsHorizontalScrollIndicator = _showsHorizontalScrollIndicator;
137
     _webView.scrollView.showsHorizontalScrollIndicator = _showsHorizontalScrollIndicator;
137
     _webView.scrollView.showsVerticalScrollIndicator = _showsVerticalScrollIndicator;
138
     _webView.scrollView.showsVerticalScrollIndicator = _showsVerticalScrollIndicator;
139
+    _webView.scrollView.directionalLockEnabled = _directionalLockEnabled;
138
     _webView.allowsLinkPreview = _allowsLinkPreview;
140
     _webView.allowsLinkPreview = _allowsLinkPreview;
139
     [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
141
     [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
140
     _webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures;
142
     _webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures;
351
   }
353
   }
352
 }
354
 }
353
 
355
 
356
+- (void)setDirectionalLockEnabled:(BOOL)directionalLockEnabled
357
+{
358
+    _directionalLockEnabled = directionalLockEnabled;
359
+    _webView.scrollView.directionalLockEnabled = directionalLockEnabled;
360
+}
361
+
354
 - (void)setShowsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator
362
 - (void)setShowsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator
355
 {
363
 {
356
     _showsHorizontalScrollIndicator = showsHorizontalScrollIndicator;
364
     _showsHorizontalScrollIndicator = showsHorizontalScrollIndicator;

+ 4
- 0
ios/RNCWKWebViewManager.m View File

85
   view.decelerationRate = json == nil ? UIScrollViewDecelerationRateNormal : [RCTConvert CGFloat: json];
85
   view.decelerationRate = json == nil ? UIScrollViewDecelerationRateNormal : [RCTConvert CGFloat: json];
86
 }
86
 }
87
 
87
 
88
+RCT_CUSTOM_VIEW_PROPERTY(directionalLockEnabled, BOOL, RNCWKWebView) {
89
+    view.directionalLockEnabled = json == nil ? true : [RCTConvert BOOL: json];
90
+}
91
+
88
 RCT_CUSTOM_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL, RNCWKWebView) {
92
 RCT_CUSTOM_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL, RNCWKWebView) {
89
   view.showsHorizontalScrollIndicator = json == nil ? true : [RCTConvert BOOL: json];
93
   view.showsHorizontalScrollIndicator = json == nil ? true : [RCTConvert BOOL: json];
90
 }
94
 }

+ 1
- 0
js/WebView.ios.js View File

286
         allowsLinkPreview={this.props.allowsLinkPreview}
286
         allowsLinkPreview={this.props.allowsLinkPreview}
287
         showsHorizontalScrollIndicator={this.props.showsHorizontalScrollIndicator}
287
         showsHorizontalScrollIndicator={this.props.showsHorizontalScrollIndicator}
288
         showsVerticalScrollIndicator={this.props.showsVerticalScrollIndicator}
288
         showsVerticalScrollIndicator={this.props.showsVerticalScrollIndicator}
289
+        directionalLockEnabled={this.props.directionalLockEnabled}
289
         {...nativeConfig.props}
290
         {...nativeConfig.props}
290
       />
291
       />
291
     );
292
     );

+ 7
- 0
js/WebViewTypes.js View File

253
    * @platform ios
253
    * @platform ios
254
    */
254
    */
255
   allowsLinkPreview?: ?boolean,
255
   allowsLinkPreview?: ?boolean,
256
+
257
+  /**
258
+   * A Boolean value that determines whether scrolling is disabled in a particular direction.
259
+   * The default value is `true`.
260
+   * @platform ios
261
+   */
262
+  directionalLockEnabled?: ?boolean,
256
 |}>;
263
 |}>;
257
 
264
 
258
 export type AndroidWebViewProps = $ReadOnly<{|
265
 export type AndroidWebViewProps = $ReadOnly<{|

+ 7
- 0
typings/index.d.ts View File

151
    */
151
    */
152
   scrollEnabled?: boolean;
152
   scrollEnabled?: boolean;
153
 
153
 
154
+  /**
155
+   * A Boolean value that determines whether scrolling is disabled in a particular direction.
156
+   * The default value is `true`.
157
+   * @platform ios
158
+   */
159
+  directionalLockEnabled?: boolean;
160
+
154
   /**
161
   /**
155
    * If the value of this property is true, the scroll view stops on multiples
162
    * If the value of this property is true, the scroll view stops on multiples
156
    * of the scroll view’s bounds when the user scrolls.
163
    * of the scroll view’s bounds when the user scrolls.