-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compose): add support for full screen in a dialog
- Loading branch information
1 parent
26e5f8a
commit aaccbe5
Showing
6 changed files
with
242 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
compose-player/src/main/java/video/api/compose/player/FullScreenDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package video.api.compose.player | ||
|
||
import android.annotation.SuppressLint | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.SideEffect | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.window.Dialog | ||
import androidx.compose.ui.window.DialogProperties | ||
import androidx.compose.ui.window.SecureFlagPolicy | ||
import video.api.compose.player.extensions.findActivity | ||
import video.api.player.extensions.hideSystemUI | ||
import video.api.player.models.VideoOptions | ||
import video.api.player.models.VideoType | ||
|
||
@SuppressLint("UnsafeOptInUsageError") | ||
@Composable | ||
fun FullScreenDialog( | ||
onDismissRequest: () -> Unit = {}, | ||
securePolicy: SecureFlagPolicy = SecureFlagPolicy.Inherit, | ||
content: @Composable () -> Unit, | ||
) { | ||
val context = LocalContext.current | ||
|
||
Dialog( | ||
onDismissRequest = onDismissRequest, | ||
properties = DialogProperties( | ||
dismissOnClickOutside = false, | ||
usePlatformDefaultWidth = false, | ||
securePolicy = securePolicy, | ||
decorFitsSystemWindows = false, | ||
), | ||
) { | ||
SideEffect { | ||
val currentActivity = context.findActivity() | ||
currentActivity!!.window.hideSystemUI() | ||
} | ||
|
||
content() | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun FullScreenDialogPreview() { | ||
MaterialTheme { | ||
FullScreenDialog { | ||
ApiVideoPlayer( | ||
VideoOptions("vi77Dgk0F8eLwaFOtC5870yn", VideoType.VOD), | ||
modifier = Modifier | ||
.fillMaxSize(), | ||
) | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
compose-player/src/main/java/video/api/compose/player/extensions/ContextExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package video.api.compose.player.extensions | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.content.ContextWrapper | ||
|
||
fun Context.findActivity(): Activity? = when (this) { | ||
is Activity -> this | ||
is ContextWrapper -> baseContext.findActivity() | ||
else -> null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters