chore: add Lifecycle utilities for Compose

and replace collectAsState() with collectAsStateWithLifecycle()
This commit is contained in:
andrekir 2023-04-10 20:29:47 -03:00
parent 8e7597704b
commit e03ab70e66
4 changed files with 8 additions and 7 deletions

View file

@ -28,7 +28,6 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.twotone.Check
import androidx.compose.material.icons.twotone.Close
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
@ -52,6 +51,7 @@ import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import com.geeksville.mesh.analytics.DataPair
import com.geeksville.mesh.android.GeeksvilleApplication
@ -115,7 +115,7 @@ fun ChannelScreen(viewModel: UIViewModel = viewModel()) {
val connectionState by viewModel.connectionState.observeAsState()
val connected = connectionState == MeshService.ConnectionState.CONNECTED
val channels by viewModel.channels.collectAsState()
val channels by viewModel.channels.collectAsStateWithLifecycle()
var channelSet by remember(channels.protobuf) { mutableStateOf(channels.protobuf) }
val primaryChannel = ChannelSet(channelSet).primaryChannel