From 7489e3d5f48191b09490a58f1b52b09ed7aa9fbe Mon Sep 17 00:00:00 2001 From: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Date: Sun, 1 Dec 2024 13:06:04 +0100 Subject: [PATCH] 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 --- support/openharmony/entry/src/main/ets/pages/Index.ets | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/support/openharmony/entry/src/main/ets/pages/Index.ets b/support/openharmony/entry/src/main/ets/pages/Index.ets index 715b4aa9007..ed67d36cb3b 100644 --- a/support/openharmony/entry/src/main/ets/pages/Index.ets +++ b/support/openharmony/entry/src/main/ets/pages/Index.ets @@ -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)