Class: Ruflet::UI::Controls::RufletComponents::WebViewControl
- Defined in:
- lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb
Overview
WebView control — parity with Flet’s WebView (flet.dev/docs/controls/webview/).
Properties: url, bgcolor, prevent_links, plus the usual layout props. Events: on_page_started, on_page_ended, on_web_resource_error,
on_progress, on_url_change, on_scroll, on_console_message,
on_javascript_alert_dialog.
Methods (invoked over the wire on a mounted control): reload, go_back,
go_forward, can_go_back, can_go_forward, run_javascript, load_html,
load_request, load_file, scroll_to, scroll_by, clear_cache,
clear_local_storage, enable_zoom, disable_zoom, set_javascript_mode,
get_current_url, get_title, get_user_agent.
Platform note: the native webview (and therefore run_javascript and the events/methods) runs on iOS, Android and macOS. On web it falls back to an <iframe>, which cannot run the methods and which most external sites block via X-Frame-Options/CSP — embed your own same-origin pages there.
Constant Summary collapse
- TYPE =
"WebView".freeze
- WIRE =
"WebView".freeze
Constants inherited from Control
Instance Attribute Summary
Attributes inherited from Control
#children, #id, #props, #runtime_page, #type, #wire_id
Instance Method Summary collapse
- #can_go_back(timeout: 10, &on_result) ⇒ Object
- #can_go_forward(timeout: 10, &on_result) ⇒ Object
-
#clear_cache ⇒ Object
— Storage / zoom ———————————————-.
- #clear_local_storage ⇒ Object
- #disable_zoom ⇒ Object
- #enable_zoom ⇒ Object
-
#get_current_url(timeout: 10, &on_result) ⇒ Object
— Introspection (result delivered to the block) —————.
- #get_title(timeout: 10, &on_result) ⇒ Object
- #get_user_agent(timeout: 10, &on_result) ⇒ Object
- #go_back ⇒ Object
- #go_forward ⇒ Object
-
#initialize(id: nil, bgcolor: nil, data: nil, enable_javascript: nil, expand: nil, height: nil, key: nil, method: nil, opacity: nil, prevent_links: nil, rtl: nil, tooltip: nil, url: nil, visible: nil, width: nil, on_page_ended: nil, on_page_started: nil, on_web_resource_error: nil, on_progress: nil, on_url_change: nil, on_scroll: nil, on_console_message: nil, on_javascript_alert_dialog: nil) ⇒ WebViewControl
constructor
A new instance of WebViewControl.
- #load_file(path) ⇒ Object
- #load_html(value, base_url: nil) ⇒ Object
-
#load_request(url, method: "get") ⇒ Object
— Loading content ———————————————.
-
#reload ⇒ Object
— Navigation ————————————————–.
-
#run_javascript(value) ⇒ Object
Run arbitrary JS inside the page — e.g.
- #scroll_by(x, y) ⇒ Object
-
#scroll_to(x, y) ⇒ Object
— Scrolling —————————————————.
- #set_javascript_mode(mode) ⇒ Object
Methods inherited from Control
#[], #[]=, #emit, generate_id, #has_handler?, #method_missing, #on, #respond_to_missing?, #to_patch
Constructor Details
#initialize(id: nil, bgcolor: nil, data: nil, enable_javascript: nil, expand: nil, height: nil, key: nil, method: nil, opacity: nil, prevent_links: nil, rtl: nil, tooltip: nil, url: nil, visible: nil, width: nil, on_page_ended: nil, on_page_started: nil, on_web_resource_error: nil, on_progress: nil, on_url_change: nil, on_scroll: nil, on_console_message: nil, on_javascript_alert_dialog: nil) ⇒ WebViewControl
Returns a new instance of WebViewControl.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 28 def initialize(id: nil, bgcolor: nil, data: nil, enable_javascript: nil, expand: nil, height: nil, key: nil, method: nil, opacity: nil, prevent_links: nil, rtl: nil, tooltip: nil, url: nil, visible: nil, width: nil, on_page_ended: nil, on_page_started: nil, on_web_resource_error: nil, on_progress: nil, on_url_change: nil, on_scroll: nil, on_console_message: nil, on_javascript_alert_dialog: nil) props = {} props[:bgcolor] = bgcolor unless bgcolor.nil? props[:data] = data unless data.nil? props[:enable_javascript] = enable_javascript unless enable_javascript.nil? props[:expand] = unless .nil? props[:height] = height unless height.nil? props[:key] = key unless key.nil? props[:method] = method unless method.nil? props[:opacity] = opacity unless opacity.nil? props[:prevent_links] = prevent_links unless prevent_links.nil? props[:rtl] = rtl unless rtl.nil? props[:tooltip] = tooltip unless tooltip.nil? props[:url] = url unless url.nil? props[:visible] = visible unless visible.nil? props[:width] = width unless width.nil? props[:on_page_ended] = on_page_ended unless on_page_ended.nil? props[:on_page_started] = on_page_started unless on_page_started.nil? props[:on_web_resource_error] = on_web_resource_error unless on_web_resource_error.nil? props[:on_progress] = on_progress unless on_progress.nil? props[:on_url_change] = on_url_change unless on_url_change.nil? props[:on_scroll] = on_scroll unless on_scroll.nil? props[:on_console_message] = unless .nil? props[:on_javascript_alert_dialog] = on_javascript_alert_dialog unless on_javascript_alert_dialog.nil? super(type: TYPE, id: id, **props) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Ruflet::Control
Instance Method Details
#can_go_back(timeout: 10, &on_result) ⇒ Object
66 67 68 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 66 def can_go_back(timeout: 10, &on_result) invoke_webview_method("can_go_back", timeout: timeout, on_result: on_result) end |
#can_go_forward(timeout: 10, &on_result) ⇒ Object
70 71 72 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 70 def can_go_forward(timeout: 10, &on_result) invoke_webview_method("can_go_forward", timeout: timeout, on_result: on_result) end |
#clear_cache ⇒ Object
— Storage / zoom ———————————————-
115 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 115 def clear_cache = invoke_webview_method("clear_cache") |
#clear_local_storage ⇒ Object
116 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 116 def clear_local_storage = invoke_webview_method("clear_local_storage") |
#disable_zoom ⇒ Object
118 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 118 def disable_zoom = invoke_webview_method("disable_zoom") |
#enable_zoom ⇒ Object
117 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 117 def enable_zoom = invoke_webview_method("enable_zoom") |
#get_current_url(timeout: 10, &on_result) ⇒ Object
— Introspection (result delivered to the block) —————
122 123 124 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 122 def get_current_url(timeout: 10, &on_result) invoke_webview_method("get_current_url", timeout: timeout, on_result: on_result) end |
#get_title(timeout: 10, &on_result) ⇒ Object
126 127 128 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 126 def get_title(timeout: 10, &on_result) invoke_webview_method("get_title", timeout: timeout, on_result: on_result) end |
#get_user_agent(timeout: 10, &on_result) ⇒ Object
130 131 132 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 130 def get_user_agent(timeout: 10, &on_result) invoke_webview_method("get_user_agent", timeout: timeout, on_result: on_result) end |
#go_back ⇒ Object
63 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 63 def go_back = invoke_webview_method("go_back") |
#go_forward ⇒ Object
64 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 64 def go_forward = invoke_webview_method("go_forward") |
#load_file(path) ⇒ Object
86 87 88 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 86 def load_file(path) invoke_webview_method("load_file", { "path" => path.to_s }) end |
#load_html(value, base_url: nil) ⇒ Object
80 81 82 83 84 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 80 def load_html(value, base_url: nil) args = { "value" => value.to_s } args["base_url"] = base_url.to_s unless base_url.nil? invoke_webview_method("load_html", args) end |
#load_request(url, method: "get") ⇒ Object
— Loading content ———————————————
76 77 78 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 76 def load_request(url, method: "get") invoke_webview_method("load_request", { "url" => url.to_s, "method" => method.to_s }) end |
#reload ⇒ Object
— Navigation ————————————————–
62 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 62 def reload = invoke_webview_method("reload") |
#run_javascript(value) ⇒ Object
Run arbitrary JS inside the page — e.g. hide a node so a native control can take its place:
webview.run_javascript("document.getElementById('banner').remove()")
95 96 97 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 95 def run_javascript(value) invoke_webview_method("run_javascript", { "value" => value.to_s }) end |
#scroll_by(x, y) ⇒ Object
109 110 111 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 109 def scroll_by(x, y) invoke_webview_method("scroll_by", { "x" => x.to_i, "y" => y.to_i }) end |
#scroll_to(x, y) ⇒ Object
— Scrolling —————————————————
105 106 107 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 105 def scroll_to(x, y) invoke_webview_method("scroll_to", { "x" => x.to_i, "y" => y.to_i }) end |
#set_javascript_mode(mode) ⇒ Object
99 100 101 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 99 def set_javascript_mode(mode) invoke_webview_method("set_javascript_mode", { "mode" => mode.to_s }) end |