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

希望支持 offAccelerometerChange #5394

Closed
ahabhgk opened this issue Jan 29, 2020 · 3 comments
Closed

希望支持 offAccelerometerChange #5394

ahabhgk opened this issue Jan 29, 2020 · 3 comments
Assignees

Comments

@ahabhgk
Copy link

ahabhgk commented Jan 29, 2020

问题描述

没有实现 wx.offAccelerometerChange(对应 Taro.offAccelerometerChange),在 @tarojs/taro/types/device/accelerometer.d.ts 中有相应的类型,然后我尝试在 @tarojs/taro/src/native-apis.js 中的 onAndSyncApis 加上 offAccelerometerChange: true 后仍然报错。

复现步骤

  1. 打开 @tarojs/taro/src/native-apis.js,在 onAndSyncApis 加上 offAccelerometerChange: true 属性
  2. yarn dev ...(进行调试)
  3. 报错...
/**
 * 这段注释后可以贴代码
 * 提供完整可复现的代码和整理好代码格式,有助于我们快速定位问题,节省你我时间
 * 代码提供不全或代码格式混乱的 issues 【有可能会被忽略】
 * 
 * 查看如何插入代码:https://coding.net/help/doc/project/markdown.html#i-5
 */
// 摇一摇然后随机抽取对应餐厅或饮品店的功能
const Rock: Taro.FC = () => {
  const [active, setActive] = useState<'food' | 'drink' | null>(null)
  const [dialog, setDialog] = useState<{
    isShow: boolean,
    shop: Shop
  }>(initialDialogState)

  useEffect(() => {
    const cb: Taro.onAccelerometerChange.Callback = (res) => {
      if (dialog.isShow) return
      if (active === null) return
      if (Math.abs(res.x) > .7) {
        setDialog({ isShow: true, shop: getRandom(active!) })
      }
    }

    Taro.onAccelerometerChange(cb)

    return () => {
      Taro.offAccelerometerChange(cb)
    }
  }, [active, dialog.isShow])
  
  return (/* jsx... */)
}

期望行为

useEffect 的 cleanup 函数能执行,并把 Taro.onAccelerometerChange 的监听取消

报错信息

截屏2020-01-2918 01 21

系统信息

👽 Taro v2.0.2

Taro CLI 2.0.2 environment info:
System:
OS: macOS 10.15.2
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.13.0 - ~/.nvm/versions/node/v12.13.0/bin/node
Yarn: 1.21.1 - ~/.yarn/bin/yarn
npm: 6.13.6 - ~/.nvm/versions/node/v12.13.0/bin/npm
npmPackages:
@tarojs/components: 2.0.2 => 2.0.2
@tarojs/components-qa: 2.0.2 => 2.0.2
@tarojs/mini-runner: 2.0.2 => 2.0.2
@tarojs/redux: 2.0.2 => 2.0.2
@tarojs/redux-h5: 2.0.2 => 2.0.2
@tarojs/router: 2.0.2 => 2.0.2
@tarojs/taro: 2.0.2 => 2.0.2
@tarojs/taro-alipay: 2.0.2 => 2.0.2
@tarojs/taro-h5: 2.0.2 => 2.0.2
@tarojs/taro-qq: 2.0.2 => 2.0.2
@tarojs/taro-quickapp: 2.0.2 => 2.0.2
@tarojs/taro-swan: 2.0.2 => 2.0.2
@tarojs/taro-tt: 2.0.2 => 2.0.2
@tarojs/taro-weapp: 2.0.2 => 2.0.2
@tarojs/webpack-runner: 2.0.2 => 2.0.2
eslint-config-taro: 2.0.2 => 2.0.2
eslint-plugin-taro: 2.0.2 => 2.0.2
nerv-devtools: ^1.5.6 => 1.5.6
nervjs: ^1.5.6 => 1.5.6
stylelint-config-taro-rn: 2.0.2 => 2.0.2
stylelint-taro-rn: 2.0.2 => 2.0.2

补充信息

如果您有功能上的建议,可以提到 FeatHub

使用上的问题,欢迎在「Taro 社区」一起交流

@taro-bot
Copy link

taro-bot bot commented Jan 29, 2020

CC @Chen-jj

@taro-bot
Copy link

taro-bot bot commented Jan 29, 2020

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@Garfield550
Copy link
Collaborator

API 说明

而对于微信小程序中没有,而某些小程序平台特有的 API,可以先尝试用 Taro. + API 名称来进行调用,如果出现未定义,则使用对应小程序平台的命名空间(如 my、swan、tt 等)来进行调用,并反馈给我们。

先直接使用 wx.offAccelerometerChange 调用吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants