Skip to main content
Version: 7.3.1

Data

API Reference: Data

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

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

Location of Local Storage on Device

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. To learn more about natively encrypted data, refer to the SecureData documentation:

Secure Data (Keystore)
import PageSampleDesign from "generated/pages/pageSample";
import { Route, Router } from "@smartface/router";
import Application from "@smartface/native/application";
import Data from "@smartface/native/global/data";

//You should create new Page from UI-Editor and extend with it.
export default class Sample extends PageSampleDesign {
constructor(private router?: Router, private route?: Route) {
super({});
}

// The page design has been made from the code for better
// showcase purposes. As a best practice, remove this and
// use WYSIWYG editor to style your pages.
centerizeTheChildrenLayout() {
this.dispatch({
type: "updateUserStyle",
userStyle: {
flexProps: {
flexDirection: 'ROW',
justifyContent: 'CENTER',
alignItems: 'CENTER'
}
}
})
}

onShow() {
super.onShow();
const { headerBar } = this;
Application.statusBar.visible = false;
headerBar.visible = false;

}

onLoad() {
super.onLoad();
this.centerizeTheChildrenLayout();
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");
}
}
}