diff --git a/src/core/helpers/index.js b/src/core/helpers/index.js index 44e260976acc6cdd26aa30ed24e2530ab12dcda9..bf0ef226d9b4d0caabcd37713d4cbd2bd142785b 100644 --- a/src/core/helpers/index.js +++ b/src/core/helpers/index.js @@ -9,8 +9,12 @@ export function isPage (vm) { return false } -export function normalizeDataset (dataset = {}) { - // ios8.x,9.x Object.assign({},dataset) 始终返回 {} +export function hasLifecycleHook (vueOptions = {}, hook) { + return Array.isArray(vueOptions[hook]) && vueOptions[hook].length +} + +export function normalizeDataset (dataset = {}) { + // ios8.x,9.x Object.assign({},dataset) 始终返回 {} // http://ask.dcloud.net.cn/question/70246 const result = JSON.parse(JSON.stringify(dataset)) if (__PLATFORM__ === 'h5') { diff --git a/src/core/view/bridge/subscribe/index.js b/src/core/view/bridge/subscribe/index.js index bc17bde0daacbeee56d9446ef54e5e6c16a21bbf..4135216aff456aba5bd19243306bcb0ff6eaa933 100644 --- a/src/core/view/bridge/subscribe/index.js +++ b/src/core/view/bridge/subscribe/index.js @@ -1,9 +1,12 @@ import { - isFn, isPlainObject, supportsPassive } from 'uni-shared' +import { + hasLifecycleHook +} from 'uni-helpers/index' + import { NAVBAR_HEIGHT, TABBAR_HEIGHT @@ -17,7 +20,10 @@ import { import requestComponentInfo from './request-component-info' -import { requestComponentObserver, destroyComponentObserver } from './request-component-observer' +import { + requestComponentObserver, + destroyComponentObserver +} from './request-component-observer' const passiveOptions = supportsPassive ? { passive: false @@ -26,7 +32,8 @@ const passiveOptions = supportsPassive ? { function updateCssVar (vm) { if (uni.canIUse('css.var')) { const pageVm = vm.$parent.$parent - const windowTop = pageVm.showNavigationBar && pageVm.navigationBar.type !== 'transparent' ? (NAVBAR_HEIGHT + 'px') + const windowTop = pageVm.showNavigationBar && pageVm.navigationBar.type !== 'transparent' ? (NAVBAR_HEIGHT + + 'px') : '0px' const windowBottom = getApp().$children[0].showTabBar ? (TABBAR_HEIGHT + 'px') : '0px' const style = document.documentElement.style @@ -69,11 +76,12 @@ export default function initSubscribe (subscribe) { document.addEventListener('touchmove', disableScrollListener, passiveOptions) } - const enablePageScroll = isFn(vm.$options.onPageScroll) - const enablePageReachBottom = isFn(vm.$options.onReachBottom) + const enablePageScroll = hasLifecycleHook(vm.$options, 'onPageScroll') + const enablePageReachBottom = hasLifecycleHook(vm.$options, 'onReachBottom') const onReachBottomDistance = pageVm.onReachBottomDistance - const enableTransparentTitleNView = isPlainObject(pageVm.titleNView) && pageVm.titleNView.type === 'transparent' + const enableTransparentTitleNView = isPlainObject(pageVm.titleNView) && pageVm.titleNView.type === + 'transparent' if (scrollListener) { document.removeEventListener('scroll', scrollListener) @@ -92,4 +100,4 @@ export default function initSubscribe (subscribe) { } }) } -} +}