Sfoglia il codice sorgente

Merge branch 'master' into android-download-try-catch

Jamon Holmgren 4 anni fa
parent
commit
b03236c5ab
No account linked to committer's email address
7 ha cambiato i file con 64 aggiunte e 2 eliminazioni
  1. 4
    0
      apple/RNCWebView.h
  2. 8
    0
      apple/RNCWebView.m
  3. 14
    0
      apple/RNCWebViewManager.m
  4. 3
    1
      docs/Debugging.md
  5. 19
    0
      docs/Reference.md
  6. 1
    1
      package.json
  7. 15
    0
      src/WebViewTypes.ts

+ 4
- 0
apple/RNCWebView.h Vedi File

@@ -63,6 +63,10 @@
63 63
 @property (nonatomic, assign) BOOL ignoreSilentHardwareSwitch;
64 64
 @property (nonatomic, copy) NSString * _Nullable allowingReadAccessToURL;
65 65
 
66
+#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* iOS 13 */
67
+@property (nonatomic, assign) WKContentMode contentMode;
68
+#endif
69
+
66 70
 + (void)setClientAuthenticationCredential:(nullable NSURLCredential*)credential;
67 71
 + (void)setCustomCertificatesForHost:(nullable NSDictionary *)certificates;
68 72
 - (void)postMessage:(NSString *_Nullable)message;

+ 8
- 0
apple/RNCWebView.m Vedi File

@@ -226,6 +226,14 @@ static NSDictionary* customCertificatesForHost;
226 226
   }
227 227
   wkWebViewConfig.userContentController = [WKUserContentController new];
228 228
 
229
+#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* iOS 13 */
230
+  if (@available(iOS 13.0, *)) {
231
+    WKWebpagePreferences *pagePrefs = [[WKWebpagePreferences alloc]init];
232
+    pagePrefs.preferredContentMode = _contentMode;
233
+    wkWebViewConfig.defaultWebpagePreferences = pagePrefs;
234
+  }
235
+#endif
236
+
229 237
   // Shim the HTML5 history API:
230 238
   [wkWebViewConfig.userContentController addScriptMessageHandler:[[RNCWeakScriptMessageDelegate alloc] initWithDelegate:self]
231 239
                                                             name:HistoryShimName];

+ 14
- 0
apple/RNCWebViewManager.m Vedi File

@@ -14,6 +14,16 @@
14 14
 @interface RNCWebViewManager () <RNCWebViewDelegate>
15 15
 @end
16 16
 
17
+@implementation RCTConvert (WKWebView)
18
+#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* iOS 13 */
19
+RCT_ENUM_CONVERTER(WKContentMode, (@{
20
+    @"recommended": @(WKContentModeRecommended),
21
+    @"mobile": @(WKContentModeMobile),
22
+    @"desktop": @(WKContentModeDesktop),
23
+}), WKContentModeRecommended, integerValue)
24
+#endif
25
+@end
26
+
17 27
 @implementation RNCWebViewManager
