Browse Source

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

* add-javaScriptEnabled-in-IOS

* Update WebViewTypes.ts
aksmfosef11 5 years ago
parent
commit
a28096bfe7
4 changed files with 14 additions and 7 deletions
  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 View File

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

+ 5
- 0
ios/RNCWKWebView.m View File

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

+ 1
- 0
src/WebView.ios.tsx View File

63
 class WebView extends React.Component<IOSWebViewProps, State> {
63
 class WebView extends React.Component<IOSWebViewProps, State> {
64
   static defaultProps = {
64
   static defaultProps = {
65
     useWebKit: true,
65
     useWebKit: true,
66
+    javaScriptEnabled: true,
66
     cacheEnabled: true,
67
     cacheEnabled: true,
67
     originWhitelist: defaultOriginWhitelist,
68
     originWhitelist: defaultOriginWhitelist,
68
     useSharedProcessPool: true,
69
     useSharedProcessPool: true,

+ 7
- 7
src/WebViewTypes.ts View File

498
    */
498
    */
499
   urlPrefixesForDefaultIntent?: ReadonlyArray<string>;
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
    * Boolean value to disable Hardware Acceleration in the `WebView`. Used on Android only
502
    * Boolean value to disable Hardware Acceleration in the `WebView`. Used on Android only
510
    * as Hardware Acceleration is a feature only for Android. The default value is `false`.
503
    * as Hardware Acceleration is a feature only for Android. The default value is `false`.
563
    */
556
    */
564
   source?: WebViewSource;
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
    * Function that returns a view to show if there's an error.
567
    * Function that returns a view to show if there's an error.
568
    */
568
    */