mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
[flutter]: highlight selected view in expanded app pannel
This commit is contained in:
parent
2245ddef1c
commit
89bb50eb44
@ -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/float_bubble/question_bubble.dart';
|
||||||
import 'package:app_flowy/workspace/presentation/widgets/prelude.dart';
|
import 'package:app_flowy/workspace/presentation/widgets/prelude.dart';
|
||||||
import 'package:app_flowy/startup/startup.dart';
|
import 'package:app_flowy/startup/startup.dart';
|
||||||
|
import 'package:flowy_infra/notifier.dart';
|
||||||
import 'package:flowy_log/flowy_log.dart';
|
import 'package:flowy_log/flowy_log.dart';
|
||||||
import 'package:flowy_infra_ui/style_widget/container.dart';
|
import 'package:flowy_infra_ui/style_widget/container.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.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}) {
|
Widget _buildHomeMenu({required HomeLayout layout, required BuildContext context}) {
|
||||||
final homeBloc = context.read<HomeBloc>();
|
final homeBloc = context.read<HomeBloc>();
|
||||||
final collapasedNotifier = getIt<HomeStackManager>().collapsedNotifier;
|
|
||||||
|
|
||||||
HomeMenu homeMenu =
|
final collapasedNotifier = getIt<HomeStackManager>().collapsedNotifier;
|
||||||
HomeMenu(user: user, workspaceId: workspaceSetting.workspace.id, collapsedNotifier: collapasedNotifier);
|
|
||||||
collapasedNotifier.addPublishListener((isCollapsed) {
|
collapasedNotifier.addPublishListener((isCollapsed) {
|
||||||
homeBloc.add(HomeEvent.forceCollapse(isCollapsed));
|
homeBloc.add(HomeEvent.forceCollapse(isCollapsed));
|
||||||
});
|
});
|
||||||
|
|
||||||
homeMenu.pageContext.addPublishListener((pageContext) {
|
final pageContext = PublishNotifier<HomeStackContext>();
|
||||||
|
pageContext.addPublishListener((pageContext) {
|
||||||
getIt<HomeStackManager>().switchStack(pageContext);
|
getIt<HomeStackManager>().switchStack(pageContext);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
HomeStackContext? initialStackContext;
|
||||||
if (workspaceSetting.hasLatestView()) {
|
if (workspaceSetting.hasLatestView()) {
|
||||||
getIt<HomeStackManager>().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));
|
return FocusTraversalGroup(child: RepaintBoundary(child: homeMenu));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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_infra_ui/widget/spacing.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.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/view_create.pb.dart';
|
||||||
|
import 'package:flowy_sdk/protobuf/flowy-workspace-infra/workspace_setting.pb.dart';
|
||||||
import 'package:flutter/material.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';
|
||||||
@ -41,17 +42,25 @@ import 'widget/menu_trash.dart';
|
|||||||
// └────────┘
|
// └────────┘
|
||||||
|
|
||||||
class HomeMenu extends StatelessWidget {
|
class HomeMenu extends StatelessWidget {
|
||||||
final PublishNotifier<HomeStackContext> pageContext = PublishNotifier();
|
final PublishNotifier<HomeStackContext> _pageContext;
|
||||||
final PublishNotifier<bool> collapsedNotifier;
|
final PublishNotifier<bool> _collapsedNotifier;
|
||||||
final UserProfile user;
|
final UserProfile user;
|
||||||
final String workspaceId;
|
final CurrentWorkspaceSetting workspaceSetting;
|
||||||
|
|
||||||
HomeMenu({
|
HomeMenu({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.user,
|
required this.user,
|
||||||
required this.workspaceId,
|
required this.workspaceSetting,
|
||||||
required this.collapsedNotifier,
|
required PublishNotifier<bool> collapsedNotifier,
|
||||||
}) : super(key: key);
|
required PublishNotifier<HomeStackContext> pageContext,
|
||||||
|
HomeStackContext? initialStackContext,
|
||||||
|
}) : _pageContext = pageContext,
|
||||||
|
_collapsedNotifier = collapsedNotifier,
|
||||||
|
super(key: key) {
|
||||||
|
if (initialStackContext != null) {
|
||||||
|
pageContext.value = initialStackContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -59,7 +68,7 @@ class HomeMenu extends StatelessWidget {
|
|||||||
providers: [
|
providers: [
|
||||||
BlocProvider<MenuBloc>(
|
BlocProvider<MenuBloc>(
|
||||||
create: (context) {
|
create: (context) {
|
||||||
final menuBloc = getIt<MenuBloc>(param1: user, param2: workspaceId);
|
final menuBloc = getIt<MenuBloc>(param1: user, param2: workspaceSetting.workspace.id);
|
||||||
menuBloc.add(const MenuEvent.initial());
|
menuBloc.add(const MenuEvent.initial());
|
||||||
return menuBloc;
|
return menuBloc;
|
||||||
},
|
},
|
||||||
@ -69,11 +78,11 @@ class HomeMenu extends StatelessWidget {
|
|||||||
listeners: [
|
listeners: [
|
||||||
BlocListener<MenuBloc, MenuState>(
|
BlocListener<MenuBloc, MenuState>(
|
||||||
listenWhen: (p, c) => p.context != c.context,
|
listenWhen: (p, c) => p.context != c.context,
|
||||||
listener: (context, state) => pageContext.value = state.context,
|
listener: (context, state) => _pageContext.value = state.context,
|
||||||
),
|
),
|
||||||
BlocListener<MenuBloc, MenuState>(
|
BlocListener<MenuBloc, MenuState>(
|
||||||
listenWhen: (p, c) => p.isCollapse != c.isCollapse,
|
listenWhen: (p, c) => p.isCollapse != c.isCollapse,
|
||||||
listener: (context, state) => collapsedNotifier.value = state.isCollapse,
|
listener: (context, state) => _collapsedNotifier.value = state.isCollapse,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
child: BlocBuilder<MenuBloc, MenuState>(
|
child: BlocBuilder<MenuBloc, MenuState>(
|
||||||
@ -88,7 +97,7 @@ class HomeMenu extends StatelessWidget {
|
|||||||
return Container(
|
return Container(
|
||||||
color: Theme.of(context).colorScheme.background,
|
color: Theme.of(context).colorScheme.background,
|
||||||
child: ChangeNotifierProvider(
|
child: ChangeNotifierProvider(
|
||||||
create: (_) => MenuSharedState(),
|
create: (_) => MenuSharedState(view: workspaceSetting.hasLatestView() ? workspaceSetting.latestView : null),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@ -162,6 +171,8 @@ class MenuSharedState extends ChangeNotifier {
|
|||||||
View? _view;
|
View? _view;
|
||||||
View? _forcedOpenView;
|
View? _forcedOpenView;
|
||||||
|
|
||||||
|
MenuSharedState({View? view}) : _view = view;
|
||||||
|
|
||||||
void addForcedOpenViewListener(void Function(View) callback) {
|
void addForcedOpenViewListener(void Function(View) callback) {
|
||||||
super.addListener(() {
|
super.addListener(() {
|
||||||
if (_forcedOpenView != null) {
|
if (_forcedOpenView != null) {
|
||||||
@ -192,5 +203,5 @@ class MenuSharedState extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
View? get selecedtView => _view;
|
View? get selectedView => _view;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,11 @@ class ViewSection extends StatelessWidget {
|
|||||||
return ChangeNotifierProxyProvider<AppDataNotifier, ViewSectionNotifier>(
|
return ChangeNotifierProxyProvider<AppDataNotifier, ViewSectionNotifier>(
|
||||||
create: (_) {
|
create: (_) {
|
||||||
final views = Provider.of<AppDataNotifier>(context, listen: false).views;
|
final views = Provider.of<AppDataNotifier>(context, listen: false).views;
|
||||||
return ViewSectionNotifier(views, context);
|
return ViewSectionNotifier(
|
||||||
|
context: context,
|
||||||
|
views: views,
|
||||||
|
selectedView: Provider.of<MenuSharedState>(context, listen: false).selectedView,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
update: (_, notifier, controller) => controller!..update(notifier),
|
update: (_, notifier, controller) => controller!..update(notifier),
|
||||||
child: Consumer(builder: (context, ViewSectionNotifier notifier, child) {
|
child: Consumer(builder: (context, ViewSectionNotifier notifier, child) {
|
||||||
@ -59,7 +63,13 @@ class ViewSectionNotifier with ChangeNotifier {
|
|||||||
List<View> _views;
|
List<View> _views;
|
||||||
View? _selectedView;
|
View? _selectedView;
|
||||||
CancelableOperation? _notifyListenerOperation;
|
CancelableOperation? _notifyListenerOperation;
|
||||||
ViewSectionNotifier(List<View> views, BuildContext context) : _views = views {
|
|
||||||
|
ViewSectionNotifier({
|
||||||
|
required BuildContext context,
|
||||||
|
required List<View> views,
|
||||||
|
View? selectedView,
|
||||||
|
}) : _views = views,
|
||||||
|
_selectedView = selectedView {
|
||||||
final menuSharedState = Provider.of<MenuSharedState>(context, listen: false);
|
final menuSharedState = Provider.of<MenuSharedState>(context, listen: false);
|
||||||
menuSharedState.addForcedOpenViewListener((forcedOpenView) {
|
menuSharedState.addForcedOpenViewListener((forcedOpenView) {
|
||||||
selectedView = forcedOpenView;
|
selectedView = forcedOpenView;
|
||||||
|
@ -118,7 +118,7 @@ impl DocumentActor {
|
|||||||
let mut document = self.document.write().await;
|
let mut document = self.document.write().await;
|
||||||
let result = document.compose_delta(&delta);
|
let result = document.compose_delta(&delta);
|
||||||
tracing::Span::current().record(
|
tracing::Span::current().record(
|
||||||
"compose_result",
|
"composed_delta",
|
||||||
&format!("doc_id:{} - {}", &self.doc_id, delta.to_json()).as_str(),
|
&format!("doc_id:{} - {}", &self.doc_id, delta.to_json()).as_str(),
|
||||||
);
|
);
|
||||||
drop(document);
|
drop(document);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user