Skip to content

Commit

Permalink
feat:add toast in trash and confirm dialog + fix issues from launch r…
Browse files Browse the repository at this point in the history
…eview (AppFlowy-IO#3787)

* chore: improve trash button

* feat: improve restore all&delete all

* refactor: add showFlowyMobileConfirmDialog

* feat: add toast in delete/restore single file

* refactor: refactor to TrashActionType enum

* fix: text invisible in signin page in dark mode

* feat: add FlowyMobileErrorStateContainer to display error state

* refactor: add FlowyMobileStateContainer to handle empty or error state

- Replace MobileErrorPage by FlowyMobileStateContainer.error
- Implement app version in reporting issue on github
- Implement FlowyMobileStateContainer in trash,setting,favorite and mobile view page

* refactor: unify bottom sheet style

- Unify bottom sheet style in add new page, page action, and trash action
- Add icon color in BottomSheetActionWidget for future use
- Add theme color in MobileBottomSheetDragHandle

* chore: unify Appbar style

* chore: remove the more button when trash list is empty

* fix: show bottom sheet error

* fix: fix merge and ui issue

* refactor: refactor ViewPageBottomSheet and origanize code

* chore: add icon color for favorite button

* fix: add missing icon color and delete comments

---------

Co-authored-by: Lucas.Xu <[email protected]>
  • Loading branch information
hyj1204 and LucasXu0 authored Nov 2, 2023
1 parent a93d325 commit 73ea1a0
Show file tree
Hide file tree
Showing 25 changed files with 592 additions and 572 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ ThemeData getMobileThemeData(
appBarTheme: AppBarTheme(
foregroundColor: mobileColorTheme.onBackground,
backgroundColor: mobileColorTheme.background,
elevation: 80,
centerTitle: false,
titleTextStyle: TextStyle(
color: mobileColorTheme.onBackground,
Expand Down Expand Up @@ -116,7 +115,7 @@ ThemeData getMobileThemeData(
foregroundColor: MaterialStateProperty.all(
mobileColorTheme.onBackground,
),
backgroundColor: MaterialStateProperty.all(Colors.white),
backgroundColor: MaterialStateProperty.all(mobileColorTheme.background),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
Expand All @@ -129,7 +128,7 @@ ThemeData getMobileThemeData(
),
),
padding: MaterialStateProperty.all(
const EdgeInsets.symmetric(horizontal: 16),
const EdgeInsets.symmetric(horizontal: 8, vertical: 12),
),
// splash color
overlayColor: MaterialStateProperty.all(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/widgets/flowy_mobile_state_container.dart';
import 'package:appflowy/mobile/presentation/base/app_bar_actions.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_view_page.dart';
import 'package:appflowy/mobile/presentation/error/error_page.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
Expand Down Expand Up @@ -56,17 +55,23 @@ class _MobileViewPageState extends State<MobileViewPage> {
child: CircularProgressIndicator(),
);
} else if (!state.hasData) {
body = MobileErrorPage(
message: LocaleKeys.error_loadingViewError.tr(),
body = FlowyMobileStateContainer.error(
emoji: '😔',
title: LocaleKeys.error_weAreSorry.tr(),
description: LocaleKeys.error_loadingViewError.tr(),
errorMsg: state.error.toString(),
);
} else {
body = state.data!.fold((view) {
viewPB = view;
actions.add(_buildAppBarMoreButton(view));
return view.plugin().widgetBuilder.buildWidget(shrinkWrap: false);
}, (error) {
return MobileErrorPage(
message: error.toString(),
return FlowyMobileStateContainer.error(
emoji: '😔',
title: LocaleKeys.error_weAreSorry.tr(),
description: LocaleKeys.error_loadingViewError.tr(),
errorMsg: error.toString(),
);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,146 +1,9 @@
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_drag_handler.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_rename_widget.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_view_item_body.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_view_item_header.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart' hide WidgetBuilder;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';

Future<void> showMobileBottomSheet({
required BuildContext context,
required WidgetBuilder builder,
}) async {
showModalBottomSheet(
context: context,
isScrollControlled: true,
enableDrag: true,
useSafeArea: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8.0),
topRight: Radius.circular(8.0),
),
),
builder: builder,
);
}

enum MobileBottomSheetType {
view,
rename,
}

class MobileViewItemBottomSheet extends StatefulWidget {
const MobileViewItemBottomSheet({
super.key,
required this.view,
this.defaultType = MobileBottomSheetType.view,
});

final ViewPB view;
final MobileBottomSheetType defaultType;

@override
State<MobileViewItemBottomSheet> createState() =>
_MobileViewItemBottomSheetState();
}

class _MobileViewItemBottomSheetState extends State<MobileViewItemBottomSheet> {
MobileBottomSheetType type = MobileBottomSheetType.view;

@override
initState() {
super.initState();

type = widget.defaultType;
}

@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
// drag handler
const MobileBottomSheetDragHandler(),

// header
_buildHeader(),
const VSpace(8.0),
const Divider(),

// body
_buildBody(),
const VSpace(12.0),
],
);
}

Widget _buildHeader() {
switch (type) {
case MobileBottomSheetType.view:
case MobileBottomSheetType.rename:
// header
return MobileViewItemBottomSheetHeader(
showBackButton: type != MobileBottomSheetType.view,
view: widget.view,
onBack: () {
setState(() {
type = MobileBottomSheetType.view;
});
},
);
}
}

Widget _buildBody() {
switch (type) {
case MobileBottomSheetType.view:
return MobileViewItemBottomSheetBody(
isFavorite: widget.view.isFavorite,
onAction: (action) {
switch (action) {
case MobileViewItemBottomSheetBodyAction.rename:
setState(() {
type = MobileBottomSheetType.rename;
});
break;
case MobileViewItemBottomSheetBodyAction.duplicate:
context.pop();
context.read<ViewBloc>().add(const ViewEvent.duplicate());
break;
case MobileViewItemBottomSheetBodyAction.share:
// unimplemented
context.pop();
break;
case MobileViewItemBottomSheetBodyAction.delete:
context.pop();
context.read<ViewBloc>().add(const ViewEvent.delete());

break;
case MobileViewItemBottomSheetBodyAction.addToFavorites:
case MobileViewItemBottomSheetBodyAction.removeFromFavorites:
context.pop();
context
.read<FavoriteBloc>()
.add(FavoriteEvent.toggle(widget.view));
break;
}
},
);
case MobileBottomSheetType.rename:
return MobileBottomSheetRenameWidget(
name: widget.view.name,
onRename: (name) {
if (name != widget.view.name) {
context.read<ViewBloc>().add(ViewEvent.rename(name));
}
context.pop();
},
);
}
}
}
export 'bottom_sheet_action_widget.dart';
export 'bottom_sheet_add_new_page.dart';
export 'bottom_sheet_drag_handler.dart';
export 'bottom_sheet_rename_widget.dart';
export 'bottom_sheet_view_item_body.dart';
export 'bottom_sheet_view_item_header.dart';
export 'bottom_sheet_view_page.dart';
export 'default_mobile_action_pane.dart';
export 'show_mobile_bottom_sheet.dart';
Original file line number Diff line number Diff line change
@@ -1,51 +1,37 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/mobile/presentation/base/box_container.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class BottomSheetActionWidget extends StatelessWidget {
const BottomSheetActionWidget({
super.key,
required this.svg,
required this.text,
required this.onTap,
this.iconColor,
});

final FlowySvgData svg;
final String text;
final VoidCallback onTap;
final Color? iconColor;

@override
Widget build(BuildContext context) {
return FlowyBoxContainer(
child: InkWell(
onTap: () {
HapticFeedback.mediumImpact();
onTap();
},
enableFeedback: true,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 10.0,
horizontal: 12.0,
),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
FlowySvg(
svg,
size: const Size.square(24.0),
blendMode: BlendMode.dst,
),
const HSpace(6.0),
FlowyText(text),
const Spacer(),
],
),
),
final iconColor =
this.iconColor ?? Theme.of(context).colorScheme.onBackground;

return OutlinedButton.icon(
icon: FlowySvg(
svg,
size: const Size.square(22.0),
color: iconColor,
),
label: Text(text),
style: Theme.of(context)
.outlinedButtonTheme
.style
?.copyWith(alignment: Alignment.centerLeft),
onPressed: onTap,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_action_widget.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_drag_handler.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_view_item_header.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
Expand All @@ -21,46 +19,9 @@ class AddNewPageWidgetBottomSheet extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
// drag handler
const MobileBottomSheetDragHandler(),

// header
MobileViewItemBottomSheetHeader(
showBackButton: false,
view: view,
onBack: () {},
),
const VSpace(8.0),
const Divider(),

// body
_AddNewPageBody(
onAction: onAction,
),
const VSpace(24.0),
],
);
}
}

