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 3115428eb5..411623cb87 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,7 +1,37 @@ 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'; +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 { @@ -16,8 +46,6 @@ class MobileBottomNavigationBar extends StatelessWidget { @override Widget build(BuildContext context) { - final style = Theme.of(context); - return Scaffold( body: navigationShell, bottomNavigationBar: Theme( @@ -31,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), ), @@ -61,6 +70,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 (_items[bottomBarIndex].label == _addLabel) { + // 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 +87,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 7bd7a50157..e21ff3be20 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 6e42b744f6..37ff786fab 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) { diff --git a/frontend/resources/flowy_icons/24x/m_home_unselected.svg b/frontend/resources/flowy_icons/24x/m_home_unselected.svg index 7c34f3371f..495c73923c 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 @@ - - - - + + + +