Using Timers

API Reference: Timer

Timer allows you to create, start and clear timers.

const Page = require("sf-core/ui/page");
const extend = require("js-base/core/extend");
const Color = require('sf-core/ui/color');
const FlexLayout = require('sf-core/ui/flexlayout');
const Button = require("sf-core/ui/button")
const Timer = require("sf-core/global/timer");
var Page1 = extend(Page)(
function(_super) {
_super(this, {
onShow: function(params) {
Application.statusBar.visible = false;
this.headerBar.visible = false;
}
});
this.layout.flexDirection = FlexLayout.FlexDirection.ROW;
this.layout.justifyContent = FlexLayout.JustifyContent.CENTER;
this.layout.alignItems = FlexLayout.AlignItems.CENTER;
var myButton = new Button({
onPress: setTimer
});
function setTimer() {
var myTimer = Timer.setTimeout({
task: changeBackgroundColor,
delay: 3000
});
}
function changeBackgroundColor() {
myButton.backgroundColor = Color.RED;
}
this.layout.addChild(myButton);
}
);
module.exports = Page1;