mirror of
https://github.com/linagora/tmail-flutter.git
synced 2026-12-06 08:06:47 +00:00
43 lines
816 B
Dart
43 lines
816 B
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
class HoverSubmenuController {
|
|
HoverSubmenuController({
|
|
this.exitDelay = const Duration(milliseconds: 120),
|
|
});
|
|
|
|
final Duration exitDelay;
|
|
|
|
final ValueNotifier<bool> isHovering = ValueNotifier(false);
|
|
|
|
int _hoverRefCount = 0;
|
|
Timer? _exitTimer;
|
|
|
|
void enter() {
|
|
_exitTimer?.cancel();
|
|
_hoverRefCount++;
|
|
if (!isHovering.value) {
|
|
isHovering.value = true;
|
|
}
|
|
}
|
|
|
|
void exit() {
|
|
_hoverRefCount = (_hoverRefCount - 1).clamp(0, 999);
|
|
|
|
if (_hoverRefCount == 0) {
|
|
_exitTimer?.cancel();
|
|
_exitTimer = Timer(exitDelay, () {
|
|
if (_hoverRefCount == 0) {
|
|
isHovering.value = false;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
void dispose() {
|
|
_exitTimer?.cancel();
|
|
isHovering.dispose();
|
|
}
|
|
}
|