From 122f02ad3c6eb59f69abf5507dc4b136fad5d9a8 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Sat, 1 Jun 2024 14:23:06 +0800 Subject: [PATCH 1/3] chore: replace home icon --- frontend/resources/flowy_icons/24x/m_home_unselected.svg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/resources/flowy_icons/24x/m_home_unselected.svg b/frontend/resources/flowy_icons/24x/m_home_unselected.svg index 7c34f3371f34..495c73923c43 100644 --- a/frontend/resources/flowy_icons/24x/m_home_unselected.svg +++ b/frontend/resources/flowy_icons/24x/m_home_unselected.svg @@ -1,6 +1,6 @@ - - - - + + + + From 217c58df7c5497cb4585e60656c8d8f9a4bd4bdb Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Sat, 1 Jun 2024 14:31:02 +0800 Subject: [PATCH 2/3] feat: implement add new page button --- .../mobile_bottom_navigation_bar.dart | 49 +++++++++++++++++++ .../page_item/mobile_view_item.dart | 8 ++- .../workspace/workspace_service.dart | 4 +- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/mobile_bottom_navigation_bar.dart b/frontend/appflowy_flutter/lib/mobile/presentation/mobile_bottom_navigation_bar.dart index 3115428eb526..007faa6db5f8 100644 --- a/frontend/appflowy_flutter/lib/mobile/presentation/mobile_bottom_navigation_bar.dart +++ b/frontend/appflowy_flutter/lib/mobile/presentation/mobile_bottom_navigation_bar.dart @@ -1,4 +1,12 @@ import 'package:appflowy/generated/flowy_svgs.g.dart'; +import 'package:appflowy/generated/locale_keys.g.dart'; +import 'package:appflowy/mobile/application/mobile_router.dart'; +import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart'; +import 'package:appflowy/workspace/application/workspace/workspace_service.dart'; +import 'package:appflowy_backend/dispatch/dispatch.dart'; +import 'package:appflowy_backend/log.dart'; +import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart'; +import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; @@ -61,6 +69,11 @@ class MobileBottomNavigationBar extends StatelessWidget { /// Navigate to the current location of the branch at the provided index when /// tapping an item in the BottomNavigationBar. void _onTap(BuildContext context, int bottomBarIndex) { + if (bottomBarIndex == 1) { + // show an add dialog + _showCreatePageBottomSheet(context); + return; + } // When navigating to a new branch, it's recommended to use the goBranch // method, as doing so makes sure the last navigation state of the // Navigator for the branch is restored. @@ -73,4 +86,40 @@ class MobileBottomNavigationBar extends StatelessWidget { initialLocation: bottomBarIndex == navigationShell.currentIndex, ); } + + void _showCreatePageBottomSheet(BuildContext context) { + showMobileBottomSheet( + context, + showHeader: true, + title: LocaleKeys.sideBar_addAPage.tr(), + showDragHandle: true, + showCloseButton: true, + useRootNavigator: true, + builder: (sheetContext) { + return AddNewPageWidgetBottomSheet( + view: ViewPB(), + onAction: (layout) async { + Navigator.of(sheetContext).pop(); + final currentWorkspaceId = + await FolderEventReadCurrentWorkspace().send(); + await currentWorkspaceId.fold((s) async { + final workspaceService = WorkspaceService(workspaceId: s.id); + final result = await workspaceService.createView( + name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(), + viewSection: ViewSectionPB.Private, + layout: layout, + ); + result.fold((s) { + context.pushView(s); + }, (e) { + Log.error('Failed to create new page: $e'); + }); + }, (e) { + Log.error('Failed to read current workspace: $e'); + }); + }, + ); + }, + ); + } } diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/page_item/mobile_view_item.dart b/frontend/appflowy_flutter/lib/mobile/presentation/page_item/mobile_view_item.dart index 7bd7a5015786..e21ff3be20c0 100644 --- a/frontend/appflowy_flutter/lib/mobile/presentation/page_item/mobile_view_item.dart +++ b/frontend/appflowy_flutter/lib/mobile/presentation/page_item/mobile_view_item.dart @@ -334,11 +334,9 @@ class _SingleMobileInnerViewItemState extends State { child: Padding( padding: const EdgeInsets.only(right: 6.0, top: 6.0, bottom: 6.0), child: FlowySvg( - widget.isExpanded - ? FlowySvgs.m_expand_s - : FlowySvgs.m_collapse_s, - blendMode: null, - ), + widget.isExpanded ? FlowySvgs.m_expand_s : FlowySvgs.m_collapse_s, + blendMode: null, + ), ), onTap: () { context diff --git a/frontend/appflowy_flutter/lib/workspace/application/workspace/workspace_service.dart b/frontend/appflowy_flutter/lib/workspace/application/workspace/workspace_service.dart index 6e42b744f65c..37ff786fab56 100644 --- a/frontend/appflowy_flutter/lib/workspace/application/workspace/workspace_service.dart +++ b/frontend/appflowy_flutter/lib/workspace/application/workspace/workspace_service.dart @@ -15,12 +15,12 @@ class WorkspaceService { required ViewSectionPB viewSection, String? desc, int? index, + ViewLayoutPB? layout, }) { final payload = CreateViewPayloadPB.create() ..parentViewId = workspaceId ..name = name - // only allow document layout for the top-level views - ..layout = ViewLayoutPB.Document + ..layout = layout ?? ViewLayoutPB.Document ..section = viewSection; if (desc != null) { From 8879e1b99587ec01121191da8c5f1da537e43b19 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Sat, 1 Jun 2024 14:47:12 +0800 Subject: [PATCH 3/3] chore: refactor navigation bottom items --- .../mobile_bottom_navigation_bar.dart | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/mobile_bottom_navigation_bar.dart b/frontend/appflowy_flutter/lib/mobile/presentation/mobile_bottom_navigation_bar.dart index 007faa6db5f8..411623cb8747 100644 --- a/frontend/appflowy_flutter/lib/mobile/presentation/mobile_bottom_navigation_bar.dart +++ b/frontend/appflowy_flutter/lib/mobile/presentation/mobile_bottom_navigation_bar.dart @@ -10,6 +10,28 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; +const _homeLabel = 'home'; +const _addLabel = 'add'; +const _notificationLabel = 'notification'; +final _items = [ + const BottomNavigationBarItem( + label: _homeLabel, + icon: FlowySvg(FlowySvgs.m_home_unselected_m), + activeIcon: FlowySvg(FlowySvgs.m_home_selected_m, blendMode: null), + ), + const BottomNavigationBarItem( + label: _addLabel, + icon: FlowySvg(FlowySvgs.m_home_add_m), + ), + const BottomNavigationBarItem( + label: _notificationLabel, + icon: FlowySvg(FlowySvgs.m_home_notification_m), + activeIcon: FlowySvg( + FlowySvgs.m_home_notification_m, + ), + ), +]; + /// Builds the "shell" for the app by building a Scaffold with a /// BottomNavigationBar, where [child] is placed in the body of the Scaffold. class MobileBottomNavigationBar extends StatelessWidget { @@ -24,8 +46,6 @@ class MobileBottomNavigationBar extends StatelessWidget { @override Widget build(BuildContext context) { - final style = Theme.of(context); - return Scaffold( body: navigationShell, bottomNavigationBar: Theme( @@ -39,26 +59,7 @@ class MobileBottomNavigationBar extends StatelessWidget { enableFeedback: false, type: BottomNavigationBarType.fixed, elevation: 0, - items: [ - const BottomNavigationBarItem( - label: 'home', - icon: FlowySvg(FlowySvgs.m_home_unselected_m), - activeIcon: - FlowySvg(FlowySvgs.m_home_selected_m, blendMode: null), - ), - const BottomNavigationBarItem( - label: 'add', - icon: FlowySvg(FlowySvgs.m_home_add_m), - ), - BottomNavigationBarItem( - label: 'notification', - icon: const FlowySvg(FlowySvgs.m_home_notification_m), - activeIcon: FlowySvg( - FlowySvgs.m_home_notification_m, - color: style.colorScheme.primary, - ), - ), - ], + items: _items, currentIndex: navigationShell.currentIndex, onTap: (int bottomBarIndex) => _onTap(context, bottomBarIndex), ), @@ -69,7 +70,7 @@ class MobileBottomNavigationBar extends StatelessWidget { /// Navigate to the current location of the branch at the provided index when /// tapping an item in the BottomNavigationBar. void _onTap(BuildContext context, int bottomBarIndex) { - if (bottomBarIndex == 1) { + if (_items[bottomBarIndex].label == _addLabel) { // show an add dialog _showCreatePageBottomSheet(context); return;