我有以下代码:
import {
ViroBox,
ViroARScene,
ViroARSceneNavigator,
} from "@reactvision/react-viro";
import { StyleSheet, TouchableOpacity, TouchableWithoutFeedback } from "react-native";
const HelloWorldSceneAR = () => {
return (
<ViroARScene>
<ViroBox onClick={()=>{console.log("Clicked")}} />
</ViroARScene>
);
};
export default () => {
return (
<ViroARSceneNavigator
autofocus={true}
initialScene={{
scene: HelloWorldSceneAR,
}}
style={styles.f1}
/>
);
};
var styles = StyleSheet.create({
f1: { flex: 1 }
});
此代码在 Android 设备上运行良好。 但在 iOS 设备上,我收到错误:
Exception thrown while executing UI block: -[VRTBox setOnClick:]: unrecognized selector sent to instance 0x111595d00
如果我删除
onClick
,那么 iOS 设备上的错误消息就会消失。 然而,这意味着我无法在 iOS 设备上点击 ViroBox。
我也尝试过这个:
<ViroARScene>
<TouchableOpacity onPress={()=>{console.log("Clicked")}}>
<ViroBox />
</TouchableOpacity>
</ViroARScene>
但这给出了错误
Exception thrown while executing UI block: -[RCTView setSuperview:]: unrecognized selector sent to instance 0x1115868e0
我也尝试过这个:
<ViroARScene>
<TouchableWithoutFeedback onPress={()=>{console.log("Clicked")}}>
<ViroBox />
</TouchableWithoutFeedback>
</ViroARScene>
但这给出了这个错误:
Exception thrown while executing UI block: -[VRTBox setOnClick:]: unrecognized selector sent to instance 0x111595d10
我做错了什么?
这是我的
package.json
{
"name": "ViroStarterKit",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"lint": "eslint .",
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"@reactvision/react-viro": "^2.41.4",
"react": "18.2.0",
"react-native": "0.73.3"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native/babel-preset": "0.73.20",
"@react-native/eslint-config": "0.73.2",
"@react-native/metro-config": "0.73.4",
"@react-native/typescript-config": "0.73.1",
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3",
"eslint": "^8.19.0",
"jest": "^29.6.3",
"prettier": "2.8.8",
"react-test-renderer": "18.2.0",
"typescript": "5.0.4"
},
"engines": {
"node": ">=18"
}
}
其他说明...我尝试过使用
@reactvision/react-viro
版本2.41.3, 2.41.4, 2.41.5 and 2.41.6
,但都遇到这个问题。
我也有同样的问题
ViroButton