Data

API Reference: Data

Data is an interface for storing key value data on Device and can be used for storing

  • Login data

  • Authentication token

  • Detecting one time activity such as showing a user for a welcome page

On Android, Data is stored under /data/data/APP_NAME/SharedPref/JS.xml

On iOS, Data is stored under /var/mobile>Contatiners>Data>Application>APP_NAME>Library>Preferences>SF_USER_DEFUALTS.plist

Stored areas are accessible by the app itself only unless the device is rooted. That is why before storing critical data, it is advised to use encryption.

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 Data = require('sf-core/global/data');
//You should create new Page from UI-Editor and extend with it.
export default class Sample extends PageSampleDesign {
router: any
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();
Data.setStringVariable('userName', 'Smartface');
Data.setStringVariable('userEmail', 'info@smartface.io');
Data.setIntVariable('userAge', 5);
Data.setBooleanVariable('userLogged', true);
if (Data.getBooleanVariable('userLogged')) {
this.router.push('/dashboard', {
userName: Data.getStringVariable('userName'),
userEmail: Data.getStringVariable('userEmail')
});
}
else {
this.router.push('/login');
}
}
JavaScript
const Data = require('sf-core/data');
Data.setStringVariable('userName','Smartface');
Data.setStringVariable('userEmail','info@smartface.io');
Data.setIntVariable('userAge',5);
Data.setBooleanVariable('userLogged',true);
...
if(Data.getBooleanVariable('userLogged')){
router.push('/dashboard', {
userName: Data.getStringVariable('userName'),
userEmail: Data.getStringVariable('userEmail')
});
}
else{
router.push('/login');
}