🏗️
MauiReactor
  • What is MauiReactor?
  • What's new in Version 2
  • What's new in Version 3
  • Getting Started
  • Getting Started Version 2
  • Components
    • State-less Components
    • Stateful Components
      • Inline Components
    • Component life-cycle
    • Component Properties
    • Component with children
    • Component Parameters
    • Theming
    • Navigation
      • NavigationPage
      • Shell
      • Back button
    • Controls
      • Button
      • RadioButton
      • FlyoutPage
      • CollectionView
        • Interactions
        • Layout
        • Selection
        • Empty view
        • Scrolling
        • Grouping
      • IndicatorView
      • Picker
      • Shell
      • Label
    • Wrap 3rd party controls
      • Lottie animations
      • Provide DataTemplate to native controls
    • Accessing native controls
    • Animation
      • Property-Based
      • AnimationController
      • Timer
    • Graphics
      • CanvasView control
    • Window
    • Testing
    • XAML Integration
  • Deep dives
    • Native tree and Visual tree
    • Dependency injection
    • Working with the GraphicsView
    • Migrating from MVVM Model
    • Using XAML Resources
    • Behaviors
  • resources
    • Source and Sample Applications
  • Q&A
    • How to deal with state shared across Components?
    • Does this support ObservableCollection for CollectionView?
    • Do we need to add states to create simple animations such as ScaleTo, FadeTo, etc on tap?
    • How to deal with custom dialogs/popups?
  • How to create a Menu/ContextMenu?
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Components
  2. Animation

Timer

This page describes how to trigger timed events using the MauiReactor Timer object

When developing an app may happen that you need a timer that raises events regularly. In MauiReactor, as in .NET MAUI applications, you can use the timer types provided by the runtime (for example, the System.Timers.Timer class).

In MauiReactor, I recommend taking a look at Timer type provided by the library that is better suited to be integrated into MVU applications.

A MauiReactor Timer can be created as any other widget and added as a child of any other object:

Grid(
    Timer()
        .IsEnabled(State.ShowCountdown)
        .Interval(1000) //interval in ms
        .OnTick(....)
)

Run the timer setting to true its IsEnabled property and pass an action to the OnTick property to implement your logic.

For example, in the following code, we create a timer and update a label every second:

class CounterPageState
{
    public int Counter { get; set; }
    public bool TimerRunning { get; set; }
}

class CounterPage : Component<CounterPageState>
{
    public override VisualNode Render()
        => ContentPage("Counter Sample",
            VStack(
                Timer()
                    .IsEnabled(State.TimerRunning)
                    .Interval(1000)
                    .OnTick(() => SetState(s => s.Counter++)),

                Label($"Counter: {State.Counter}"),

                Button(State.TimerRunning ? "Pause" : "Run")
                    .OnClicked(() => SetState(s => s.TimerRunning = !s.TimerRunning))
            )
            .Spacing(10)
            .Center()
        );
}
PreviousAnimationControllerNextGraphics

Last updated 1 month ago

Was this helpful?