ohos: Support swiping to go back (#34433)

Override the `onBackPress` callback, which by default
brings the application to the background and instead
tell servo to go back one page.
Users can invoke this by swiping from the left edge to the middle.
There is no equivalent callback / gesture to go forward.
In the default browser swiping from the right side to the middle
also invokes the goBack callback.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
Jonathan Schwender 2024-12-01 13:06:04 +01:00 committed by GitHub
parent f2b5f515d7
commit 7489e3d5f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -67,6 +67,13 @@ struct Index {
@LocalStorageProp('CommandlineArgs') CommandlineArgs: string = ""
@State urlToLoad: string = this.InitialURI
// Called when the user swipes from the right or left edge to the middle
// Default behavior is bringing the app to the background.
onBackPress(): boolean | void {
this.xComponentContext?.goBack()
return true;
}
build() {
Column() {
Row() {
@ -76,7 +83,7 @@ struct Index {
.width('12%')
.fontSize(12)
.onClick(()=>{
this.xComponentContext?.goBack()
this.onBackPress()
})
Button('⇨').backgroundColor(Color.White)
.fontColor(Color.Black)