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