ohos: Add toast prompt (#33621)

* ohos: Add toast prompt

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* ohos: Add toast on `load_ended`

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* Apply review feedback

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>

---------

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
Jonathan Schwender 2024-10-03 18:33:21 +02:00 committed by GitHub
parent f2f5614ad6
commit 9fcfe09e51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 70 additions and 22 deletions

View file

@ -1,12 +1,14 @@
import { common } from '@kit.AbilityKit';
import display from '@ohos.display';
import deviceInfo from '@ohos.deviceInfo';
import promptAction from '@ohos.promptAction';
interface ServoXComponentInterface {
loadURL(url: string): void;
goBack(): void;
goForward(): void;
registerURLcallback(callback: (url: string) => void): void;
registerPromptToastCallback(callback: (msg: string) => void): void
initServo(options: InitOpts): void;
}
@ -40,6 +42,13 @@ function get_device_type(): string {
return device_type;
}
function prompt_toast(msg: string) {
promptAction.showToast({
message: msg,
duration: 2000
});
}
// Use the getShared API to obtain the LocalStorage instance shared by stage.
let storage = LocalStorage.getShared()
@ -107,6 +116,7 @@ struct Index {
console.info('New URL from native: ', new_url)
this.urlToLoad = new_url
})
this.xComponentContext.registerPromptToastCallback(prompt_toast)
})
}
.width('100%')