Merge pull request #660 from matrixhead/main

feat: resize the left-hand sidebar
This commit is contained in:
Lucas.Xu 2022-07-20 23:08:49 +08:00 committed by GitHub
commit 3411c42b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 36 deletions

View File

@ -16,42 +16,48 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
HomeBloc(UserProfilePB user, CurrentWorkspaceSettingPB workspaceSetting) HomeBloc(UserProfilePB user, CurrentWorkspaceSettingPB workspaceSetting)
: _listener = UserWorkspaceListener(userProfile: user), : _listener = UserWorkspaceListener(userProfile: user),
super(HomeState.initial(workspaceSetting)) { super(HomeState.initial(workspaceSetting)) {
on<HomeEvent>((event, emit) async { on<HomeEvent>(
await event.map( (event, emit) async {
initial: (_Initial value) { await event.map(
_listener.start( initial: (_Initial value) {
onAuthChanged: (result) => _authDidChanged(result), _listener.start(
onSettingUpdated: (result) { onAuthChanged: (result) => _authDidChanged(result),
result.fold( onSettingUpdated: (result) {
(setting) => add(HomeEvent.didReceiveWorkspaceSetting(setting)), result.fold(
(r) => Log.error(r), (setting) => add(HomeEvent.didReceiveWorkspaceSetting(setting)),
); (r) => Log.error(r),
}, );
); },
}, );
showLoading: (e) async { },
emit(state.copyWith(isLoading: e.isLoading)); showLoading: (e) async {
}, emit(state.copyWith(isLoading: e.isLoading));
setEditPannel: (e) async { },
emit(state.copyWith(pannelContext: some(e.editContext))); setEditPannel: (e) async {
}, emit(state.copyWith(pannelContext: some(e.editContext)));
dismissEditPannel: (value) async { },
emit(state.copyWith(pannelContext: none())); dismissEditPannel: (value) async {
}, emit(state.copyWith(pannelContext: none()));
forceCollapse: (e) async { },
emit(state.copyWith(forceCollapse: e.forceCollapse)); forceCollapse: (e) async {
}, emit(state.copyWith(forceCollapse: e.forceCollapse));
didReceiveWorkspaceSetting: (_DidReceiveWorkspaceSetting value) { },
emit(state.copyWith(workspaceSetting: value.setting)); didReceiveWorkspaceSetting: (_DidReceiveWorkspaceSetting value) {
}, emit(state.copyWith(workspaceSetting: value.setting));
unauthorized: (_Unauthorized value) { },
emit(state.copyWith(unauthorized: true)); unauthorized: (_Unauthorized value) {
}, emit(state.copyWith(unauthorized: true));
collapseMenu: (e) { },
emit(state.copyWith(isMenuCollapsed: !state.isMenuCollapsed)); collapseMenu: (e) {
}, emit(state.copyWith(isMenuCollapsed: !state.isMenuCollapsed));
); },
}); editPannelResized: (e) {
final newOffset = (state.resizeOffset + e.offset).clamp(-50, 200).toDouble();
emit(state.copyWith(resizeOffset: newOffset));
},
);
},
);
} }
@override @override
@ -79,6 +85,7 @@ class HomeEvent with _$HomeEvent {
const factory HomeEvent.didReceiveWorkspaceSetting(CurrentWorkspaceSettingPB setting) = _DidReceiveWorkspaceSetting; const factory HomeEvent.didReceiveWorkspaceSetting(CurrentWorkspaceSettingPB setting) = _DidReceiveWorkspaceSetting;
const factory HomeEvent.unauthorized(String msg) = _Unauthorized; const factory HomeEvent.unauthorized(String msg) = _Unauthorized;
const factory HomeEvent.collapseMenu() = _CollapseMenu; const factory HomeEvent.collapseMenu() = _CollapseMenu;
const factory HomeEvent.editPannelResized(double offset) = _EditPannelResized;
} }
@freezed @freezed
@ -90,6 +97,7 @@ class HomeState with _$HomeState {
required CurrentWorkspaceSettingPB workspaceSetting, required CurrentWorkspaceSettingPB workspaceSetting,
required bool unauthorized, required bool unauthorized,
required bool isMenuCollapsed, required bool isMenuCollapsed,
required double resizeOffset,
}) = _HomeState; }) = _HomeState;
factory HomeState.initial(CurrentWorkspaceSettingPB workspaceSetting) => HomeState( factory HomeState.initial(CurrentWorkspaceSettingPB workspaceSetting) => HomeState(
@ -99,5 +107,6 @@ class HomeState with _$HomeState {
workspaceSetting: workspaceSetting, workspaceSetting: workspaceSetting,
unauthorized: false, unauthorized: false,
isMenuCollapsed: false, isMenuCollapsed: false,
resizeOffset: 0,
); );
} }

