带有Expo的React-Native振动事件检测器 [英] React-Native Shake Event Detector With Expo
问题描述
我在iOS手机上使用的是
Expo v2.3.8
和Expo客户端v2.9.0
.
我正在尝试测试摇晃 addEventListener
事件,但总是以Expo Expo开发者菜单打开而告终.因此我关闭了Expo中的"shake"选项,但是这一次,当我摇晃手机时,会打开电话旧的Expo开发者菜单.
I'm trying to test shake addEventListener
event but always end up Expo developer menu opens. So I closed the shake option in Expo but this time when I shake, the phone old Expo developer menu opens.
这是我的代码:
import RNShake from 'react-native-shake';
export default class Starting extends Component {
static navigationOptions = {
title: 'MyApp',
};
componentWillMount() {
RNShake.addEventListener('shake', () => {
this.props.navigation.push('Register');
});
}
componentWillUnmount() {
RNShake.removeEventListener('shake');
}
.
.
.
}
我尝试打开生产模式.它没有工作.如何通过世博会测试摇奖活动?React Native Shake Detector- https://www.npmjs.com/package/react-native-摇动
I tried turn on production mode. It didnt work. How can I test shake event with Expo? React Native Shake Detector - https://www.npmjs.com/package/react-native-shake
推荐答案
react-native-shake
库需要链接本机代码,因此,如果不先将它从Expo弹出到Expokit,它将无法工作此处: https://docs.expo.io/versions/latest/expokit/eject/
The react-native-shake
library requires linking native code, so it will not work without first ejecting from Expo to Expokit as explained here: https://docs.expo.io/versions/latest/expokit/eject/
在您的项目目录中,运行 expo弹出
.这将下载所需的依赖项,并在ios和android目录下构建本机项目.然后按照库安装说明运行 react-native链接react-native-shake
.
From your project directory, run expo eject
. This will download the required dependencies and build native projects under the ios and android directories. Then run react-native link react-native-shake
as per the library install instructions.
这篇关于带有Expo的React-Native振动事件检测器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!