Просмотр исходного кода

fix(iOS): Trigger _onContentProcessDidTerminate when removing webview from superview (#1378 by @pmusaraj)

[skip ci]
Penar Musaraj 4 лет назад
Родитель
Сommit
9240536afa
No account linked to committer's email address
1 измененных файлов: 17 добавлений и 13 удалений
  1. 17
    13
      apple/RNCWebView.m

+ 17
- 13
apple/RNCWebView.m Просмотреть файл

@@ -146,7 +146,7 @@ static NSDictionary* customCertificatesForHost;
146 146
     selector:@selector(appDidBecomeActive)
147 147
         name:UIApplicationDidBecomeActiveNotification
148 148
       object:nil];
149
-    
149
+
150 150
     [[NSNotificationCenter defaultCenter]addObserver:self
151 151
     selector:@selector(appWillResignActive)
152 152
         name:UIApplicationWillResignActiveNotification
@@ -174,7 +174,7 @@ static NSDictionary* customCertificatesForHost;
174 174
                                                selector:@selector(hideFullScreenVideoStatusBars)
175 175
                                                    name:UIWindowDidBecomeHiddenNotification
176 176
                                                  object:nil];
177
-      
177
+
178 178
   }
179 179
 #endif // !TARGET_OS_OSX
180 180
   return self;
@@ -242,7 +242,7 @@ static NSDictionary* customCertificatesForHost;
242 242
   if (_applicationNameForUserAgent) {
243 243
       wkWebViewConfig.applicationNameForUserAgent = [NSString stringWithFormat:@"%@ %@", wkWebViewConfig.applicationNameForUserAgent, _applicationNameForUserAgent];
244 244
   }
245
-  
245
+
246 246
   return wkWebViewConfig;
247 247
 }
248 248
 
@@ -307,6 +307,10 @@ static NSDictionary* customCertificatesForHost;
307 307
         _webView.scrollView.delegate = nil;
308 308
 #endif // !TARGET_OS_OSX
309 309
         _webView = nil;
310
+        if (_onContentProcessDidTerminate) {
311
+          NSMutableDictionary<NSString *, id> *event = [self baseEvent];
312
+          _onContentProcessDidTerminate(event);
313
+        }
310 314
     }
311 315
 
312 316
     [super removeFromSuperview];
@@ -1102,7 +1106,7 @@ static NSDictionary* customCertificatesForHost;
1102 1106
   if (_ignoreSilentHardwareSwitch) {
1103 1107
     [self forceIgnoreSilentHardwareSwitch:true];
1104 1108
   }
1105
-    
1109
+
1106 1110
   if (_onLoadingFinish) {
1107 1111
     _onLoadingFinish([self baseEvent]);
1108 1112
   }
@@ -1155,11 +1159,11 @@ static NSDictionary* customCertificatesForHost;
1155 1159
 
1156 1160
 - (void)setInjectedJavaScript:(NSString *)source {
1157 1161
   _injectedJavaScript = source;
1158
-  
1162
+
1159 1163
   self.atEndScript = source == nil ? nil : [[WKUserScript alloc] initWithSource:source
1160 1164
       injectionTime:WKUserScriptInjectionTimeAtDocumentEnd
1161 1165
     forMainFrameOnly:_injectedJavaScriptForMainFrameOnly];
1162
-  
1166
+
1163 1167
   if(_webView != nil){
1164 1168
     [self resetupScripts:_webView.configuration];
1165 1169
   }
@@ -1167,11 +1171,11 @@ static NSDictionary* customCertificatesForHost;
1167 1171
 
1168 1172
 - (void)setInjectedJavaScriptBeforeContentLoaded:(NSString *)source {
1169 1173
   _injectedJavaScriptBeforeContentLoaded = source;
1170
-  
1174
+
1171 1175
   self.atStartScript = source == nil ? nil : [[WKUserScript alloc] initWithSource:source
1172 1176
        injectionTime:WKUserScriptInjectionTimeAtDocumentStart
1173 1177
     forMainFrameOnly:_injectedJavaScriptBeforeContentLoadedForMainFrameOnly];
1174
-  
1178
+
1175 1179
   if(_webView != nil){
1176 1180
     [self resetupScripts:_webView.configuration];
1177 1181
   }
@@ -1189,7 +1193,7 @@ static NSDictionary* customCertificatesForHost;
1189 1193
 
1190 1194
 - (void)setMessagingEnabled:(BOOL)messagingEnabled {
1191 1195
   _messagingEnabled = messagingEnabled;
1192
-  
1196
+
1193 1197
   self.postMessageScript = _messagingEnabled ?
1194 1198
   [
1195 1199
    [WKUserScript alloc]
@@ -1209,7 +1213,7 @@ static NSDictionary* customCertificatesForHost;
1209 1213
    forMainFrameOnly:YES
1210 1214
    ] :
1211 1215
   nil;
1212
-  
1216
+
1213 1217
   if(_webView != nil){
1214 1218
     [self resetupScripts:_webView.configuration];
1215 1219
   }
@@ -1218,7 +1222,7 @@ static NSDictionary* customCertificatesForHost;
1218 1222
 - (void)resetupScripts:(WKWebViewConfiguration *)wkWebViewConfig {
1219 1223
   [wkWebViewConfig.userContentController removeAllUserScripts];
1220 1224
   [wkWebViewConfig.userContentController removeScriptMessageHandlerForName:MessageHandlerName];
1221
-  
1225
+
1222 1226
   NSString *html5HistoryAPIShimSource = [NSString stringWithFormat:
1223 1227
     @"(function(history) {\n"
1224 1228
     "  function notify(type) {\n"
@@ -1241,7 +1245,7 @@ static NSDictionary* customCertificatesForHost;
1241 1245
   ];
1242 1246
   WKUserScript *script = [[WKUserScript alloc] initWithSource:html5HistoryAPIShimSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES];
1243 1247
   [wkWebViewConfig.userContentController addUserScript:script];
1244
-  
1248
+
1245 1249
   if(_sharedCookiesEnabled) {
1246 1250
     // More info to sending cookies with WKWebView
1247 1251
     // https://stackoverflow.com/questions/26573137/can-i-set-the-cookies-to-be-used-by-a-wkwebview/26577303#26577303
@@ -1303,7 +1307,7 @@ static NSDictionary* customCertificatesForHost;
1303 1307
       [wkWebViewConfig.userContentController addUserScript:cookieInScript];
1304 1308
     }
1305 1309
   }
1306
-  
1310
+
1307 1311
   if(_messagingEnabled){
1308 1312
     if (self.postMessageScript){
1309 1313
       [wkWebViewConfig.userContentController addScriptMessageHandler:[[RNCWeakScriptMessageDelegate alloc] initWithDelegate:self]