Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit ed60ea9

Browse files
authored
Merge pull request #152 from UnityTech/yczhang
Yczhang
2 parents 9c8658e + 9f14feb commit ed60ea9

File tree

102 files changed

+4389
-950
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+4389
-950
lines changed

Runtime/foundation/change_notifier.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,23 @@ protected virtual void notifyListeners() {
8686
}
8787
}
8888

89-
class _MergingListenable : ChangeNotifier {
89+
class _MergingListenable : Listenable {
9090
internal _MergingListenable(List<Listenable> _children) {
9191
this._children = _children;
92-
93-
foreach (Listenable child in _children) {
94-
if (child != null) {
95-
child.addListener(this.notifyListeners);
96-
}
97-
}
9892
}
9993

10094
readonly List<Listenable> _children;
10195

102-
public override void dispose() {
96+
public void addListener(VoidCallback listener) {
10397
foreach (Listenable child in this._children) {
104-
if (child != null) {
105-
child.removeListener(this.notifyListeners);
106-
}
98+
child?.addListener(listener);
10799
}
100+
}
108101

109-
base.dispose();
102+
public void removeListener(VoidCallback listener) {
103+
foreach (Listenable child in this._children) {
104+
child?.removeListener(listener);
105+
}
110106
}
111107

112108
public override string ToString() {

Runtime/foundation/constants.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using UnityEngine;
2+
3+
namespace Unity.UIWidgets.foundation {
4+
public class FoundationConstants {
5+
public static bool kReleaseMode = !Debug.isDebugBuild;
6+
}
7+
}

Runtime/foundation/constants.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/gestures/binding.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,27 @@ void _handlePointerEvent(PointerEvent evt) {
6464
this._handlePointerHoverEvent(evt);
6565
}
6666

67-
HitTestResult result = null;
67+
HitTestResult hitTestResult = null;
6868
if (evt is PointerDownEvent) {
6969
D.assert(!this._hitTests.ContainsKey(evt.pointer));
70-
result = new HitTestResult();
71-
this.hitTest(result, evt.position);
70+
hitTestResult = new HitTestResult();
71+
this.hitTest(hitTestResult, evt.position);
7272

73-
this._hitTests[evt.pointer] = result;
73+
this._hitTests[evt.pointer] = hitTestResult;
7474
D.assert(() => {
7575
if (D.debugPrintHitTestResults) {
76-
Debug.LogFormat("{0}: {1}", evt, result);
76+
Debug.LogFormat("{0}: {1}", evt, hitTestResult);
7777
}
7878

7979
return true;
8080
});
8181
}
8282
else if (evt is PointerUpEvent || evt is PointerCancelEvent) {
83-
result = this._hitTests.getOrDefault(evt.pointer);
83+
hitTestResult = this._hitTests.getOrDefault(evt.pointer);
8484
this._hitTests.Remove(evt.pointer);
8585
}
8686
else if (evt.down) {
87-
result = this._hitTests.getOrDefault(evt.pointer);
87+
hitTestResult = this._hitTests.getOrDefault(evt.pointer);
8888
}
8989

9090
D.assert(() => {
@@ -95,12 +95,12 @@ void _handlePointerEvent(PointerEvent evt) {
9595
return true;
9696
});
9797

98-
if (result != null ||
98+
if (hitTestResult != null ||
9999
evt is PointerHoverEvent ||
100100
evt is PointerAddedEvent ||
101101
evt is PointerRemovedEvent
102102
) {
103-
this.dispatchEvent(evt, result);
103+
this.dispatchEvent(evt, hitTestResult);
104104
}
105105
}
106106

@@ -162,8 +162,8 @@ public virtual void hitTest(HitTestResult result, Offset position) {
162162
result.add(new HitTestEntry(this));
163163
}
164164

165-
public void dispatchEvent(PointerEvent evt, HitTestResult result) {
166-
if (result == null) {
165+
public void dispatchEvent(PointerEvent evt, HitTestResult hitTestResult) {
166+
if (hitTestResult == null) {
167167
D.assert(evt is PointerHoverEvent || evt is PointerAddedEvent || evt is PointerRemovedEvent);
168168
try {
169169
this.pointerRouter.route(evt);
@@ -184,7 +184,7 @@ public void dispatchEvent(PointerEvent evt, HitTestResult result) {
184184
return;
185185
}
186186

187-
foreach (HitTestEntry entry in result.path) {
187+
foreach (HitTestEntry entry in hitTestResult.path) {
188188
try {
189189
entry.target.handleEvent(evt, entry);
190190
}

Runtime/gestures/hit_test.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface HitTestable {
99
}
1010

1111
public interface HitTestDispatcher {
12-
void dispatchEvent(PointerEvent evt, HitTestResult result);
12+
void dispatchEvent(PointerEvent evt, HitTestResult hitTestResult);
1313
}
1414

1515
public interface HitTestTarget {

Runtime/gestures/long_press.cs

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,65 @@
1+
using System;
12
using Unity.UIWidgets.ui;
23

34
namespace Unity.UIWidgets.gestures {
45
public delegate void GestureLongPressCallback();
56

7+
public delegate void GestureLongPressUpCallback();
8+
9+
public delegate void GestureLongPressDragStartCallback(GestureLongPressDragStartDetails details);
10+
11+
public delegate void GestureLongPressDragUpdateCallback(GestureLongPressDragUpdateDetails details);
12+
13+
public delegate void GestureLongPressDragUpCallback(GestureLongPressDragUpDetails details);
14+
15+
public class GestureLongPressDragStartDetails {
16+
public GestureLongPressDragStartDetails(
17+
TimeSpan? sourceTimeStamp = null,
18+
Offset globalPosition = null
19+
) {
20+
this.sourceTimeStamp = sourceTimeStamp;
21+
this.globalPosition = globalPosition ?? Offset.zero;
22+
}
23+
24+
25+
public readonly TimeSpan? sourceTimeStamp;
26+
27+
public readonly Offset globalPosition;
28+
}
29+
30+
public class GestureLongPressDragUpdateDetails {
31+
public GestureLongPressDragUpdateDetails(
32+
TimeSpan? sourceTimeStamp = null,
33+
Offset globalPosition = null,
34+
Offset offsetFromOrigin = null
35+
) {
36+
this.sourceTimeStamp = sourceTimeStamp;
37+
this.globalPosition = globalPosition ?? Offset.zero;
38+
this.offsetFromOrigin = offsetFromOrigin ?? Offset.zero;
39+
}
40+
41+
public readonly TimeSpan? sourceTimeStamp;
42+
43+
public readonly Offset globalPosition;
44+
45+
public readonly Offset offsetFromOrigin;
46+
}
47+
48+
public class GestureLongPressDragUpDetails {
49+
public GestureLongPressDragUpDetails(
50+
TimeSpan? sourceTimeStamp = null,
51+
Offset globalPosition = null
52+
) {
53+
this.sourceTimeStamp = sourceTimeStamp;
54+
this.globalPosition = globalPosition ?? Offset.zero;
55+
}
56+
57+
public readonly TimeSpan? sourceTimeStamp;
58+
59+
public readonly Offset globalPosition;
60+
}
61+
62+
663
public class LongPressGestureRecognizer : PrimaryPointerGestureRecognizer {
764
public LongPressGestureRecognizer(object debugOwner = null, PointerDeviceKind? kind = null) :
865
base(deadline: Constants.kLongPressTimeout, debugOwner: debugOwner, kind: kind) {
@@ -30,4 +87,87 @@ public override string debugDescription {
3087
get { return "long press"; }
3188
}
3289
}
90+
91+
public class LongPressDragGestureRecognizer : PrimaryPointerGestureRecognizer {
92+
public LongPressDragGestureRecognizer(object debugOwner = null) : base(
93+
deadline: Constants.kLongPressTimeout,
94+
postAcceptSlopTolerance: null,
95+
debugOwner: debugOwner
96+
) {
97+
}
98+
99+
bool _longPressAccepted = false;
100+
101+
Offset _longPressOrigin;
102+
103+
TimeSpan? _longPressStartTimestamp;
104+
105+
public GestureLongPressDragStartCallback onLongPressStart;
106+
107+
public GestureLongPressDragUpdateCallback onLongPressDragUpdate;
108+
109+
public GestureLongPressDragUpCallback onLongPressUp;
110+
111+
protected override void didExceedDeadline() {
112+
this.resolve(GestureDisposition.accepted);
113+
this._longPressAccepted = true;
114+
base.acceptGesture(this.primaryPointer);
115+
if (this.onLongPressStart != null) {
116+
this.invokeCallback<object>("onLongPressStart", () => {
117+
this.onLongPressStart(new GestureLongPressDragStartDetails(
118+
sourceTimeStamp: this._longPressStartTimestamp,
119+
globalPosition: this._longPressOrigin
120+
));
121+
return null;
122+
});
123+
}
124+
}
125+
126+
protected override void handlePrimaryPointer(PointerEvent e) {
127+
if (e is PointerUpEvent) {
128+
if (this._longPressAccepted == true && this.onLongPressUp != null) {
129+
this._longPressAccepted = false;
130+
this.invokeCallback<object>("onLongPressUp", () => {
131+
this.onLongPressUp(new GestureLongPressDragUpDetails(
132+
sourceTimeStamp: e.timeStamp,
133+
globalPosition: e.position
134+
));
135+
return null;
136+
});
137+
}
138+
else {
139+
this.resolve(GestureDisposition.rejected);
140+
}
141+
}
142+
else if (e is PointerDownEvent) {
143+
this._longPressAccepted = false;
144+
this._longPressStartTimestamp = e.timeStamp;
145+
this._longPressOrigin = e.position;
146+
}
147+
else if (e is PointerMoveEvent && this._longPressAccepted && this.onLongPressDragUpdate != null) {
148+
this.invokeCallback<object>("onLongPressDrag", () => {
149+
this.onLongPressDragUpdate(new GestureLongPressDragUpdateDetails(
150+
sourceTimeStamp: e.timeStamp,
151+
globalPosition: e.position,
152+
offsetFromOrigin: e.position - this._longPressOrigin
153+
));
154+
return null;
155+
});
156+
}
157+
}
158+
159+
public override void acceptGesture(int pointer) {
160+
}
161+
162+
protected override void didStopTrackingLastPointer(int pointer) {
163+
this._longPressAccepted = false;
164+
this._longPressOrigin = null;
165+
this._longPressStartTimestamp = null;
166+
base.didStopTrackingLastPointer(pointer);
167+
}
168+
169+
public override string debugDescription {
170+
get { return "long press drag"; }
171+
}
172+
}
33173
}

Runtime/gestures/recognizer.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,25 +203,25 @@ protected PrimaryPointerGestureRecognizer(
203203
TimeSpan? deadline = null,
204204
object debugOwner = null,
205205
PointerDeviceKind? kind = null,
206-
float? preAcceptSlotTolerance = Constants.kTouchSlop,
207-
float? postAcceptSlotTolerance = Constants.kTouchSlop
206+
float? preAcceptSlopTolerance = Constants.kTouchSlop,
207+
float? postAcceptSlopTolerance = Constants.kTouchSlop
208208
) : base(debugOwner: debugOwner, kind: kind) {
209-
D.assert(preAcceptSlotTolerance == null || preAcceptSlotTolerance >= 0,
209+
D.assert(preAcceptSlopTolerance == null || preAcceptSlopTolerance >= 0,
210210
"The preAcceptSlopTolerance must be positive or null");
211211

212-
D.assert(postAcceptSlotTolerance == null || postAcceptSlotTolerance >= 0,
212+
D.assert(postAcceptSlopTolerance == null || postAcceptSlopTolerance >= 0,
213213
"The postAcceptSlopTolerance must be positive or null");
214214

215215
this.deadline = deadline;
216-
this.preAcceptSlotTolerance = preAcceptSlotTolerance;
217-
this.postAcceptSlotTolerance = postAcceptSlotTolerance;
216+
this.preAcceptSlopTolerance = preAcceptSlopTolerance;
217+
this.postAcceptSlopTolerance = postAcceptSlopTolerance;
218218
}
219219

220220
public readonly TimeSpan? deadline;
221221

222-
public readonly float? preAcceptSlotTolerance;
222+
public readonly float? preAcceptSlopTolerance;
223223

224-
public readonly float? postAcceptSlotTolerance;
224+
public readonly float? postAcceptSlopTolerance;
225225

226226
public GestureRecognizerState state = GestureRecognizerState.ready;
227227

@@ -248,11 +248,11 @@ protected override void handleEvent(PointerEvent evt) {
248248

249249
if (evt.pointer == this.primaryPointer) {
250250
bool isPreAcceptSlopPastTolerance = this.state == GestureRecognizerState.possible &&
251-
this.preAcceptSlotTolerance != null &&
252-
this._getDistance(evt) > this.preAcceptSlotTolerance;
251+
this.preAcceptSlopTolerance != null &&
252+
this._getDistance(evt) > this.preAcceptSlopTolerance;
253253
bool isPostAcceptSlopPastTolerance = this.state == GestureRecognizerState.accepted &&
254-
this.postAcceptSlotTolerance != null &&
255-
this._getDistance(evt) > this.postAcceptSlotTolerance;
254+
this.postAcceptSlopTolerance != null &&
255+
this._getDistance(evt) > this.postAcceptSlopTolerance;
256256

257257
if (evt is PointerMoveEvent && (isPreAcceptSlopPastTolerance || isPostAcceptSlopPastTolerance)) {
258258
this.resolve(GestureDisposition.rejected);

0 commit comments

Comments
 (0)