Skip to content

Commit ef14713

Browse files
fix: also enable predictive back navigation if hardwareBack is false
Context: If it is false, it means we want to simply close the WebView and not navigate to the previous URL. This means that we can simply use predictive back navigation instead of handling this case in the `onBackPressedCallback` References: https://outsystemsrd.atlassian.net/browse/RMET-4335
1 parent ff49db6 commit ef14713

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

src/main/java/com.outsystems.plugins.inappbrowser/osinappbrowserlib/views/OSIABWebViewActivity.kt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,8 @@ class OSIABWebViewActivity : AppCompatActivity() {
110110
onBackPressedCallback = object : OnBackPressedCallback(true) {
111111
override fun handleOnBackPressed() {
112112
if (!webView.canGoBack()) return
113-
if (options.hardwareBack) {
114-
hideErrorScreen()
115-
webView.goBack()
116-
} else {
117-
// if hardwareBack is false, we want to finish the activity (close the WebView)
118-
// and not go back in the WebView history
119-
finish()
120-
}
113+
hideErrorScreen()
114+
webView.goBack()
121115
}
122116
}
123117
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
@@ -403,9 +397,10 @@ class OSIABWebViewActivity : AppCompatActivity() {
403397
override fun doUpdateVisitedHistory(view: WebView?, url: String?, isReload: Boolean) {
404398
// to implement predictive back navigation
405399
// we only want to have the callback enabled if the WebView can go back to previous page
400+
// and if the hardwareBack option is enabled
406401
// if not, we want the system to handle the back press, which will enable the
407-
// predictive back animation
408-
onBackPressedCallback.isEnabled = webView.canGoBack()
402+
// predictive back animation and simply close the WebView
403+
onBackPressedCallback.isEnabled = webView.canGoBack() && options.hardwareBack
409404
}
410405

411406
/**

0 commit comments

Comments
 (0)