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 (https://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 runs on iOS, Android, macOS, Windows, and Linux. Linux distributions must provide WebKitGTK 4.1. On web it uses an iframe, so browser cross-origin restrictions still apply.
Constant Summary collapse
- TYPE =
"WebView".freeze
- WIRE =
"WebView".freeze
- KEYWORDS =
[].freeze
Constants inherited from Control
Control::HOST_EXPANDED_TYPES, Control::SCHEMA_METADATA_CACHE
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, **props) ⇒ 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
#attach_handler, #emit, generate_id, #has_handler?, #merge_props, #on, #to_patch
Constructor Details
#initialize(id: nil, **props) ⇒ WebViewControl
Returns a new instance of WebViewControl.
28 29 30 31 32 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 28 def initialize(id: nil, **props) compact = {} props.each { |key, value| compact[key] = value unless value.nil? } super(type: TYPE, id: id, **compact) end |
Instance Method Details
#can_go_back(timeout: 10, &on_result) ⇒ Object
40 41 42 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 40 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
44 45 46 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 44 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 ----------------------------------------------
89 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 89 def clear_cache = invoke_webview_method("clear_cache") |
#clear_local_storage ⇒ Object
90 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 90 def clear_local_storage = invoke_webview_method("clear_local_storage") |
#disable_zoom ⇒ Object
92 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 92 def disable_zoom = invoke_webview_method("disable_zoom") |
#enable_zoom ⇒ Object
91 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 91 def enable_zoom = invoke_webview_method("enable_zoom") |
#get_current_url(timeout: 10, &on_result) ⇒ Object
--- Introspection (result delivered to the block) ---------------
96 97 98 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 96 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
100 101 102 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 100 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
104 105 106 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 104 def get_user_agent(timeout: 10, &on_result) invoke_webview_method("get_user_agent", timeout: timeout, on_result: on_result) end |
#go_back ⇒ Object
37 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 37 def go_back = invoke_webview_method("go_back") |
#go_forward ⇒ Object
38 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 38 def go_forward = invoke_webview_method("go_forward") |
#load_file(path) ⇒ Object
60 61 62 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 60 def load_file(path) invoke_webview_method("load_file", { "path" => path.to_s }) end |
#load_html(value, base_url: nil) ⇒ Object
54 55 56 57 58 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 54 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 ---------------------------------------------
50 51 52 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 50 def load_request(url, method: "get") invoke_webview_method("load_request", { "url" => url.to_s, "method" => method.to_s }) end |
#reload ⇒ Object
--- Navigation --------------------------------------------------
36 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 36 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()")
69 70 71 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 69 def run_javascript(value) invoke_webview_method("run_javascript", { "value" => value.to_s }) end |
#scroll_by(x, y) ⇒ Object
83 84 85 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 83 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 ---------------------------------------------------
79 80 81 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 79 def scroll_to(x, y) invoke_webview_method("scroll_to", { "x" => x.to_i, "y" => y.to_i }) end |
#set_javascript_mode(mode) ⇒ Object
73 74 75 |
# File 'lib/ruflet_ui/ruflet/ui/controls/materials/webview_control.rb', line 73 def set_javascript_mode(mode) invoke_webview_method("set_javascript_mode", { "mode" => mode.to_s }) end |