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

fix: toolbar menu not showing beacase keyboard height is not updated in time #7060

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

abstract class AppFlowyMobileToolbarWidgetService {
void closeItemMenu();

void closeKeyboard();

PropertyValueNotifier<bool> get showMenuNotifier;
Expand Down Expand Up @@ -179,7 +180,13 @@ class _MobileToolbarState extends State<_MobileToolbar>
// but in this case, we don't want to update the cached keyboard height.
// This is because we want to keep the same height when the menu is shown.
bool canUpdateCachedKeyboardHeight = true;
ValueNotifier<double> cachedKeyboardHeight = ValueNotifier(0.0);

/// when the [_MobileToolbar] disposed before the keyboard height can be updated in time,
/// there will be an issue with the height being 0
/// this is used to globally record the height.
static double _globalCachedKeyboardHeight = 0.0;
ValueNotifier<double> cachedKeyboardHeight =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If _maxKeyboardHeight is used as the initial value every time, cachedKeyboardHeight will never be 0 after the first initialization. I assume this might have side effects on other logic, such as closing the keyboard.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cachedKeyboardHeight is used to keep the same height when the menu is shown, and it was controlled by canUpdateCachedKeyboardHeight, after _MobileToolbar disposed and recreated a new one, cachedKeyboardHeight will be set to 0, that will cause the issue —— #7049, and using _globalCachedKeyboardHeight can prevent the issue caused by its rapid re-initialization before the height can be obtained

ValueNotifier(_globalCachedKeyboardHeight);

// used to check if click the same item again
int? selectedMenuIndex;
Expand Down Expand Up @@ -408,6 +415,9 @@ class _MobileToolbarState extends State<_MobileToolbar>
);
}
}
if (keyboardHeight > 0) {
_globalCachedKeyboardHeight = keyboardHeight;
}
return SizedBox(
height: keyboardHeight,
child: (showingMenu && selectedMenuIndex != null)
Expand Down
Loading