Screen

API Reference: Device.Screen

Screen is used to retrieve device display properties.

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 Screen = require('sf-core/device/screen');
//You should create new Page from UI-Editor and extend with it.
export default class Sample extends PageSampleDesign {
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.COLUMN;
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();
console.log("Device.Screen.dpi: " + Screen.dpi);
console.log("Device.Screen.width: " + Screen.width);
console.log("Device.Screen.height: " + Screen.height);
console.log("Device.Screen.touchSupported: " + Screen.touchSupported);
console.log("Device.Screen.orientation: " + Screen.orientation);
}
JavaScript
const Page = require("sf-core/ui/page");
const extend = require("js-base/core/extend");
const Screen = require('sf-core/device/screen');
var Page1 = extend(Page)(
function(_super) {
_super(this, {
onShow: function(params) {
Application.statusBar.visible = false;
this.headerBar.visible = false;
}
});
console.log("Device.Screen.dpi: " + Screen.dpi);
console.log("Device.Screen.width: " + Screen.width);
console.log("Device.Screen.height: " + Screen.height);
console.log("Device.Screen.touchSupported: " + Screen.touchSupported);
console.log("Device.Screen.orientation: " + Screen.orientation);
}
);
module.exports = Page1;

It is also possible to capture a screenshot with the Device.Screen.capture function.

TypeScript
JavaScript
TypeScript
import PageSampleDesign from 'generated/pages/pageSample';
import FlexLayout = require('sf-core/ui/flexlayout');
import Application = require('sf-core/application');
import ImageView = require('sf-core/ui/imageview');
import Button = require('sf-core/ui/button');
import Screen = require('sf-core/device/screen');
//You should create new Page from UI-Editor and extend with it.
export default class Sample extends PageSampleDesign {
myImageView: ImageView;
myButton: 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.COLUMN;
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.myImageView = new ImageView();
this.layout.addChild(this.myImageView, "myImageView", ".sf-imageView", {
width: 500,
height: 500
});
this.myButton = new Button({
onPress: () => {
this.myImageView.image = Screen.capture();
}
})
this.layout.addChild(this.myButton, "myButton", ".sf-button", {
width: 100,
height: 100,
backgroundColor: "#FFFF00"
});
}
JavaScript
const Page = require("sf-core/ui/page");
const extend = require("js-base/core/extend");
const Image = require('sf-core/ui/image');
const ImageView = require('sf-core/ui/imageview');
const Button = require('sf-core/ui/button');
const Color = require('sf-core/ui/color');
const Screen = require('sf-core/device/screen');
var Page1 = extend(Page)(
function(_super) {
_super(this, {
onShow: function(params) {
Application.statusBar.visible = false;
this.headerBar.visible = false;
}
});
var screenshot;
var myImageView = new ImageView({
width: 500,
height: 500,
backgroundColor: Color.BLACK,
});
this.layout.addChild(myImageView);
var myButton = new Button({
width: 100,
height: 100,
backgroundColor: Color.RED,
onPress: function() {
myImageView.image = Screen.capture();
}
})
this.layout.addChild(myButton);
}
);
module.exports = Page1;