Browse Source

add prop autoManageStatusBarEnabled

Kesha Antonov 5 years ago
parent
commit
b46144d629
5 changed files with 36 additions and 3 deletions
  1. 21
    2
      docs/Reference.md
  2. 1
    0
      ios/RNCWebView.h
  3. 5
    1
      ios/RNCWebView.m
  4. 1
    0
      ios/RNCWebViewManager.m
  5. 8
    0
      src/WebViewTypes.ts

+ 21
- 2
docs/Reference.md View File

@@ -58,6 +58,7 @@ This document lays out the current public properties and methods for the React N
58 58
 - [`allowsLinkPreview`](Reference.md#allowsLinkPreview)
59 59
 - [`sharedCookiesEnabled`](Reference.md#sharedCookiesEnabled)
60 60
 - [`textZoom`](Reference.md#textZoom)
61
+- [`autoManageStatusBarEnabled`](Reference.md#autoManageStatusBarEnabled)
61 62
 
62 63
 ## Methods Index
63 64
 
@@ -343,6 +344,7 @@ url
343 344
 ### `onHttpError`
344 345
 
345 346
 Function that is invoked when the `WebView` receives an http error.
347
+
346 348
 > **_Note_**
347 349
 > Android API minimum level 23.
348 350
 
@@ -357,7 +359,10 @@ Example:
357 359
   source={{ uri: 'https://facebook.github.io/react-native' }}
358 360
   onHttpError={syntheticEvent => {
359 361
     const { nativeEvent } = syntheticEvent;
360
-    console.warn('WebView received error status code: ', nativeEvent.statusCode);
362
+    console.warn(
363
+      'WebView received error status code: ',
364
+      nativeEvent.statusCode,
365
+    );
361 366
   }}
362 367
 />
363 368
 ```
@@ -446,7 +451,7 @@ Example:
446 451
   onContentProcessDidTerminate={syntheticEvent => {
447 452
     const { nativeEvent } = syntheticEvent;
448 453
     console.warn('Content process terminated, reloading', nativeEvent);
449
-    this.refs.webview.reload()
454
+    this.refs.webview.reload();
450 455
   }}
451 456
 />
452 457
 ```
@@ -1005,6 +1010,20 @@ Example:
1005 1010
 
1006 1011
 `<WebView textZoom={100} />`
1007 1012
 
1013
+---
1014
+
1015
+### `autoManageStatusBarEnabled`
1016
+
1017
+If the user watch fullscreen video in WebView then StatusBar will be light. The default value is `true`.
1018
+
1019
+| Type   | Required | Platform |
1020
+| ------ | -------- | -------- |
1021
+| number | No       | iOS      |
1022
+
1023
+Example:
1024
+
1025
+`<WebView autoManageStatusBarEnabled={false} />`
1026
+
1008 1027
 ## Methods
1009 1028
 
1010 1029
 ### `extraNativeComponentConfig()`

+ 1
- 0
ios/RNCWebView.h View File

@@ -27,6 +27,7 @@
27 27
 @property (nonatomic, copy) NSString * _Nullable injectedJavaScript;
28 28
 @property (nonatomic, assign) BOOL scrollEnabled;
29 29
 @property (nonatomic, assign) BOOL sharedCookiesEnabled;
30
+@property (nonatomic, assign) BOOL autoManageStatusBarEnabled;
30 31
 @property (nonatomic, assign) BOOL pagingEnabled;
31 32
 @property (nonatomic, assign) CGFloat decelerationRate;
32 33
 @property (nonatomic, assign) BOOL allowsInlineMediaPlayback;

+ 5
- 1
ios/RNCWebView.m View File

@@ -68,6 +68,7 @@ static NSDictionary* customCertificatesForHost;
68 68
     _showsVerticalScrollIndicator = YES;
69 69
     _directionalLockEnabled = YES;
70 70
     _automaticallyAdjustContentInsets = YES;
71
+    _autoManageStatusBarEnabled = YES;
71 72
     _contentInset = UIEdgeInsetsZero;
72 73
     _savedKeyboardDisplayRequiresUserAction = YES;
73 74
     _savedStatusBarStyle = RCTSharedApplication().statusBarStyle;
@@ -278,6 +279,9 @@ static NSDictionary* customCertificatesForHost;
278 279
 -(void)toggleFullScreenVideoStatusBars
279 280
 {
280 281
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
282
+  if (!_autoManageStatusBarEnabled) {
283
+    return;
284
+  }
281 285
   if (!_isFullScreenVideoOpen) {
282 286
     _isFullScreenVideoOpen = YES;
283 287
     RCTUnsafeExecuteOnMainQueueSync(^{
@@ -870,7 +874,7 @@ static NSDictionary* customCertificatesForHost;
870 874
         _onHttpError(event);
871 875
       }
872 876
     }
873
-  }  
877
+  }
874 878
 
875 879
   decisionHandler(WKNavigationResponsePolicyAllow);
876 880
 }

+ 1
- 0
ios/RNCWebViewManager.m View File

@@ -59,6 +59,7 @@ RCT_EXPORT_VIEW_PROPERTY(dataDetectorTypes, WKDataDetectorTypes)
59 59
 #endif
60 60
 RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
61 61
 RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
62
+RCT_EXPORT_VIEW_PROPERTY(autoManageStatusBarEnabled, BOOL)
62 63
 RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL)
63 64
 RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
64 65
 RCT_EXPORT_VIEW_PROPERTY(incognito, BOOL)

+ 8
- 0
src/WebViewTypes.ts View File

@@ -257,6 +257,7 @@ export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
257 257
   allowsInlineMediaPlayback?: boolean;
258 258
   allowsLinkPreview?: boolean;
259 259
   automaticallyAdjustContentInsets?: boolean;
260
+  autoManageStatusBarEnabled?: boolean;
260 261
   bounces?: boolean;
261 262
   contentInset?: ContentInsetProp;
262 263
   contentInsetAdjustmentBehavior?:
@@ -415,6 +416,13 @@ export interface IOSWebViewProps extends WebViewSharedProps {
415 416
    */
416 417
   sharedCookiesEnabled?: boolean;
417 418
 
419
+  /**
420
+   * Set true if StatusBar should be light when user watch video fullscreen.
421
+   * The default value is `true`.
422
+   * @platform ios
423
+   */
424
+  autoManageStatusBarEnabled?: boolean;
425
+
418 426
   /**
419 427
    * A Boolean value that determines whether scrolling is disabled in a particular direction.
420 428
    * The default value is `true`.