View File

@ -27,6 +27,8 @@ class HomeLayout {
menuWidth = Sizes.sideBarLg; menuWidth = Sizes.sideBarLg;
} }
menuWidth += homeBlocState.resizeOffset;
if (forceCollapse) { if (forceCollapse) {
showMenu = false; showMenu = false;
} else { } else {

View File

@ -7,6 +7,7 @@ import 'package:flowy_sdk/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' show UserProfilePB; import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfilePB;
import 'package:flowy_sdk/protobuf/flowy-folder/protobuf.dart'; import 'package:flowy_sdk/protobuf/flowy-folder/protobuf.dart';
import 'package:flutter/gestures.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:styled_widget/styled_widget.dart'; import 'package:styled_widget/styled_widget.dart';
@ -87,6 +88,7 @@ class _HomeScreenState extends State<HomeScreen> {
context: context, context: context,
state: state, state: state,
); );
final homeMenuResizer = _buildHomeMenuResizer(context: context);
final editPannel = _buildEditPannel( final editPannel = _buildEditPannel(
homeState: state, homeState: state,
layout: layout, layout: layout,
@ -99,6 +101,7 @@ class _HomeScreenState extends State<HomeScreen> {
homeMenu: menu, homeMenu: menu,
editPannel: editPannel, editPannel: editPannel,
bubble: bubble, bubble: bubble,
homeMenuResizer: homeMenuResizer,
); );
}, },
); );
@ -150,12 +153,31 @@ class _HomeScreenState extends State<HomeScreen> {
); );
} }
Widget _buildHomeMenuResizer({
required BuildContext context,
}) {
return MouseRegion(
cursor: SystemMouseCursors.resizeLeftRight,
child: GestureDetector(
dragStartBehavior: DragStartBehavior.down,
onPanUpdate: ((details) {
context.read<HomeBloc>().add(HomeEvent.editPannelResized(details.delta.dx));
}),
behavior: HitTestBehavior.translucent,
child: SizedBox(
width: 10,
height: MediaQuery.of(context).size.height,
)),
);
}
Widget _layoutWidgets({ Widget _layoutWidgets({
required HomeLayout layout, required HomeLayout layout,
required Widget homeMenu, required Widget homeMenu,
required Widget homeStack, required Widget homeStack,
required Widget editPannel, required Widget editPannel,
required Widget bubble, required Widget bubble,
required Widget homeMenuResizer,
}) { }) {
return Stack( return Stack(
children: [ children: [
@ -170,6 +192,7 @@ class _HomeScreenState extends State<HomeScreen> {
.constrained(minWidth: 500) .constrained(minWidth: 500)
.positioned(left: layout.homePageLOffset, right: layout.homePageROffset, bottom: 0, top: 0, animate: true) .positioned(left: layout.homePageLOffset, right: layout.homePageROffset, bottom: 0, top: 0, animate: true)
.animate(layout.animDuration, Curves.easeOut), .animate(layout.animDuration, Curves.easeOut),
homeMenuResizer.positioned(left: layout.homePageLOffset - 5),
bubble bubble
.positioned( .positioned(
right: 20, right: 20,