-
Notifications
You must be signed in to change notification settings - Fork 169
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
onClick prop does not work #272
Comments
I have the same problem .. |
onClick was being sent to the native code as a prop incorrectly. This forces it to undefined, since we use the onClickViro to pass the onClick function to the native iOS code. I will note that other props not defined on ViroBase were not causing this crash, it was specific to onClick. resolves #272
) * fix(ViroBase): fix onClick not working for <ViroText /> components onClick was being sent to the native code as a prop incorrectly. This forces it to undefined, since we use the onClickViro to pass the onClick function to the native iOS code. I will note that other props not defined on ViroBase were not causing this crash, it was specific to onClick. resolves #272
This is fixed in 2.41.1! I'm doing a final test on android before I publish the release. Release will be done by the end of the day! https://github.com/NativeVision/viro-test-bed/blob/main/src/screens/github_issues/Issue272.tsx trim.3E03E1C5-0E5B-4CD0-BA9E-45416A2146FA.MOV |
Hi @robertjcolley, as I commented in the discord, this issue is not fully resolved. The change I made to the example scene is:
And added the function:
If I change the ViroButton to ViroText, it works. |
Hi @robertjcolley. This error occurs in ViroARPlaneSelector too. Download expo startkit and edit App.tsx to
Error was |
I have the same issue as you @Deegiimurun however, I was able to use |
@LuisRodriguezLD, do you mind sharing your implementation, I get the same error for the |
@varun-raj I think Luis is refering to change the onClick prop to onClickState:
|
@psanchezUndanet Unfortunetlt I still get that error, Im farily new to this, am I doing something wrong? import React from "react";
import { StyleSheet } from "react-native";
import {
ViroARScene,
ViroTrackingStateConstants,
ViroARSceneNavigator,
ViroTrackingReason,
ViroARPlaneSelector,
ViroTrackingState,
ViroARTrackingReasonConstants,
ViroImage,
} from "@viro-community/react-viro";
const HelloWorldSceneAR = () => {
function onTrackingUpdated(state: ViroTrackingState, reason: ViroTrackingReason) {
console.log("====================================");
// Print State Label
if (state === ViroTrackingStateConstants.TRACKING_NORMAL) {
console.log("state:", "Tracking Normal");
} else if (state === ViroTrackingStateConstants.TRACKING_LIMITED) {
console.log("state:", "Tracking Limited");
} else if (state === ViroTrackingStateConstants.TRACKING_UNAVAILABLE) {
console.log("state:", "Tracking Not Available");
}
// Print Reason Label
if (reason === ViroARTrackingReasonConstants.TRACKING_REASON_NONE) {
console.log("reason:", "None");
} else if (reason === ViroARTrackingReasonConstants.TRACKING_REASON_EXCESSIVE_MOTION) {
console.log("reason:", "EXCESSIVE_MOTION");
} else if (reason === ViroARTrackingReasonConstants.TRACKING_REASON_INSUFFICIENT_FEATURES) {
console.log("reason:", "INSUFFICIENT_FEATURES");
}
console.log("====================================\n\n");
if (state === ViroTrackingStateConstants.TRACKING_NORMAL) {
// Handle tracking normal
} else if (state === ViroTrackingStateConstants.TRACKING_UNAVAILABLE) {
// Handle loss of tracking
}
}
return (
<ViroARScene
onTrackingUpdated={onTrackingUpdated}
anchorDetectionTypes="Horizontal"
onAnchorFound={(foundAnchor) => {
console.log('onAnchorFound')
}}>
<ViroARPlaneSelector
onClickState={() => {}}
minHeight={0.1} minWidth={0.1} alignment={'Horizontal'}>
<ViroImage
source={require('./assets/adaptive-icon.png')}
scale={[1,1,1]}
position={[-3, 0, -2]}
height={1}
width={1}
//onClick={(...args) => {poiFunction("poi pressed");}}
onClickState={() => {console.log("poi pressed");}}
transformBehaviors={["billboard"]}
/>
</ViroARPlaneSelector>
</ViroARScene>
);
};
export default () => {
return (
<ViroARSceneNavigator
autofocus={true}
initialScene={{
scene: HelloWorldSceneAR,
}}
style={styles.f1}
/>
);
};
var styles = StyleSheet.create({
f1: { flex: 1 },
helloWorldTextStyle: {
fontFamily: "Arial",
fontSize: 30,
color: "#ffffff",
textAlignVertical: "center",
textAlign: "center",
},
}); |
@varun-raj Sorry for not being able to answer sooner. In the docs, the ViroARPlaneSelector gets the onClickState from ViroNode. I don't know if the onClickState from ViroImage has its own config for that method or is also from ViroNode. The AR Scene that I tested is similar to this:
|
I have the same issue, still relying on onClickState |
Requirements:
Please go through this checklist before opening a new issue
Environment
Description
I am learning to use Viro and I am trying to add a click event to a ViroText component. I have tried to add the onClick prop to the ViroText component but it does not seem to work.
Error is
Exception thrown while executing UI block: -[VRTNodeContainer setOnClick:]: unrecognized selector sent to instance 0x12f310a50
after setting onClick prop to ViroText component.I am curious to know if there is a way to add a click event to a ViroText component or any other Viro component. Prop onPinch is working fine but onClick is not working.
Reproducible Demo
Here is the codes that i would like to do onClick event.
Build the project by xcode and got this error on device.
![image](https://private-user-images.githubusercontent.com/121847865/308782976-7b1703f2-e738-456a-b9e1-c607654f87cb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NjY2MTQsIm5iZiI6MTczOTQ2NjMxNCwicGF0aCI6Ii8xMjE4NDc4NjUvMzA4NzgyOTc2LTdiMTcwM2YyLWU3MzgtNDU2YS1iOWUxLWM2MDc2NTRmODdjYi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxM1QxNzA1MTRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0yZDMwZDBiNjFkOGMzYjllMzMzMmRmMzMyMzIzZDk3MjIzMjRlOGFjMDEyZDFhZTNkMWYwYTIwYTFkNWZkY2Y2JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.ffn7eXAK3hY6LQJeDNAERTvtociz5j5-dItEgWTTZHQ)
The text was updated successfully, but these errors were encountered: