From 89bb50eb44c9cdf7f42c15b3afa6819d38541de4 Mon Sep 17 00:00:00 2001 From: appflowy Date: Thu, 11 Nov 2021 10:55:13 +0800 Subject: [PATCH] [flutter]: highlight selected view in expanded app pannel --- .../presentation/home/home_screen.dart | 19 ++++++++--- .../presentation/widgets/menu/menu.dart | 33 ++++++++++++------- .../menu/widget/app/section/section.dart | 14 ++++++-- .../src/services/doc/edit/doc_actor.rs | 2 +- 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/app_flowy/lib/workspace/presentation/home/home_screen.dart b/app_flowy/lib/workspace/presentation/home/home_screen.dart index 7a9a32a409..104f652066 100644 --- a/app_flowy/lib/workspace/presentation/home/home_screen.dart +++ b/app_flowy/lib/workspace/presentation/home/home_screen.dart @@ -6,6 +6,7 @@ import 'package:app_flowy/workspace/presentation/stack_page/home_stack.dart'; import 'package:app_flowy/workspace/presentation/widgets/float_bubble/question_bubble.dart'; import 'package:app_flowy/workspace/presentation/widgets/prelude.dart'; import 'package:app_flowy/startup/startup.dart'; +import 'package:flowy_infra/notifier.dart'; import 'package:flowy_log/flowy_log.dart'; import 'package:flowy_infra_ui/style_widget/container.dart'; import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart'; @@ -87,22 +88,30 @@ class HomeScreen extends StatelessWidget { Widget _buildHomeMenu({required HomeLayout layout, required BuildContext context}) { final homeBloc = context.read(); - final collapasedNotifier = getIt().collapsedNotifier; - HomeMenu homeMenu = - HomeMenu(user: user, workspaceId: workspaceSetting.workspace.id, collapsedNotifier: collapasedNotifier); + final collapasedNotifier = getIt().collapsedNotifier; collapasedNotifier.addPublishListener((isCollapsed) { homeBloc.add(HomeEvent.forceCollapse(isCollapsed)); }); - homeMenu.pageContext.addPublishListener((pageContext) { + final pageContext = PublishNotifier(); + pageContext.addPublishListener((pageContext) { getIt().switchStack(pageContext); }); + HomeStackContext? initialStackContext; if (workspaceSetting.hasLatestView()) { - getIt().switchStack(workspaceSetting.latestView.stackContext()); + initialStackContext = workspaceSetting.latestView.stackContext(); } + HomeMenu homeMenu = HomeMenu( + user: user, + workspaceSetting: workspaceSetting, + collapsedNotifier: collapasedNotifier, + pageContext: pageContext, + initialStackContext: initialStackContext, + ); + return FocusTraversalGroup(child: RepaintBoundary(child: homeMenu)); } diff --git a/app_flowy/lib/workspace/presentation/widgets/menu/menu.dart b/app_flowy/lib/workspace/presentation/widgets/menu/menu.dart index 8c163b9f5f..467d0be4d0 100644 --- a/app_flowy/lib/workspace/presentation/widgets/menu/menu.dart +++ b/app_flowy/lib/workspace/presentation/widgets/menu/menu.dart @@ -5,6 +5,7 @@ import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-workspace-infra/view_create.pb.dart'; +import 'package:flowy_sdk/protobuf/flowy-workspace-infra/workspace_setting.pb.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:provider/provider.dart'; @@ -41,17 +42,25 @@ import 'widget/menu_trash.dart'; // └────────┘ class HomeMenu extends StatelessWidget { - final PublishNotifier pageContext = PublishNotifier(); - final PublishNotifier collapsedNotifier; + final PublishNotifier _pageContext; + final PublishNotifier _collapsedNotifier; final UserProfile user; - final String workspaceId; + final CurrentWorkspaceSetting workspaceSetting; HomeMenu({ Key? key, required this.user, - required this.workspaceId, - required this.collapsedNotifier, - }) : super(key: key); + required this.workspaceSetting, + required PublishNotifier collapsedNotifier, + required PublishNotifier pageContext, + HomeStackContext? initialStackContext, + }) : _pageContext = pageContext, + _collapsedNotifier = collapsedNotifier, + super(key: key) { + if (initialStackContext != null) { + pageContext.value = initialStackContext; + } + } @override Widget build(BuildContext context) { @@ -59,7 +68,7 @@ class HomeMenu extends StatelessWidget { providers: [ BlocProvider( create: (context) { - final menuBloc = getIt(param1: user, param2: workspaceId); + final menuBloc = getIt(param1: user, param2: workspaceSetting.workspace.id); menuBloc.add(const MenuEvent.initial()); return menuBloc; }, @@ -69,11 +78,11 @@ class HomeMenu extends StatelessWidget { listeners: [ BlocListener( listenWhen: (p, c) => p.context != c.context, - listener: (context, state) => pageContext.value = state.context, + listener: (context, state) => _pageContext.value = state.context, ), BlocListener( listenWhen: (p, c) => p.isCollapse != c.isCollapse, - listener: (context, state) => collapsedNotifier.value = state.isCollapse, + listener: (context, state) => _collapsedNotifier.value = state.isCollapse, ) ], child: BlocBuilder( @@ -88,7 +97,7 @@ class HomeMenu extends StatelessWidget { return Container( color: Theme.of(context).colorScheme.background, child: ChangeNotifierProvider( - create: (_) => MenuSharedState(), + create: (_) => MenuSharedState(view: workspaceSetting.hasLatestView() ? workspaceSetting.latestView : null), child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ @@ -162,6 +171,8 @@ class MenuSharedState extends ChangeNotifier { View? _view; View? _forcedOpenView; + MenuSharedState({View? view}) : _view = view; + void addForcedOpenViewListener(void Function(View) callback) { super.addListener(() { if (_forcedOpenView != null) { @@ -192,5 +203,5 @@ class MenuSharedState extends ChangeNotifier { } } - View? get selecedtView => _view; + View? get selectedView => _view; } diff --git a/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/section/section.dart b/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/section/section.dart index 388d7ac913..3c97dc0851 100644 --- a/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/section/section.dart +++ b/app_flowy/lib/workspace/presentation/widgets/menu/widget/app/section/section.dart @@ -21,7 +21,11 @@ class ViewSection extends StatelessWidget { return ChangeNotifierProxyProvider( create: (_) { final views = Provider.of(context, listen: false).views; - return ViewSectionNotifier(views, context); + return ViewSectionNotifier( + context: context, + views: views, + selectedView: Provider.of(context, listen: false).selectedView, + ); }, update: (_, notifier, controller) => controller!..update(notifier), child: Consumer(builder: (context, ViewSectionNotifier notifier, child) { @@ -59,7 +63,13 @@ class ViewSectionNotifier with ChangeNotifier { List _views; View? _selectedView; CancelableOperation? _notifyListenerOperation; - ViewSectionNotifier(List views, BuildContext context) : _views = views { + + ViewSectionNotifier({ + required BuildContext context, + required List views, + View? selectedView, + }) : _views = views, + _selectedView = selectedView { final menuSharedState = Provider.of(context, listen: false); menuSharedState.addForcedOpenViewListener((forcedOpenView) { selectedView = forcedOpenView; diff --git a/rust-lib/flowy-document/src/services/doc/edit/doc_actor.rs b/rust-lib/flowy-document/src/services/doc/edit/doc_actor.rs index 75acb15a8c..1d27123fca 100644 --- a/rust-lib/flowy-document/src/services/doc/edit/doc_actor.rs +++ b/rust-lib/flowy-document/src/services/doc/edit/doc_actor.rs @@ -118,7 +118,7 @@ impl DocumentActor { let mut document = self.document.write().await; let result = document.compose_delta(&delta); tracing::Span::current().record( - "compose_result", + "composed_delta", &format!("doc_id:{} - {}", &self.doc_id, delta.to_json()).as_str(), ); drop(document);