class _AddNewPageBody extends StatelessWidget {
const _AddNewPageBody({
required this.onAction,
});

final void Function(ViewLayoutPB layout) onAction;

@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// rename, duplicate
// new document, new grid
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: BottomSheetActionWidget(
Expand All @@ -69,6 +30,7 @@ class _AddNewPageBody extends StatelessWidget {
onTap: () => onAction(ViewLayoutPB.Document),
),
),
const HSpace(8),
Expanded(
child: BottomSheetActionWidget(
svg: FlowySvgs.grid_s,
Expand All @@ -78,10 +40,10 @@ class _AddNewPageBody extends StatelessWidget {
),
],
),
const VSpace(8),

// share, delete
// new board, new calendar
Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: BottomSheetActionWidget(
Expand All @@ -90,6 +52,7 @@ class _AddNewPageBody extends StatelessWidget {
onTap: () => onAction(ViewLayoutPB.Board),
),
),
const HSpace(8),
Expanded(
child: BottomSheetActionWidget(
svg: FlowySvgs.date_s,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MobileBottomSheetDragHandler extends StatelessWidget {
height: 4,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(2.0),
color: Theme.of(context).colorScheme.onSecondary,
color: Theme.of(context).hintColor,
),
),
);
Expand Down
Loading

0 comments on commit 73ea1a0

Please sign in to comment.