Skip to content

Commit 2abad48

Browse files
committed
Use onBackPressedDispatcher to handle back press
1 parent c5de12e commit 2abad48

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

bottomsheetdialog-compose/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ android {
5151

5252
dependencies {
5353
implementation Dependencies.composeUI
54+
implementation Dependencies.androidxActivityKtx
5455
implementation Dependencies.androidxCoreKtx
5556
implementation Dependencies.material
5657
testImplementation 'junit:junit:4.13.2'

bottomsheetdialog-compose/src/main/kotlin/com/holix/android/bottomsheetdialog/compose/BottomSheetDialog.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.Context
55
import android.graphics.Outline
66
import android.os.Build
77
import android.view.*
8+
import androidx.activity.addCallback
89
import androidx.annotation.FloatRange
910
import androidx.annotation.IntRange
1011
import androidx.annotation.Px
@@ -438,6 +439,12 @@ private class BottomSheetDialogWrapper(
438439

439440
// Initial setup
440441
updateParameters(onDismissRequest, properties, layoutDirection)
442+
443+
onBackPressedDispatcher.addCallback(this) {
444+
if (properties.dismissOnBackPress) {
445+
cancel()
446+
}
447+
}
441448
}
442449

443450
private fun setLayoutDirection(layoutDirection: LayoutDirection) {
@@ -538,14 +545,6 @@ private class BottomSheetDialogWrapper(
538545
onDismissRequest()
539546
}
540547
}
541-
542-
@Deprecated("Deprecated")
543-
@SuppressLint("MissingSuperCall")
544-
override fun onBackPressed() {
545-
if (properties.dismissOnBackPress) {
546-
cancel()
547-
}
548-
}
549548
}
550549

551550
@Composable

buildSrc/src/main/kotlin/com/holix/android/bottomsheetdialog/compose/Versions.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ object Versions {
55
internal const val GRADLE_NEXUS_PUBLISH_PLUGIN = "1.1.0"
66
internal const val KOTLIN = "1.7.20"
77

8-
internal const val MATERIAL = "1.7.0"
8+
internal const val MATERIAL = "1.8.0"
99
internal const val ANDROIDX_CORE_KTX = "1.9.0"
1010

1111
internal const val COMPOSE = "1.3.0"
1212
const val COMPOSE_COMPILER = "1.3.2"
13-
internal const val COMPOSE_ACTIVITY = "1.6.1"
13+
internal const val ANDROIDX_ACTIVITY = "1.5.1"
1414

1515
internal const val COLOR_PICKER = "1.0.0"
1616
}
@@ -23,6 +23,7 @@ object Dependencies {
2323
const val kotlinGradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.KOTLIN}"
2424

2525
const val material = "com.google.android.material:material:${Versions.MATERIAL}"
26+
const val androidxActivityKtx = "androidx.activity:activity-ktx:${Versions.ANDROIDX_ACTIVITY}"
2627
const val androidxCoreKtx = "androidx.core:core-ktx:${Versions.ANDROIDX_CORE_KTX}"
2728

2829
const val composeUI = "androidx.compose.ui:ui:${Versions.COMPOSE}"

0 commit comments

Comments
 (0)