View

API Reference: UI.View

View class represents a rectangular area on the screen and it is responsible for event handling. View is the base of all UI classes.

TypeScript code blocks include examples of how to implement, override and components within the theme. You can create page with the UI Editor to make your page compatible with theming and then you can implement themable components programmatically. Once the page is created with the UI Editor, it generates a class under scripts/generated/pages. You can then extend that class with the following 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 View = require('sf-core/ui/view');
//You should create new Page from UI-Editor and extend with it.
export default class Sample extends PageSampleDesign {
myView: View;
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 } = this;
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.myView = new View();
this.layout.addChild(this.myView, "myView", ".sf-view", {
width: 250,
flexGrow: 1,
height: 200,
backgroundColor: "#00A1F1",
flexProps: {
alignSelf: "CENTER"
}
});
}
JavaScript
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 View = require('sf-core/ui/view');
const Button = require('sf-core/ui/button');
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;
var myView = new View({
flexGrow: 1,
height: 200,
backgroundColor : Color.create("#00A1F1"),
alignSelf : FlexLayout.AlignSelf.CENTER
});
this.layout.addChild(myView);
}
);
module.exports = Page1;

Removed Or Added Child

Get information about removed or added child.

TypeScript
JavaScript
TypeScript
import PageSampleDesign from 'generated/pages/pageSample';
import FlexLayout = require('sf-core/ui/flexlayout');
import Application = require('sf-core/application');
import Label = require('sf-core/ui/label');
import View = require('sf-core/ui/view');
import Button = require('sf-core/ui/button');
//You should create new Page from UI-Editor and extend with it.
export default class Sample extends PageSampleDesign {
myFl: FlexLayout;
myLabel: Label;
myChildBtn: Button;
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 } = this;
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.myFl = new FlexLayout({
text: "Touch Me",
onTouch: () => {
this.myFl.addChild(this.myChildBtn, "myChildBtn", ".sf-button", {
width: 100,
height: 50,
textColor: "#FFFFFF"
});
this.myLabel.visible = false
},
});
this.myFl.onViewRemoved = function (removedChild) {
alert("removed child type: " + removedChild)
}
this.myFl.onViewAdded = function (addedChild) {
if (addedChild == 'Button') alert("added child type: " + addedChild)
}
this.myLabel = new Label({
text: "Touch in blue"
});
this.myChildBtn = new Button({
text: "Remove Me",
onPress: () => {
this.myFl.removeChild(this.myChildBtn);
this.myLabel.visible = true
}
});
this.layout.addChild(this.myFl, "myFl", ".sf-flexLayout", {
flexGrow: 1,
height: 200,
backgroundColor: "#00A1F1",
flexProps: {
alignSelf: "CENTER"
},
textColor: "#FFFFFF"
});
this.layout.addChild(this.myLabel, "myLabel", ".sf-label", {
width: 100,
height: 70,
top: 50,
backgroundColor: "#FFFFFF",
flexProps: {
alignSelf: "CENTER"
},
textColor: "#00A1F1"
});
}
JavaScript
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 Label = require('sf-core/ui/label');
const View = require('sf-core/ui/view');
const Button = require('sf-core/ui/button');
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;
var myFl = new FlexLayout({
flexGrow: 1,
height: 200,
backgroundColor: Color.create("#00A1F1"),
alignSelf: FlexLayout.AlignSelf.CENTER,
text: "Touch Me",
textColor: Color.create("#FFFFFF"),
onTouch: function() {
myFl.addChild(myChildBtn);
myLabel.visible = false
},
});
myFl.onViewRemoved = function(removedChild) { alert("removed child type: " + removedChild) }
myFl.onViewAdded = function(addedChild) {
if (addedChild=='Button') alert("added child type: " + addedChild)
}
var myLabel = new Label({
width: 100,
height: 50,
text: "Touch in blue",
textColor: Color.WHITE,
});
myFl.addChild(myLabel);
var myChildBtn = new Button({
width: 100,
height: 70,
top: 50,
backgroundColor: Color.create("#FFFFFF"),
alignSelf: FlexLayout.AlignSelf.CENTER,
text: "Remove Me",
textColor: Color.create("#00A1F1"),
onPress: function() {
myFl.removeChild(myChildBtn);
myLabel.visible = true
}
});
this.layout.addChild(myFl);
}
);
module.exports = Page1;