From 057e6fe171acab4cfdff37f35763984e8a39eb1c Mon Sep 17 00:00:00 2001 From: squidrye Date: Wed, 15 Nov 2023 13:24:11 +0530 Subject: [PATCH] fix: board popover rebuilds --- .../presentation/home/home_stack.dart | 5 ++++ .../home/menu/view/view_item.dart | 1 - .../home/panes/draggable_pane_item.dart | 8 +++--- .../presentation/home/panes/flowy_pane.dart | 10 -------- .../home/panes/flowy_pane_group.dart | 25 +++++++++++++++---- .../presentation/widgets/view_title_bar.dart | 6 +++-- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart index a0b75e6a248e..2ae5e467d891 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/home_stack.dart @@ -47,6 +47,11 @@ class HomeStack extends StatelessWidget { @override Widget build(BuildContext context) { return BlocBuilder( + buildWhen: (previous, current) => + previous.count != current.count || + previous.root != current.root || + previous.allowPaneDrag != current.allowPaneDrag || + previous.firstLeafNode != current.firstLeafNode, builder: (context, state) { return BlocBuilder( builder: (context, homeState) { diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_item.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_item.dart index 7fc28247f27b..4a46affd7c34 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_item.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_item.dart @@ -5,7 +5,6 @@ import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart'; import 'package:appflowy/workspace/application/panes/panes_bloc/panes_bloc.dart'; import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart'; -import 'package:appflowy/workspace/application/view/view_bloc.dart'; import 'package:appflowy/workspace/application/view/prelude.dart'; import 'package:appflowy/workspace/application/view/view_ext.dart'; import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart'; diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/panes/draggable_pane_item.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/panes/draggable_pane_item.dart index 01b9e0e1bcfc..929c3f043bff 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/home/panes/draggable_pane_item.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/panes/draggable_pane_item.dart @@ -36,11 +36,9 @@ class _DraggablePaneItemState extends State { data: widget.pane, enableAutoScroll: false, feedback: Material( - child: IntrinsicWidth( - child: Opacity( - opacity: 0.5, - child: widget.feedback?.call(context) ?? widget.child, - ), + child: Opacity( + opacity: 0.5, + child: widget.feedback?.call(context) ?? widget.child, ), ), child: widget.child, diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/panes/flowy_pane.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/panes/flowy_pane.dart index 40e3535202f4..fcb6a8dd5180 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/home/panes/flowy_pane.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/panes/flowy_pane.dart @@ -1,6 +1,4 @@ -import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/workspace/application/panes/panes.dart'; -import 'package:appflowy/workspace/application/panes/panes_bloc/panes_bloc.dart'; import 'package:appflowy/workspace/application/tabs/tabs_controller.dart'; import 'package:appflowy/workspace/presentation/home/home_draggables.dart'; import 'package:appflowy/workspace/presentation/home/home_layout.dart'; @@ -178,14 +176,6 @@ class _FlowyPaneState extends State { pageController.dispose(); super.dispose(); } - - @override - void didChangeDependencies() { - if (widget.node != getIt().state.activePane) { - FocusScope.of(widget.paneContext).unfocus(); - } - super.didChangeDependencies(); - } } class _StickyHeaderDelegate extends SliverPersistentHeaderDelegate { diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/panes/flowy_pane_group.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/panes/flowy_pane_group.dart index fb5a484d0b31..fce508e7de54 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/home/panes/flowy_pane_group.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/panes/flowy_pane_group.dart @@ -7,6 +7,7 @@ import 'package:appflowy/workspace/presentation/home/home_stack.dart'; import 'package:appflowy/workspace/presentation/home/panes/panes_layout.dart'; import 'package:flowy_infra_ui/style_widget/extension.dart'; import 'package:flowy_infra_ui/style_widget/hover.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -31,12 +32,21 @@ class FlowyPaneGroup extends StatelessWidget { @override Widget build(BuildContext context) { if (node.children.isEmpty) { - return Listener( + final activePaneGestureRecognizerFactory = + GestureRecognizerFactoryWithHandlers( + () => AllowMultipleTap(), + (AllowMultipleTap instance) { + instance.onTap = () => + context.read().add(SetActivePane(activePane: node)); + }, + ); + return RawGestureDetector( behavior: HitTestBehavior.translucent, - onPointerDown: (_) => - context.read().add(SetActivePane(activePane: node)), + gestures: { + AllowMultipleTap: activePaneGestureRecognizerFactory, + }, child: FlowyPane( - key: ValueKey(node.tabsController.tabId), + key: ValueKey(node.paneId + node.tabsController.tabId), node: node, allowPaneDrag: allowPaneDrag, delegate: delegate, @@ -48,7 +58,7 @@ class FlowyPaneGroup extends StatelessWidget { } return BlocProvider( - key: ValueKey(node.paneId), + key: ValueKey(node.paneId + node.tabsController.tabId), create: (context) => PaneNodeCubit( node.children.length, node.axis == Axis.horizontal @@ -159,3 +169,8 @@ class FlowyPaneGroup extends StatelessWidget { ); } } + +class AllowMultipleTap extends TapGestureRecognizer { + @override + void rejectGesture(int pointer) => acceptGesture(pointer); +} diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart index 7d07f490f892..9fb8dc47d3ae 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart @@ -1,6 +1,6 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/base/emoji_picker_button.dart'; import 'package:appflowy/startup/tasks/app_window_size_manager.dart'; -import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart'; +import 'package:appflowy/workspace/application/panes/panes_bloc/panes_bloc.dart'; import 'package:appflowy/workspace/application/view/view_ext.dart'; import 'package:appflowy/workspace/application/view/view_listener.dart'; import 'package:appflowy/workspace/application/view/view_service.dart'; @@ -210,7 +210,9 @@ class _ViewTitleState extends State<_ViewTitle> { return FlowyButton( useIntrinsicWidth: true, onTap: () { - context.read().openPlugin(widget.view); + context + .read() + .add(OpenPluginInActivePane(plugin: widget.view.plugin())); }, text: child, );