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

+ 7
- 1
ios/RNCWebView.m View File

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

+ 1
- 0
ios/RNCWebViewManager.m View File

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