Skip to content

Commit 07dc283

Browse files
fix(ViroBase): fix onClick not working for <ViroText /> components (#277)
* 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
1 parent f273fb3 commit 07dc283

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

components/ViroBase.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ export class ViroBase<T> extends React.Component<ViroBaseProps & T> {
5757
event.nativeEvent.position,
5858
event.nativeEvent.source
5959
);
60-
let CLICKED = ViroClickStateTypes.CLICKED; // Value representation of Clicked ClickState within EventDelegateJni.
61-
if (event.nativeEvent.clickState == CLICKED) {
60+
61+
// Value representation of Clicked ClickState within EventDelegateJni.
62+
if (event.nativeEvent.clickState == ViroClickStateTypes.CLICKED) {
6263
this._onClick(event);
6364
}
6465
};

components/ViroText.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ export class ViroText extends ViroBase<Props> {
9797
canFuse={this.props.onFuse != undefined}
9898
onHoverViro={this._onHover}
9999
onClickViro={this._onClickState}
100+
// Fixes #272. for some reason, onClick was making it
101+
// to the native code. Other incorrect props don't make it
102+
// to the native code.
103+
// https://github.com/NativeVision/viro/issues/272
104+
onClick={undefined}
100105
onTouchViro={this._onTouch}
101106
onScrollViro={this._onScroll}
102107
onSwipeViro={this._onSwipe}

dist/components/ViroBase.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class ViroBase extends React.Component {
4040
_onClickState = (event) => {
4141
this.props.onClickState &&
4242
this.props.onClickState(event.nativeEvent.clickState, event.nativeEvent.position, event.nativeEvent.source);
43-
let CLICKED = ViroEvents_1.ViroClickStateTypes.CLICKED; // Value representation of Clicked ClickState within EventDelegateJni.
44-
if (event.nativeEvent.clickState == CLICKED) {
43+
// Value representation of Clicked ClickState within EventDelegateJni.
44+
if (event.nativeEvent.clickState == ViroEvents_1.ViroClickStateTypes.CLICKED) {
4545
this._onClick(event);
4646
}
4747
};

dist/components/ViroText.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ class ViroText extends ViroBase_1.ViroBase {
7373
return (<VRTText {...this.props} ref={(component) => {
7474
this._component = component;
7575
}} onNativeTransformDelegateViro={transformDelegate} hasTransformDelegate={this.props.onTransformUpdate != undefined} style={[this.props.style]} canHover={this.props.onHover != undefined} canClick={this.props.onClick != undefined ||
76-
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}/>);
76+
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}
77+
// Fixes #272. this.props
78+
// https://github.com/NativeVision/viro/issues/272
79+
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}/>);
7780
}
7881
}
7982
exports.ViroText = ViroText;

0 commit comments

Comments
 (0)