# compose

Colton Idle

05/25/2022, 4:20 PM
My slack/twitter search skills are failing me. I could have sworn someone posted something about moving a composable (like a credit card or something) based off of the phones gyroscope sensors so it created a cool effect. Does anyone know what I'm talking about or am I mis-remembering{}?
aha. but its not based off sensors. cool. anyway. ive got some research to do. this seems fun.
Also, @jim FWIW I was searching "compose gyroscope" and that had 0 hits.


05/25/2022, 4:33 PM
Yeah, I think connecting it to the gyroscope is more-or-less left as an exercise for the user for most implementations.
👍 1

Colton Idle

05/25/2022, 4:36 PM
Yeah. I think I was confusing it with swift gyroscope examples, because if you search that on twitter you get a BUNCH of really cool swiftui gyro examples.


05/25/2022, 4:51 PM
Thanks for the first link Jim! I had my own implementation of parallax but the one from the link seems better on performance, really cool!

Colton Idle

05/25/2022, 11:25 PM
Somewhat related so Im posting here. How would I log gyro events in a composaable. Having a listener isnt the right approach right? Could I put this in a VM? Or am I missing something else basic here
Copy code
fun ParallaxTest() {

  val sensorManager = LocalContext.current.getSystemService(SENSOR_SERVICE) as SensorManager
  val gravitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);

  sensorManager.registerListener(object : SensorEventListener {
    override fun onSensorChanged(event: SensorEvent?) {
      if (event?.sensor?.type == Sensor.TYPE_GYROSCOPE){
      Log.e("Test", "X"+event.values[0])
      Log.e("Test", "Y"+event.values[1])
      Log.e("Test", "Z"+event.values[2])

    override fun onAccuracyChanged(p0: Sensor?, p1: Int) {
  }, gravitySensor, SensorManager.SENSOR_DELAY_FASTEST)