Jetpack Compose - How to extract target from pointerInteropFilter

Viewed 833

I making a custom progressbar with touch control (for music player). So now i need to calculate percentage using formula like this: (event.x/target.width)*100, where target.width is pseudo code. How to get reference to view on which event occurred?

    Box(modifier= Modifier
        .clip(clipShape)
        .pointerInteropFilter { event->
            when(event.action){
                MotionEvent.ACTION_UP->{
                    Log.d("Touches", event.x.toString())
                }
            }
            true
        }
    ){...}
1 Answers

UPD, archived desired behavior using onSizeChanged

var width: Int by mutableStateOf(0)
...
    Box(modifier= Modifier
        .clip(clipShape)
        .onSizeChanged { it: IntSize ->
            width = it.width
        }
        .pointerInteropFilter { event->
            when(event.action){
                MotionEvent.ACTION_UP->{
                    Log.d("ListeningProgress", (event.x / width * 100).roundToInt().toString())
                }
            }
            true
        }
    )
Related