Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2.1.9 (issue #545) #549

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading