util.js 1.7 KB
Newer Older
fxy060608's avatar
init v3  
fxy060608 已提交
1
import {
fxy060608's avatar
fxy060608 已提交
2 3 4 5 6 7
  ANI_SHOW,
  ANI_DURATION
} from '../../constants'

import {
  navigateFinish
fxy060608's avatar
init v3  
fxy060608 已提交
8 9
} from '../../framework/navigator'

fxy060608's avatar
fxy060608 已提交
10 11 12 13
export function closeWebview (webview, animationType, animationDuration) {
  webview[webview.__preload__ ? 'hide' : 'close'](animationType, animationDuration)
}

fxy060608's avatar
fxy060608 已提交
14
export function showWebview (webview, animationType, animationDuration, showCallback, delay) {
fxy060608's avatar
fxy060608 已提交
15 16 17 18 19 20 21 22 23
  if (typeof delay === 'undefined') {
    delay = webview.nvue ? 0 : 100
  }

  if (typeof animationDuration === 'undefined') {
    animationDuration = ANI_DURATION
  } else {
    animationDuration = parseInt(animationDuration)
  }
fxy060608's avatar
init v3  
fxy060608 已提交
24

fxy060608's avatar
fxy060608 已提交
25 26 27
  if (process.env.NODE_ENV !== 'production') {
    console.log(`[show][${Date.now()}]`, delay)
  }
fxy060608's avatar
fxy060608 已提交
28
  const duration = animationDuration || ANI_DURATION
fxy060608's avatar
init v3  
fxy060608 已提交
29
  setTimeout(() => {
fxy060608's avatar
fxy060608 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    const execShowCallback = function () {
      if (execShowCallback._called) {
        if (process.env.NODE_ENV !== 'production') {
          console.log('execShowCallback.prevent')
        }
        return
      }
      execShowCallback._called = true
      showCallback && showCallback()
      navigateFinish(webview)
    }
    const timer = setTimeout(() => {
      if (process.env.NODE_ENV !== 'production') {
        console.log(`[show.callback.timer][${Date.now()}]`)
      }
      execShowCallback()
    }, duration + 150)
fxy060608's avatar
init v3  
fxy060608 已提交
47 48
    webview.show(
      animationType || ANI_SHOW,
fxy060608's avatar
fxy060608 已提交
49
      duration,
fxy060608's avatar
init v3  
fxy060608 已提交
50
      () => {
fxy060608's avatar
fxy060608 已提交
51 52 53
        if (process.env.NODE_ENV !== 'production') {
          console.log(`[show.callback][${Date.now()}]`)
        }
fxy060608's avatar
fxy060608 已提交
54 55 56 57
        if (!execShowCallback._called) {
          clearTimeout(timer)
        }
        execShowCallback()
fxy060608's avatar
init v3  
fxy060608 已提交
58 59
      }
    )
fxy060608's avatar
fxy060608 已提交
60
  }, delay)
fxy060608's avatar
init v3  
fxy060608 已提交
61
}