ソースを参照

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

Peter Ho 5 年 前
コミット
231100dc3c
共有1 個のファイルを変更した9 個の追加4 個の削除を含む
  1. 9
    4
      ios/RNCWKWebView.m

+ 9
- 4
ios/RNCWKWebView.m ファイルの表示

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