Skip to content

Commit 3f853e0

Browse files
committed
Fix iOS
1 parent 6c25a68 commit 3f853e0

1 file changed

Lines changed: 34 additions & 10 deletions

File tree

packages/react-native-gesture-handler/apple/RNGestureHandlerPointerTracker.mm

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,25 @@ - (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
116116
_eventType = RNGHTouchEventTypePointerDown;
117117

118118
NSDictionary *data[touches.count];
119+
int changedCount = 0;
119120

120121
for (int i = 0; i < [touches count]; i++) {
121122
RNGHUITouch *touch = [[touches allObjects] objectAtIndex:i];
122123
int index = [self registerTouch:touch];
123-
if (index >= 0) {
124-
_trackedPointersCount++;
124+
125+
if (index < 0) {
126+
continue;
125127
}
126128

127-
data[i] = [self extractPointerData:index forTouch:touch];
129+
_trackedPointersCount++;
130+
data[changedCount++] = [self extractPointerData:index forTouch:touch];
131+
}
132+
133+
if (changedCount == 0) {
134+
return;
128135
}
129136

130-
_changedPointersData = [[NSArray alloc] initWithObjects:data count:[touches count]];
137+
_changedPointersData = [[NSArray alloc] initWithObjects:data count:changedCount];
131138
// extract all touches last to include the ones that were just added
132139
[self extractAllTouches];
133140
[self sendEvent];
@@ -142,14 +149,24 @@ - (void)touchesMoved:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
142149
_eventType = RNGHTouchEventTypePointerMove;
143150

144151
NSDictionary *data[touches.count];
152+
int changedCount = 0;
145153

146154
for (int i = 0; i < [touches count]; i++) {
147155
RNGHUITouch *touch = [[touches allObjects] objectAtIndex:i];
148156
int index = [self findTouchIndex:touch];
149-
data[i] = [self extractPointerData:index forTouch:touch];
157+
158+
if (index < 0) {
159+
continue;
160+
}
161+
162+
data[changedCount++] = [self extractPointerData:index forTouch:touch];
150163
}
151164

152-
_changedPointersData = [[NSArray alloc] initWithObjects:data count:[touches count]];
165+
if (changedCount == 0) {
166+
return;
167+
}
168+
169+
_changedPointersData = [[NSArray alloc] initWithObjects:data count:changedCount];
153170
[self extractAllTouches];
154171
[self sendEvent];
155172
}
@@ -166,18 +183,25 @@ - (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
166183
_eventType = RNGHTouchEventTypePointerUp;
167184

168185
NSDictionary *data[touches.count];
186+
int changedCount = 0;
169187

170188
for (int i = 0; i < [touches count]; i++) {
171189
RNGHUITouch *touch = [[touches allObjects] objectAtIndex:i];
172190
int index = [self unregisterTouch:touch];
173-
if (index >= 0) {
174-
_trackedPointersCount--;
191+
192+
if (index < 0) {
193+
continue;
175194
}
176195

177-
data[i] = [self extractPointerData:index forTouch:touch];
196+
_trackedPointersCount--;
197+
data[changedCount++] = [self extractPointerData:index forTouch:touch];
198+
}
199+
200+
if (changedCount == 0) {
201+
return;
178202
}
179203

180-
_changedPointersData = [[NSArray alloc] initWithObjects:data count:[touches count]];
204+
_changedPointersData = [[NSArray alloc] initWithObjects:data count:changedCount];
181205
[self sendEvent];
182206
}
183207

0 commit comments

Comments
 (0)