fix: hide menu resize when collapsed (#5076)

This commit is contained in:
Mathias Mogensen 2024-04-09 13:27:23 +02:00 committed by GitHub
parent 2126e6e449
commit 72049d28d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 75 additions and 95 deletions

View File

@ -6,9 +6,10 @@ import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_result/appflowy_result.dart'; import 'package:appflowy_result/appflowy_result.dart';
class HomeService { class HomeService {
Future<FlowyResult<ViewPB, FlowyError>> readApp({required String appId}) { static Future<FlowyResult<ViewPB, FlowyError>> readApp({
required String appId,
}) {
final payload = ViewIdPB.create()..value = appId; final payload = ViewIdPB.create()..value = appId;
return FolderEventGetView(payload).send(); return FolderEventGetView(payload).send();
} }
} }

View File

@ -76,13 +76,11 @@ class DesktopHomeScreen extends StatelessWidget {
HomeBloc(workspaceSetting)..add(const HomeEvent.initial()), HomeBloc(workspaceSetting)..add(const HomeEvent.initial()),
), ),
BlocProvider<HomeSettingBloc>( BlocProvider<HomeSettingBloc>(
create: (_) { create: (_) => HomeSettingBloc(
return HomeSettingBloc( workspaceSetting,
workspaceSetting, context.read<AppearanceSettingsCubit>(),
context.read<AppearanceSettingsCubit>(), context.widthPx,
context.widthPx, )..add(const HomeSettingEvent.initial()),
)..add(const HomeSettingEvent.initial());
},
), ),
BlocProvider<FavoriteBloc>( BlocProvider<FavoriteBloc>(
create: (context) => create: (context) =>
@ -91,44 +89,38 @@ class DesktopHomeScreen extends StatelessWidget {
], ],
child: HomeHotKeys( child: HomeHotKeys(
child: Scaffold( child: Scaffold(
body: MultiBlocListener(
listeners: [
BlocListener<HomeBloc, HomeState>(
listenWhen: (p, c) => p.latestView != c.latestView,
listener: (context, state) {
final view = state.latestView;
if (view != null) {
// Only open the last opened view if the [TabsState.currentPageManager] current opened plugin is blank and the last opened view is not null.
// All opened widgets that display on the home screen are in the form of plugins. There is a list of built-in plugins defined in the [PluginType] enum, including board, grid and trash.
final currentPageManager =
context.read<TabsBloc>().state.currentPageManager;
if (currentPageManager.plugin.pluginType ==
PluginType.blank) {
getIt<TabsBloc>().add(
TabsEvent.openPlugin(plugin: view.plugin()),
);
}
}
},
),
],
child: BlocBuilder<HomeSettingBloc, HomeSettingState>(
buildWhen: (previous, current) => previous != current,
builder: (context, state) {
return FlowyContainer(
Theme.of(context).colorScheme.surface,
child: _buildBody(context, userProfile, workspaceSetting),
);
},
),
),
floatingActionButton: enableMemoryLeakDetect floatingActionButton: enableMemoryLeakDetect
? FloatingActionButton( ? const FloatingActionButton(
onPressed: () async => dumpMemoryLeak(), onPressed: dumpMemoryLeak,
child: const Icon(Icons.memory), child: Icon(Icons.memory),
) )
: null, : null,
body: BlocListener<HomeBloc, HomeState>(
listenWhen: (p, c) => p.latestView != c.latestView,
listener: (context, state) {
final view = state.latestView;
if (view != null) {
// Only open the last opened view if the [TabsState.currentPageManager] current opened plugin is blank and the last opened view is not null.
// All opened widgets that display on the home screen are in the form of plugins. There is a list of built-in plugins defined in the [PluginType] enum, including board, grid and trash.
final currentPageManager =
context.read<TabsBloc>().state.currentPageManager;
if (currentPageManager.plugin.pluginType ==
PluginType.blank) {
getIt<TabsBloc>().add(
TabsEvent.openPlugin(plugin: view.plugin()),
);
}
}
},
child: BlocBuilder<HomeSettingBloc, HomeSettingState>(
buildWhen: (previous, current) => previous != current,
builder: (context, state) => FlowyContainer(
Theme.of(context).colorScheme.surface,
child: _buildBody(context, userProfile, workspaceSetting),
),
),
),
), ),
), ),
); );
@ -147,35 +139,30 @@ class DesktopHomeScreen extends StatelessWidget {
final layout = HomeLayout(context); final layout = HomeLayout(context);
final homeStack = HomeStack( final homeStack = HomeStack(
layout: layout, layout: layout,
delegate: DesktopHomeScreenStackAdaptor( delegate: DesktopHomeScreenStackAdaptor(context),
buildContext: context,
),
); );
final menu = _buildHomeSidebar( final menu = _buildHomeSidebar(
context,
layout: layout, layout: layout,
context: context,
userProfile: userProfile, userProfile: userProfile,
workspaceSetting: workspaceSetting, workspaceSetting: workspaceSetting,
); );
final homeMenuResizer = _buildHomeMenuResizer(context: context); final homeMenuResizer = _buildHomeMenuResizer(context, layout: layout);
final editPanel = _buildEditPanel( final editPanel = _buildEditPanel(context, layout: layout);
layout: layout,
context: context,
);
const bubble = QuestionBubble();
return _layoutWidgets( return _layoutWidgets(
layout: layout, layout: layout,
homeStack: homeStack, homeStack: homeStack,
homeMenu: menu, homeMenu: menu,
editPanel: editPanel, editPanel: editPanel,
bubble: bubble, bubble: const QuestionBubble(),
homeMenuResizer: homeMenuResizer, homeMenuResizer: homeMenuResizer,
); );
} }
Widget _buildHomeSidebar({ Widget _buildHomeSidebar(
BuildContext context, {
required HomeLayout layout, required HomeLayout layout,
required BuildContext context,
required UserProfilePB userProfile, required UserProfilePB userProfile,
required WorkspaceSettingPB workspaceSetting, required WorkspaceSettingPB workspaceSetting,
}) { }) {
@ -186,8 +173,8 @@ class DesktopHomeScreen extends StatelessWidget {
return FocusTraversalGroup(child: RepaintBoundary(child: homeMenu)); return FocusTraversalGroup(child: RepaintBoundary(child: homeMenu));
} }
Widget _buildEditPanel({ Widget _buildEditPanel(
required BuildContext context, BuildContext context, {
required HomeLayout layout, required HomeLayout layout,
}) { }) {
final homeBloc = context.read<HomeSettingBloc>(); final homeBloc = context.read<HomeSettingBloc>();
@ -199,12 +186,14 @@ class DesktopHomeScreen extends StatelessWidget {
if (panelContext == null) { if (panelContext == null) {
return const SizedBox.shrink(); return const SizedBox.shrink();
} }
return FocusTraversalGroup( return FocusTraversalGroup(
child: RepaintBoundary( child: RepaintBoundary(
child: EditPanel( child: EditPanel(
panelContext: panelContext, panelContext: panelContext,
onEndEdit: () => onEndEdit: () => homeBloc.add(
homeBloc.add(const HomeSettingEvent.dismissEditPanel()), const HomeSettingEvent.dismissEditPanel(),
),
), ),
), ),
); );
@ -212,9 +201,14 @@ class DesktopHomeScreen extends StatelessWidget {
); );
} }
Widget _buildHomeMenuResizer({ Widget _buildHomeMenuResizer(
required BuildContext context, BuildContext context, {
required HomeLayout layout,
}) { }) {
if (!layout.showMenu) {
return const SizedBox.shrink();
}
return MouseRegion( return MouseRegion(
cursor: SystemMouseCursors.resizeLeftRight, cursor: SystemMouseCursors.resizeLeftRight,
child: GestureDetector( child: GestureDetector(
@ -261,11 +255,7 @@ class DesktopHomeScreen extends StatelessWidget {
) )
.animate(layout.animDuration, Curves.easeOutQuad), .animate(layout.animDuration, Curves.easeOutQuad),
bubble bubble
.positioned( .positioned(right: 20, bottom: 16, animate: true)
right: 20,
bottom: 16,
animate: true,
)
.animate(layout.animDuration, Curves.easeOut), .animate(layout.animDuration, Curves.easeOut),
editPanel editPanel
.animatedPanelX( .animatedPanelX(
@ -275,8 +265,8 @@ class DesktopHomeScreen extends StatelessWidget {
curve: Curves.easeOutQuad, curve: Curves.easeOutQuad,
) )
.positioned( .positioned(
right: 0,
top: 0, top: 0,
right: 0,
bottom: 0, bottom: 0,
width: layout.editPanelWidth, width: layout.editPanelWidth,
), ),
@ -287,12 +277,7 @@ class DesktopHomeScreen extends StatelessWidget {
curve: Curves.easeOutQuad, curve: Curves.easeOutQuad,
duration: layout.animDuration.inMilliseconds * 0.001, duration: layout.animDuration.inMilliseconds * 0.001,
) )
.positioned( .positioned(left: 0, top: 0, width: layout.menuWidth, bottom: 0),
left: 0,
top: 0,
width: layout.menuWidth,
bottom: 0,
),
homeMenuResizer homeMenuResizer
.positioned(left: layout.menuWidth - 5) .positioned(left: layout.menuWidth - 5)
.animate(layout.animDuration, Curves.easeOutQuad), .animate(layout.animDuration, Curves.easeOutQuad),
@ -302,14 +287,13 @@ class DesktopHomeScreen extends StatelessWidget {
} }
class DesktopHomeScreenStackAdaptor extends HomeStackDelegate { class DesktopHomeScreenStackAdaptor extends HomeStackDelegate {
DesktopHomeScreenStackAdaptor({required this.buildContext}); DesktopHomeScreenStackAdaptor(this.buildContext);
final BuildContext buildContext; final BuildContext buildContext;
@override @override
void didDeleteStackWidget(ViewPB view, int? index) { void didDeleteStackWidget(ViewPB view, int? index) {
final homeService = HomeService(); HomeService.readApp(appId: view.parentViewId).then((result) {
homeService.readApp(appId: view.parentViewId).then((result) {
result.fold( result.fold(
(parentView) { (parentView) {
final List<ViewPB> views = parentView.childViews; final List<ViewPB> views = parentView.childViews;
@ -319,16 +303,12 @@ class DesktopHomeScreenStackAdaptor extends HomeStackDelegate {
lastView = views[index - 1]; lastView = views[index - 1];
} }
getIt<TabsBloc>().add( return getIt<TabsBloc>()
TabsEvent.openPlugin(plugin: lastView.plugin()), .add(TabsEvent.openPlugin(plugin: lastView.plugin()));
);
} else {
getIt<TabsBloc>().add(
TabsEvent.openPlugin(
plugin: BlankPagePlugin(),
),
);
} }
getIt<TabsBloc>()
.add(TabsEvent.openPlugin(plugin: BlankPagePlugin()));
}, },
(err) => Log.error(err), (err) => Log.error(err),
); );

View File

@ -1,5 +1,7 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart'; import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/home/home_setting_bloc.dart'; import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
@ -9,7 +11,6 @@ import 'package:flowy_infra/size.dart';
import 'package:flowy_infra_ui/style_widget/icon_button.dart'; import 'package:flowy_infra_ui/style_widget/icon_button.dart';
import 'package:flowy_infra_ui/style_widget/text.dart'; import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart'; import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:styled_widget/styled_widget.dart'; import 'package:styled_widget/styled_widget.dart';
@ -75,11 +76,9 @@ class FlowyNavigation extends StatelessWidget {
child: FlowyIconButton( child: FlowyIconButton(
width: 24, width: 24,
hoverColor: Colors.transparent, hoverColor: Colors.transparent,
onPressed: () { onPressed: () => context
context .read<HomeSettingBloc>()
.read<HomeSettingBloc>() .add(const HomeSettingEvent.collapseMenu()),
.add(const HomeSettingEvent.collapseMenu());
},
iconPadding: const EdgeInsets.fromLTRB(2, 2, 2, 2), iconPadding: const EdgeInsets.fromLTRB(2, 2, 2, 2),
icon: FlowySvg( icon: FlowySvg(
FlowySvgs.hide_menu_m, FlowySvgs.hide_menu_m,
@ -88,9 +87,9 @@ class FlowyNavigation extends StatelessWidget {
), ),
), ),
); );
} else {
return const SizedBox.shrink();
} }
return const SizedBox.shrink();
}, },
); );
} }