Sensors - how can I listen and react to changes?

Hi!

So I have a container, which is 100% height / width size (systemVars.dimensions.viewport). This container has justifyContent: center and alignItems: center.

Inside this container I have a red box with 32x32 size. At first it’s in the middle of the screen. This is correct, cool.

Now I want to move the red box with gyroscope. For example - rotate device to the left will move the ball to the left edge of the device.

Is it possible? I can assign sensorVars.gyroscope.latestValue.x / y to paragraph / title and just display it on the screen, but I can’t find an option to - for example:

  • create page vars X=0 and Y=0
  • remove / add gyroscope value to those X and Y vars on every change

What’s my use case is just trying to play with sensors - it’s fun :smiley:

Couldn’t bother to do the math for anything useful but you can certainly do stuff like this.

What I did was at the app launch I used start gyroscope poller flow function and then bound a formula sensorVars.gyroscope.latestValue.x * 100 to the box’s X position and y to Y respectively.

3 Likes