index.ts 1011 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 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 28
import { onWebviewClose } from './close'
import { onWebviewResize } from './resize'

const WEBVIEW_LISTENERS = {
  pullToRefresh: 'onPullDownRefresh',
  titleNViewSearchInputChanged: 'onNavigationBarSearchInputChanged',
  titleNViewSearchInputConfirmed: 'onNavigationBarSearchInputConfirmed',
  titleNViewSearchInputClicked: 'onNavigationBarSearchInputClicked',
  titleNViewSearchInputFocusChanged: 'onNavigationBarSearchInputFocusChanged',
} as const

export function initWebviewEvent(webview: PlusWebviewWebviewObject) {
  const { emit } = UniServiceJSBridge
  const id = parseInt(webview.id!)
  Object.keys(WEBVIEW_LISTENERS).forEach((name) => {
    webview.addEventListener(name as any, (e) => {
      emit(WEBVIEW_LISTENERS[name as keyof typeof WEBVIEW_LISTENERS], e, id)
    })
  })
  onWebviewClose(webview)
  onWebviewResize(webview)

  // TODO
  // if (plus.os.name === 'iOS') {
  //     !(webview as any).nvue && onWebviewRecovery(webview, routeOptions)
  //     onWebviewPopGesture(webview)
  // }
}