Преглед на файлове

feat(WKWebView): [ios] Add allowsLinkPreview property to WKWebView (#170)

* [ios] Add ‘allowsLinkPreview’ property to iOS WKWebView.

* Add divider in docs

* Typo: add hyphen -> _allowsLinkPreview
Jermaine Oosterling преди 6 години
родител
ревизия
731dd03fc6
променени са 7 файла, в които са добавени 37 реда и са изтрити 1 реда
  1. 11
    0
      docs/Reference.md
  2. 1
    0
      ios/RNCWKWebView.h
  3. 2
    0
      ios/RNCWKWebView.m
  4. 1
    0
      ios/RNCWKWebViewManager.m
  5. 1
    0
      js/WebView.ios.js
  6. 10
    0
      js/WebViewTypes.js
  7. 11
    1
      typings/index.d.ts

+ 11
- 0
docs/Reference.md Целия файл

@@ -47,6 +47,7 @@ This document lays out the current public properties and methods for the React N
47 47
 - [`allowFileAccess`](Reference.md#allowFileAccess)
48 48
 - [`saveFormDataDisabled`](Reference.md#saveFormDataDisabled)
49 49
 - [`pagingEnabled`](Reference.md#pagingEnabled)
50
+- [`allowsLinkPreview`](Reference.md#allowsLinkPreview)
50 51
 
51 52
 ## Methods Index
52 53
 
@@ -528,6 +529,16 @@ If the value of this property is true, the scroll view stops on multiples of the
528 529
 | ------- | -------- | -------- |
529 530
 | boolean | No       | iOS      |
530 531
 
532
+---
533
+
534
+### `allowsLinkPreview`
535
+
536
+A Boolean value that determines whether pressing on a link displays a preview of the destination for the link. In iOS this property is available on devices that support 3D Touch. In iOS 10 and later, the default value is true; before that, the default value is false.
537
+
538
+| Type    | Required | Platform |
539
+| ------- | -------- | -------- |
540
+| boolean | No       | iOS      |
541
+
531 542
 ## Methods
532 543
 
533 544
 ### `extraNativeComponentConfig()`

+ 1
- 0
ios/RNCWKWebView.h Целия файл

@@ -39,6 +39,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
39 39
 @property (nonatomic, assign) BOOL hideKeyboardAccessoryView;
40 40
 @property (nonatomic, assign) BOOL allowsBackForwardNavigationGestures;
41 41
 @property (nonatomic, copy) NSString *userAgent;
42
+@property (nonatomic, assign) BOOL allowsLinkPreview;
42 43
 
43 44
 - (void)postMessage:(NSString *)message;
44 45
 - (void)injectJavaScript:(NSString *)script;

+ 2
- 0
ios/RNCWKWebView.m Целия файл

@@ -113,8 +113,10 @@ static NSString *const MessageHanderName = @"ReactNative";
113 113
     _webView.scrollView.scrollEnabled = _scrollEnabled;
114 114
     _webView.scrollView.pagingEnabled = _pagingEnabled;
115 115
     _webView.scrollView.bounces = _bounces;
116
+    _webView.allowsLinkPreview = _allowsLinkPreview;
116 117
     [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
117 118
     _webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures;
119
+
118 120
     if (_userAgent) {
119 121
       _webView.customUserAgent = _userAgent;
120 122
     }

+ 1
- 0
ios/RNCWKWebViewManager.m Целия файл

@@ -47,6 +47,7 @@ RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL)
47 47
 RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
48 48
 RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
49 49
 RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
50
+RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL)
50 51
 
51 52
 /**
52 53
  * Expose methods to enable messaging the webview.

+ 1
- 0
js/WebView.ios.js Целия файл

@@ -291,6 +291,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
291 291
           this.props.mediaPlaybackRequiresUserAction
292 292
         }
293 293
         dataDetectorTypes={this.props.dataDetectorTypes}
294
+        allowsLinkPreview={this.props.allowsLinkPreview}
294 295
         {...nativeConfig.props}
295 296
       />
296 297
     );

+ 10
- 0
js/WebViewTypes.js Целия файл

@@ -241,6 +241,16 @@ export type IOSWebViewProps = $ReadOnly<{|
241 241
    * The custom user agent string.
242 242
    */
243 243
   userAgent?: ?string,
244
+
245
+  /**
246
+   * A Boolean value that determines whether pressing on a link
247
+   * displays a preview of the destination for the link.
248
+   *
249
+   * This property is available on devices that support 3D Touch.
250
+   * In iOS 10 and later, the default value is `true`; before that, the default value is `false`.
251
+   * @platform ios
252
+   */
253
+  allowsLinkPreview?: ?boolean,
244 254
 |}>;
245 255
 
246 256
 export type AndroidWebViewProps = $ReadOnly<{|

+ 11
- 1
typings/index.d.ts Целия файл

@@ -216,7 +216,17 @@ export interface IOSWebViewProps {
216 216
   /**
217 217
    * If true, this will be able horizontal swipe gestures when using the WKWebView. The default value is `false`.
218 218
    */
219
-  allowsBackForwardNavigationGestures?: boolean
219
+  allowsBackForwardNavigationGestures?: boolean;
220
+
221
+  /**
222
+   * A Boolean value that determines whether pressing on a link
223
+   * displays a preview of the destination for the link.
224
+   *
225
+   * This property is available on devices that support 3D Touch.
226
+   * In iOS 10 and later, the default value is `true`; before that, the default value is `false`.
227
+   * @platform ios
228
+   */
229
+  allowsLinkPreview?: boolean;
220 230
 }
221 231
 
222 232
 export interface AndroidWebViewProps {