Services

ShakeDetector

ShakeDetector service

Create or retrieve this service with page.shake_detector(**properties). Ruflet reuses the registered service unless you supply a different id.

Example

status = text(value: "Shake the device to refresh")
page.add(status)
page.shake_detector(
  minimum_shake_count: 2,
  on_shake: ->(_event) { page.update(status, value: "Refreshing…") }
)

Page accessor

  • page.shake_detector(**props)

Properties

  • data — Arbitrary value you can attach to the control and read back in handlers.
  • key — Stable identity used to preserve state across rebuilds.
  • minimum_shake_count — Sets the minimum shake count property.
  • shake_count_reset_time_ms — Sets the shake count reset time ms property.
  • shake_slop_time_ms — Sets the shake slop time ms property.
  • shake_threshold_gravity — Sets the shake threshold gravity property.

Events

  • on_shake — Fired on shake.

Result and error handling

Client calls are asynchronous. When a method accepts on_result:, handle both callback values: |result, error|. Availability and returned data can vary by platform.

Common service API

The service also supports the common Ruflet control API: attach_handler(event_name, handler), children, emit(event_name, event), has_handler?(event_name), id, merge_props(values = ...), on(event_name, &block), props, runtime_page, runtime_page=, to_patch, type, wire_id, wire_id=.

Use the named methods above for application code; common control methods mainly support event registration, updates, and runtime integration.

Wire reference

  • Service helper: shake_detector
  • Wire type: shakedetector
  • Aliases: shakedetector

Protected device access

Declare motion access in services.yaml, then rebuild the native client:

services:
  - motion:
      description: Explain why your app reads motion sensor data.