Skip to main content
Version: v3

AppWidget

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

Register AppWidget, specify the lifecycle callback for the current AppWidget, etc. Each AppWidget file must call the AppWidget() constructor only once.

Type

function AppWidget(option: Option): Result

Parameters

Option

PropertyTypeRequiredDefaultValueDescriptionAPI_LEVEL
stateobjectN-A data object mounted on a AppWidget instance that can be used to store the state of the current AppWidget2.0
onInit(params?: string) => voidN-It is triggered once per AppWidget and can be used to initialize the AppWidget state2.0
build(params?: string) => voidN-Triggered after onInit execution completes, recommended for UI drawing in the build lifecycle2.0
onResume() => voidN-Triggered when the screen focus is on this AppWidget2.0
onPause() => voidN-Triggered when the screen focus leaves this AppWidget2.0
onDestroy() => voidN-The onDestroy lifecycle function is triggered when the AppWidget is destroyed2.0

Result

TypeDescription
unknownAppWidget instance

Example

appWidget.js
AppWidget({
state: {
text: 'Hello Zepp OS',
},
onInit() {
console.log('onInit')
},
build() {
console.log('build')
console.log(this.state.text)
},
})