Kaynağa Gözat

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

Jian Wei 5 yıl önce
ebeveyn
işleme
08cc600eb8

+ 12
- 0
docs/Reference.md Dosyayı Görüntüle

@@ -36,6 +36,7 @@ This document lays out the current public properties and methods for the React N
36 36
 - [`contentInset`](Reference.md#contentinset)
37 37
 - [`dataDetectorTypes`](Reference.md#datadetectortypes)
38 38
 - [`scrollEnabled`](Reference.md#scrollenabled)
39
+- [`directionalLockEnabled`](Reference.md#directionalLockEnabled)
39 40
 - [`geolocationEnabled`](Reference.md#geolocationenabled)
40 41
 - [`allowUniversalAccessFromFileURLs`](Reference.md#allowUniversalAccessFromFileURLs)
41 42
 - [`useWebKit`](Reference.md#usewebkit)
@@ -700,6 +701,17 @@ Boolean value that determines whether scrolling is enabled in the `WebView`. The
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 715
 ### `showsHorizontalScrollIndicator`
704 716
 
705 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 Dosyayı Görüntüle

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

+ 1
- 0
ios/RNCWKWebView.h Dosyayı Görüntüle

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

+ 8
- 0
ios/RNCWKWebView.m Dosyayı Görüntüle

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

+ 4
- 0
ios/RNCWKWebViewManager.m Dosyayı Görüntüle

@@ -85,6 +85,10 @@ RCT_CUSTOM_VIEW_PROPERTY(decelerationRate, CGFloat, RNCWKWebView) {
85 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 92
 RCT_CUSTOM_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL, RNCWKWebView) {
89 93
   view.showsHorizontalScrollIndicator = json == nil ? true : [RCTConvert BOOL: json];
90 94
 }

+ 1
- 0
js/WebView.ios.js Dosyayı Görüntüle

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

+ 7
- 0
js/WebViewTypes.js Dosyayı Görüntüle

@@ -253,6 +253,13 @@ export type IOSWebViewProps = $ReadOnly<{|
253 253
    * @platform ios
254 254
    */
255 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 265
 export type AndroidWebViewProps = $ReadOnly<{|

+ 7
- 0
typings/index.d.ts Dosyayı Görüntüle

@@ -151,6 +151,13 @@ export interface IOSWebViewProps {
151 151
    */
152 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 162
    * If the value of this property is true, the scroll view stops on multiples
156 163
    * of the scroll view’s bounds when the user scrolls.