Skip to content

Commit

Permalink
feat: Add a delay to the reveal highlight wrapped container
Browse files Browse the repository at this point in the history
  • Loading branch information
Losses committed Nov 25, 2024
1 parent f20fb85 commit 55a5f9c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/widgets/tile/tile.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:fluent_ui/fluent_ui.dart';

import '../../widgets/navigation_bar/utils/activate_link_action.dart';
Expand All @@ -24,6 +26,8 @@ class TileState extends State<Tile> {
bool _isHovered = false;
bool _isFocused = false;

Timer? _delayTimer;

final FocusNode _focusNode = FocusNode(debugLabel: 'Tile');

@override
Expand All @@ -44,6 +48,20 @@ class TileState extends State<Tile> {
});
}

void _handleDelayedPress() {
if (widget.onPressed == null) return;

// Cancel any existing timer
_delayTimer?.cancel();

// Create new timer for 50ms delay
_delayTimer = Timer(const Duration(milliseconds: 50), () {
if (mounted) {
widget.onPressed?.call();
}
});
}

@override
Widget build(BuildContext context) {
final theme = FluentTheme.of(context);
Expand All @@ -68,7 +86,7 @@ class TileState extends State<Tile> {
}

return GestureDetector(
onTap: widget.onPressed,
onTap: _handleDelayedPress,
child: FocusableActionDetector(
focusNode: _focusNode,
onShowFocusHighlight: _handleFocusHighlight,
Expand Down

0 comments on commit 55a5f9c

Please sign in to comment.