index.ts 1.6 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
  routeMeta: UniApp.PageRouteMeta,
  webview: PlusWebviewWebviewObject
fxy060608's avatar
fxy060608 已提交
12 13 14 15
): PlusWebviewWebviewStyles & {
  uniPageUrl?: InitUniPageUrl
  debugRefresh?: DebugRefresh
  isTab?: boolean
Q
qiang 已提交
16
  locale?: string
fxy060608's avatar
fxy060608 已提交
17
} {
fxy060608's avatar
fxy060608 已提交
18 19 20 21 22 23 24 25 26 27
  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]
    }
  })
fxy060608's avatar
fxy060608 已提交
28 29 30 31
  if (webview.id !== '1') {
    // 首页 nvue 已经在 manifest.json 中设置了 uniNView,不能再次设置,否则会二次加载
    initNVue(webviewStyle, routeMeta, path)
  }
fxy060608's avatar
fxy060608 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  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 已提交
57
  'pullToRefresh',
fxy060608's avatar
fxy060608 已提交
58 59 60 61
  'onReachBottomDistance',
  'pageOrientation',
  'backgroundColor',
]