|
4 | 4 | using ReactNative.UIManager.Events;
|
5 | 5 | using System;
|
6 | 6 | using System.Collections.Generic;
|
| 7 | +using Windows.Foundation; |
| 8 | +using Windows.UI.Input; |
7 | 9 | using Windows.UI.Xaml;
|
8 | 10 | using Windows.UI.Xaml.Input;
|
9 | 11 | using Windows.UI.Xaml.Media;
|
@@ -46,17 +48,25 @@ private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
|
46 | 48 | throw new InvalidOperationException("A pointer with this ID already exists.");
|
47 | 49 | }
|
48 | 50 |
|
49 |
| - var reactView = GetReactViewTarget(e); |
| 51 | + var originalSource = e.OriginalSource as DependencyObject; |
| 52 | + var rootPoint = e.GetCurrentPoint(_view); |
| 53 | + var reactView = GetReactViewTarget(originalSource, rootPoint.Position); |
50 | 54 | if (reactView != null && _view.CapturePointer(e.Pointer))
|
51 | 55 | {
|
52 |
| - var reactTag = reactView.GetReactCompoundView().GetReactTagAtPoint(reactView, |
53 |
| - e.GetCurrentPoint(reactView).Position); |
| 56 | + var viewPoint = e.GetCurrentPoint(reactView); |
| 57 | + var reactTag = reactView.GetReactCompoundView().GetReactTagAtPoint(reactView, viewPoint.Position); |
54 | 58 | var pointer = new ReactPointer();
|
55 | 59 | pointer.Target = reactTag;
|
56 | 60 | pointer.PointerId = e.Pointer.PointerId;
|
57 | 61 | pointer.Identifier = ++_pointerIDs;
|
| 62 | + pointer.PointerType = e.Pointer.PointerDeviceType.GetPointerDeviceTypeName(); |
| 63 | + pointer.IsLeftButton = viewPoint.Properties.IsLeftButtonPressed; |
| 64 | + pointer.IsRightButton = viewPoint.Properties.IsRightButtonPressed; |
| 65 | + pointer.IsMiddleButton = viewPoint.Properties.IsMiddleButtonPressed; |
| 66 | + pointer.IsHorizontalMouseWheel = viewPoint.Properties.IsHorizontalMouseWheel; |
| 67 | + pointer.IsEraser = viewPoint.Properties.IsEraser; |
58 | 68 | pointer.ReactView = reactView;
|
59 |
| - UpdatePointerForEvent(pointer, e); |
| 69 | + UpdatePointerForEvent(pointer, rootPoint, viewPoint); |
60 | 70 |
|
61 | 71 | var pointerIndex = _pointers.Count;
|
62 | 72 | _pointers.Add(pointer);
|
@@ -123,16 +133,15 @@ private int IndexOfPointerWithId(uint pointerId)
|
123 | 133 | return -1;
|
124 | 134 | }
|
125 | 135 |
|
126 |
| - private UIElement GetReactViewTarget(PointerRoutedEventArgs e) |
| 136 | + private UIElement GetReactViewTarget(DependencyObject originalSource, Point point) |
127 | 137 | {
|
128 | 138 | // If the target is not a child of the root view, then this pointer
|
129 | 139 | // event does not belong to React.
|
130 |
| - if (!RootViewHelper.IsReactSubview(e.OriginalSource as DependencyObject)) |
| 140 | + if (!RootViewHelper.IsReactSubview(originalSource)) |
131 | 141 | {
|
132 | 142 | return null;
|
133 | 143 | }
|
134 | 144 |
|
135 |
| - var point = e.GetCurrentPoint(_view).Position; |
136 | 145 | var sources = VisualTreeHelper.FindElementsInHostCoordinates(point, _view);
|
137 | 146 |
|
138 | 147 | // Get the first React view that does not have pointer events set
|
@@ -167,15 +176,23 @@ private UIElement GetReactViewTarget(PointerRoutedEventArgs e)
|
167 | 176 |
|
168 | 177 | private void UpdatePointerForEvent(ReactPointer pointer, PointerRoutedEventArgs e)
|
169 | 178 | {
|
170 |
| - var viewPoint = e.GetCurrentPoint(_view); |
171 |
| - var positionInRoot = viewPoint.Position; |
172 |
| - var positionInView = e.GetCurrentPoint(pointer.ReactView).Position; |
| 179 | + var rootPoint = e.GetCurrentPoint(_view); |
| 180 | + var viewPoint = e.GetCurrentPoint(pointer.ReactView); |
| 181 | + UpdatePointerForEvent(pointer, rootPoint, viewPoint); |
| 182 | + } |
| 183 | + |
| 184 | + private void UpdatePointerForEvent(ReactPointer pointer, PointerPoint rootPoint, PointerPoint viewPoint) |
| 185 | + { |
| 186 | + var positionInRoot = rootPoint.Position; |
| 187 | + var positionInView = viewPoint.Position; |
173 | 188 |
|
174 | 189 | pointer.PageX = (float)positionInRoot.X;
|
175 | 190 | pointer.PageY = (float)positionInRoot.Y;
|
176 | 191 | pointer.LocationX = (float)positionInView.X;
|
177 | 192 | pointer.LocationY = (float)positionInView.Y;
|
178 |
| - pointer.Timestamp = viewPoint.Timestamp / 1000; // Convert microseconds to milliseconds; |
| 193 | + pointer.Timestamp = rootPoint.Timestamp / 1000; // Convert microseconds to milliseconds; |
| 194 | + pointer.Force = rootPoint.Properties.Pressure; |
| 195 | + pointer.IsBarrelButtonPressed = rootPoint.Properties.IsBarrelButtonPressed; |
179 | 196 | }
|
180 | 197 |
|
181 | 198 | private void DispatchTouchEvent(TouchEventType touchEventType, List<ReactPointer> activePointers, int pointerIndex)
|
@@ -312,6 +329,30 @@ class ReactPointer
|
312 | 329 |
|
313 | 330 | [JsonProperty(PropertyName = "pageY")]
|
314 | 331 | public float PageY { get; set; }
|
| 332 | + |
| 333 | + [JsonProperty(PropertyName = "pointerType")] |
| 334 | + public string PointerType { get; set; } |
| 335 | + |
| 336 | + [JsonProperty(PropertyName = "force")] |
| 337 | + public double Force { get; set; } |
| 338 | + |
| 339 | + [JsonProperty(PropertyName = "isLeftButton", DefaultValueHandling = DefaultValueHandling.Ignore)] |
| 340 | + public bool IsLeftButton { get; set; } |
| 341 | + |
| 342 | + [JsonProperty(PropertyName = "isRightButton", DefaultValueHandling = DefaultValueHandling.Ignore)] |
| 343 | + public bool IsRightButton { get; set; } |
| 344 | + |
| 345 | + [JsonProperty(PropertyName = "isMiddleButton", DefaultValueHandling = DefaultValueHandling.Ignore)] |
| 346 | + public bool IsMiddleButton { get; set; } |
| 347 | + |
| 348 | + [JsonProperty(PropertyName = "isBarrelButtonPressed", DefaultValueHandling = DefaultValueHandling.Ignore)] |
| 349 | + public bool IsBarrelButtonPressed { get; set; } |
| 350 | + |
| 351 | + [JsonProperty(PropertyName = "isHorizontalScrollWheel", DefaultValueHandling = DefaultValueHandling.Ignore)] |
| 352 | + public bool IsHorizontalMouseWheel { get; set; } |
| 353 | + |
| 354 | + [JsonProperty(PropertyName = "isEraser", DefaultValueHandling = DefaultValueHandling.Ignore)] |
| 355 | + public bool IsEraser { get; set; } |
315 | 356 | }
|
316 | 357 | }
|
317 | 358 | }
|
0 commit comments