popGesture.ts 1.1 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
import { invokeHook } from '@dcloudio/uni-core'
fxy060608's avatar
fxy060608 已提交
2
import { ON_SHOW } from '@dcloudio/uni-shared'
fxy060608's avatar
fxy060608 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
import {
  lastStatusBarStyle,
  setStatusBarStyle,
  StatusBarStyle,
} from '../../../../statusBar'
import { removeCurrentPage } from '../../../page/getCurrentPages'

export function onWebviewPopGesture(webview: PlusWebviewWebviewObject) {
  let popStartStatusBarStyle: StatusBarStyle
  webview.addEventListener('popGesture', (e) => {
    if (e.type === 'start') {
      // 设置下一个页面的 statusBarStyle
      const pages = getCurrentPages()
      const page = pages[pages.length - 2]
      popStartStatusBarStyle = lastStatusBarStyle
      const statusBarStyle =
        page && (page.$page.statusBarStyle as StatusBarStyle)
      statusBarStyle && setStatusBarStyle(statusBarStyle)
    } else if (e.type === 'end' && !e.result) {
      // 拖拽未完成,设置为当前状态栏前景色
      setStatusBarStyle(popStartStatusBarStyle)
    } else if (e.type === 'end' && e.result) {
      removeCurrentPage()
      setStatusBarStyle()
      // 触发前一个页面 onShow
fxy060608's avatar
fxy060608 已提交
28
      invokeHook(ON_SHOW)
fxy060608's avatar
fxy060608 已提交
29 30 31
    }
  })
}