-
-
Notifications
You must be signed in to change notification settings - Fork 984
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
Add number of touches on Android and iOS if needed #152
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also update description and link to the issue this is resolving.
Also, can you please respond to my inline comment>
@@ -133,6 +133,7 @@ public void configure(NativeViewGestureHandler handler, ReadableMap config) { | |||
@Override | |||
public void extractEventData(NativeViewGestureHandler handler, WritableMap eventData) { | |||
eventData.putBoolean("pointerInside", handler.isWithinBounds()); | |||
eventData.putDouble("numberOfTouches", handler.getMaxNumberOfPointers()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it was intended to provide a max number of pointers here but my intuition for this particular event param would be that it represents the current number of touches (much like pointerInside refers to the current state of the handler).
Also consider the edge case when this method is used for the state change event and make sure this is consistent with the behaviour on iOS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did observe its behaviour on iOS. Well, you're right that numberOfTouches return number oft touches in current situation and I gonna change it.
However, don't you consider introduction the mechanism of returning total number of touches involved in gesture?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there 💪
Just a few final comments
@@ -161,6 +166,9 @@ public final void handle(MotionEvent event) { | |||
} | |||
return; | |||
} | |||
if (mNumberOfPointers != event.getPointerCount()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check doesn't save much, can you get rid of it?
@@ -133,6 +133,7 @@ public void configure(NativeViewGestureHandler handler, ReadableMap config) { | |||
@Override | |||
public void extractEventData(NativeViewGestureHandler handler, WritableMap eventData) { | |||
eventData.putBoolean("pointerInside", handler.isWithinBounds()); | |||
eventData.putDouble("numberOfTouches", handler.getNumberOfPointers()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG. I don't know how this slipped into here under this name. Do you mind renaming to numberOfPointers
here and on iOS for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming is not a good idea since some people are already using this. I just borrowed the name that is used on iOS 🤔 If you really want to change it, it's better to set a getter for numberOfTouches
in nativeEvent
that returns numberOfPointers
and warns that it's deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fields returned in the event are not documented at all, so certainly people are checking what it has and trying on their own. If someone has reported a problem, it means that someone is using it.
Also, we don't have a changelog where we could explain that change and how to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the lib is still in alpha so breaking changes is just sth people will have to deal with when upgrading. Let's make sure to communicate this change to people reporting the issue and also when the next release comes out. We don't have capacity at the moment to support backward compatibility.
Also, we now publish change logs in the releases section on GH
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we have event field definition in typescript def file, so lets make sure to update it there too
@@ -35,6 +35,7 @@ | |||
private float mHitSlop[]; | |||
|
|||
private boolean mShouldCancelWhenOutside; | |||
private int mNumberOfPointers = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't matter too much but 0 would be a more appropriate initial value as there are no pointers when handler gets instantiated
@@ -161,6 +166,9 @@ public final void handle(MotionEvent event) { | |||
} | |||
return; | |||
} | |||
if (mNumberOfPointers != event.getPointerCount()) { | |||
mNumberOfPointers = event.getPointerCount(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to move it up a bit as there is some logic that may cause the gesture to fail in which case it would emit an event with an incorrect number of pointers
@@ -370,6 +378,8 @@ public void extractEventData(RotationGestureHandler handler, WritableMap eventDa | |||
eventData.putDouble("anchorX", PixelUtil.toDIPFromPixel(handler.getAnchorX())); | |||
eventData.putDouble("anchorY", PixelUtil.toDIPFromPixel(handler.getAnchorY())); | |||
eventData.putDouble("velocity", handler.getVelocity()); | |||
eventData.putDouble("numberOfTouches", handler.getNumberOfPointers()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I'm curious why did you skip fling, tap and long press handlers when adding this new parameter? Looks like we can add it directly to the base class's HandlerFactory.extractEventData
and call super in all subclasses (you can use https://developer.android.com/reference/android/support/annotation/CallSuper.html
to ensure that it gets called)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kmagiera ,
Well, I wish to follow current iOS state and not to add this field where it was not before.
I found it also quite useles on fling as long as iOS requires exact number of pointers.
However, I will add it everywhere for consciousness
I will add corresponing numberOfPointers on Tap on iOS when PR related to changes in Tap will be merged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there. Added a few comments inline
ios/Handlers/RNFlingHandler.m
Outdated
@@ -27,5 +27,11 @@ - (void)configure:(NSDictionary *)config | |||
} | |||
} | |||
|
|||
- (RNGestureHandlerEventExtraData *)eventExtraData:(UISwipeGestureRecognizer *)recognizer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ios/Handlers/RNNativeViewHandler.m
Outdated
@@ -99,21 +99,21 @@ - (void)handleTouchDown:(UIView *)sender forEvent:(UIEvent *)event | |||
|
|||
[self sendEventsInState:RNGestureHandlerStateActive | |||
forViewWithTag:sender.reactTag | |||
withExtraData:[RNGestureHandlerEventExtraData forPointerInside:YES]]; | |||
withExtraData:[RNGestureHandlerEventExtraData forPointerInside:YES withNumberOfTouches: _recognizer.numberOfTouches]]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
withNumberOfTouches: _recognizer.numberOfTouches]];
should be:
withNumberOfTouches:_recognizer.numberOfTouches]];
(no space after colon)
Same applies below
ios/RNGestureHandlerEvents.h
Outdated
+ (RNGestureHandlerEventExtraData *)forPointerInside:(BOOL)pointerInside; | ||
+ (RNGestureHandlerEventExtraData *)forPointerInside:(BOOL)pointerInside | ||
withNumberOfTouches:(NSUInteger)numberOfTouches; | ||
+ (RNGestureHandlerEventExtraData *)withNumberOfTouches:(NSUInteger)numberOfTouches; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't be necessary if you add withNumberOfTouches
to the very first method and use it from base class RNGestureHandler
ios/Handlers/RNNativeViewHandler.m
Outdated
@@ -99,21 +99,21 @@ - (void)handleTouchDown:(UIView *)sender forEvent:(UIEvent *)event | |||
|
|||
[self sendEventsInState:RNGestureHandlerStateActive | |||
forViewWithTag:sender.reactTag | |||
withExtraData:[RNGestureHandlerEventExtraData forPointerInside:YES]]; | |||
withExtraData:[RNGestureHandlerEventExtraData forPointerInside:YES withNumberOfTouches:_recognizer.numberOfTouches]]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe numberOfTouches should be extracted from event
not _recognizer
in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just stop sending numberOfPoiners for UIControl subclasses as it may not be that important
ios/RNGestureHandlerEvents.m
Outdated
@"numberOfPointers": @(numberOfTouches)}]; | ||
} | ||
|
||
+ (RNGestureHandlerEventExtraData *)withNumberOfTouches:(NSUInteger)numberOfTouches |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Motivation
#134
This PR refers to changes made someday by @tsapeta involving passing natively number of touches given out-of-box on iOS
I just provide same mechanism on Android which seems to be quite useful.
Changes
Added addditional field in
GestureHandler.java
, getter and few lines to update this field. Now it's also exported to js bridge