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

Commit b104398

Browse files
authored
Merge pull request #273 from UnityTech/yczhang1.5.4
[To 1.5.4] Finish src/widgets.
2 parents d9601b2 + b44034c commit b104398

Some content is hidden

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

56 files changed

+1918
-624
lines changed

Runtime/gestures/binding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void _handlePointerEvent(PointerEvent evt) {
6363
}
6464

6565
HitTestResult hitTestResult = null;
66-
if (evt is PointerDownEvent || evt is PointerSignalResolver) {
66+
if (evt is PointerDownEvent || evt is PointerSignalEvent) {
6767
D.assert(!this._hitTests.ContainsKey(evt.pointer));
6868
hitTestResult = new HitTestResult();
6969
this.hitTest(hitTestResult, evt.position);

Runtime/gestures/long_press.cs

Lines changed: 56 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -6,168 +6,123 @@ namespace Unity.UIWidgets.gestures {
66

77
public delegate void GestureLongPressUpCallback();
88

9-
public delegate void GestureLongPressDragStartCallback(GestureLongPressDragStartDetails details);
9+
public delegate void GestureLongPressStartCallback(LongPressStartDetails details);
1010

11-
public delegate void GestureLongPressDragUpdateCallback(GestureLongPressDragUpdateDetails details);
11+
public delegate void GestureLongPressMoveUpdateCallback(LongPressMoveUpdateDetails details);
1212

13-
public delegate void GestureLongPressDragUpCallback(GestureLongPressDragUpDetails details);
13+
public delegate void GestureLongPressEndCallback(LongPressEndDetails details);
1414

15-
public class GestureLongPressDragStartDetails {
16-
public GestureLongPressDragStartDetails(
17-
TimeSpan? sourceTimeStamp = null,
15+
public class LongPressStartDetails {
16+
public LongPressStartDetails(
1817
Offset globalPosition = null
1918
) {
20-
this.sourceTimeStamp = sourceTimeStamp;
2119
this.globalPosition = globalPosition ?? Offset.zero;
2220
}
2321

24-
25-
public readonly TimeSpan? sourceTimeStamp;
26-
2722
public readonly Offset globalPosition;
2823
}
2924

30-
public class GestureLongPressDragUpdateDetails {
31-
public GestureLongPressDragUpdateDetails(
32-
TimeSpan? sourceTimeStamp = null,
25+
public class LongPressMoveUpdateDetails {
26+
public LongPressMoveUpdateDetails(
3327
Offset globalPosition = null,
3428
Offset offsetFromOrigin = null
3529
) {
36-
this.sourceTimeStamp = sourceTimeStamp;
3730
this.globalPosition = globalPosition ?? Offset.zero;
3831
this.offsetFromOrigin = offsetFromOrigin ?? Offset.zero;
3932
}
4033

41-
public readonly TimeSpan? sourceTimeStamp;
42-
4334
public readonly Offset globalPosition;
4435

4536
public readonly Offset offsetFromOrigin;
4637
}
4738

48-
public class GestureLongPressDragUpDetails {
49-
public GestureLongPressDragUpDetails(
50-
TimeSpan? sourceTimeStamp = null,
39+
public class LongPressEndDetails {
40+
public LongPressEndDetails(
5141
Offset globalPosition = null
5242
) {
53-
this.sourceTimeStamp = sourceTimeStamp;
5443
this.globalPosition = globalPosition ?? Offset.zero;
5544
}
5645

57-
public readonly TimeSpan? sourceTimeStamp;
58-
5946
public readonly Offset globalPosition;
6047
}
6148

6249

6350
public class LongPressGestureRecognizer : PrimaryPointerGestureRecognizer {
64-
public LongPressGestureRecognizer(object debugOwner = null, PointerDeviceKind? kind = null) :
65-
base(deadline: Constants.kLongPressTimeout, debugOwner: debugOwner, kind: kind) {
66-
}
51+
public LongPressGestureRecognizer(
52+
float? postAcceptSlopTolerance = null,
53+
object debugOwner = null,
54+
PointerDeviceKind? kind = null) : base(
55+
deadline: Constants.kLongPressTimeout,
56+
postAcceptSlopTolerance: postAcceptSlopTolerance,
57+
kind: kind,
58+
debugOwner: debugOwner) { }
6759

6860
bool _longPressAccepted = false;
6961

62+
Offset _longPressOrigin;
63+
7064
public GestureLongPressCallback onLongPress;
7165

66+
public GestureLongPressStartCallback onLongPressStart;
67+
68+
public GestureLongPressMoveUpdateCallback onLongPressMoveUpdate;
69+
7270
public GestureLongPressUpCallback onLongPressUp;
7371

72+
public GestureLongPressEndCallback onLongPressEnd;
73+
7474
protected override void didExceedDeadline() {
7575
this.resolve(GestureDisposition.accepted);
7676
this._longPressAccepted = true;
77-
77+
base.acceptGesture(this.primaryPointer);
7878
if (this.onLongPress != null) {
7979
this.invokeCallback<object>("onLongPress", () => {
8080
this.onLongPress();
8181
return null;
8282
});
8383
}
84-
}
8584

86-
protected override void handlePrimaryPointer(PointerEvent evt) {
87-
if (evt is PointerUpEvent) {
88-
if (this._longPressAccepted && this.onLongPressUp != null) {
89-
this._longPressAccepted = false;
90-
this.invokeCallback<object>("onLongPressUp", () => {
91-
this.onLongPressUp();
85+
if (this.onLongPressStart != null) {
86+
this.invokeCallback<object>("onLongPressStart",
87+
() => {
88+
this.onLongPressStart(new LongPressStartDetails(globalPosition: this._longPressOrigin));
9289
return null;
9390
});
94-
}
95-
else {
96-
this.resolve(GestureDisposition.rejected);
97-
}
98-
}
99-
else if (evt is PointerDownEvent || evt is PointerCancelEvent) {
100-
this._longPressAccepted = false;
101-
}
102-
}
103-
104-
public override string debugDescription {
105-
get { return "long press"; }
106-
}
107-
}
108-
109-
public class LongPressDragGestureRecognizer : PrimaryPointerGestureRecognizer {
110-
public LongPressDragGestureRecognizer(object debugOwner = null) : base(
111-
deadline: Constants.kLongPressTimeout,
112-
postAcceptSlopTolerance: null,
113-
debugOwner: debugOwner
114-
) {
115-
}
116-
117-
bool _longPressAccepted = false;
118-
119-
Offset _longPressOrigin;
120-
121-
TimeSpan? _longPressStartTimestamp;
122-
123-
public GestureLongPressDragStartCallback onLongPressStart;
124-
125-
public GestureLongPressDragUpdateCallback onLongPressDragUpdate;
126-
127-
public GestureLongPressDragUpCallback onLongPressUp;
128-
129-
protected override void didExceedDeadline() {
130-
this.resolve(GestureDisposition.accepted);
131-
this._longPressAccepted = true;
132-
base.acceptGesture(this.primaryPointer);
133-
if (this.onLongPressStart != null) {
134-
this.invokeCallback<object>("onLongPressStart", () => {
135-
this.onLongPressStart(new GestureLongPressDragStartDetails(
136-
sourceTimeStamp: this._longPressStartTimestamp,
137-
globalPosition: this._longPressOrigin
138-
));
139-
return null;
140-
});
14191
}
14292
}
14393

144-
protected override void handlePrimaryPointer(PointerEvent e) {
145-
if (e is PointerUpEvent) {
146-
if (this._longPressAccepted == true && this.onLongPressUp != null) {
147-
this._longPressAccepted = false;
148-
this.invokeCallback<object>("onLongPressUp", () => {
149-
this.onLongPressUp(new GestureLongPressDragUpDetails(
150-
sourceTimeStamp: e.timeStamp,
151-
globalPosition: e.position
152-
));
153-
return null;
154-
});
94+
protected override void handlePrimaryPointer(PointerEvent evt) {
95+
if (evt is PointerUpEvent) {
96+
if (this._longPressAccepted) {
97+
if (this.onLongPressUp != null) {
98+
this.invokeCallback<object>("onLongPressUp", () => {
99+
this.onLongPressUp();
100+
return null;
101+
});
102+
}
103+
104+
if (this.onLongPressEnd != null) {
105+
this.invokeCallback<object>("onLongPressEnd", () => {
106+
this.onLongPressEnd(new LongPressEndDetails(globalPosition: evt.position));
107+
return null;
108+
});
109+
}
110+
111+
this._longPressAccepted = true;
155112
}
156113
else {
157114
this.resolve(GestureDisposition.rejected);
158115
}
159116
}
160-
else if (e is PointerDownEvent) {
117+
else if (evt is PointerDownEvent || evt is PointerCancelEvent) {
161118
this._longPressAccepted = false;
162-
this._longPressStartTimestamp = e.timeStamp;
163-
this._longPressOrigin = e.position;
119+
this._longPressOrigin = evt.position;
164120
}
165-
else if (e is PointerMoveEvent && this._longPressAccepted && this.onLongPressDragUpdate != null) {
166-
this.invokeCallback<object>("onLongPressDrag", () => {
167-
this.onLongPressDragUpdate(new GestureLongPressDragUpdateDetails(
168-
sourceTimeStamp: e.timeStamp,
169-
globalPosition: e.position,
170-
offsetFromOrigin: e.position - this._longPressOrigin
121+
else if (evt is PointerMoveEvent && this._longPressAccepted && this.onLongPressMoveUpdate != null) {
122+
this.invokeCallback<object>("onLongPressMoveUpdate", () => {
123+
this.onLongPressMoveUpdate(new LongPressMoveUpdateDetails(
124+
globalPosition: evt.position,
125+
offsetFromOrigin: evt.position - this._longPressOrigin
171126
));
172127
return null;
173128
});
@@ -177,15 +132,8 @@ protected override void handlePrimaryPointer(PointerEvent e) {
177132
public override void acceptGesture(int pointer) {
178133
}
179134

180-
protected override void didStopTrackingLastPointer(int pointer) {
181-
this._longPressAccepted = false;
182-
this._longPressOrigin = null;
183-
this._longPressStartTimestamp = null;
184-
base.didStopTrackingLastPointer(pointer);
185-
}
186-
187135
public override string debugDescription {
188-
get { return "long press drag"; }
136+
get { return "long press"; }
189137
}
190138
}
191139
}

Runtime/material/app.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,19 @@ public override State createState() {
106106

107107

108108
class _MaterialAppState : State<MaterialApp> {
109+
HeroController _heroController;
110+
109111
public override void initState() {
110112
base.initState();
113+
this._heroController = new HeroController(createRectTween: this._createRectTween);
111114
this._updateNavigator();
112115
}
113116

114117
public override void didUpdateWidget(StatefulWidget oldWidget) {
115118
base.didUpdateWidget(oldWidget);
119+
if (this.widget.navigatorKey != (oldWidget as MaterialApp).navigatorKey) {
120+
this._heroController = new HeroController(createRectTween: this._createRectTween);
121+
}
116122
this._updateNavigator();
117123
}
118124

@@ -124,6 +130,7 @@ void _updateNavigator() {
124130
this.widget.onGenerateRoute != null ||
125131
this.widget.onUnknownRoute != null) {
126132
this._navigatorObservers = new List<NavigatorObserver>(this.widget.navigatorObservers);
133+
this._navigatorObservers.Add(this._heroController);
127134
}
128135
else {
129136
this._navigatorObservers = null;

0 commit comments

Comments
 (0)