From c53500812ce0bb1014b520cd45ae86e579243ffc Mon Sep 17 00:00:00 2001
From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
Date: Tue, 22 Feb 2022 20:52:02 +0000
Subject: [PATCH] android: fix bottom sheet delay and graying out the rest of
the screen (#356)
---
apps/android/.idea/codeStyles/Project.xml | 8 +-
.../.idea/codeStyles/codeStyleConfig.xml | 1 -
.../app/views/chatlist/ChatListView.kt | 92 +++++++++++--------
3 files changed, 59 insertions(+), 42 deletions(-)
diff --git a/apps/android/.idea/codeStyles/Project.xml b/apps/android/.idea/codeStyles/Project.xml
index 1901f77e30..9dd7fe45d6 100644
--- a/apps/android/.idea/codeStyles/Project.xml
+++ b/apps/android/.idea/codeStyles/Project.xml
@@ -3,6 +3,7 @@
+
@@ -121,10 +122,15 @@
-
+
+
+
+
+
+
diff --git a/apps/android/.idea/codeStyles/codeStyleConfig.xml b/apps/android/.idea/codeStyles/codeStyleConfig.xml
index 6e6eec1148..79ee123c2b 100644
--- a/apps/android/.idea/codeStyles/codeStyleConfig.xml
+++ b/apps/android/.idea/codeStyles/codeStyleConfig.xml
@@ -1,6 +1,5 @@
-
\ No newline at end of file
diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chatlist/ChatListView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chatlist/ChatListView.kt
index ba35676549..73474a4c3e 100644
--- a/apps/android/app/src/main/java/chat/simplex/app/views/chatlist/ChatListView.kt
+++ b/apps/android/app/src/main/java/chat/simplex/app/views/chatlist/ChatListView.kt
@@ -29,28 +29,42 @@ import com.google.accompanist.permissions.ExperimentalPermissionsApi
import kotlinx.coroutines.*
@ExperimentalMaterialApi
-class ScaffoldController(val state: BottomSheetScaffoldState, val scope: CoroutineScope) {
- fun expand() = scope.launch { state.bottomSheetState.expand() }
- fun collapse() = scope.launch { state.bottomSheetState.collapse() }
- fun toggleSheet() = scope.launch {
- val s = state.bottomSheetState
- if (s.isExpanded) s.collapse() else s.expand()
+class ScaffoldController(val scope: CoroutineScope) {
+ lateinit var state: BottomSheetScaffoldState
+ val expanded = mutableStateOf(false)
+
+ fun expand() {
+ expanded.value = true
+ scope.launch { state.bottomSheetState.expand() }
+ }
+
+ fun collapse() {
+ expanded.value = false
+ scope.launch { state.bottomSheetState.collapse() }
+ }
+
+ fun toggleSheet() {
+ if (state.bottomSheetState.isExpanded ?: false) collapse() else expand()
}
fun toggleDrawer() = scope.launch {
- state.drawerState.apply {
- if (isClosed) open() else close()
- }
+ state.drawerState.apply { if (isClosed) open() else close() }
}
}
@ExperimentalMaterialApi
@Composable
fun scaffoldController(): ScaffoldController {
- return ScaffoldController(
- state = rememberBottomSheetScaffoldState(),
- scope = rememberCoroutineScope()
+ val ctrl = ScaffoldController(scope = rememberCoroutineScope())
+ val bottomSheetState = rememberBottomSheetState(
+ BottomSheetValue.Collapsed,
+ confirmStateChange = {
+ ctrl.expanded.value = it == BottomSheetValue.Expanded
+ true
+ }
)
+ ctrl.state = rememberBottomSheetScaffoldState(bottomSheetState = bottomSheetState)
+ return ctrl
}
@DelicateCoroutinesApi
@@ -61,39 +75,37 @@ fun ChatListView(chatModel: ChatModel, nav: NavController) {
val scaffoldCtrl = scaffoldController()
BottomSheetScaffold(
scaffoldState = scaffoldCtrl.state,
- topBar = {
- ChatListToolbar(scaffoldCtrl)
- },
- drawerContent = {
- SettingsView(chatModel, nav)
- },
+ drawerContent = { SettingsView(chatModel, nav) },
sheetPeekHeight = 0.dp,
sheetContent = { NewChatSheet(chatModel, scaffoldCtrl, nav) },
sheetShape = RoundedCornerShape(topStart = 18.dp, topEnd = 18.dp),
) {
- Column(
- modifier = Modifier
- .padding(vertical = 8.dp)
- .fillMaxSize()
- .background(MaterialTheme.colors.background)
- ) {
- when (chatModel.chatsLoaded.value) {
- true -> if (chatModel.chats.isNotEmpty()) {
- ChatList(chatModel, nav)
- } else {
- val user = chatModel.currentUser.value
- Help(scaffoldCtrl, displayName = user?.profile?.displayName)
- }
- else -> ChatList(chatModel, nav)
- }
- }
- if (scaffoldCtrl.state.bottomSheetState.isExpanded) {
- Surface(
- Modifier
+ Box {
+ Column(
+ modifier = Modifier
+ .padding(vertical = 8.dp)
.fillMaxSize()
- .clickable { scaffoldCtrl.collapse() },
- color = Color.Black.copy(alpha = 0.12F)
- ) {}
+ .background(MaterialTheme.colors.background)
+ ) {
+ ChatListToolbar(scaffoldCtrl)
+ when (chatModel.chatsLoaded.value) {
+ true -> if (chatModel.chats.isNotEmpty()) {
+ ChatList(chatModel, nav)
+ } else {
+ val user = chatModel.currentUser.value
+ Help(scaffoldCtrl, displayName = user?.profile?.displayName)
+ }
+ else -> ChatList(chatModel, nav)
+ }
+ }
+ if (scaffoldCtrl.expanded.value) {
+ Surface(
+ Modifier
+ .fillMaxSize()
+ .clickable { scaffoldCtrl.collapse() },
+ color = Color.Black.copy(alpha = 0.12F)
+ ) {}
+ }
}
}
}