Accelerometer
API Reference: Device.Accelerometer
Accelerometer allows capturing accelerometer (motion) events on the device.
TypeScript
import PageSampleDesign from "generated/pages/pageSample";
import { Route, Router } from "@smartface/router";
import Application from "@smartface/native/application";
import Accelerometer from "@smartface/native/device/accelerometer";
//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();
Accelerometer.start();
Accelerometer.onAccelerate = (event: {
x: number;
y: number;
z: number;
}): void => {
console.log("x: " + event.x + " y : " + event.y + " z : " + event.z);
if (event.z > 9) {
Accelerometer.stop();
}
};
}
}