From af98889dc11e91c7102ea138e7ab6d8086709378 Mon Sep 17 00:00:00 2001 From: Pedro Bilro Date: Fri, 8 Nov 2024 11:28:10 +0000 Subject: [PATCH] RMET-3597 ::: Android 15 - Support edge-to-edge and drop Configuration for layout size (#37) * fix: edge-to-edge support for barcode scan on Android 15 References: https://outsystemsrd.atlassian.net/browse/RMET-3597 * fix: replace configuration with WindowMetrics to retrieve screen size Left orientation as-is because it only impacts close-to-square devices References: https://outsystemsrd.atlassian.net/browse/RMET-3597 * chore: Update CHANGELOG.md References: https://outsystemsrd.atlassian.net/browse/RMET-3597 * chore: set pom.xml version to dev --------- Co-authored-by: Alexandre Jacinto --- CHANGELOG.md | 5 +++++ build.gradle | 1 + pom.xml | 2 +- .../barcode/view/OSBARCScannerActivity.kt | 19 ++++++++++++++----- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2496b57..aad814a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 The changes documented here do not include those from the original repository. +## [Unreleased] + +### 05-11-2024 +- Fix: Edge-to-edge support on Android 15 (https://outsystemsrd.atlassian.net/browse/RMET-3597) + ## [1.1.4] ### 08-10-2024 diff --git a/build.gradle b/build.gradle index 1c8922e..20ea4f3 100644 --- a/build.gradle +++ b/build.gradle @@ -108,6 +108,7 @@ dependencies { implementation "androidx.activity:activity-compose:1.4.0" implementation 'androidx.compose.material3:material3:1.0.0' implementation 'androidx.compose.material3:material3-window-size-class:1.0.0' + implementation 'androidx.window:window:1.3.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' diff --git a/pom.xml b/pom.xml index 96be72f..d998a2a 100644 --- a/pom.xml +++ b/pom.xml @@ -7,5 +7,5 @@ 4.0.0 com.github.outsystems osbarcode-android - 1.1.4 + 1.1.5-dev diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt index ae61fea..8993a1f 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt @@ -77,6 +77,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Path import androidx.compose.ui.graphics.drawscope.Stroke import androidx.compose.ui.graphics.drawscope.clipPath +import androidx.compose.ui.graphics.toComposeRect import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext @@ -89,6 +90,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView import androidx.core.content.ContextCompat import androidx.core.view.WindowCompat +import androidx.window.layout.WindowMetricsCalculator import com.outsystems.plugins.barcode.R import com.outsystems.plugins.barcode.controller.OSBARCBarcodeAnalyzer import com.outsystems.plugins.barcode.controller.OSBARCScanLibraryFactory @@ -286,7 +288,6 @@ class OSBARCScannerActivity : ComponentActivity() { Box( modifier = Modifier .fillMaxSize() - .safeDrawingPadding() ) { AndroidView( factory = { context -> @@ -338,8 +339,13 @@ class OSBARCScannerActivity : ComponentActivity() { fun ScanScreenUI(parameters: OSBARCScanParameters, windowSizeClass: WindowSizeClass) { // actual UI on top of the camera stream val configuration = LocalConfiguration.current - screenHeight = configuration.screenHeightDp.dp - screenWidth = configuration.screenWidthDp.dp + val windowMetrics = + WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(this) + val rect = windowMetrics.bounds.toComposeRect() + with(LocalDensity.current) { + screenHeight = rect.height.toDp() + screenWidth = rect.width.toDp() + } val isPortrait = configuration.orientation == Configuration.ORIENTATION_PORTRAIT @@ -505,7 +511,8 @@ class OSBARCScannerActivity : ComponentActivity() { modifier = Modifier .fillMaxWidth() .background(ScannerBackgroundBlack) - .weight(1f, fill = true), + .weight(1f, fill = true) + .safeDrawingPadding(), ) { CloseButton( modifier = Modifier @@ -541,7 +548,8 @@ class OSBARCScannerActivity : ComponentActivity() { modifier = Modifier .fillMaxWidth() .background(ScannerBackgroundBlack) - .weight(1f, fill = true), + .weight(1f, fill = true) + .safeDrawingPadding(), ) { val showTorch = camera.cameraInfo.hasFlashUnit() val showScan = parameters.scanButton @@ -651,6 +659,7 @@ class OSBARCScannerActivity : ComponentActivity() { rightButtonsWidth = with(density) { coordinates.size.width.toDp() } } .background(ScannerBackgroundBlack) + .safeDrawingPadding() ) { CloseButton(