Skip to content

Commit aa4b347

Browse files
committed
feat(TouchHandler): Adds coalescing to move events
When multiple move events fire within a single frame, they can be coalesced to reduce the communication to JavaScript.
1 parent 19b0b2c commit aa4b347

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

ReactWindows/ReactNative/Touch/TouchHandler.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,32 +161,30 @@ private void DispatchTouchEvent(TouchEventType touchEventType, List<ReactPointer
161161
var changedIndices = new JArray();
162162
changedIndices.Add(JToken.FromObject(pointerIndex));
163163

164-
var touchEvent = new TouchEvent(touchEventType, touches, changedIndices);
164+
var coalescingKey = activePointers[pointerIndex].PointerId;
165+
166+
var touchEvent = new TouchEvent(touchEventType, touches, changedIndices, coalescingKey);
165167

166168
_view.GetReactContext()
167169
.GetNativeModule<UIManagerModule>()
168170
.EventDispatcher
169171
.DispatchEvent(touchEvent);
170172
}
171173

172-
/// <summary>
173-
/// Simple touch event.
174-
/// </summary>
175-
/// <remarks>
176-
/// TODO: revisit how to capture active pointers and coalesce efficiently.
177-
/// </remarks>
178174
class TouchEvent : Event
179175
{
180176
private readonly TouchEventType _touchEventType;
181177
private readonly JArray _touches;
182178
private readonly JArray _changedIndices;
179+
private readonly uint _coalescingKey;
183180

184-
public TouchEvent(TouchEventType touchEventType, JArray touches, JArray changedIndices)
181+
public TouchEvent(TouchEventType touchEventType, JArray touches, JArray changedIndices, uint coalescingKey)
185182
: base(-1, TimeSpan.FromTicks(Environment.TickCount))
186183
{
187184
_touchEventType = touchEventType;
188185
_touches = touches;
189186
_changedIndices = changedIndices;
187+
_coalescingKey = coalescingKey;
190188
}
191189

192190
public override string EventName
@@ -201,7 +199,18 @@ public override bool CanCoalesce
201199
{
202200
get
203201
{
204-
return false;
202+
return _touchEventType == TouchEventType.Move;
203+
}
204+
}
205+
206+
public override short CoalescingKey
207+
{
208+
get
209+
{
210+
unchecked
211+
{
212+
return (short)_coalescingKey;
213+
}
205214
}
206215
}
207216

0 commit comments

Comments
 (0)