Skip to content

Commit

Permalink
fix(ViroBase): fix onClick not working for <ViroText /> components (#277
Browse files Browse the repository at this point in the history
)

* 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
  • Loading branch information
robertjcolley authored Mar 6, 2024
1 parent f273fb3 commit 07dc283
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions components/ViroBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ export class ViroBase<T> extends React.Component<ViroBaseProps & T> {
event.nativeEvent.position,
event.nativeEvent.source
);
let CLICKED = ViroClickStateTypes.CLICKED; // Value representation of Clicked ClickState within EventDelegateJni.
if (event.nativeEvent.clickState == CLICKED) {

// Value representation of Clicked ClickState within EventDelegateJni.
if (event.nativeEvent.clickState == ViroClickStateTypes.CLICKED) {
this._onClick(event);
}
};
Expand Down
5 changes: 5 additions & 0 deletions components/ViroText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ export class ViroText extends ViroBase<Props> {
canFuse={this.props.onFuse != undefined}
onHoverViro={this._onHover}
onClickViro={this._onClickState}
// Fixes #272. for some reason, onClick was making it
// to the native code. Other incorrect props don't make it
// to the native code.
// https://github.com/NativeVision/viro/issues/272
onClick={undefined}
onTouchViro={this._onTouch}
onScrollViro={this._onScroll}
onSwipeViro={this._onSwipe}
Expand Down
4 changes: 2 additions & 2 deletions dist/components/ViroBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class ViroBase extends React.Component {
_onClickState = (event) => {
this.props.onClickState &&
this.props.onClickState(event.nativeEvent.clickState, event.nativeEvent.position, event.nativeEvent.source);
let CLICKED = ViroEvents_1.ViroClickStateTypes.CLICKED; // Value representation of Clicked ClickState within EventDelegateJni.
if (event.nativeEvent.clickState == CLICKED) {
// Value representation of Clicked ClickState within EventDelegateJni.
if (event.nativeEvent.clickState == ViroEvents_1.ViroClickStateTypes.CLICKED) {
this._onClick(event);
}
};
Expand Down
5 changes: 4 additions & 1 deletion dist/components/ViroText.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ class ViroText extends ViroBase_1.ViroBase {
return (<VRTText {...this.props} ref={(component) => {
this._component = component;
}} onNativeTransformDelegateViro={transformDelegate} hasTransformDelegate={this.props.onTransformUpdate != undefined} style={[this.props.style]} canHover={this.props.onHover != undefined} canClick={this.props.onClick != undefined ||
this.props.onClickState != undefined} canTouch={this.props.onTouch != undefined} canScroll={this.props.onScroll != undefined} canSwipe={this.props.onSwipe != undefined} canDrag={this.props.onDrag != undefined} canPinch={this.props.onPinch != undefined} canRotate={this.props.onRotate != undefined} canFuse={this.props.onFuse != undefined} onHoverViro={this._onHover} onClickViro={this._onClickState} onTouchViro={this._onTouch} onScrollViro={this._onScroll} onSwipeViro={this._onSwipe} onDragViro={this._onDrag} onPinchViro={this._onPinch} onRotateViro={this._onRotate} onFuseViro={this._onFuse} onAnimationStartViro={this._onAnimationStart} onAnimationFinishViro={this._onAnimationFinish} materials={materials} transformBehaviors={transformBehaviors} outerStroke={outerStroke} canCollide={this.props.onCollision != undefined} onCollisionViro={this._onCollision} timeToFuse={timeToFuse}/>);
this.props.onClickState != undefined} canTouch={this.props.onTouch != undefined} canScroll={this.props.onScroll != undefined} canSwipe={this.props.onSwipe != undefined} canDrag={this.props.onDrag != undefined} canPinch={this.props.onPinch != undefined} canRotate={this.props.onRotate != undefined} canFuse={this.props.onFuse != undefined} onHoverViro={this._onHover} onClickViro={this._onClickState}
// Fixes #272. this.props
// https://github.com/NativeVision/viro/issues/272
onClick={undefined} onTouchViro={this._onTouch} onScrollViro={this._onScroll} onSwipeViro={this._onSwipe} onDragViro={this._onDrag} onPinchViro={this._onPinch} onRotateViro={this._onRotate} onFuseViro={this._onFuse} onAnimationStartViro={this._onAnimationStart} onAnimationFinishViro={this._onAnimationFinish} materials={materials} transformBehaviors={transformBehaviors} outerStroke={outerStroke} canCollide={this.props.onCollision != undefined} onCollisionViro={this._onCollision} timeToFuse={timeToFuse}/>);
}
}
exports.ViroText = ViroText;
Expand Down

0 comments on commit 07dc283

Please sign in to comment.