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
  • Loading branch information
deckameron committed Oct 7, 2024
1 parent 81d5d1e commit cd95b88
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 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 *drag_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:drag_dict];
}
if ([self _hasListeners:@"dragstart"]) {
[self fireEvent:@"dragstart" withObject:nil];
[self fireEvent:@"dragstart" withObject:drag_dict];
}
}

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

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
CGPoint offset = [scrollView contentOffset];
NSDictionary *drag_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:drag_dict];
}
if ([self _hasListeners:@"dragend"]) {
[self fireEvent:@"dragend" withObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:decelerate], @"decelerate", nil]];
[self fireEvent:@"dragend" withObject:drag_dict];
}
}

Expand Down

0 comments on commit cd95b88

Please # to comment.