@@ -74,7 +74,7 @@ - (NSString *)stringFromAction:(SEL) action {
7474 @" toggleUnderline:" : @" underline" ,
7575 @" _share:" : @" share" ,
7676 };
77-
77+
7878 return map[sel] ?: sel;
7979}
8080
@@ -86,7 +86,7 @@ - (BOOL)canPerformAction:(SEL)action
8686 return NO ;
8787 }
8888 }
89-
89+
9090 if (!self.menuItems ) {
9191 return [super canPerformAction: action withSender: sender];
9292 }
@@ -143,6 +143,8 @@ @implementation RNCWebViewImpl
143143 UIStatusBarStyle _savedStatusBarStyle;
144144#endif // !TARGET_OS_OSX
145145 BOOL _savedStatusBarHidden;
146+ // Disables the display of prompts during site navigation/loading
147+ BOOL _disablePromptDuringLoading;
146148
147149#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
148150 UIScrollViewContentInsetAdjustmentBehavior _savedContentInsetAdjustmentBehavior;
@@ -177,6 +179,7 @@ - (instancetype)initWithFrame:(CGRect)frame
177179 _injectedJavaScriptForMainFrameOnly = YES ;
178180 _injectedJavaScriptBeforeContentLoaded = nil ;
179181 _injectedJavaScriptBeforeContentLoadedForMainFrameOnly = YES ;
182+ _disablePromptDuringLoading = YES ;
180183
181184#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
182185 _savedContentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
@@ -649,6 +652,7 @@ -(void)keyboardDisplacementFix
649652- (void )observeValueForKeyPath : (NSString *)keyPath ofObject : (id )object change : (NSDictionary <NSKeyValueChangeKey,id> *)change context : (void *)context {
650653 if ([keyPath isEqual: @" estimatedProgress" ] && object == self.webView ) {
651654 if (_onLoadingProgress){
655+ _disablePromptDuringLoading = YES ;
652656 NSMutableDictionary <NSString *, id > *event = [self baseEvent ];
653657 [event addEntriesFromDictionary: @{@" progress" :[NSNumber numberWithDouble: self .webView.estimatedProgress]}];
654658 _onLoadingProgress (event);
@@ -726,6 +730,7 @@ - (void)userContentController:(WKUserContentController *)userContentController
726730 NSMutableDictionary <NSString *, id > *event = [self baseEvent ];
727731 [event addEntriesFromDictionary: @{@" navigationType" : message.body }];
728732 _onLoadingFinish (event);
733+ _disablePromptDuringLoading = NO ;
729734 }
730735 } else if ([message.name isEqualToString: MessageHandlerName]) {
731736 if (_onMessage) {
@@ -1150,44 +1155,48 @@ - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSStr
11501155 * prompt
11511156 */
11521157- (void )webView : (WKWebView *)webView runJavaScriptTextInputPanelWithPrompt : (NSString *)prompt defaultText : (NSString *)defaultText initiatedByFrame : (WKFrameInfo *)frame completionHandler : (void (^)(NSString *))completionHandler {
1158+ if (!_disablePromptDuringLoading) {
11531159#if !TARGET_OS_OSX
1154- UIAlertController *alert = [UIAlertController alertControllerWithTitle: @" " message: prompt preferredStyle: UIAlertControllerStyleAlert];
1155- [alert addTextFieldWithConfigurationHandler: ^(UITextField *textField) {
1156- textField.text = defaultText;
1157- }];
1158- UIAlertAction *okAction = [UIAlertAction actionWithTitle: @" Ok" style: UIAlertActionStyleDefault handler: ^(UIAlertAction *action) {
1159- completionHandler ([[alert.textFields lastObject ] text ]);
1160- }];
1161- [alert addAction: okAction];
1162- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle: @" Cancel" style: UIAlertActionStyleCancel handler: ^(UIAlertAction *action) {
1163- completionHandler (nil );
1164- }];
1165- [alert addAction: cancelAction];
1166- alert.preferredAction = okAction;
1167- [[self topViewController ] presentViewController: alert animated: YES completion: NULL ];
1168- #else
1169- NSAlert *alert = [[NSAlert alloc ] init ];
1170- [alert setMessageText: prompt];
1171-
1172- const NSRect RCTSingleTextFieldFrame = NSMakeRect (0.0 , 0.0 , 275.0 , 22.0 );
1173- NSTextField *textField = [[NSTextField alloc ] initWithFrame: RCTSingleTextFieldFrame];
1174- textField.cell .scrollable = YES ;
1175- if (@available (macOS 10.11 , *)) {
1176- textField.maximumNumberOfLines = 1 ;
1177- }
1178- textField.stringValue = defaultText;
1179- [alert setAccessoryView: textField];
1180-
1181- [alert addButtonWithTitle: NSLocalizedString(@" OK" , @" OK button" )];
1182- [alert addButtonWithTitle: NSLocalizedString(@" Cancel" , @" Cancel button" )];
1183- [alert beginSheetModalForWindow: [NSApp keyWindow ] completionHandler: ^(NSModalResponse response) {
1184- if (response == NSAlertFirstButtonReturn ) {
1185- completionHandler ([textField stringValue ]);
1186- } else {
1160+ UIAlertController *alert = [UIAlertController alertControllerWithTitle: @" " message: prompt preferredStyle: UIAlertControllerStyleAlert];
1161+ [alert addTextFieldWithConfigurationHandler: ^(UITextField *textField) {
1162+ textField.text = defaultText;
1163+ }];
1164+ UIAlertAction *okAction = [UIAlertAction actionWithTitle: @" Ok" style: UIAlertActionStyleDefault handler: ^(UIAlertAction *action) {
1165+ completionHandler ([[alert.textFields lastObject ] text ]);
1166+ }];
1167+ [alert addAction: okAction];
1168+ UIAlertAction *cancelAction = [UIAlertAction actionWithTitle: @" Cancel" style: UIAlertActionStyleCancel handler: ^(UIAlertAction *action) {
11871169 completionHandler (nil );
1170+ }];
1171+ [alert addAction: cancelAction];
1172+ alert.preferredAction = okAction;
1173+ [[self topViewController ] presentViewController: alert animated: YES completion: NULL ];
1174+ #else
1175+ NSAlert *alert = [[NSAlert alloc ] init ];
1176+ [alert setMessageText: prompt];
1177+
1178+ const NSRect RCTSingleTextFieldFrame = NSMakeRect (0.0 , 0.0 , 275.0 , 22.0 );
1179+ NSTextField *textField = [[NSTextField alloc ] initWithFrame: RCTSingleTextFieldFrame];
1180+ textField.cell .scrollable = YES ;
1181+ if (@available (macOS 10.11 , *)) {
1182+ textField.maximumNumberOfLines = 1 ;
11881183 }
1189- }];
1184+ textField.stringValue = defaultText;
1185+ [alert setAccessoryView: textField];
1186+
1187+ [alert addButtonWithTitle: NSLocalizedString(@" OK" , @" OK button" )];
1188+ [alert addButtonWithTitle: NSLocalizedString(@" Cancel" , @" Cancel button" )];
1189+ [alert beginSheetModalForWindow: [NSApp keyWindow ] completionHandler: ^(NSModalResponse response) {
1190+ if (response == NSAlertFirstButtonReturn ) {
1191+ completionHandler ([textField stringValue ]);
1192+ } else {
1193+ completionHandler (nil );
1194+ }
1195+ }];
11901196#endif // !TARGET_OS_OSX
1197+ } else {
1198+ completionHandler (nil );
1199+ }
11911200}
11921201
11931202#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 /* iOS 15 */
@@ -1480,6 +1489,7 @@ - (void)webView:(WKWebView *)webView
14801489 }
14811490
14821491 if (_onLoadingFinish) {
1492+ _disablePromptDuringLoading = NO ;
14831493 _onLoadingFinish ([self baseEvent ]);
14841494 }
14851495}
0 commit comments