Skip to content

Instantly share code, notes, and snippets.

@feresr
Created Dec 6, 2020
Embed
What would you like to do?
Gist
package com.feresr.threedp
import android.os.Bundle
import android.view.MotionEvent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.size
import androidx.compose.material.Surface
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInteropFilter
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.unit.dp
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val verticalOffset = remember { mutableStateOf(500f) }
val horizontalOffset = remember { mutableStateOf(500f) }
Surface(
modifier = Modifier.size(
horizontalOffset.value.dp, // .div(3)
verticalOffset.value.dp // .div(3),
).pointerInteropFilter {
when (it.action) {
MotionEvent.ACTION_MOVE -> {
horizontalOffset.value = it.rawX
verticalOffset.value = it.rawY
}
}
true
},
color = Color.Red) {}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment