Timer Controller

A Timer Controller is a special variable type that controls timer widgets, allowing you to start, pause, resume, and reset timers programmatically. It's essential for building countdown timers, stopwatches, or any time-based functionality.

Supported Widgets

The Timer Controller can be used with:

  • Timer

When to Use

Use a Timer Controller when you need to:

  • Control countdown timers programmatically

  • Build stopwatch functionality

  • Implement time-based challenges or games

  • Create OTP/verification code timers

  • Pause and resume timers based on user actions

  • Reset timers for repeated use

Creating a Timer Controller

  1. Navigate to Variables in your project

  2. Click Add Variable

  3. Select Timer Controller as the type

  4. Give it a descriptive name (e.g., countdownController, otpTimerController)

Binding to Widgets

Timer Widget Example

Controller Methods

Use the Control Object action to invoke these methods on the controller.

start

Starts the timer from the beginning.

No parameters required.

When to Use:

  • Begin a countdown timer

  • Start a stopwatch

  • Initiate time-based challenges

Example:


resume

Resumes a paused timer from where it left off.

No parameters required.

When to Use:

  • Continue a paused timer

  • Resume after user interaction

  • Unpause functionality

Example:


pause

Pauses the timer, keeping the current time.

No parameters required.

When to Use:

  • Allow users to pause countdowns

  • Pause during app backgrounding

  • Temporary timer suspension

Example:


reset

Resets the timer back to its initial duration.

No parameters required.

When to Use:

  • Restart timer from beginning

  • Reset after completion

  • Provide "Try Again" functionality

Example:


Common Use Cases

1. OTP Verification Timer

Countdown timer for resending OTP codes.

Setup:

Implementation:

2. Quiz Timer with Pause/Resume

Timer for timed quizzes with pause functionality.

Setup:

Implementation:

3. Workout Interval Timer

Timer that resets and restarts for interval training.

Setup:

4. Stopwatch with Lap Times

Stopwatch that can be paused and reset.

Setup:

Implementation:

5. Session Timeout Warning

Warning users before session expires.

Setup:

Implementation:

Best Practices

  • One controller per timer: Each Timer widget should have its own controller

  • Use descriptive names: Name controllers after their purpose (quizTimerController, otpTimerController)

  • Track timer state: Use variables to track whether timer is running/paused for better UI control

  • Handle completion: Always provide On Complete handlers to manage what happens when timer ends

  • Reset appropriately: Reset timers before restarting to ensure they begin from the correct duration

  • Provide visual feedback: Show clear UI indicators for timer state (running, paused, completed)

  • Consider auto-start: Decide if timers should start automatically or require user action

Common Patterns

Start Timer

Pause/Resume Toggle

Reset and Restart

Conditional Start

Auto-Restart on Complete

Timer States

Understanding timer states helps manage control flow:

State
Description
Next Action

Not Started

Initial state, duration at max

start to begin

Running

Timer is actively counting

pause to pause

Paused

Timer stopped but time retained

resume to continue, reset to restart

Completed

Timer reached 0 (countdown) or max (stopwatch)

reset to restart

Troubleshooting

Controller Not Working

  • Ensure the controller variable is properly created

  • Check that the controller is bound to the Timer widget using ${controllerName}

  • Verify the widget supports Timer Controller

Timer Not Starting

  • Confirm start() is being called

  • Check that timer has a valid duration configured

  • Ensure timer isn't already running

Pause/Resume Not Working

  • Verify timer is in the correct state (running for pause, paused for resume)

  • Check that the correct method is being called

  • Ensure controller is properly bound

Reset Not Working

  • Confirm reset() is being invoked correctly

  • Check that timer widget has a valid initial duration

Last updated