Skip to content

Instantly share code, notes, and snippets.

@Debdutta-Panda
Created July 22, 2022 03:49
Show Gist options
  • Save Debdutta-Panda/2db64ebac52c8c8863144e0489b0fc4c to your computer and use it in GitHub Desktop.
Save Debdutta-Panda/2db64ebac52c8c8863144e0489b0fc4c to your computer and use it in GitHub Desktop.
Jetpack Compose pointerInterOpFilter
package com.debduttapanda.pointerinteropfilter
import android.os.Bundle
import android.util.Log
import android.view.MotionEvent
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInteropFilter
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.debduttapanda.pointerinteropfilter.ui.theme.PointerInterOpFilterTheme
class MainActivity : ComponentActivity() {
@OptIn(ExperimentalComposeUiApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
PointerInterOpFilterTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
) {
Box(){
Box(
modifier = Modifier
.size(200.dp)
.background(Color.Red)
.pointerInteropFilter {event->
Log.d("pointer_log__","${event.pointerCount}")
when(event.action){
MotionEvent.ACTION_UP->{
Log.d("pointer_log","action_up ${event.x},${event.y}")
}
MotionEvent.ACTION_DOWN->{
Log.d("pointer_log","action_down ${event.x},${event.y}")
}
MotionEvent.ACTION_MOVE->{
Log.d("pointer_log","action_move ${event.x},${event.y}")
}
}
true
}
){
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment