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

Box doesn't overlap #1087

Closed
theapache64 opened this issue Aug 21, 2021 · 10 comments
Closed

Box doesn't overlap #1087

theapache64 opened this issue Aug 21, 2021 · 10 comments
Assignees
Labels
bug Something isn't working desktop swing interop Swing interop issue

Comments

@theapache64
Copy link
Contributor

Composable placed on top of SwingPanel or vlcj media player ( I don't know which one is causing the issue) doesn't respect the rules of Box

Structure:

Box{
  VideoPlayer() // visible
  Button() // not visible
}

Reproducible Code:

import androidx.compose.desktop.SwingPanel
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import uk.co.caprica.vlcj.factory.discovery.NativeDiscovery
import uk.co.caprica.vlcj.player.component.CallbackMediaPlayerComponent

@ExperimentalComposeUiApi
fun main(args: Array<String>) = application {
    Window {
        Box(
            modifier = Modifier.fillMaxSize()
        ) {
            val playerState = remember { PlayerState() }

            VideoPlayer(
                modifier = Modifier.fillMaxSize(),
                url = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
                playerState = playerState
            )

            @Suppress("SameParameterValue")
            PlayPauseButton(
                modifier = Modifier.align(Alignment.BottomCenter).padding(bottom = 30.dp),
                isPlay = playerState.isPlay(),
                onPlayClicked = {
                    playerState.play()
                },
                onPauseClicked = {
                    playerState.pause()
                }
            )

        }
    }
}

@Composable
fun PlayPauseButton(
    modifier: Modifier = Modifier,
    isPlay: Boolean,
    onPlayClicked: () -> Unit,
    onPauseClicked: () -> Unit
) {
    Button(
        modifier = modifier,
        onClick = {
            if (isPlay) {
                onPauseClicked()
            } else {
                onPlayClicked()
            }
        },
    ) {
        Text(
            if (isPlay) {
                "PAUSE"
            } else {
                "PLAY"
            }
        )
    }
}

private class PlayerState {
    var playPause by mutableStateOf(true)

    fun play() {
        playPause = true
    }


    fun pause() {
        playPause = false
    }

    fun isPlay() = playPause
    fun isPause() = !playPause
}


@Composable
private fun VideoPlayer(
    modifier: Modifier = Modifier,
    url: String,
    playerState: PlayerState
) {
    println("Video player for $url")
    NativeDiscovery().discover()
    val mediaPlayerComponent = remember { CallbackMediaPlayerComponent() }

    LaunchedEffect(Unit) {
        val ok = mediaPlayerComponent.mediaPlayer().media().play(url)
        println("play gave $ok")
    }

    // Play/Pause control
    mediaPlayerComponent.mediaPlayer().controls().let { controls ->
        if (playerState.isPlay()) {
            controls.play()
        }

        if (playerState.isPause()) {
            controls.pause()
        }
    }

    return SwingPanel(
        background = Color.Transparent,
        modifier = modifier,
        factory = {
            mediaPlayerComponent
        }
    )
}
@JoeSteven
Copy link

had same issue here, looks like VideoPlayer always on top level of the screen, when i put video player in a lazy column and put a floatingActionButton outside LazyColumn, the VideoPlayer also covered it。like this:
image

And there is another problem, VideoPlayer has no response to click events, here is my code:

 VideoPlayer(
     modifier = Modifier
                .fillMaxSize()
                .clickable( onClick = { //do something here } ),
     url = it,
) 

@HuixingWong
Copy link

This is an issue that is seriously affecting people starting to use the compose desktop, please consider raising its priority, similar issues have been around for dozens of months

@igordmn igordmn added the swing interop Swing interop issue label Nov 24, 2021
@akurasov akurasov added this to the 1.1 milestone Dec 16, 2021
@akurasov akurasov modified the milestones: 1.1, 1.1? Jan 11, 2022
@wispborne
Copy link

Here is another screenshot to show how jarring this is.
The webview is a SwingPanel, everything else is Compose. The webview should be dimmed, with the AlertDialog in front of it.
Instead, the webview stands above everything, cutting off any Compose content, which doesn't know that it's being cut off.

image

@akurasov
Copy link
Contributor

akurasov commented Mar 9, 2022

@DavidWhitman have you seen Swing interop tutorial hear?

@wispborne
Copy link

wispborne commented Mar 9, 2022

@DavidWhitman have you seen Swing interop tutorial hear?

It simply says that this is the way that SwingPanel works and you should design around the limitation or try to implement it in Compose (good luck to anyone with building a WebView component in Compose - that's no small thing).

Link: https://github.com/JetBrains/compose-jb/tree/master/tutorials/Swing_Integration

Did I miss your point @akurasov?

@igordmn igordmn removed this from the 1.1? milestone May 26, 2022
@egorikftp
Copy link

Any updates?

@pjBooms pjBooms assigned igordmn and unassigned Rsedaikin Feb 13, 2023
@KevinnZou
Copy link

Any updates? Facing the same issue with WebView wrapped in SwingPanel.

@MatkovIvan
Copy link
Member

With some limitations (due to OS level blending) it's available under the flag now - JetBrains/compose-multiplatform-core#915

@tangshimin
Copy link

I'm using windows, and when I upgraded compose to v1.6.0, and use EmbeddedMediaPlayerComponent to render the video, the video doesn't show up, only the sound is heard.

@MatkovIvan
Copy link
Member

@tangshimin it's not enabled by default and has some limitations (because of OS blending). See #4389 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working desktop swing interop Swing interop issue
Projects
None yet
Development

No branches or pull requests