18 28
 {
19 29
   NSConditionLock *_shouldStartLoadLock;
@@ -70,6 +80,10 @@ RCT_EXPORT_VIEW_PROPERTY(allowingReadAccessToURL, NSString)
70 80
 RCT_EXPORT_VIEW_PROPERTY(contentInsetAdjustmentBehavior, UIScrollViewContentInsetAdjustmentBehavior)
71 81
 #endif
72 82
 
83
+#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* iOS 13 */
84
+RCT_EXPORT_VIEW_PROPERTY(contentMode, WKContentMode)
85
+#endif
86
+
73 87
 /**
74 88
  * Expose methods to enable messaging the webview.
75 89
  */

+ 3
- 1
docs/Debugging.md Vedi File

@@ -15,12 +15,14 @@ It's possible to debug WebView contents in the iOS simulator or on a device usin
15 15
 3. Safari -> Develop -> [device name] -> [app name] -> [url - title]
16 16
 4. You can now debug the WebView contents just as you would on the web
17 17
 
18
-##### Note:
18
+##### Notes:
19 19
 
20 20
 When debugging on device you must enable Web Inspector in your device settings:
21 21
 
22 22
 Settings -> Safari -> Advanced -> Web Inspector
23 23
 
24
+Also, if you don't see your device in the Develop menu, and you started Safari before you started your simulator, try restarting Safari.
25
+
24 26
 ### Android & Chrome
25 27
 
26 28
 It's possible to debug WebView contents in the Android emulator or on a device using Chrome DevTools.

+ 19
- 0
docs/Reference.md Vedi File

@@ -45,6 +45,7 @@ This document lays out the current public properties and methods for the React N
45 45
 - [`overScrollMode`](Reference.md#overscrollmode)
46 46
 - [`contentInset`](Reference.md#contentinset)
47 47
 - [`contentInsetAdjustmentBehavior`](Reference.md#contentInsetAdjustmentBehavior)
48
+- [`contentMode`](Reference.md#contentMode)
48 49
 - [`dataDetectorTypes`](Reference.md#datadetectortypes)
49 50
 - [`scrollEnabled`](Reference.md#scrollenabled)
50 51
 - [`directionalLockEnabled`](Reference.md#directionalLockEnabled)
@@ -917,6 +918,24 @@ Possible values:
917 918
 
918 919
 ---
919 920
 
921
+### `contentMode`[⬆](#props-index)<!-- Link generated with jump2header -->
922
+
923
+Controls the type of content to load. Available on iOS 13 and later. Defaults to `recommended`, which loads mobile content on iPhone & iPad Mini but desktop content on larger iPads.
924
+
925
+See [Introducing Desktop-class Browsing on iPad](https://developer.apple.com/videos/play/wwdc2019/203/) for more.
926
+
927
+Possible values:
928
+
929
+- `recommended`
930
+- `mobile`
931
+- `desktop`
932
+
933
+| Type   | Required | Platform |
934
+| ------ | -------- | -------- |
935
+| string | No       | iOS      |
936
+
937
+---
938
+
920 939
 ### `dataDetectorTypes`[⬆](#props-index)<!-- Link generated with jump2header -->
921 940
 
922 941
 Determines the types of data converted to clickable URLs in the web view's content. By default only phone numbers are detected.

+ 1
- 1
package.json Vedi File

@@ -8,7 +8,7 @@
8 8
     "Thibault Malbranche <malbranche.thibault@gmail.com>"
9 9
   ],
10 10
   "license": "MIT",
11
-  "version": "10.4.1",
11
+  "version": "10.5.0",
12 12
   "homepage": "https://github.com/react-native-community/react-native-webview#readme",
13 13
   "scripts": {
14 14
     "start": "node node_modules/react-native/local-cli/cli.js start",

+ 15
- 0
src/WebViewTypes.ts Vedi File

@@ -299,6 +299,8 @@ export enum ContentInsetAdjustmentBehavior {
299 299
   always = 'always'
300 300
 };
301 301
 
302
+export declare type ContentMode = 'recommended' | 'mobile' | 'desktop';
303
+
302 304
 export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
303 305
   allowingReadAccessToURL?: string;
304 306
   allowsBackForwardNavigationGestures?: boolean;
@@ -308,6 +310,7 @@ export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
308 310
   bounces?: boolean;
309 311
   contentInset?: ContentInsetProp;
310 312
   contentInsetAdjustmentBehavior?: ContentInsetAdjustmentBehavior;
313
+  contentMode?: ContentMode;
311 314
   readonly dataDetectorTypes?: DataDetectorTypes | DataDetectorTypes[];
312 315
   decelerationRate?: number;
313 316
   directionalLockEnabled?: boolean;
@@ -405,6 +408,18 @@ export interface IOSWebViewProps extends WebViewSharedProps {
405 408
    */
406 409
   contentInset?: ContentInsetProp;
407 410
 
411
+  /**
412
+   * Defaults to `recommended`, which loads mobile content on iPhone
413
+   * and iPad Mini but desktop content on other iPads.
414
+   * 
415
+   * Possible values are:
416
+   * - `'recommended'`
417
+   * - `'mobile'`
418
+   * - `'desktop'`
419
+   * @platform ios
420
+   */
421
+  contentMode?: ContentMode;
422
+
408 423
   /**
409 424
    * Determines the types of data converted to clickable URLs in the web view's content.
410 425
    * By default only phone numbers are detected.