This module provides the handwriting suite components, including the canvas and toolbar, which are integrated to quickly implement the handwriting capability.
You need to provide entrances and callbacks to the handwriting canvas. The canvas will trigger a callback when the initialization, loading, and saving actions are complete. You can customize app behavior in the callback.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Stylus.Handwrite
Start version: 5.0.0(12)
Parameters:
Name | Type | Read-only | Optional | Description |
|---|---|---|---|---|
handwriteController | No | Yes | Instance of the handwriting suite function class. | |
onInit | () => void | No | Yes | Callback for suite initialization. |
onScale | (scale: number) => void | No | Yes | Callback for canvas scaling. The parameter of the callback method is the scaling factor of the current canvas. |
@Component
struct HandWritingComponent {
controller: HandwriteController = new HandwriteController();
// Obtain the path for storing the handwritten file based on the app storage rule. The path is for reference only.
initPath : string = "aa";
aboutToAppear(){
// Set the callback for the completion of the saving action during loading.
this.controller.onLoad(this.callback);
}
// Callback triggered once the handwritten file is loaded and rendered on the screen. You will be notified of the result and can then customize actions here that custom action can be performed here.
callback = () => {
// Custom action, for example, displaying the user operation guide after the file is loaded.
}
aboutToDisappear(){
// Call the saving API when HandWriteDemo exits.
const path : string = `savePath`; // Obtain the path for storing the handwritten file based on the app storage rule. The path is for reference only.
this.controller?.save(path);
}
build() {
Row() {
Column() {
HandwriteComponent({
handwriteController: this.controller,
onInit: () => {
// Callback triggered once the canvas initialization is complete. In this case, you can call the API to load and display the note content.
this.controller?.load(this.initPath);
},
onScale: (scale: number) => {
// Callback triggered when the canvas is zoomed in or out. The scaling factor of the current handwriting control is returned. Custom actions can be performed here.
}
})
}
.width('100%')
}
.height('100%')
}
}