Skip to content

Commit

Permalink
Use collectAsStateWithLifecycle over collectAsState (#935)
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves authored Nov 21, 2023
1 parent c3d6e32 commit 51c36b0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Popup
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import io.getstream.video.android.compose.theme.VideoTheme
import io.getstream.video.android.core.Call
import kotlinx.coroutines.delay
Expand All @@ -47,7 +47,7 @@ fun AvailableDeviceMenu(
onDismissed: () -> Unit,
) {
val context = LocalContext.current
val availableDevices by call.microphone.devices.collectAsState()
val availableDevices by call.microphone.devices.collectAsStateWithLifecycle()

LaunchedEffect(key1 = availableDevices) {
delay(3000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import androidx.compose.material.Text
import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateListOf
Expand All @@ -47,6 +46,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import io.getstream.chat.android.ui.common.state.messages.list.MessageItemState
import io.getstream.video.android.BuildConfig
import io.getstream.video.android.compose.theme.VideoTheme
Expand Down Expand Up @@ -77,9 +77,9 @@ fun CallScreen(
onUserLeaveCall: () -> Unit = {},
) {
val context = LocalContext.current
val isCameraEnabled by call.camera.isEnabled.collectAsState()
val isMicrophoneEnabled by call.microphone.isEnabled.collectAsState()
val speakingWhileMuted by call.state.speakingWhileMuted.collectAsState()
val isCameraEnabled by call.camera.isEnabled.collectAsStateWithLifecycle()
val isMicrophoneEnabled by call.microphone.isEnabled.collectAsStateWithLifecycle()
val speakingWhileMuted by call.state.speakingWhileMuted.collectAsStateWithLifecycle()
var isShowingSettingMenu by remember { mutableStateOf(false) }
var isShowingLayoutChooseMenu by remember { mutableStateOf(false) }
var isShowingReactionsMenu by remember { mutableStateOf(false) }
Expand All @@ -95,7 +95,7 @@ fun CallScreen(
val scope = rememberCoroutineScope()
val messageScope = rememberCoroutineScope()

val callState by call.state.connection.collectAsState()
val callState by call.state.connection.collectAsStateWithLifecycle()

LaunchedEffect(key1 = callState) {
if (callState == RealtimeConnection.Disconnected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import androidx.compose.material.Card
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
Expand All @@ -44,6 +43,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Popup
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import io.getstream.video.android.compose.theme.VideoTheme
import io.getstream.video.android.core.Call
import io.getstream.video.android.core.call.audio.AudioFilter
Expand Down Expand Up @@ -75,7 +75,7 @@ internal fun SettingsMenu(
},
)

val isScreenSharing by call.screenShare.isEnabled.collectAsState()
val isScreenSharing by call.screenShare.isEnabled.collectAsStateWithLifecycle()
val screenShareButtonText = if (isScreenSharing) {
"Stop screen-sharing"
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import io.getstream.video.android.compose.theme.VideoTheme
import io.getstream.video.android.core.Call
import io.getstream.video.android.mock.StreamPreviewDataUtils
Expand Down Expand Up @@ -61,7 +61,7 @@ public fun LivestreamPlayer(
LivestreamPlayerOverlay(call = call)
},
) {
val backstage by call.state.backstage.collectAsState()
val backstage by call.state.backstage.collectAsStateWithLifecycle()

Box(
modifier = modifier.fillMaxSize(),
Expand Down

0 comments on commit 51c36b0

Please sign in to comment.