Browse Source

Attempting to add multiple message handlers.

Joe Carioti 5 years ago
parent
commit
55d6bc3ecc
3 changed files with 9 additions and 1 deletions
  1. 1
    0
      ios/RNCWebView.h
  2. 7
    1
      ios/RNCWebView.m
  3. 1
    0
      ios/RNCWebViewManager.m

+ 1
- 0
ios/RNCWebView.h View File

@@ -29,6 +29,7 @@
29 29
 @property (nonatomic, weak) id<RNCWebViewDelegate> _Nullable delegate;
30 30
 @property (nonatomic, copy) NSDictionary * _Nullable source;
31 31
 @property (nonatomic, assign) BOOL messagingEnabled;
32
+@property (nonatomic, copy) NSArray  * _Nullable messageHandlers;
32 33
 @property (nonatomic, copy) NSString * _Nullable injectedJavaScript;
33 34
 @property (nonatomic, copy) NSString * _Nullable injectedJavaScriptBeforeContentLoaded;
34 35
 @property (nonatomic, assign) BOOL scrollEnabled;

+ 7
- 1
ios/RNCWebView.m View File

@@ -188,6 +188,12 @@ static NSDictionary* customCertificatesForHost;
188 188
     [wkWebViewConfig.userContentController addUserScript:script];
189 189
 
190 190
     if (_messagingEnabled) {
191
+        for (NSString *handler in _messageHandlers)
192
+        {
193
+            [wkWebViewConfig.userContentController addScriptMessageHandler:[[RNCWeakScriptMessageDelegate alloc] initWithDelegate:self]
194
+            name:handler];
195
+        }
196
+        
191 197
       [wkWebViewConfig.userContentController addScriptMessageHandler:[[RNCWeakScriptMessageDelegate alloc] initWithDelegate:self]
192 198
                                                                 name:MessageHandlerName];
193 199
 
@@ -942,7 +948,7 @@ static NSDictionary* customCertificatesForHost;
942 948
         _onHttpError(event);
943 949
       }
944 950
     }
945
-  }  
951
+  }
946 952
 
947 953
   decisionHandler(WKNavigationResponsePolicyAllow);
948 954
 }

+ 1
- 0
ios/RNCWebViewManager.m View File

@@ -79,6 +79,7 @@ RCT_EXPORT_VIEW_PROPERTY(contentInsetAdjustmentBehavior, UIScrollViewContentInse
79 79
  * Expose methods to enable messaging the webview.
80 80
  */
81 81
 RCT_EXPORT_VIEW_PROPERTY(messagingEnabled, BOOL)
82
+RCT_EXPORT_VIEW_PROPERTY(messageHandlers, NSArray)
82 83
 RCT_EXPORT_VIEW_PROPERTY(onMessage, RCTDirectEventBlock)
83 84
 RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
84 85