浏览代码

Merge pull request #246 from UnityTech/longpressup

Longpressup
/main
GitHub 5 年前
当前提交
fbc7ffaa
共有 3 个文件被更改,包括 35 次插入21 次删除
  1. 22
      Runtime/gestures/long_press.cs
  2. 11
      Runtime/widgets/gesture_detector.cs
  3. 23
      Samples/UIWidgetSample/LongPressSample.cs

22
Runtime/gestures/long_press.cs


base(deadline: Constants.kLongPressTimeout, debugOwner: debugOwner, kind: kind) {
}
bool _longPressAccepted = false;
public GestureLongPressUpCallback onLongPressUp;
this._longPressAccepted = true;
if (this.onLongPress != null) {
this.invokeCallback<object>("onLongPress", () => {
this.onLongPress();

protected override void handlePrimaryPointer(PointerEvent evt) {
if (evt is PointerUpEvent) {
this.resolve(GestureDisposition.rejected);
if (this._longPressAccepted && this.onLongPressUp != null) {
this._longPressAccepted = false;
this.invokeCallback<object>("onLongPressUp", () => {
this.onLongPressUp();
return null;
});
}
else {
this.resolve(GestureDisposition.rejected);
}
}
else if (evt is PointerDownEvent || evt is PointerCancelEvent) {
this._longPressAccepted = false;
}
}

Offset _longPressOrigin;
TimeSpan? _longPressStartTimestamp;
public GestureLongPressDragStartCallback onLongPressStart;
public GestureLongPressDragUpdateCallback onLongPressDragUpdate;

11
Runtime/widgets/gesture_detector.cs


throw new UIWidgetsError(
"Incorrect GestureDetector arguments.\n" +
"Having both a pan gesture recognizer and a scale gesture recognizer is redundant; scale is a superset of pan. Just use the scale gesture recognizer."
);
);
string recognizer = havePan ? "pan" : "scale";
if (haveVerticalDrag && haveHorizontalDrag) {
throw new UIWidgetsError(

);
}
}
if (haveLongPress && haveLongPressDrag) {
throw new UIWidgetsError(
"Incorrect GestureDetector arguments.\n" +

gestures[typeof(LongPressGestureRecognizer)] =
new GestureRecognizerFactoryWithHandlers<LongPressGestureRecognizer>(
() => new LongPressGestureRecognizer(debugOwner: this),
instance => { instance.onLongPress = this.onLongPress; }
instance => {
instance.onLongPress = this.onLongPress;
instance.onLongPressUp = this.onLongPressUp;
}
);
}

23
Samples/UIWidgetSample/LongPressSample.cs


using Unity.UIWidgets.animation;
using Unity.UIWidgets.engine;
public class LongPressSample: UIWidgetsSamplePanel {
protected override Widget createWidget() {
public class LongPressSample : UIWidgetsSamplePanel {
protected override Widget createWidget() {
return new WidgetsApp(
home: new LongPressSampleWidget(),
pageRouteBuilder: this.pageRouteBuilder);

public class LongPressSampleWidget: StatefulWidget {
public class LongPressSampleWidget : StatefulWidget {
public override State createState() {
return new _LongPressSampleWidgetState();
}

public override Widget build(BuildContext context) {
return new GestureDetector(
onLongPressDragStart: (value) => {
Debug.Log($"Long Press Drag Start: {value}");
},
onLongPressDragUpdate: (value) => {
Debug.Log($"Long Press Drag Update: {value}");
},
onLongPressDragUp: (value) => {
Debug.Log($"Long Press Drag Up: {value}");
},
onLongPressDragStart: (value) => { Debug.Log($"Long Press Drag Start: {value}"); },
onLongPressDragUpdate: (value) => { Debug.Log($"Long Press Drag Update: {value}"); },
onLongPressDragUp: (value) => { Debug.Log($"Long Press Drag Up: {value}"); },
onLongPressUp: () => { Debug.Log($"Long Press Up"); },
onLongPress: () => { Debug.Log($"Long Press"); },
child: new Center(
child: new Container(
width: 200,

正在加载...
取消
保存