Skip to content

Commit 67e46a1

Browse files
Merge pull request #50 from OutSystems/fix/RMET-4335/migrate-back-navigation
RMET-4335 - Migrate back navigation to API supported for Android 16 and update lib to Android 16 (API 36)
2 parents 84f9a0d + ef14713 commit 67e46a1

6 files changed

Lines changed: 56 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.4.1]
8+
9+
### Features
10+
11+
- Added support for predictive back navigation for Android 13+ (https://outsystemsrd.atlassian.net/browse/RMET-4335)
12+
13+
### Fixes
14+
15+
- Migrate back button navigation on `OSIABWebViewActivity` to support apps targeting Android 16 (https://outsystemsrd.atlassian.net/browse/RMET-4335)
16+
717
## [1.4.0]
818

919
### Features

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = "1.9.24"
2+
ext.kotlin_version = "1.9.25"
33
ext.jacocoVersion = '0.8.7'
44
repositories {
55
google()
@@ -12,7 +12,7 @@ buildscript {
1212
if (System.getenv("SHOULD_PUBLISH") == "true") {
1313
classpath("io.github.gradle-nexus:publish-plugin:1.1.0")
1414
}
15-
classpath 'com.android.tools.build:gradle:8.7.3'
15+
classpath 'com.android.tools.build:gradle:8.11.1'
1616
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1717
classpath "org.jacoco:org.jacoco.core:$jacocoVersion"
1818
}
@@ -41,11 +41,11 @@ apply plugin: "jacoco"
4141

4242
android {
4343
namespace "com.outsystems.plugins.inappbrowser.osinappbrowserlib"
44-
compileSdk 35
44+
compileSdk 36
4545

4646
defaultConfig {
4747
minSdk 26
48-
targetSdk 35
48+
targetSdk 36
4949
versionCode 1
5050
versionName "1.0"
5151

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Wed May 29 18:08:54 CDT 2024
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>io.ionic.libs</groupId>
88
<artifactId>ioninappbrowser-android</artifactId>
9-
<version>1.4.0</version>
9+
<version>1.4.1</version>
1010
</project>

src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
package="com.outsystems.plugins.inappbrowser.osinappbrowserlib">
45

56
<uses-permission android:name="android.permission.INTERNET" />
@@ -18,7 +19,9 @@
1819
android:exported="false"
1920
android:configChanges="orientation|screenSize|uiMode"
2021
android:label="OSIABWebViewActivity"
21-
android:theme="@style/AppTheme.WebView" />
22+
android:theme="@style/AppTheme.WebView"
23+
android:enableOnBackInvokedCallback="true"
24+
tools:targetApi="33" />
2225
<activity android:name=".views.OSIABCustomTabsControllerActivity"
2326
android:exported="false"
2427
android:theme="@style/Theme.Transparent"

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

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import android.widget.Button
2424
import android.widget.ImageButton
2525
import android.widget.LinearLayout
2626
import android.widget.TextView
27+
import androidx.activity.OnBackPressedCallback
2728
import androidx.activity.enableEdgeToEdge
2829
import androidx.activity.result.contract.ActivityResultContracts
2930
import androidx.appcompat.app.AppCompatActivity
@@ -84,6 +85,9 @@ class OSIABWebViewActivity : AppCompatActivity() {
8485
filePathCallback = null
8586
}
8687

88+
// for back navigation
89+
private lateinit var onBackPressedCallback: OnBackPressedCallback
90+
8791
companion object {
8892
const val WEB_VIEW_URL_EXTRA = "WEB_VIEW_URL_EXTRA"
8993
const val WEB_VIEW_OPTIONS_EXTRA = "WEB_VIEW_OPTIONS_EXTRA"
@@ -103,6 +107,15 @@ class OSIABWebViewActivity : AppCompatActivity() {
103107
override fun onCreate(savedInstanceState: Bundle?) {
104108
super.onCreate(savedInstanceState)
105109

110+
onBackPressedCallback = object : OnBackPressedCallback(true) {
111+
override fun handleOnBackPressed() {
112+
if (!webView.canGoBack()) return
113+
hideErrorScreen()
114+
webView.goBack()
115+
}
116+
}
117+
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
118+
106119
browserId = intent.getStringExtra(OSIABEvents.EXTRA_BROWSER_ID) ?: ""
107120

108121
sendWebViewEvent(OSIABWebViewEvent(browserId, this@OSIABWebViewActivity))
@@ -137,8 +150,6 @@ class OSIABWebViewActivity : AppCompatActivity() {
137150
closeButton = findViewById(R.id.close_button)
138151
closeButton.text = options.closeButtonText.ifBlank { "Close" }
139152
closeButton.setOnClickListener {
140-
sendWebViewEvent(OSIABEvents.BrowserFinished(browserId))
141-
webView.destroy()
142153
finish()
143154
}
144155

@@ -176,6 +187,18 @@ class OSIABWebViewActivity : AppCompatActivity() {
176187
}
177188
}
178189

190+
override fun onStop() {
191+
super.onStop()
192+
if (isFinishing) {
193+
sendWebViewEvent(OSIABEvents.BrowserFinished(browserId))
194+
}
195+
}
196+
197+
override fun onDestroy() {
198+
webView.destroy()
199+
super.onDestroy()
200+
}
201+
179202
override fun onResume() {
180203
super.onResume()
181204
if (options.pauseMedia) {
@@ -237,7 +260,7 @@ class OSIABWebViewActivity : AppCompatActivity() {
237260
*/
238261
private fun customWebViewClient(
239262
hasNavigationButtons: Boolean,
240-
showURL: Boolean,
263+
showURL: Boolean
241264
): WebViewClient {
242265
return OSIABWebViewClient(hasNavigationButtons, showURL)
243266
}
@@ -249,20 +272,6 @@ class OSIABWebViewActivity : AppCompatActivity() {
249272
return OSIABWebChromeClient()
250273
}
251274

252-
/**
253-
* Handle the back button press
254-
*/
255-
override fun onBackPressed() {
256-
if (options.hardwareBack && webView.canGoBack()) {
257-
hideErrorScreen()
258-
webView.goBack()
259-
} else {
260-
sendWebViewEvent(OSIABEvents.BrowserFinished(browserId))
261-
webView.destroy()
262-
onBackPressedDispatcher.onBackPressed()
263-
}
264-
}
265-
266275
/**
267276
* Handle permission requests
268277
*/
@@ -300,7 +309,7 @@ class OSIABWebViewActivity : AppCompatActivity() {
300309
*/
301310
private inner class OSIABWebViewClient(
302311
val hasNavigationButtons: Boolean,
303-
val showURL: Boolean
312+
val showURL: Boolean,
304313
) : WebViewClient() {
305314

306315
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
@@ -385,6 +394,15 @@ class OSIABWebViewActivity : AppCompatActivity() {
385394
}
386395
}
387396

397+
override fun doUpdateVisitedHistory(view: WebView?, url: String?, isReload: Boolean) {
398+
// to implement predictive back navigation
399+
// 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
401+
// if not, we want the system to handle the back press, which will enable the
402+
// predictive back animation and simply close the WebView
403+
onBackPressedCallback.isEnabled = webView.canGoBack() && options.hardwareBack
404+
}
405+
388406
/**
389407
* Responsible for handling and launching intents based on a URL.
390408
* @param intentAction Action for the intent

0 commit comments

Comments
 (0)