Skip to content

Commit

Permalink
fix: call controls visibility after closing PiP mode [#WPB-15142] (#3770
Browse files Browse the repository at this point in the history
)

Co-authored-by: sergei.bakhtiarov <[email protected]>
  • Loading branch information
sergeibakhtiarov and sbakhtiarov authored Dec 27, 2024
1 parent 188bc6c commit f1c158b
Showing 1 changed file with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package com.wire.android.ui.calling.ongoing
import android.content.pm.PackageManager
import android.view.View
import androidx.activity.compose.BackHandler
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
Expand Down Expand Up @@ -56,6 +57,8 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.core.app.PictureInPictureModeChangedInfo
import androidx.core.util.Consumer
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
Expand Down Expand Up @@ -130,10 +133,14 @@ fun OngoingCallScreen(

val inCallReactionsState = rememberInCallReactionsState()

val activity = LocalActivity.current
val isPiPAvailableOnThisDevice =
activity.packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
val activity = LocalActivity.current as AppCompatActivity
val isPiPAvailableOnThisDevice = activity.packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
val shouldUsePiPMode = BuildConfig.PICTURE_IN_PICTURE_ENABLED && isPiPAvailableOnThisDevice
var inPictureInPictureMode by remember { mutableStateOf(shouldUsePiPMode && activity.isInPictureInPictureMode) }

if (shouldUsePiPMode) {
activity.observePictureInPictureMode { inPictureInPictureMode = it }
}

LaunchedEffect(ongoingCallViewModel.state.flowState) {
when (ongoingCallViewModel.state.flowState) {
Expand Down Expand Up @@ -183,7 +190,6 @@ fun OngoingCallScreen(
}
}

val inPictureInPictureMode = activity.isInPictureInPictureMode
OngoingCallContent(
callState = sharedCallingViewModel.callState,
inCallReactionsState = inCallReactionsState,
Expand Down Expand Up @@ -624,6 +630,23 @@ private fun CallingControls(
}
}

@Composable
private fun AppCompatActivity.observePictureInPictureMode(onChanged: (Boolean) -> Unit) {
DisposableEffect(Unit) {
val consumer = object : Consumer<PictureInPictureModeChangedInfo> {
override fun accept(info: PictureInPictureModeChangedInfo) {
onChanged(info.isInPictureInPictureMode)
}
}

addOnPictureInPictureModeChangedListener(consumer)

onDispose {
removeOnPictureInPictureModeChangedListener(consumer)
}
}
}

@Suppress("EmptyFunctionBlock")
@Composable
fun PreviewOngoingCallContent(participants: PersistentList<UICallParticipant>) {
Expand Down

0 comments on commit f1c158b

Please sign in to comment.