17
17
package com.example.compose.jetchat
18
18
19
19
import android.os.Bundle
20
- import androidx.activity.compose.setContent
21
20
import androidx.activity.viewModels
22
21
import androidx.appcompat.app.AppCompatActivity
22
+ import androidx.compose.foundation.layout.consumeWindowInsets
23
23
import androidx.compose.material3.DrawerValue.Closed
24
24
import androidx.compose.material3.ExperimentalMaterial3Api
25
25
import androidx.compose.material3.rememberDrawerState
@@ -28,6 +28,7 @@ import androidx.compose.runtime.LaunchedEffect
28
28
import androidx.compose.runtime.collectAsState
29
29
import androidx.compose.runtime.getValue
30
30
import androidx.compose.runtime.rememberCoroutineScope
31
+ import androidx.compose.ui.platform.ComposeView
31
32
import androidx.compose.ui.viewinterop.AndroidViewBinding
32
33
import androidx.core.os.bundleOf
33
34
import androidx.core.view.WindowCompat
@@ -53,51 +54,56 @@ class NavActivity : AppCompatActivity() {
53
54
// including IME animations
54
55
WindowCompat .setDecorFitsSystemWindows(window, false )
55
56
56
- setContent {
57
- CompositionLocalProvider (
58
- LocalBackPressedDispatcher provides this .onBackPressedDispatcher
59
- ) {
60
- val drawerState = rememberDrawerState(initialValue = Closed )
57
+ setContentView(
58
+ ComposeView (this ).apply {
59
+ consumeWindowInsets = false
60
+ setContent {
61
+ CompositionLocalProvider (
62
+ LocalBackPressedDispatcher provides this @NavActivity.onBackPressedDispatcher
63
+ ) {
64
+ val drawerState = rememberDrawerState(initialValue = Closed )
61
65
62
- val drawerOpen by viewModel.drawerShouldBeOpened.collectAsState()
63
- if (drawerOpen) {
64
- // Open drawer and reset state in VM.
65
- LaunchedEffect (Unit ) {
66
- drawerState.open()
67
- viewModel.resetOpenDrawerAction()
68
- }
69
- }
70
-
71
- // Intercepts back navigation when the drawer is open
72
- val scope = rememberCoroutineScope()
73
- if (drawerState.isOpen) {
74
- BackPressHandler {
75
- scope.launch {
76
- drawerState.close()
66
+ val drawerOpen by viewModel.drawerShouldBeOpened.collectAsState()
67
+ if (drawerOpen) {
68
+ // Open drawer and reset state in VM.
69
+ LaunchedEffect (Unit ) {
70
+ drawerState.open()
71
+ viewModel.resetOpenDrawerAction()
72
+ }
77
73
}
78
- }
79
- }
80
74
81
- JetchatScaffold (
82
- drawerState = drawerState,
83
- onChatClicked = {
84
- findNavController().popBackStack(R .id.nav_home, false )
85
- scope.launch {
86
- drawerState.close()
75
+ // Intercepts back navigation when the drawer is open
76
+ val scope = rememberCoroutineScope()
77
+ if (drawerState.isOpen) {
78
+ BackPressHandler {
79
+ scope.launch {
80
+ drawerState.close()
81
+ }
82
+ }
87
83
}
88
- },
89
- onProfileClicked = {
90
- val bundle = bundleOf(" userId" to it)
91
- findNavController().navigate(R .id.nav_profile, bundle)
92
- scope.launch {
93
- drawerState.close()
84
+
85
+ JetchatScaffold (
86
+ drawerState = drawerState,
87
+ onChatClicked = {
88
+ findNavController().popBackStack(R .id.nav_home, false )
89
+ scope.launch {
90
+ drawerState.close()
91
+ }
92
+ },
93
+ onProfileClicked = {
94
+ val bundle = bundleOf(" userId" to it)
95
+ findNavController().navigate(R .id.nav_profile, bundle)
96
+ scope.launch {
97
+ drawerState.close()
98
+ }
99
+ }
100
+ ) {
101
+ AndroidViewBinding (ContentMainBinding ::inflate)
94
102
}
95
103
}
96
- ) {
97
- AndroidViewBinding (ContentMainBinding ::inflate)
98
104
}
99
105
}
100
- }
106
+ )
101
107
}
102
108
103
109
override fun onSupportNavigateUp (): Boolean {
0 commit comments