10
10
#import < React/RCTUtils.h>
11
11
#import < React/RCTViewComponentView.h>
12
12
#import < UIKit/UIGestureRecognizerSubclass.h>
13
+ #import < UIKit/UIKit.h>
13
14
14
15
#import " RCTConversions.h"
15
16
#import " RCTTouchableComponentViewProtocol.h"
@@ -82,7 +83,8 @@ static void UpdateActiveTouchWithUITouch(
82
83
ActiveTouch &activeTouch,
83
84
UITouch *uiTouch,
84
85
UIView *rootComponentView,
85
- CGPoint rootViewOriginOffset)
86
+ CGPoint rootViewOriginOffset,
87
+ NSTimeInterval unixTimestampBasis)
86
88
{
87
89
CGPoint offsetPoint = [uiTouch locationInView: activeTouch.componentView];
88
90
CGPoint screenPoint = [uiTouch locationInView: uiTouch.window];
@@ -93,14 +95,18 @@ static void UpdateActiveTouchWithUITouch(
93
95
activeTouch.touch .screenPoint = RCTPointFromCGPoint (screenPoint);
94
96
activeTouch.touch .pagePoint = RCTPointFromCGPoint (pagePoint);
95
97
96
- activeTouch.touch .timestamp = uiTouch.timestamp ;
98
+ activeTouch.touch .timestamp = unixTimestampBasis + uiTouch.timestamp ;
97
99
98
100
if (RCTForceTouchAvailable ()) {
99
101
activeTouch.touch .force = RCTZeroIfNaN (uiTouch.force / uiTouch.maximumPossibleForce );
100
102
}
101
103
}
102
104
103
- static ActiveTouch CreateTouchWithUITouch (UITouch *uiTouch, UIView *rootComponentView, CGPoint rootViewOriginOffset)
105
+ static ActiveTouch CreateTouchWithUITouch (
106
+ UITouch *uiTouch,
107
+ UIView *rootComponentView,
108
+ CGPoint rootViewOriginOffset,
109
+ NSTimeInterval unixTimestampBasis)
104
110
{
105
111
ActiveTouch activeTouch = {};
106
112
@@ -117,7 +123,7 @@ static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponen
117
123
componentView = componentView.superview ;
118
124
}
119
125
120
- UpdateActiveTouchWithUITouch (activeTouch, uiTouch, rootComponentView, rootViewOriginOffset);
126
+ UpdateActiveTouchWithUITouch (activeTouch, uiTouch, rootComponentView, rootViewOriginOffset, unixTimestampBasis );
121
127
return activeTouch;
122
128
}
123
129
@@ -167,6 +173,12 @@ @implementation RCTSurfaceTouchHandler {
167
173
*/
168
174
__weak UIView *_rootComponentView;
169
175
IdentifierPool<11 > _identifierPool;
176
+
177
+ /*
178
+ * See Touch.h and usage. This gives us a time-basis for a monotonic
179
+ * clock that acts like a timestamp of milliseconds elapsed since UNIX epoch.
180
+ */
181
+ NSTimeInterval _unixEpochBasisTime;
170
182
}
171
183
172
184
- (instancetype )init
@@ -181,6 +193,8 @@ - (instancetype)init
181
193
self.delaysTouchesEnded = NO ;
182
194
183
195
self.delegate = self;
196
+
197
+ _unixEpochBasisTime = [[NSDate date ] timeIntervalSince1970 ] - [NSProcessInfo processInfo ].systemUptime ;
184
198
}
185
199
186
200
return self;
@@ -208,7 +222,7 @@ - (void)detachFromView:(UIView *)view
208
222
- (void )_registerTouches : (NSSet <UITouch *> *)touches
209
223
{
210
224
for (UITouch *touch in touches) {
211
- auto activeTouch = CreateTouchWithUITouch (touch, _rootComponentView, _viewOriginOffset);
225
+ auto activeTouch = CreateTouchWithUITouch (touch, _rootComponentView, _viewOriginOffset, _unixEpochBasisTime );
212
226
activeTouch.touch .identifier = _identifierPool.dequeue ();
213
227
_activeTouches.emplace (touch, activeTouch);
214
228
}
@@ -223,7 +237,7 @@ - (void)_updateTouches:(NSSet<UITouch *> *)touches
223
237
continue ;
224
238
}
225
239
226
- UpdateActiveTouchWithUITouch (iterator->second , touch, _rootComponentView, _viewOriginOffset);
240
+ UpdateActiveTouchWithUITouch (iterator->second , touch, _rootComponentView, _viewOriginOffset, _unixEpochBasisTime );
227
241
}
228
242
}
229
243
0 commit comments