AlignSelf

API Reference: UI.FlexLayout.AlignSelf

This allows the default alignment (or the ones specified by AlignItems) to be overridden for individual FlexLayout items.

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.

If any of the items' cross-axis margin is set to auto, then AlignSelf is ignored.

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');
//You should create new Page from UI-Editor and extend with it.
export default class Sample extends PageSampleDesign {
myFlexLayout: FlexLayout;
label1: Label;
label2: Label;
label3: Label;
label4: Label;
label5: Label;
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.FLEX_START;
this.layout.alignItems = FlexLayout.AlignItems.FLEX_START;
}
}
/**
* @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.myFlexLayout = new FlexLayout()
this.layout.addChild(this.myFlexLayout, "myFlexLayout", ".sf-flexLayout", {
top: 0,
left: 0,
bottom: 0,
right: 0,
flexProps: {
positionType: "ABSOLUTE",
flexDirection: "ROW",
justifyContent: "SPACE_BETWEEN",
alignItems: "CENTER"
},
backgroundColor: "#FFFFFF"
});
let userProps1 = {
width: 100,
height: 80,
textAlignment: "MIDCENTER"
};
this.label1 = new Label({
text: "1"
})
this.label2 = new Label({
text: "2"
})
let userProps2 = {
width: 80,
height: 80,
textAlignment: "MIDCENTER"
};
this.label3 = new Label({
text: "3"
})
this.label4 = new Label({
text: "4"
})
this.label5 = new Label({
text: "5"
})
//@ts-ignore
this.myFlexLayout.addChild(this.label1, "label1", ".sf-flexLayout", Object.assign(userProps2, {
backgroundColor: "#2a80b9",
flexProps: {
alignSelf: "AUTO"
}
}));
//@ts-ignore
this.myFlexLayout.addChild(this.label2, "label2", ".sf-flexLayout", Object.assign(userProps2, {
backgroundColor: "#8f44ad",
flexProps: {
alignSelf: "FLEX_START"
}
}));
//@ts-ignore
this.myFlexLayout.addChild(this.label3, "label3", ".sf-flexLayout", Object.assign(userProps2, {
backgroundColor: "#16a086",
flexProps: {
alignSelf: "FLEX_END"
}
}));
//@ts-ignore
this.myFlexLayout.addChild(this.label4, "label4", ".sf-flexLayout", Object.assign(userProps2, {
backgroundColor: "#f1c40f",
flexProps: {
alignSelf: "CENTER"
}
}));
//@ts-ignore
this.myFlexLayout.addChild(this.label5, "label5", ".sf-flexLayout", Object.assign(userProps1, {
backgroundColor: "#e77e23",
flexProps: {
alignSelf: "STRETCH"
}
}));
}
JavaScript
const Page = require("nf-core/ui/page");
const extend = require("js-base/core/extend");
const FlexLayout = require('nf-core/ui/flexlayout');
const Color = require('nf-core/ui/color');
const TextAlignment = require('nf-core/ui/textalignment');
const Label = require('nf-core/ui/label');
var Page1 = extend(Page)(
function(_super) {
_super(this, {
onShow: function(params) {
this.statusBar.visible = false;
this.headerBar.visible = false;
}
});
var myFlexLayout = new FlexLayout({
top: 0,
left: 0,
bottom: 0,
right: 0,
backgroundColor: Color.WHITE,
positionType: FlexLayout.PositionType.ABSOLUTE,
flexDirection: FlexLayout.FlexDirection.ROW,
justifyContent: FlexLayout.JustifyContent.SPACE_BETWEEN,
alignItems: FlexLayout.AlignItems.CENTER
})
this.layout.addChild(myFlexLayout);
var label1 = new Label({
width: 50,
height: 50,
alignSelf: FlexLayout.AlignSelf.AUTO,
text: "auto",
textAlignment: TextAlignment.MIDCENTER,
backgroundColor: Color.create("#2a80b9")
})
var label2 = new Label({
width: 50,
height: 50,
alignSelf: FlexLayout.AlignSelf.FLEX_START,
text: "flex start",
textAlignment: TextAlignment.MIDCENTER,
backgroundColor: Color.create("#8f44ad")
})
var label3 = new Label({
width: 50,
height: 50,
alignSelf: FlexLayout.AlignSelf.FLEX_END,
text: "flex end",
textAlignment: TextAlignment.MIDCENTER,
backgroundColor: Color.create("#16a086")
})
var label4 = new Label({
width: 50,
height: 50,
alignSelf: FlexLayout.AlignSelf.CENTER,
text: "center",
textAlignment: TextAlignment.MIDCENTER,
backgroundColor: Color.create("#f1c40f")
})
var label5 = new Label({
width: 50,
alignSelf: FlexLayout.AlignSelf.STRETCH,
text: "stretch",
textAlignment: TextAlignment.MIDCENTER,
backgroundColor: Color.create("#e77e23")
})
myFlexLayout.addChild(label1);
myFlexLayout.addChild(label2);
myFlexLayout.addChild(label3);
myFlexLayout.addChild(label4);
myFlexLayout.addChild(label5);
}
);
module.exports = Page1;