-
-
Notifications
You must be signed in to change notification settings - Fork 1k
[iOS] Change when Native gesture states are changed
#4036
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
base: main
Are you sure you want to change the base?
Changes from all commits
eace4ec
75666db
3f12e06
83b52cc
71d5b2b
c73ec16
26d763b
cb58495
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,6 +146,12 @@ - (void)bindToView:(UIView *)view | |
| action:@selector(handleTouchUpInside:forEvent:) | ||
| forControlEvents:UIControlEventTouchUpInside]; | ||
| [control addTarget:self action:@selector(handleDragExit:forEvent:) forControlEvents:UIControlEventTouchDragExit]; | ||
| [control addTarget:self | ||
| action:@selector(handleDragInside:forEvent:) | ||
| forControlEvents:UIControlEventTouchDragInside]; | ||
| [control addTarget:self | ||
| action:@selector(handleDragOutside:forEvent:) | ||
| forControlEvents:UIControlEventTouchDragOutside]; | ||
| [control addTarget:self action:@selector(handleDragEnter:forEvent:) forControlEvents:UIControlEventTouchDragEnter]; | ||
| [control addTarget:self action:@selector(handleTouchCancel:forEvent:) forControlEvents:UIControlEventTouchCancel]; | ||
| } else { | ||
|
|
@@ -184,7 +190,7 @@ - (void)handleTouchDown:(UIView *)sender forEvent:(UIEvent *)event | |
| } | ||
| } | ||
|
|
||
| [self sendEventsInState:RNGestureHandlerStateActive | ||
| [self sendEventsInState:RNGestureHandlerStateBegan | ||
| forViewWithTag:sender.reactTag | ||
| withExtraData:[RNGestureHandlerEventExtraData forPointerInside:YES | ||
|
Comment on lines
+193
to
195
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, maybe the "correct" approach would be to send This may be weird that the button isn't "active" unless the pointer moves.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also thought about it. This would also match current |
||
| withNumberOfTouches:event.allTouches.count | ||
|
Comment on lines
+193
to
196
|
||
|
|
@@ -211,22 +217,21 @@ - (void)handleTouchUpInside:(UIView *)sender forEvent:(UIEvent *)event | |
|
|
||
| - (void)handleDragExit:(UIView *)sender forEvent:(UIEvent *)event | ||
| { | ||
| RNGestureHandlerState newState = RNGestureHandlerStateActive; | ||
|
|
||
| // Pointer is moved outside of the view bounds, we cancel button when `shouldCancelWhenOutside` is set | ||
| if (self.shouldCancelWhenOutside) { | ||
| UIControl *control = (UIControl *)sender; | ||
| [control cancelTrackingWithEvent:event]; | ||
| [self sendEventsInState:RNGestureHandlerStateEnd | ||
| forViewWithTag:sender.reactTag | ||
| withExtraData:[RNGestureHandlerEventExtraData forPointerInside:NO | ||
| withNumberOfTouches:event.allTouches.count | ||
| withPointerType:_pointerType]]; | ||
| } else { | ||
| [self sendEventsInState:RNGestureHandlerStateActive | ||
| forViewWithTag:sender.reactTag | ||
| withExtraData:[RNGestureHandlerEventExtraData forPointerInside:NO | ||
| withNumberOfTouches:event.allTouches.count | ||
| withPointerType:_pointerType]]; | ||
|
|
||
| newState = RNGestureHandlerStateEnd; | ||
| } | ||
|
|
||
| [self sendEventsInState:newState | ||
| forViewWithTag:sender.reactTag | ||
| withExtraData:[RNGestureHandlerEventExtraData forPointerInside:NO | ||
| withNumberOfTouches:event.allTouches.count | ||
| withPointerType:_pointerType]]; | ||
| } | ||
|
|
||
| - (void)handleDragEnter:(UIView *)sender forEvent:(UIEvent *)event | ||
|
|
@@ -238,6 +243,24 @@ - (void)handleDragEnter:(UIView *)sender forEvent:(UIEvent *)event | |
| withPointerType:_pointerType]]; | ||
| } | ||
|
|
||
| - (void)handleDragInside:(UIView *)sender forEvent:(UIEvent *)event | ||
| { | ||
| [self sendEventsInState:RNGestureHandlerStateActive | ||
| forViewWithTag:sender.reactTag | ||
| withExtraData:[RNGestureHandlerEventExtraData forPointerInside:YES | ||
| withNumberOfTouches:event.allTouches.count | ||
| withPointerType:_pointerType]]; | ||
| } | ||
|
|
||
| - (void)handleDragOutside:(UIView *)sender forEvent:(UIEvent *)event | ||
| { | ||
| [self sendEventsInState:RNGestureHandlerStateActive | ||
| forViewWithTag:sender.reactTag | ||
| withExtraData:[RNGestureHandlerEventExtraData forPointerInside:NO | ||
| withNumberOfTouches:event.allTouches.count | ||
| withPointerType:_pointerType]]; | ||
| } | ||
|
|
||
| - (void)handleTouchCancel:(UIView *)sender forEvent:(UIEvent *)event | ||
| { | ||
| [self sendEventsInState:RNGestureHandlerStateCancelled | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,26 +38,26 @@ export const BaseButton = (props: BaseButtonProps) => { | |
| }; | ||
|
|
||
| const onBegin = (e: CallbackEventType) => { | ||
| if (Platform.OS === 'android' && e.pointerInside) { | ||
| longPressDetected.current = false; | ||
| if (onLongPress) { | ||
| longPressTimeout.current = setTimeout(wrappedLongPress, delayLongPress); | ||
| } | ||
| if (!e.pointerInside) { | ||
| return; | ||
| } | ||
|
|
||
| props.onBegin?.(e); | ||
| // iOS, macOS. Web has its own implementation of button. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if (Platform.OS !== 'android') { | ||
| onActiveStateChange?.(true); | ||
| } | ||
| }; | ||
|
|
||
| const onActivate = (e: CallbackEventType) => { | ||
| onActiveStateChange?.(true); | ||
| longPressDetected.current = false; | ||
| if (onLongPress) { | ||
| longPressTimeout.current = setTimeout(wrappedLongPress, delayLongPress); | ||
| } | ||
|
|
||
| if (Platform.OS !== 'android' && e.pointerInside) { | ||
| longPressDetected.current = false; | ||
| if (onLongPress) { | ||
| longPressTimeout.current = setTimeout(wrappedLongPress, delayLongPress); | ||
| } | ||
| props.onBegin?.(e); | ||
| }; | ||
|
|
||
| props.onBegin?.(e); | ||
| const onActivate = (e: CallbackEventType) => { | ||
| if (Platform.OS === 'android' && e.pointerInside) { | ||
| onActiveStateChange?.(true); | ||
| } | ||
|
|
||
| if (!e.pointerInside && longPressTimeout.current !== undefined) { | ||
|
|
||
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.
So this means that ios buttons will also spam events when pointer moves when pressed?
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.
Basically yes.