Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: call controls visibility after closing PiP mode [#WPB-15142] #3770

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading