MobTouch (mob_touch v0.1.0)

Copy Markdown View Source

Stream the user's raw screen touches to a screen — a Mob plugin.

Unlike per-widget on_tap (which only fires for a tapped button), this observes every touch on the app's surface and reports its coordinates, so you can build drawing, custom gestures, heatmaps, joysticks, and the like.

It observes without consuming: the touches still reach the app's normal UI, so buttons and scrolling keep working while you stream. No runtime permission.

Updates arrive in the screen's handle_info/2:

handle_info({:touch, %{phase: phase, x: x, y: y, pointer: pointer,
                       timestamp: ms}}, socket)
  • phase:down (finger lands), :move, :up (finger lifts), or :cancel (the OS took the gesture, e.g. a system swipe).
  • x, ydp (logical pixels), origin top-left of the app window; the same coordinate space the layout uses.
  • pointer — a stable id per finger across a gesture, so multi-touch is distinguishable. Single-finger use can ignore it.
  • timestamp — unix milliseconds.

iOS: a passive UIGestureRecognizer on the key window. Android: a Window.Callback that observes dispatchTouchEvent and forwards it on.

Call stop/1 when you no longer need the stream — the observer stays installed (and keeps the screen's mailbox busy on every touch) until you do.

Summary

Functions

Start streaming touches to the calling screen.

Stop streaming touches and remove the observer.

Functions

start(socket, opts \\ [])

@spec start(
  Mob.Socket.t(),
  keyword()
) :: Mob.Socket.t()

Start streaming touches to the calling screen.

Options:

  • :throttle_ms — the minimum interval between :move deliveries (default 16, ≈ 60 Hz). :down/:up/:cancel are never throttled. Raise it to cut mailbox traffic for coarse gestures; set 0 for every raw move.

stop(socket)

@spec stop(Mob.Socket.t()) :: Mob.Socket.t()

Stop streaming touches and remove the observer.