Do not use MutableState in Composable function parameter.
This commit is contained in:
parent
d19238fc60
commit
d1a3daaa8e
4 changed files with 15 additions and 13 deletions
|
|
@ -134,7 +134,8 @@ fun ConfigureRoomView(
|
||||||
|
|
||||||
AvatarActionBottomSheet(
|
AvatarActionBottomSheet(
|
||||||
actions = state.avatarActions,
|
actions = state.avatarActions,
|
||||||
isVisible = isAvatarActionsSheetVisible,
|
isVisible = isAvatarActionsSheetVisible.value,
|
||||||
|
onDismiss = { isAvatarActionsSheetVisible.value = false },
|
||||||
onActionSelected = { state.eventSink(ConfigureRoomEvents.HandleAvatarAction(it)) }
|
onActionSelected = { state.eventSink(ConfigureRoomEvents.HandleAvatarAction(it)) }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,8 @@ fun EditUserProfileView(
|
||||||
|
|
||||||
AvatarActionBottomSheet(
|
AvatarActionBottomSheet(
|
||||||
actions = state.avatarActions,
|
actions = state.avatarActions,
|
||||||
isVisible = isAvatarActionsSheetVisible,
|
isVisible = isAvatarActionsSheetVisible.value,
|
||||||
|
onDismiss = { isAvatarActionsSheetVisible.value = false },
|
||||||
onActionSelected = { state.eventSink(EditUserProfileEvents.HandleAvatarAction(it)) }
|
onActionSelected = { state.eventSink(EditUserProfileEvents.HandleAvatarAction(it)) }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,8 @@ fun RoomDetailsEditView(
|
||||||
|
|
||||||
AvatarActionBottomSheet(
|
AvatarActionBottomSheet(
|
||||||
actions = state.avatarActions,
|
actions = state.avatarActions,
|
||||||
isVisible = isAvatarActionsSheetVisible,
|
isVisible = isAvatarActionsSheetVisible.value,
|
||||||
|
onDismiss = { isAvatarActionsSheetVisible.value = false },
|
||||||
onActionSelected = { state.eventSink(RoomDetailsEditEvents.HandleAvatarAction(it)) }
|
onActionSelected = { state.eventSink(RoomDetailsEditEvents.HandleAvatarAction(it)) }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,6 @@ import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
import androidx.compose.material3.rememberModalBottomSheetState
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.MutableState
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
|
@ -53,8 +50,9 @@ import kotlinx.collections.immutable.persistentListOf
|
||||||
@Composable
|
@Composable
|
||||||
fun AvatarActionBottomSheet(
|
fun AvatarActionBottomSheet(
|
||||||
actions: ImmutableList<AvatarAction>,
|
actions: ImmutableList<AvatarAction>,
|
||||||
isVisible: MutableState<Boolean>,
|
isVisible: Boolean,
|
||||||
onActionSelected: (action: AvatarAction) -> Unit,
|
onActionSelected: (action: AvatarAction) -> Unit,
|
||||||
|
onDismiss: () -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
@ -62,19 +60,19 @@ fun AvatarActionBottomSheet(
|
||||||
skipPartiallyExpanded = true
|
skipPartiallyExpanded = true
|
||||||
)
|
)
|
||||||
|
|
||||||
BackHandler(enabled = isVisible.value) {
|
BackHandler(enabled = isVisible) {
|
||||||
sheetState.hide(coroutineScope, then = { isVisible.value = false })
|
sheetState.hide(coroutineScope, then = { onDismiss() })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onItemActionClicked(itemAction: AvatarAction) {
|
fun onItemActionClicked(itemAction: AvatarAction) {
|
||||||
onActionSelected(itemAction)
|
onActionSelected(itemAction)
|
||||||
sheetState.hide(coroutineScope, then = { isVisible.value = false })
|
sheetState.hide(coroutineScope, then = { onDismiss() })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVisible.value) {
|
if (isVisible) {
|
||||||
ModalBottomSheet(
|
ModalBottomSheet(
|
||||||
onDismissRequest = {
|
onDismissRequest = {
|
||||||
sheetState.hide(coroutineScope, then = { isVisible.value = false })
|
sheetState.hide(coroutineScope, then = { onDismiss() })
|
||||||
},
|
},
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
sheetState = sheetState,
|
sheetState = sheetState,
|
||||||
|
|
@ -126,7 +124,8 @@ private fun AvatarActionBottomSheetContent(
|
||||||
internal fun AvatarActionBottomSheetPreview() = ElementPreview {
|
internal fun AvatarActionBottomSheetPreview() = ElementPreview {
|
||||||
AvatarActionBottomSheet(
|
AvatarActionBottomSheet(
|
||||||
actions = persistentListOf(AvatarAction.TakePhoto, AvatarAction.ChoosePhoto, AvatarAction.Remove),
|
actions = persistentListOf(AvatarAction.TakePhoto, AvatarAction.ChoosePhoto, AvatarAction.Remove),
|
||||||
isVisible = remember { mutableStateOf(true) },
|
isVisible = true,
|
||||||
onActionSelected = { },
|
onActionSelected = { },
|
||||||
|
onDismiss = { },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue