AlertView

API Reference: UI.AlertView

AlertView is a dialog that can be used to provide information to the user or to prompt for confirmation. AlertView has buttons with callbacks so you can execute different actions for each button.

TypeScript code blocks includes example of how to implement, override & add components with theme. Create page with UI-Editor to make your page themeable and then able to implement themeable components programmatically. Once page created with UI-Editor, it generates class under scripts/generated/pages. Extend that class with below typescript classes.

TypeScript
JavaScript
TypeScript
import PageSampleDesign from 'generated/pages/pageSample';
import FlexLayout = require('sf-core/ui/flexlayout');
import Application = require('sf-core/application');
import System = require("sf-core/device/system");
import AlertView = require('sf-core/ui/alertview');
//You should create new Page from UI-Editor and extend with it.
export default class AlertViewSample extends PageSampleDesign {
myAlertView: AlertView;
constructor() {
super();
// Overrides super.onShow method
this.onShow = onShow.bind(this, this.onShow.bind(this));
// Overrides super.onLoad method
this.onLoad = onLoad.bind(this, this.onLoad.bind(this));
this.layout.flexDirection = FlexLayout.FlexDirection.ROW;
this.layout.justifyContent = FlexLayout.JustifyContent.CENTER;
this.layout.alignItems = FlexLayout.AlignItems.CENTER;
}
}
/**
* @event onShow
* This event is called when a page appears on the screen (everytime).
* @param {function} superOnShow super onShow function
* @param {Object} parameters passed from Router.go function
*/
function onShow(superOnShow: () => void) {
const { headerBar } = System.OS === "Android" ? this : this.parentController;
superOnShow();
Application.statusBar.visible = false;
headerBar.visible = false;
}
/**
* @event onLoad
* This event is called once when page is created.
* @param {function} superOnLoad super onLoad function
*/
function onLoad(superOnLoad: () => void) {
superOnLoad();
this.myAlertView = new AlertView({
title: "Alert Title",
message: "Alert Message"
});
this.myAlertView.addButton({
index: AlertView.ButtonType.NEGATIVE,
text: "Cancel"
});
this.myAlertView.addButton({
index: AlertView.ButtonType.POSITIVE,
text: "OK",
onClick: function () : void {
console.log("OK clicked.");
}
});
this.myAlertView.show();
}
JavaScript
const Page = require("sf-core/ui/page");
const extend = require("js-base/core/extend");
const AlertView = require('sf-core/ui/alertview');
var Page1 = extend(Page)(
function(_super) {
_super(this, {
onShow: function(params) {
Application.statusBar.visible = false;
this.headerBar.visible = false; //For Android
}
});
var myAlertView = new AlertView({
title: "Alert Title",
message: "Alert Message"
});
myAlertView.addButton({
index: AlertView.ButtonType.NEGATIVE,
text: "Cancel"
});
myAlertView.addButton({
index: AlertView.ButtonType.POSITIVE,
text: "OK",
onClick: function() {
console.log("OK clicked.");
}
});
myAlertView.show();
}
);
module.exports = Page1;

Extension AlertView

AlertView with editable fields.

TypeScript
JavaScript
TypeScript
import PageSampleDesign from 'generated/pages/pageSample';
import FlexLayout = require('sf-core/ui/flexlayout');
import Application = require('sf-core/application');
import System = require("sf-core/device/system");
import AlertView = require('sf-core/ui/alertview');
//You should create new Page from UI-Editor and extend with it.
export default class AlertViewSample extends PageSampleDesign {
myAlertView: AlertView;
constructor() {
super();
// Overrides super.onShow method
this.onShow = onShow.bind(this, this.onShow.bind(this));
// Overrides super.onLoad method
this.onLoad = onLoad.bind(this, this.onLoad.bind(this));
this.layout.flexDirection = FlexLayout.FlexDirection.ROW;
this.layout.justifyContent = FlexLayout.JustifyContent.CENTER;
this.layout.alignItems = FlexLayout.AlignItems.CENTER;
}
}
/**
* @event onShow
* This event is called when a page appears on the screen (everytime).
* @param {function} superOnShow super onShow function
* @param {Object} parameters passed from Router.go function
*/
function onShow(superOnShow: () => void) {
const { headerBar } = System.OS === "Android" ? this : this.parentController;
superOnShow();
Application.statusBar.visible = false;
headerBar.visible = false;
}
/**
* @event onLoad
* This event is called once when page is created.
* @param {function} superOnLoad super onLoad function
*/
function onLoad(superOnLoad: () => void) {
superOnLoad();
this.myAlertView = new AlertView({
title: "Alert Title",
message: "Alert Message"
});
this.myAlertView.addButton({
index: AlertView.ButtonType.NEGATIVE,
text: "Cancel"
});
this.myAlertView.addButton({
index: AlertView.ButtonType.POSITIVE,
text: "OK",
onClick: function (): void {
console.log("OK clicked.");
}
});
this.myAlertView.addTextBox({
text: "Hello!",
hint: "Hint!",
isPassword: false,
android: {
viewSpacings: { left: 50, right: 50 }
}
});
this.myAlertView.show();
}
JavaScript
const Application = require("sf-core/application");
const Page = require("sf-core/ui/page");
const extend = require("js-base/core/extend");
const AlertView = require('sf-core/ui/alertview');
var Page1 = extend(Page)(
function(_super) {
_super(this, {
onShow: function(params) {
Application.statusBar.visible = false;
this.headerBar.visible = false; //For Android
}
});
var myAlertView = new AlertView({
title: "Alert Title",
message: "Alert Message"
});
myAlertView.addButton({
index: AlertView.ButtonType.NEGATIVE,
text: "Cancel"
});
myAlertView.addButton({
index: AlertView.ButtonType.POSITIVE,
text: "OK",
onClick: function() {
console.log("OK clicked.");
}
});
myAlertView.addTextBox({
text: "Hello!",
hint: "Hint!",
isPassword: false,
android: {
viewSpacings: { left: 50, right: 50 }
}
});
myAlertView.show();
}
);
module.exports = Page1;