FlexShrink

API Reference: UI.View.flexShrink

This property specifies how much a view will shrink relative to the other views inside the same FlexLayout. It aims to shrink the view to fit to the screen.

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.

Tip

You need to set wrap property as flexWrap.NOWRAP to observe effects of flexShrink.

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;
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.myFlexLayout = new FlexLayout()
this.layout.addChild(this.myFlexLayout, "myFlexLayout", ".sf-flexLayout", {
top: 0,
left: 0,
bottom: 0,
right: 0,
flexProps: {
positionType: "ABSOLUTE",
flexDirection: "ROW"
},
backgroundColor: "#FFFFFF"
});
this.label1 = new Label({
text: "flexShrink:1"
});
this.label2 = new Label({
text: "flexShrink:5"
});
this.label3 = new Label({
text: "flexShrink:10"
});
//@ts-ignore
this.myFlexLayout.addChild(this.label1, "label1", ".sf-flexLayout", {
width: 170,
height: 80,
textAlignment: "MIDCENTER",
backgroundColor: "#2a80b9",
flexProps: {
flexShrink: 1
}
});
//@ts-ignore
this.myFlexLayout.addChild(this.label2, "label2", ".sf-flexLayout", {
width: 170,
height: 80,
textAlignment: "MIDCENTER",
backgroundColor: "#8f44ad",
flexProps: {
flexShrink: 5
}
});
//@ts-ignore
this.myFlexLayout.addChild(this.label3, "label3", ".sf-flexLayout", {
width: 170,
height: 80,
textAlignment: "MIDCENTER",
backgroundColor: "#16a086",
flexProps: {
flexShrink: 10
}
});
}
JavaScript
const Page = require("sf-core/ui/page");
const extend = require("js-base/core/extend");
const FlexLayout = require('sf-core/ui/flexlayout');
const Color = require('sf-core/ui/color');
const TextAlignment = require('sf-core/ui/textalignment');
const Label = require('sf-core/ui/label');
var Page1 = extend(Page)(
function(_super) {
_super(this, {
onShow: function(params) {
Application.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,
})
this.layout.addChild(myFlexLayout);
var label1 = new Label({
width: 170,
height: 80,
flexShrink:1,
text: "flexShrink:1",
textAlignment: TextAlignment.MIDCENTER,
backgroundColor: Color.create("#2a80b9")
})
var label2 = new Label({
width: 170,
height: 80,
flexShrink:5,
text: "flexShrink:5",
textAlignment: TextAlignment.MIDCENTER,
backgroundColor: Color.create("#8f44ad")
})
var label3 = new Label({
width: 170,
height: 80,
flexShrink:10,
text: "flexShrink:10",
textAlignment: TextAlignment.MIDCENTER,
backgroundColor: Color.create("#16a086")
})
myFlexLayout.addChild(label1);
myFlexLayout.addChild(label2);
myFlexLayout.addChild(label3);
}
);
module.exports = Page1;

Before FlexShrink is set

After FlexShrink is set