Skip to main content
Version: 7.3.2

Using Timers

API Reference: Timer

Timer allows you to create, start and clear timers.

note

The components in the example are added from the code for better showcase purposes. To learn more about the subject you can refer to:

Adding Component From Code

As a best practice, Smartface recommends using the WYSIWYG editor in order to add components and styles to your page or library. To learn how to use UI Editor better, please refer to this documentation

UI Editor Basics
TypeScript
import PageSampleDesign from "generated/pages/pageSample";
import { Route, Router } from "@smartface/router";
import System from "@smartface/native/device/system";
import Button from "@smartface/native/ui/button";
import Timer from "@smartface/native/global/timer";
import Application from "@smartface/native/application";
import { styleableComponentMixin } from "@smartface/styling-context";

class StyleableButton extends styleableComponentMixin(Button) {}


//You should create new Page from UI-Editor and extend with it.
export default class Sample extends PageSampleDesign {
myButton: StyleableButton;
constructor(private router?: Router, private route?: Route) {
super({});
}

// The page design has been made from the code for better
// showcase purposes. As a best practice, remove this and
// use WYSIWYG editor to style your pages.
centerizeTheChildrenLayout() {
this.dispatch({
type: "updateUserStyle",
userStyle: {
flexProps: {
flexDirection: 'COLUMN',
justifyContent: 'CENTER',
alignItems: 'CENTER'
}
}
})
}

setTimer(): void {
const { myButton } = this;

Timer.setTimeout({
task: (): void => {
myButton.dispatch({
type: "updateUserStyle",
userStyle: {
backgroundColor: "#FF0000",
},
});
},
delay: 3000,
});
}

onShow() {
super.onShow();
const { headerBar } = System.OS === System.OSType.ANDROID ? this : this.parentController;
Application.statusBar.visible = true;
headerBar.visible = true;
}

onLoad() {
super.onLoad();
this.centerizeTheChildrenLayout();

this.myButton = new StyleableButton({
text: "Set Timer",
onPress: this.setTimer.bind(this),
});

this.addChild(this.myButton, "myButton", ".sf-button");
}
}

Global access

You can use global setTimeout and setInterval functions.


setTimeout(() => {
// your code
}, 1000);

setInterval(() => {
// your code
}, 1000)