From 3c832a254f81b203381003064fd0bb692b2a8525 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Mon, 28 Jul 2025 11:19:10 -0300 Subject: [PATCH 1/7] feat: migrate from onBackPressed to OnBackPressedCallback Context: For apps targeting 16, onBackPressed no longer works, as it is no longer called. Instead, apps should migrate to the new back navigation APIs - for example, OnBackPressedCallback. More info here: https://developer.android.com/about/versions/16/behavior-changes-16#predictive-back References: https://outsystemsrd.atlassian.net/browse/RMET-4335 --- .../views/OSIABWebViewActivity.kt | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/com.outsystems.plugins.inappbrowser/osinappbrowserlib/views/OSIABWebViewActivity.kt b/src/main/java/com.outsystems.plugins.inappbrowser/osinappbrowserlib/views/OSIABWebViewActivity.kt index a739ab4..3d48c13 100644 --- a/src/main/java/com.outsystems.plugins.inappbrowser/osinappbrowserlib/views/OSIABWebViewActivity.kt +++ b/src/main/java/com.outsystems.plugins.inappbrowser/osinappbrowserlib/views/OSIABWebViewActivity.kt @@ -24,6 +24,7 @@ import android.widget.Button import android.widget.ImageButton import android.widget.LinearLayout import android.widget.TextView +import androidx.activity.OnBackPressedCallback import androidx.activity.enableEdgeToEdge import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity @@ -103,6 +104,20 @@ class OSIABWebViewActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + if (options.hardwareBack && webView.canGoBack()) { + hideErrorScreen() + webView.goBack() + } else { + sendWebViewEvent(OSIABEvents.BrowserFinished(browserId)) + webView.destroy() + this.isEnabled = false // disable the callback to prevent it from being called again + onBackPressedDispatcher.onBackPressed() + } + } + }) + browserId = intent.getStringExtra(OSIABEvents.EXTRA_BROWSER_ID) ?: "" sendWebViewEvent(OSIABWebViewEvent(browserId, this@OSIABWebViewActivity)) @@ -249,20 +264,6 @@ class OSIABWebViewActivity : AppCompatActivity() { return OSIABWebChromeClient() } - /** - * Handle the back button press - */ - override fun onBackPressed() { - if (options.hardwareBack && webView.canGoBack()) { - hideErrorScreen() - webView.goBack() - } else { - sendWebViewEvent(OSIABEvents.BrowserFinished(browserId)) - webView.destroy() - onBackPressedDispatcher.onBackPressed() - } - } - /** * Handle permission requests */ From ffc706993499397f817976a25ad598f6831027d9 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Mon, 28 Jul 2025 11:47:57 -0300 Subject: [PATCH 2/7] feat: update library to Android 16 (API 36), and also update Kotlin, Gradle, and AGP References: https://outsystemsrd.atlassian.net/browse/RMET-4335 --- build.gradle | 8 ++++---- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 8618dd9..d6de6e9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = "1.9.24" + ext.kotlin_version = "1.9.25" ext.jacocoVersion = '0.8.7' repositories { google() @@ -12,7 +12,7 @@ buildscript { if (System.getenv("SHOULD_PUBLISH") == "true") { classpath("io.github.gradle-nexus:publish-plugin:1.1.0") } - classpath 'com.android.tools.build:gradle:8.7.3' + classpath 'com.android.tools.build:gradle:8.11.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jacoco:org.jacoco.core:$jacocoVersion" } @@ -41,11 +41,11 @@ apply plugin: "jacoco" android { namespace "com.outsystems.plugins.inappbrowser.osinappbrowserlib" - compileSdk 35 + compileSdk 36 defaultConfig { minSdk 26 - targetSdk 35 + targetSdk 36 versionCode 1 versionName "1.0" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2791f36..a32fa94 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed May 29 18:08:54 CDT 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 1a33cf926f18c9af596039ad3d52f8ca0c999ce3 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Mon, 28 Jul 2025 11:52:26 -0300 Subject: [PATCH 3/7] test: set version to 1.4.1-dev to test References: https://outsystemsrd.atlassian.net/browse/RMET-4335 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cf63ce3..54a3536 100644 --- a/pom.xml +++ b/pom.xml @@ -6,5 +6,5 @@ 4.0.0 io.ionic.libs ioninappbrowser-android - 1.4.0 + 1.4.1-dev From 79d87ba330d69549dc7dda45cb55b0986939d517 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Mon, 28 Jul 2025 17:37:02 -0300 Subject: [PATCH 4/7] chore: raise version to 1.4.1 and update changelog References: https://outsystemsrd.atlassian.net/browse/RMET-4335 --- CHANGELOG.md | 6 ++++++ pom.xml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a801b6e..747a3c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.4.1] + +### Fixes + +- Migrate back button navigation on `OSIABWebViewActivity` to support apps targeting Android 16 (https://outsystemsrd.atlassian.net/browse/RMET-4335) + ## [1.4.0] ### Features diff --git a/pom.xml b/pom.xml index 54a3536..e4235fb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,5 +6,5 @@ 4.0.0 io.ionic.libs ioninappbrowser-android - 1.4.1-dev + 1.4.1 From 5d3f84c3c8e5111efa10f4eb2b9b8ed32025349a Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Tue, 29 Jul 2025 12:56:44 -0300 Subject: [PATCH 5/7] feat: enable predictive back navigation for Android 13+ (API 33+) References: https://outsystemsrd.atlassian.net/browse/RMET-4335 --- src/main/AndroidManifest.xml | 5 ++- .../views/OSIABWebViewActivity.kt | 44 ++++++++++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 1057ea8..6004314 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ @@ -18,7 +19,9 @@ android:exported="false" android:configChanges="orientation|screenSize|uiMode" android:label="OSIABWebViewActivity" - android:theme="@style/AppTheme.WebView" /> + android:theme="@style/AppTheme.WebView" + android:enableOnBackInvokedCallback="true" + tools:targetApi="33" /> Date: Tue, 29 Jul 2025 14:02:43 -0300 Subject: [PATCH 6/7] chore: update changelog References: https://outsystemsrd.atlassian.net/browse/RMET-4335 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 747a3c6..48ee9ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.4.1] +### Features + +- Added support for predictive back navigation for Android 13+ (https://outsystemsrd.atlassian.net/browse/RMET-4335) + ### Fixes - Migrate back button navigation on `OSIABWebViewActivity` to support apps targeting Android 16 (https://outsystemsrd.atlassian.net/browse/RMET-4335) From ef147136ffd4cc3914f187cd58f651c60a77db77 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Tue, 29 Jul 2025 14:12:52 -0300 Subject: [PATCH 7/7] 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 --- .../views/OSIABWebViewActivity.kt | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/com.outsystems.plugins.inappbrowser/osinappbrowserlib/views/OSIABWebViewActivity.kt b/src/main/java/com.outsystems.plugins.inappbrowser/osinappbrowserlib/views/OSIABWebViewActivity.kt index f7f66da..95076aa 100644 --- a/src/main/java/com.outsystems.plugins.inappbrowser/osinappbrowserlib/views/OSIABWebViewActivity.kt +++ b/src/main/java/com.outsystems.plugins.inappbrowser/osinappbrowserlib/views/OSIABWebViewActivity.kt @@ -110,14 +110,8 @@ class OSIABWebViewActivity : AppCompatActivity() { onBackPressedCallback = object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { if (!webView.canGoBack()) return - if (options.hardwareBack) { - hideErrorScreen() - webView.goBack() - } else { - // if hardwareBack is false, we want to finish the activity (close the WebView) - // and not go back in the WebView history - finish() - } + hideErrorScreen() + webView.goBack() } } onBackPressedDispatcher.addCallback(this, onBackPressedCallback) @@ -403,9 +397,10 @@ class OSIABWebViewActivity : AppCompatActivity() { override fun doUpdateVisitedHistory(view: WebView?, url: String?, isReload: Boolean) { // to implement predictive back navigation // we only want to have the callback enabled if the WebView can go back to previous page + // and if the hardwareBack option is enabled // if not, we want the system to handle the back press, which will enable the - // predictive back animation - onBackPressedCallback.isEnabled = webView.canGoBack() + // predictive back animation and simply close the WebView + onBackPressedCallback.isEnabled = webView.canGoBack() && options.hardwareBack } /**