Workaround for drawerLayout handle OnBackPressedInvoked only above API 33

This commit is contained in:
tarsin committed 2023-03-23 13:03:49 +08:00
1 parent 095a9149b4
commit f81ca0688e
1 file changed
+12
@@ -118,6 +118,18 @@ class MainActivity : EhActivity() {
startActivity(intent)
}
@Suppress("OVERRIDE_DEPRECATION")
override fun onBackPressed() {
check(Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
val isDrawerOpen = binding.drawView.isDrawerOpen(GravityCompat.START) or
binding.drawView.isDrawerOpen(GravityCompat.END)
if (isDrawerOpen) {
binding.drawView.closeDrawers()
} else {
super.onBackPressed()
}
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
lifecycleScope.launchUI {