diff --git a/src/main/ets/view/SafeView.ets b/src/main/ets/view/SafeView.ets index db845a5..ced175b 100644 --- a/src/main/ets/view/SafeView.ets +++ b/src/main/ets/view/SafeView.ets @@ -1,6 +1,6 @@ import { WindowHelper } from '../utils/WindowHelper'; import { inputMethod } from '@kit.IMEKit'; -import { GlobalContext } from '../ContextConfig'; +import { ToolsHelper } from '../utils/ToolsHelper'; export interface TitleBarBtn { text?: string | Resource; @@ -28,6 +28,8 @@ export struct SafeView { @Prop opacitys: number | Resource // 是否显示返回按钮 @Prop hideBack: boolean + // 物理返回按键是否需要双击触发 + @Prop doubleBack: boolean // 是否显示浅色返回按钮 @Prop lightBack: boolean // 是否显示导航栏 @@ -237,10 +239,24 @@ export struct SafeView { .backgroundColor(this.backgroundColorView ?? '#ffffff') .onBackPressed(() => { if (this.onBackEvent) { - this.onBackEvent() + if (this.doubleBack) { + const t = this.onBackEvent + ToolsHelper.doubleAndExit(() => { + t() + }) + } else { + this.onBackEvent() + } return true } else if (this.pageInfos) { - this.pageInfos.pop() + if (this.doubleBack) { + const t = this.pageInfos + ToolsHelper.doubleAndExit(() => { + t.pop() + }) + } else { + this.pageInfos.pop() + } return true } else { return false