Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private WebView1 As WebView
Private WebViewExtras1 As WebViewExtras
Private WebChromeClient1 As DefaultWebChromeClient
Private JavascriptInterface1 As DefaultJavascriptInterface
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
JavascriptInterface1.Initialize
WebViewExtras1.Initialize(WebView1)
WebChromeClient1.Initialize("DefaultWebChromeClient1")
'Webview Acceleration
Dim jo As JavaObject = WebView1
jo.RunMethod("setLayerType", Array(2, Null))
WebViewExtras1.SetWebChromeClient(WebChromeClient1)
WebViewExtras1.addJavascriptInterface(JavascriptInterface1, "B4A")
End Sub
Sub B4XPage_Appear
WebView1.LoadUrl("https://www.b4x.com/")
End Sub
Private Sub WebView1_PageFinished (Url As String)
Dim bottom_of_page_hook_js As String = ($"
var bottom_reached = false;
window.addEventListener('scroll', function() {
const scrolledTo = window.scrollY + window.innerHeight;
const totalHeight = document.documentElement.scrollHeight;
if (scrolledTo >= totalHeight - 1 && bottom_reached == false) {
bottom_reached = true;
B4A.CallSub('WebView_PageAtBottom', true);
}
});
"$)
WebViewExtras1.ExecuteJavascript(bottom_of_page_hook_js)
End Sub
Sub WebView_PageAtBottom
MsgboxAsync("Bottom of WebView Page Reached!", "Test")
End Sub