Skip to content

Commit

Permalink
fix: the toolbar will be blocked if the scroll bar is hidden (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 authored Jul 5, 2024
1 parent 8b9ccf8 commit 7f05000
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
38 changes: 26 additions & 12 deletions lib/src/editor/toolbar/mobile/mobile_toolbar_v2.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/toolbar/mobile/utils/keyboard_height_observer.dart';
import 'package:flutter/foundation.dart';
Expand Down Expand Up @@ -274,6 +276,12 @@ class _MobileToolbarState extends State<_MobileToolbar>

if (canUpdateCachedKeyboardHeight) {
cachedKeyboardHeight.value = height;
if (defaultTargetPlatform == TargetPlatform.android) {
if (cachedKeyboardHeight.value != 0) {
cachedKeyboardHeight.value +=
MediaQuery.of(context).viewPadding.bottom;
}
}
}

if (height == 0) {
Expand Down Expand Up @@ -385,24 +393,30 @@ class _MobileToolbarState extends State<_MobileToolbar>
return ValueListenableBuilder(
valueListenable: showMenuNotifier,
builder: (_, showingMenu, __) {
var toolbarHeight = height;
var keyboardHeight = height;
if (defaultTargetPlatform == TargetPlatform.android) {
toolbarHeight += MediaQuery.of(context).viewPadding.bottom;
if (!showingMenu) {
keyboardHeight = max(
keyboardHeight,
MediaQuery.of(context).viewInsets.bottom,
);
}
}
return SizedBox(
height: toolbarHeight,
height: keyboardHeight,
child: (showingMenu && selectedMenuIndex != null)
? MobileToolbarItemMenu(
editorState: widget.editorState,
itemMenuBuilder: () =>
widget
.toolbarItems[selectedMenuIndex!].itemMenuBuilder!
.call(
context,
widget.editorState,
this,
) ??
const SizedBox.shrink(),
itemMenuBuilder: () {
final menu = widget
.toolbarItems[selectedMenuIndex!].itemMenuBuilder!
.call(
context,
widget.editorState,
this,
);
return menu ?? const SizedBox.shrink();
},
)
: const SizedBox.shrink(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ class KeyboardHeightObserver {
}

void notify(double height) {
// the keyboard height will notify twice with the same value on Android 14
if (androidSDKVersion == 34) {
if (height == 0 && currentKeyboardHeight == 0) {
return;
}
// the keyboard height will notify twice with the same value on Android
if (Platform.isAndroid && height == currentKeyboardHeight) {
return;
}

for (final listener in _listeners) {
Expand Down

0 comments on commit 7f05000

Please sign in to comment.