Pārlūkot izejas kodu

feat(iOS): add-javaScriptEnabled prop (#592)

* add-javaScriptEnabled-in-IOS

* Update WebViewTypes.ts
aksmfosef11 5 gadus atpakaļ
vecāks
revīzija
a28096bfe7
4 mainītis faili ar 14 papildinājumiem un 7 dzēšanām
  1. 1
    0
      ios/RNCWKWebView.h
  2. 5
    0
      ios/RNCWKWebView.m
  3. 1
    0
      src/WebView.ios.tsx
  4. 7
    7
      src/WebViewTypes.ts

+ 1
- 0
ios/RNCWKWebView.h Parādīt failu

@@ -45,6 +45,7 @@
45 45
 @property (nonatomic, copy) NSString *userAgent;
46 46
 @property (nonatomic, copy) NSString *applicationNameForUserAgent;
47 47
 @property (nonatomic, assign) BOOL cacheEnabled;
48
+@property (nonatomic, assign) BOOL javaScriptEnabled;
48 49
 @property (nonatomic, assign) BOOL allowsLinkPreview;
49 50
 @property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;
50 51
 @property (nonatomic, assign) BOOL showsVerticalScrollIndicator;

+ 5
- 0
ios/RNCWKWebView.m Parādīt failu

@@ -115,6 +115,11 @@ static NSURLCredential* clientAuthenticationCredential;
115 115
 {
116 116
   if (self.window != nil && _webView == nil) {
117 117
     WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new];
118
+    WKPreferences *prefs = [[WKPreferences alloc]init];
119
+    if (!_javaScriptEnabled) {
120
+      prefs.javaScriptEnabled = NO;
121
+      wkWebViewConfig.preferences = prefs;
122
+    }
118 123
     if (_incognito) {
119 124
       wkWebViewConfig.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
120 125
     } else if (_cacheEnabled) {

+ 1
- 0
src/WebView.ios.tsx Parādīt failu

@@ -63,6 +63,7 @@ const RNCWKWebView: typeof NativeWebViewIOS = requireNativeComponent(
63 63
 class WebView extends React.Component<IOSWebViewProps, State> {
64 64
   static defaultProps = {
65 65
     useWebKit: true,
66
+    javaScriptEnabled: true,
66 67
     cacheEnabled: true,
67 68
     originWhitelist: defaultOriginWhitelist,
68 69
     useSharedProcessPool: true,

+ 7
- 7
src/WebViewTypes.ts Parādīt failu

@@ -498,13 +498,6 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
498 498
    */
499 499
   urlPrefixesForDefaultIntent?: ReadonlyArray<string>;
500 500
 
501
-  /**
502
-   * Boolean value to enable JavaScript in the `WebView`. Used on Android only
503
-   * as JavaScript is enabled by default on iOS. The default value is `true`.
504
-   * @platform android
505
-   */
506
-  javaScriptEnabled?: boolean;
507
-
508 501
   /**
509 502
    * Boolean value to disable Hardware Acceleration in the `WebView`. Used on Android only
510 503
    * as Hardware Acceleration is a feature only for Android. The default value is `false`.
@@ -563,6 +556,13 @@ export interface WebViewSharedProps extends ViewProps {
563 556
    */
564 557
   source?: WebViewSource;
565 558
 
559
+  /**
560
+   * Boolean value to enable JavaScript in the `WebView`. Used on Android only
561
+   * as JavaScript is enabled by default on iOS. The default value is `true`.
562
+   * @platform android
563
+   */
564
+  javaScriptEnabled?: boolean;
565
+  
566 566
   /**
567 567
    * Function that returns a view to show if there's an error.
568 568
    */