Преглед изворни кода

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

wiscat пре 6 година
родитељ
комит
4870e1f06a
7 измењених фајлова са 34 додато и 3 уклоњено
  1. 11
    0
      docs/Reference.md
  2. 1
    0
      ios/RNCWKWebView.h
  3. 4
    3
      ios/RNCWKWebView.m
  4. 1
    0
      ios/RNCWKWebViewManager.m
  5. 1
    0
      js/WebView.ios.js
  6. 8
    0
      js/WebViewTypes.js
  7. 8
    0
      typings/index.d.ts

+ 11
- 0
docs/Reference.md Прегледај датотеку

@@ -46,6 +46,7 @@ This document lays out the current public properties and methods for the React N
46 46
 - [`allowsBackForwardNavigationGestures`](Reference.md#allowsbackforwardnavigationgestures)
47 47
 - [`allowFileAccess`](Reference.md#allowFileAccess)
48 48
 - [`saveFormDataDisabled`](Reference.md#saveFormDataDisabled)
49
+- [`pagingEnabled`](Reference.md#pagingEnabled)
49 50
 
50 51
 ## Methods Index
51 52
 
@@ -517,6 +518,16 @@ Sets whether the WebView should disable saving form data. The default value is `
517 518
 | ------- | -------- | -------- |
518 519
 | boolean | No       | Android  |
519 520
 
521
+---
522
+
523
+### `pagingEnabled`
524
+
525
+If the value of this property is true, the scroll view stops on multiples of the scroll view’s bounds when the user scrolls. The default value is false.
526
+
527
+| Type    | Required | Platform |
528
+| ------- | -------- | -------- |
529
+| boolean | No       | iOS      |
530
+
520 531
 ## Methods
521 532
 
522 533
 ### `extraNativeComponentConfig()`

+ 1
- 0
ios/RNCWKWebView.h Прегледај датотеку

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

+ 4
- 3
ios/RNCWKWebView.m Прегледај датотеку

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

+ 1
- 0
ios/RNCWKWebViewManager.m Прегледај датотеку

@@ -45,6 +45,7 @@ RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
45 45
 RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
46 46
 RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL)
47 47
 RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
48
+RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
48 49
 RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
49 50
 
50 51
 /**

+ 1
- 0
js/WebView.ios.js Прегледај датотеку

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

+ 8
- 0
js/WebViewTypes.js Прегледај датотеку

@@ -168,6 +168,14 @@ export type IOSWebViewProps = $ReadOnly<{|
168 168
    */
169 169
   scrollEnabled?: ?boolean,
170 170
 
171
+  /**
172
+   * If the value of this property is true, the scroll view stops on multiples
173
+   * of the scroll view’s bounds when the user scrolls.
174
+   * The default value is false.
175
+   * @platform ios
176
+   */
177
+  pagingEnabled?: ?boolean,
178
+
171 179
   /**
172 180
    * The amount by which the web view content is inset from the edges of
173 181
    * the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.

+ 8
- 0
typings/index.d.ts Прегледај датотеку

@@ -145,6 +145,14 @@ export interface IOSWebViewProps {
145 145
    */
146 146
   scrollEnabled?: boolean;
147 147
 
148
+  /**
149
+   * If the value of this property is true, the scroll view stops on multiples
150
+   * of the scroll view’s bounds when the user scrolls.
151
+   * The default value is false.
152
+   * @platform ios
153
+   */
154
+  pagingEnabled?: boolean,
155
+
148 156
   /**
149 157
    * The amount by which the web view content is inset from the edges of
150 158
    * the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.