Skip to content

Commit

Permalink
fix: handle x/y position for touch in dragstart/dragend events on iOS (
Browse files Browse the repository at this point in the history
…#14134)

* fix: handle x/y position for touch in dragstart/dragend events on iOS

* fix: handle x/y position for touch in dragstart/dragend events on iOS

* refactor: rename 'drag_dict' to 'dict' for better consistency

---------

Co-authored-by: Michael Gangolf <[email protected]>
  • Loading branch information
deckameron and m1ga authored Oct 17, 2024
1 parent 6f0d755 commit 62e9d4a
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions iphone/Classes/TiUIScrollViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -430,23 +430,36 @@ - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)vi

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
CGPoint offset = [scrollView contentOffset];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
NUMFLOAT(offset.x), @"x",
NUMFLOAT(offset.y), @"y",
NUMBOOL([scrollView isDecelerating]), @"decelerating",
[TiUtils sizeToDictionary:scrollView.contentSize], @"contentSize",
nil];
if ([self _hasListeners:@"dragStart"]) { // TODO: Deprecate old event
[self fireEvent:@"dragStart" withObject:nil];
[self fireEvent:@"dragStart" withObject:dict];
}
if ([self _hasListeners:@"dragstart"]) {
[self fireEvent:@"dragstart" withObject:nil];
[self fireEvent:@"dragstart" withObject:dict];
}
}

// listerner which tells when dragging ended in the scroll view.

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
CGPoint offset = [scrollView contentOffset];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
NUMFLOAT(offset.x), @"x",
NUMFLOAT(offset.y), @"y",
[NSNumber numberWithBool:decelerate], @"decelerate", nil,
[TiUtils sizeToDictionary:scrollView.contentSize], @"contentSize",
nil];
if ([self _hasListeners:@"dragEnd"]) { // TODO: Deprecate old event
[self fireEvent:@"dragEnd" withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:decelerate], @"decelerate", nil]];
[self fireEvent:@"dragEnd" withObject:dict];
}
if ([self _hasListeners:@"dragend"]) {
[self fireEvent:@"dragend" withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:decelerate], @"decelerate", nil]];
[self fireEvent:@"dragend" withObject:dict];
}
}

Expand Down

0 comments on commit 62e9d4a

Please sign in to comment.