fix(iOS): Align look and feel of Window.prompt() to Mobile Safari (#677)

This commit is contained in:
Peter Ho 2019-08-02 21:00:05 +12:00 committed by Thibault Malbranche
parent 234075c524
commit 231100dc3c
1 changed files with 9 additions and 4 deletions

View File

@ -643,12 +643,17 @@ static NSURLCredential* clientAuthenticationCredential;
- (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString *))completionHandler{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:prompt preferredStyle:UIAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.textColor = [UIColor lightGrayColor];
textField.placeholder = defaultText;
textField.text = defaultText;
}];
[alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
completionHandler([[alert.textFields lastObject] text]);
}]];
}];
[alert addAction:okAction];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
completionHandler(nil);
}];
[alert addAction:cancelAction];
alert.preferredAction = okAction;
[[self topViewController] presentViewController:alert animated:YES completion:NULL];
}