Module: ProMotion::WKWebScreenModule
- Included in:
- WebScreenModule
- Defined in:
- lib/ProMotion/web/wk_web_screen_module.rb
Instance Method Summary collapse
- #back_forward_list ⇒ Object
- #evaluate(js, &block) ⇒ Object
- #evaluate_async(js, &block) ⇒ Object
- #go_to_item(item) ⇒ Object
- #progress ⇒ Object
- #web_view_setup ⇒ Object
-
#webView(view, didFinishNavigation: navigation) ⇒ Object
CocoaTouch methods.
Instance Method Details
#back_forward_list ⇒ Object
44 45 46 |
# File 'lib/ProMotion/web/wk_web_screen_module.rb', line 44 def back_forward_list self.webview.backForwardList end |
#evaluate(js, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ProMotion/web/wk_web_screen_module.rb', line 16 def evaluate(js, &block) if block evaluate_async(js) do |result, error| block.call(result) # ignore error end return end res = nil semaphore = Dispatch::Semaphore.new(0) # FIXME: this blocks and never returns evaluate_async(js) do |result, error| res = result semaphore.signal end semaphore.wait(Dispatch::TIME_FOREVER) return res end |
#evaluate_async(js, &block) ⇒ Object
34 35 36 37 38 |
# File 'lib/ProMotion/web/wk_web_screen_module.rb', line 34 def evaluate_async(js, &block) self.webview.evaluateJavaScript(js, completionHandler: -> (result, error) { block.call(result, error) }) end |
#go_to_item(item) ⇒ Object
40 41 42 |
# File 'lib/ProMotion/web/wk_web_screen_module.rb', line 40 def go_to_item(item) self.webview.goToBackForwardListItem(item) end |
#progress ⇒ Object
48 49 50 |
# File 'lib/ProMotion/web/wk_web_screen_module.rb', line 48 def progress self.webview.estimatedProgress end |
#web_view_setup ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/ProMotion/web/wk_web_screen_module.rb', line 3 def web_view_setup configuration = WKWebViewConfiguration.alloc.init configuration.dataDetectorTypes = data_detector_types frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) # FIXME: get this working: wkwebview = WKWebView.alloc.initWithFrame(frame, configuration: configuration) wkwebview = WKWebView.alloc.initWithFrame(frame) self.webview = add(wkwebview) self.webview.UIDelegate = self self.webview. = self self.webview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight self.webview.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal end |
#webView(view, didFinishNavigation: navigation) ⇒ Object
CocoaTouch methods
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ProMotion/web/wk_web_screen_module.rb', line 54 def webView(view, decidePolicyForNavigationAction: , decisionHandler: decisionHandler) request = .request nav_type = . if %w(http https).include?(request.URL.scheme) if self.external_links == true && nav_type == WKNavigationTypeLinkActivated if defined?(OpenInChromeController) open_in_chrome(request) else open_in_safari(request) end decisionHandler.call(WKNavigationActionPolicyCancel) # don't allow the web view to load the link return end end load_request_enable = true # return true by default for local file loading load_request_enable = !!on_request(request, nav_type) if self.respond_to?(:on_request) decisionHandler.call(load_request_enable ? WKNavigationActionPolicyAllow : WKNavigationActionPolicyCancel) end |