Skip to content

Commit

Permalink
Version 2.1.9 (issue #545) (#549)
Browse files Browse the repository at this point in the history
* fix #545

* document some fields that were introduced in 6c15da0

* bump version to 2.1.9

* add changelog entry for version 2.1.9
  • Loading branch information
Adrian-Samoticha authored Jan 28, 2025
1 parent faea7a0 commit 4da96e4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [2.1.9]
### 🛠️ Fixed 🛠️
* Fix incorrect highlighting and focusing behavior of `_MacosPopupMenuItemButton`.
* Remove scrolling animation from dropdown menus when manipulating the focus with the keyboard to mimic native macOS behavior.

## [2.1.8]
### 🛠️ Fixed 🛠️
* Fixed `shownByDefault` not being respected for the left sidebar of the `MacosWindow` (thanks, [@ShayperCool](https://github.com/ShayperCool)).
Expand Down
60 changes: 40 additions & 20 deletions lib/src/buttons/popup_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,37 @@ class _MacosPopupMenuItemButton<T> extends StatefulWidget {

class _MacosPopupMenuItemButtonState<T>
extends State<_MacosPopupMenuItemButton<T>> {
bool _isHovered = false;
final _focusNode = FocusNode();

bool _isFocused = false;

bool get _isHighlighted => _isFocused;

/// The last time the mouse entered this item.
static DateTime _lastMouseEnterTime = DateTime.now();

/// The last time the focus changed that wasn’t caused by the mouse.
static DateTime _lastNonMouseFocusChange = DateTime.now();

void _handleFocusChange(bool focused) {
if (focused) {
final _MenuLimits menuLimits = widget.route.getMenuLimits(
widget.buttonRect,
widget.constraints.maxHeight,
widget.itemIndex,
);
widget.route.scrollController!.animateTo(
menuLimits.scrollOffset,
curve: Curves.easeInOut,
duration: const Duration(milliseconds: 100),
);
setState(() => _isHovered = true);
final timeSinceMouseEnter =
DateTime.now().difference(_lastMouseEnterTime);
if (timeSinceMouseEnter > const Duration(milliseconds: 50)) {
_lastNonMouseFocusChange = DateTime.now();

final _MenuLimits menuLimits = widget.route.getMenuLimits(
widget.buttonRect,
widget.constraints.maxHeight,
widget.itemIndex,
);
widget.route.scrollController!.jumpTo(
menuLimits.scrollOffset,
);
}
setState(() => _isFocused = true);
} else {
setState(() => _isHovered = false);
setState(() => _isFocused = false);
}
}

Expand Down Expand Up @@ -91,14 +105,20 @@ class _MacosPopupMenuItemButtonState<T>
child = MouseRegion(
cursor: SystemMouseCursors.basic,
onEnter: (_) {
setState(() => _isHovered = true);
},
onExit: (_) {
setState(() => _isHovered = false);
final timeSinceLastNonMouseFocusChange =
DateTime.now().difference(_lastNonMouseFocusChange);
if (timeSinceLastNonMouseFocusChange <
const Duration(milliseconds: 200)) {
return;
}

_lastMouseEnterTime = DateTime.now();
FocusScope.of(context).requestFocus(_focusNode);
},
child: GestureDetector(
onTap: _handleOnTap,
child: Focus(
focusNode: _focusNode,
onKeyEvent: (FocusNode node, KeyEvent event) {
if (event.logicalKey == LogicalKeyboardKey.enter) {
_handleOnTap();
Expand All @@ -110,7 +130,7 @@ class _MacosPopupMenuItemButtonState<T>
autofocus: widget.itemIndex == widget.route.selectedIndex,
child: Container(
decoration: BoxDecoration(
color: _isHovered
color: _isHighlighted
? MacosPopupButtonTheme.of(context).highlightColor
: Colors.transparent,
borderRadius: _kBorderRadius,
Expand All @@ -123,7 +143,7 @@ class _MacosPopupMenuItemButtonState<T>
child: MacosIcon(
CupertinoIcons.checkmark_alt,
size: 16.0,
color: _isHovered
color: _isHighlighted
? MacosColors.white
: brightness.resolve(
MacosColors.black,
Expand All @@ -135,7 +155,7 @@ class _MacosPopupMenuItemButtonState<T>
DefaultTextStyle(
style: TextStyle(
fontSize: 13.0,
color: _isHovered
color: _isHighlighted
? MacosColors.white
: brightness.resolve(
MacosColors.black,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: macos_ui
description: Flutter widgets and themes implementing the current macOS design language.
version: 2.1.8
version: 2.1.9
homepage: "https://macosui.dev"
repository: "https://github.com/GroovinChip/macos_ui"

Expand Down

0 comments on commit 4da96e4

Please sign in to comment.