mirror of
https://github.com/google/blockly.git
synced 2026-01-07 17:10:11 +01:00
Doc comments and style corrections.
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
//
|
|
||||||
// ViewController.swift
|
// ViewController.swift
|
||||||
// Blockly WebView
|
// Blockly WebView UI controller.
|
||||||
//
|
//
|
||||||
// Created by Andrew Marshall on 8/7/18.
|
// Created by Andrew Marshall on 8/7/18.
|
||||||
// Copyright © 2018 Google. All rights reserved.
|
// Copyright © 2018 Google. All rights reserved.
|
||||||
@@ -9,6 +8,9 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import WebKit
|
import WebKit
|
||||||
|
|
||||||
|
|
||||||
|
/// A basic ViewController for a WebView.
|
||||||
|
/// It handles the initial page load, and functions like window.prompt().
|
||||||
class ViewController: UIViewController, WKUIDelegate {
|
class ViewController: UIViewController, WKUIDelegate {
|
||||||
/// The name used to reference this iOS object when executing callbacks from the JS code.
|
/// The name used to reference this iOS object when executing callbacks from the JS code.
|
||||||
/// If this value is changed, it should also be changed in the `CODE_GENERATOR_BRIDGE_JS` file.
|
/// If this value is changed, it should also be changed in the `CODE_GENERATOR_BRIDGE_JS` file.
|
||||||
@@ -16,6 +18,7 @@ class ViewController: UIViewController, WKUIDelegate {
|
|||||||
|
|
||||||
@IBOutlet weak var webView: WKWebView!
|
@IBOutlet weak var webView: WKWebView!
|
||||||
|
|
||||||
|
/// Additional setup after loading the UI NIB.
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
webView.uiDelegate = self
|
webView.uiDelegate = self
|
||||||
@@ -23,12 +26,17 @@ class ViewController: UIViewController, WKUIDelegate {
|
|||||||
loadWebContent()
|
loadWebContent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Load the root HTML page into the webview.
|
||||||
func loadWebContent() {
|
func loadWebContent() {
|
||||||
if let htmlUrl = Bundle.main.url(forResource: "webview", withExtension: "html", subdirectory: "Blockly") {
|
if let htmlUrl = Bundle.main.url(forResource: "webview", withExtension: "html",
|
||||||
|
subdirectory: "Blockly") {
|
||||||
webView.load(URLRequest.init(url: htmlUrl))
|
webView.load(URLRequest.init(url: htmlUrl))
|
||||||
|
} else {
|
||||||
|
NSLog("Failed to load HTML. Could not find resource.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Handle window.alert() with a native dialog.
|
||||||
func webView(_ webView: WKWebView,
|
func webView(_ webView: WKWebView,
|
||||||
runJavaScriptAlertPanelWithMessage message: String,
|
runJavaScriptAlertPanelWithMessage message: String,
|
||||||
initiatedByFrame frame: WKFrameInfo,
|
initiatedByFrame frame: WKFrameInfo,
|
||||||
@@ -44,6 +52,7 @@ class ViewController: UIViewController, WKUIDelegate {
|
|||||||
completionHandler()
|
completionHandler()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Handle window.confirm() with a native dialog.
|
||||||
func webView(_ webView: WKWebView,
|
func webView(_ webView: WKWebView,
|
||||||
runJavaScriptConfirmPanelWithMessage message: String,
|
runJavaScriptConfirmPanelWithMessage message: String,
|
||||||
initiatedByFrame frame: WKFrameInfo,
|
initiatedByFrame frame: WKFrameInfo,
|
||||||
@@ -62,13 +71,15 @@ class ViewController: UIViewController, WKUIDelegate {
|
|||||||
alert.addAction(ok)
|
alert.addAction(ok)
|
||||||
|
|
||||||
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel button title")
|
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel button title")
|
||||||
let cancel = UIAlertAction(title: cancelTitle, style: .default) { (action: UIAlertAction) -> Void in
|
let cancel = UIAlertAction(title: cancelTitle, style: .default) {
|
||||||
|
(action: UIAlertAction) -> Void in
|
||||||
closeAndHandle(false)
|
closeAndHandle(false)
|
||||||
}
|
}
|
||||||
alert.addAction(cancel)
|
alert.addAction(cancel)
|
||||||
present(alert, animated: true)
|
present(alert, animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Handle window.prompt() with a native dialog.
|
||||||
func webView(_ webView: WKWebView,
|
func webView(_ webView: WKWebView,
|
||||||
runJavaScriptTextInputPanelWithPrompt prompt: String,
|
runJavaScriptTextInputPanelWithPrompt prompt: String,
|
||||||
defaultText: String?,
|
defaultText: String?,
|
||||||
@@ -96,10 +107,5 @@ class ViewController: UIViewController, WKUIDelegate {
|
|||||||
|
|
||||||
present(alert, animated: true)
|
present(alert, animated: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func didReceiveMemoryWarning() {
|
|
||||||
super.didReceiveMemoryWarning()
|
|
||||||
// Dispose of any resources that can be recreated.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user