long_press.dart 1.38 KB
Newer Older
1 2 3 4
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
import 'arena.dart';
import 'constants.dart';
7
import 'events.dart';
8
import 'recognizer.dart';
9

10 11
/// Signature for when a pointer has remained in contact with the screen at the
/// same location for a long period of time.
12
typedef void GestureLongPressCallback();
13

14 15
/// Recognizes when the user has pressed down at the same location for a long
/// period of time.
16
class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
17 18 19
  /// Creates a long-press gesture recognizer.
  ///
  /// Consider assigning the [onLongPress] callback after creating this object.
20
  LongPressGestureRecognizer({ Object debugOwner }) : super(deadline: kLongPressTimeout, debugOwner: debugOwner);
21

22
  /// Called when a long-press is recongized.
23
  GestureLongPressCallback onLongPress;
24

25
  @override
26 27
  void didExceedDeadline() {
    resolve(GestureDisposition.accepted);
Ian Hickson's avatar
Ian Hickson committed
28
    if (onLongPress != null)
29
      invokeCallback<Null>('onLongPress', onLongPress); // ignore: STRONG_MODE_INVALID_CAST_FUNCTION_EXPR, https://github.com/dart-lang/sdk/issues/27504
30 31
  }

32
  @override
Ian Hickson's avatar
Ian Hickson committed
33 34
  void handlePrimaryPointer(PointerEvent event) {
    if (event is PointerUpEvent)
35 36
      resolve(GestureDisposition.rejected);
  }
37

38
  @override
39
  String get debugDescription => 'long press';
40
}