-
-
Notifications
You must be signed in to change notification settings - Fork 908
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add custom long tap delay (#3110)
Currently `longTapDelay` is hardcoded to 300ms. This is good for most of the games. But same games required custom long press values. This PR allows it. --------- Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
- Loading branch information
Showing
5 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'dart:math'; | ||
|
||
/// [TapConfig] is used to expose specific configurations | ||
/// related to the tap dispatcher. | ||
final class TapConfig { | ||
TapConfig._(); | ||
|
||
static double _longTapDelay = _defaultLongTapDelay; | ||
|
||
/// The delay (in seconds) after which a tap is considered a long tap. | ||
static double get longTapDelay => _longTapDelay; | ||
|
||
/// Set the delay (in seconds) after which a tap is considered a long tap. | ||
/// Same games may want to change the long tap delay to better | ||
/// fit their needs or accessibility requirements. | ||
static set longTapDelay(double value) { | ||
_longTapDelay = max(_minLongTapDelay, value); | ||
} | ||
|
||
/// Min delay to long tap delay is defined below. | ||
/// Values too low don't make sense because they | ||
/// would be basically a regular tap. | ||
static const double _minLongTapDelay = 0.150; | ||
|
||
/// Default long tap delay is 0.3 seconds. | ||
static const double _defaultLongTapDelay = 0.3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:flame/src/events/tap_config.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('TapConfig', () { | ||
test('default longTapDelay is 0.3', () { | ||
expect(TapConfig.longTapDelay, 0.3); | ||
}); | ||
|
||
test('longTapDelay can be set new values', () { | ||
TapConfig.longTapDelay = 0.5; | ||
expect(TapConfig.longTapDelay, 0.5); | ||
}); | ||
|
||
test('longTapDelay cannot be set to a value lower than 0.150', () { | ||
TapConfig.longTapDelay = 0.1; | ||
expect(TapConfig.longTapDelay, 0.150); | ||
}); | ||
}); | ||
} |