最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - How can I detect the blue box space minus the red box to detect events? - Stack Overflow

programmeradmin6浏览0评论

I am currently working with Rive, the red box is a hitbox where clicking launches the animation, the blue box is the space required by Rive. But I want to detect event outside the red box but inside the blue box so I can pause or play the video, as I currently have an event that does that on the entire screen.

@Composable
fun VideoBox(modifier: Modifier = Modifier) {

    var animation : RiveAnimationView? by remember { mutableStateOf(null) }


    Box(
        modifier = modifier.fillMaxSize()
    ) {
        Box(
            modifier = Modifier
                .fillMaxSize()
                .background(Color.DarkGray)
                .pointerInput(Unit){
                    detectTapGestures(
                        onDoubleTap = {
                            animation?.fireState(stateMachineName = "stateMachine", inputName = "tapTrigger")
                        },
                        onTap = {
                            Log.d("OverlappingBox" ,"Pause or play video")
                        }
                    )
                }
        )
        Box(
            modifier = Modifier
                .padding(end = 24.dp, bottom = 96.dp)
                .size(64.dp, 118.dp)
                .background(Color.Blue)
                .align(Alignment.BottomEnd)
        ){
            AndroidView(
                factory = { context ->
                    RiveAnimationView(context).apply {
                        setRiveResource(
                            resId = R.raw.likebutton_03,
                            artboardName = "heart_Particle",
                            stateMachineName = "stateMachine",
                        )
                    }
                },
                update = { view ->
                    animation = view
                }
            )
            Box(
                modifier = Modifier
                    .size(40.dp)
                    .background(Color.Red)
                    .align(Alignment.BottomCenter)
                    .clickable {
                        animation?.fireState(stateMachineName = "stateMachine", inputName = "tapTrigger")
                    }
            )
        }
    }
}

发布评论

评论列表(0)

  1. 暂无评论