index.ts 1.4 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5
import { initNVue } from './nvue'
import { initBackgroundColor } from './backgroundColor'
import { initPopGesture } from './popGesture'
import { initPullToRefresh } from './pullToRefresh'
import { initTitleNView } from './titleNView'
fxy060608's avatar
fxy060608 已提交
6
import { DebugRefresh, InitUniPageUrl } from '../utils'
fxy060608's avatar
fxy060608 已提交
7 8 9

export function parseWebviewStyle(
  path: string,
fxy060608's avatar
fxy060608 已提交
10 11 12 13 14
  routeMeta: UniApp.PageRouteMeta
): PlusWebviewWebviewStyles & {
  uniPageUrl?: InitUniPageUrl
  debugRefresh?: DebugRefresh
  isTab?: boolean
Q
qiang 已提交
15
  locale?: string
fxy060608's avatar
fxy060608 已提交
16
} {
fxy060608's avatar
fxy060608 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  const webviewStyle: PlusWebviewWebviewStyles = {
    bounce: 'vertical',
  }

  Object.keys(routeMeta).forEach((name) => {
    if (WEBVIEW_STYLE_BLACKLIST.indexOf(name) === -1) {
      webviewStyle[name as keyof PlusWebviewWebviewStyles] =
        routeMeta[name as keyof UniApp.PageRouteMeta]
    }
  })
  initNVue(webviewStyle, routeMeta, path)
  initPopGesture(webviewStyle, routeMeta)
  initBackgroundColor(webviewStyle, routeMeta)
  initTitleNView(webviewStyle, routeMeta)
  initPullToRefresh(webviewStyle, routeMeta)

  return webviewStyle
}

const WEBVIEW_STYLE_BLACKLIST = [
  'id',
  'route',
  'isNVue',
  'isQuit',
  'isEntry',
  'isTabBar',
  'tabBarIndex',
  'windowTop',
  'topWindow',
  'leftWindow',
  'rightWindow',
  'maxWidth',
  'usingComponents',
  'disableScroll',
  'enablePullDownRefresh',
  'navigationBar',
fxy060608's avatar
fxy060608 已提交
53
  'pullToRefresh',
fxy060608's avatar
fxy060608 已提交
54 55 56 57
  'onReachBottomDistance',
  'pageOrientation',
  'backgroundColor',
]