SecondaryWidget
Start from API_LEVEL
2.0
. Please refer to API_LEVEL.
Register SecondaryWidget, specify the lifecycle callback for the current SecondaryWidget, etc. Each SecondaryWidget file must call the SecondaryWidget()
constructor only once.
Type
function SecondaryWidget(option: Option): Result
Parameters
Option
Property | Type | Required | DefaultValue | Description | API_LEVEL |
---|---|---|---|---|---|
state | object | N | - | A data object mounted on a SecondaryWidget instance that can be used to store the state of the current SecondaryWidget | 2.0 |
onInit | (params?: string) => void | N | - | It is triggered once per SecondaryWidget and can be used to initialize the SecondaryWidget state | 2.0 |
build | (params?: string) => void | N | - | Triggered after onInit execution completes, recommended for UI drawing in the build lifecycle | 2.0 |
onResume | () => void | N | - | Triggered when the screen focus is on this SecondaryWidget | 2.0 |
onPause | () => void | N | - | Triggered when the screen focus leaves this SecondaryWidget | 2.0 |
onDestroy | () => void | N | - | The onDestroy lifecycle function is triggered when the SecondaryWidget is destroyed | 2.0 |
Result
Type | Description |
---|---|
unknown | SecondaryWidget instance |
Example
secondaryWidget.js
SecondaryWidget({
state: {
text: 'Hello Zepp OS',
},
onInit() {
console.log('onInit')
},
build() {
console.log('build')
console.log(this.state.text)
},
})