Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当在有小程序原生Tabbar页面使用了Notify,会导致在没有Tabbar的页面的DropdownMenu显示不正确 #564

Closed
1 of 7 tasks
NickeyLin opened this issue Aug 29, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@NickeyLin
Copy link

NickeyLin commented Aug 29, 2023

这个 Issue 涉及以下平台:

  • 微信小程序
  • 支付宝小程序
  • 百度小程序
  • 头条小程序
  • 快手小程序
  • QQ 轻应用
  • Web 平台(H5)

BUG 描述

当在有小程序Tabbar页面使用了Notify,会导致在没有Tabbar的页面的DropdownMenu显示不正确

复现步骤

  1. 在小程序tabbar页面插入 <Notify id='vanNotify' />
  2. 在非tabbar页面使用 DropdownMenu

期望结果

DropdownMenu 正常使用

实际结果

DropdownMenu 下拉列表位置不正确

截图

image

环境

  • @antmjs/vantui: 3.1.6
  • taro: 3.6.14

附加信息

此问题的原因应该是 common/utils.ts 中的 getSystemInfoSync 方法导致。该方法使用静态变量缓存了第一次获取的系统信息。在 Notify组件useEffect中调用了此方法,缓存了系统信息,然后 DropdownMenu 组件通过此方法计算下拉列表位置。但是,在tabbar和没有tabbar的页面的windowHeight并不一样,所以,如果仍然使用第一次缓存的systemInfo来计算下拉列表位置就不对了。

// common/utils.ts
let systemInfo: any
export function getSystemInfoSync() {
  if (systemInfo == null) {
    systemInfo = TaroGetSystemInfoSync()
  }
  return systemInfo
}
  // notify/index.tsx
  useEffect(() => {
    const { statusBarHeight } = getSystemInfoSync()
    setState((state) => {
      return {
        ...state,
        statusBarHeight,
      }
    })
  }, [])
  // dropdown-item/index.tsx
  const updateStyle = useCallback(() => {
    parentInstance?.getChildWrapperStyle().then((wrapperStyle: any) => {
      const rect = wrapperStyle.rect
      delete wrapperStyle.rect
      if (wrapperStyle) {
        wrapperStyle.width = '100vw'
        wrapperStyle.position = 'fixed'
      }

      if (parentInstance.direction === 'down') {
        const winHeight = getSystemInfoSync().windowHeight
        const bottom = winHeight - rect.top
        wrapperStyle.bottom = -rect.height + 'PX'
        wrapperStyle.height = bottom + 'PX'
        setWrapperStyle(wrapperStyle)
        setShowWrapper(true)
        rerender()
      }

      if (parentInstance.direction === 'up') {
        wrapperStyle.height = rect.top + 'PX'
        setWrapperStyle(wrapperStyle)
        setShowWrapper(true)
        rerender()
      }
    })
  }, [parentInstance, rerender])
@NickeyLin NickeyLin changed the title 当在有小程序原生Tabbar页面使用了Notify,会导致在没有Tabbar的页面的DropdownMenu 当在有小程序原生Tabbar页面使用了Notify,会导致在没有Tabbar的页面的DropdownMenu显示不正确 Aug 29, 2023
@liaoyu
Copy link

liaoyu commented Nov 29, 2023

我这也遇到同样的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants