Skip to content

Commit

Permalink
chore: added suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
squidrye committed Sep 29, 2023
1 parent 3920b31 commit d8d46d3
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:appflowy/core/config/kv.dart';
import 'package:appflowy/core/config/kv_keys.dart';
import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy_backend/log.dart';

class TabsService {
const TabsService();
Expand All @@ -31,14 +30,12 @@ class TabsService {
(l) => {},
(r) => jsonDecode(r),
);
// Log.warn("Result Map $map ${map[plugin.id]} ${plugin.id}");
if (map[plugin.id] != null) {
map[plugin.id] += 1;
return true;
}

map[plugin.id] = 1;
Log.warn(map);
await getIt<KeyValueStorage>().set(KVKeys.openedPlugins, jsonEncode(map));
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class HomeLayout {
menuIsDrawer = context.widthPx <= PageBreaks.tabletPortrait;
}

homePageLOffset = (showMenu) ? menuWidth : 0.0;
homePageLOffset = showMenu ? menuWidth : 0.0;

menuSpacing = !showMenu && Platform.isMacOS ? 80.0 : 0.0;
animDuration = homeSetting.resizeType.duration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class HomeSizes {
static const double editPanelWidth = 400;
static const double tabBarHeigth = 40;
static const double tabBarWidth = 200;
static const double resizeBarThickness = 4;
}

class HomeInsets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class HomeStack extends StatelessWidget {
);
}

//TODO(squidrye): Remove before merge
void _printTree(PaneNode node, [String prefix = '']) {
print('$prefix${node.tabs.hashCode}');
for (var child in node.children) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ class HomeHotKeys extends StatelessWidget {

void _selectTab(BuildContext context, int change) {
final bloc = context.read<PanesCubit>();
context
.read<PanesCubit>()
.selectTab(index: bloc.state.activePane.tabs.currentIndex + change);
bloc.selectTab(index: bloc.state.activePane.tabs.currentIndex + change);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:appflowy/workspace/application/view/view_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/home/home_draggables.dart';
import 'package:appflowy/workspace/presentation/widgets/draggable_item/combined_draggable_item.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -81,9 +80,6 @@ class _DraggableViewItemState extends State<DraggableViewItem> {
return;
}
setState(() {
Log.debug(
'offset: $offset, position: $position, size: ${renderBox.size}',
);
this.position = position;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DraggablePaneTarget extends StatefulWidget {
this.allowDrag = true,
});

final CrossDraggablesEntity pane; //pass target pane
final CrossDraggablesEntity pane;
final Widget child;
final BuildContext paneContext;
final bool allowDrag;
Expand Down Expand Up @@ -76,54 +76,67 @@ class _DraggablePaneTargetState extends State<DraggablePaneTarget> {
BuildContext context,
FlowyDraggableHoverPosition position,
) {
final top = (widget.pane.draggable as PaneNode).tabs.pages > 1
final (left, top, height, width) = _getHoverWidgetPosition(position);

if (position == FlowyDraggableHoverPosition.none) {
return const SizedBox.shrink();
}

return Positioned(
top: top,
left: left,
child: Container(
height: height,
width: width,
color: Theme.of(context).hoverColor.withOpacity(0.5),
),
);
}

(double? left, double? top, double? height, double? width)
_getHoverWidgetPosition(FlowyDraggableHoverPosition position) {
double? left, top, height, width;

final topOffset = (widget.pane.draggable as PaneNode).tabs.pages > 1
? HomeSizes.tabBarHeigth + HomeSizes.topBarHeight
: HomeSizes.topBarHeight;
return switch (position) {
FlowyDraggableHoverPosition.top => Positioned(
top: top,
child: Container(
height: (widget.size.height) / 2,
width: widget.size.width,
color: Theme.of(context).hoverColor.withOpacity(0.5),
),
),
FlowyDraggableHoverPosition.left => Positioned(
left: 0,
top: top,
child: Container(
width: widget.size.width / 2,
height: widget.size.height,
color: Theme.of(context).hoverColor.withOpacity(0.5),
),
),
FlowyDraggableHoverPosition.right => Positioned(
top: top,
left: widget.size.width / 2,
child: Container(
width: widget.size.width / 2,
height: widget.size.height,
color: Theme.of(context).hoverColor.withOpacity(0.5),
),
),
FlowyDraggableHoverPosition.bottom => Positioned(
top: widget.size.height / 2,
child: Container(
height: widget.size.height / 2,
width: widget.size.width,
color: Theme.of(context).hoverColor.withOpacity(0.5),
),
),
FlowyDraggableHoverPosition.tab => Positioned(
top: 0,
child: Container(
height: top,
width: widget.size.width,
color: Theme.of(context).hoverColor.withOpacity(0.5),
),
),
FlowyDraggableHoverPosition.none => const SizedBox.shrink(),
};

switch (position) {
case FlowyDraggableHoverPosition.top:
top = topOffset;
left = null;
height = widget.size.height / 2;
width = widget.size.width;
break;
case FlowyDraggableHoverPosition.left:
top = topOffset;
left = 0;
height = widget.size.height;
width = widget.size.width / 2;
break;
case FlowyDraggableHoverPosition.right:
top = topOffset;
left = widget.size.width / 2;
height = widget.size.height;
width = widget.size.width / 2;
break;
case FlowyDraggableHoverPosition.bottom:
top = widget.size.height / 2;
height = widget.size.height / 2;
width = widget.size.width;
left = null;
break;
case FlowyDraggableHoverPosition.tab:
top = 0;
left = null;
height = top;
width = widget.size.width;
break;
default:
break;
}

return (left, top, height, width);
}

FlowyDraggableHoverPosition _computeHoverPosition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:appflowy/workspace/application/panes/panes_cubit/panes_cubit.dar
import 'package:appflowy/workspace/presentation/home/home_layout.dart';
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
import 'package:appflowy/workspace/presentation/home/panes/panes_layout.dart';
import 'package:flowy_infra_ui/style_widget/extension.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -16,6 +17,7 @@ class FlowyPaneGroup extends StatelessWidget {
final double groupHeight;
final HomeLayout layout;
final HomeStackDelegate delegate;

const FlowyPaneGroup({
super.key,
required this.node,
Expand Down Expand Up @@ -43,7 +45,10 @@ class FlowyPaneGroup extends StatelessWidget {

return BlocProvider(
key: ValueKey(node.paneId),
create: (context) => PaneNodeCubit(node.children.length),
create: (context) => PaneNodeCubit(
node.children.length,
node.axis == Axis.horizontal ? groupHeight : groupWidth,
),
child: BlocBuilder<PaneNodeCubit, PaneNodeState>(
builder: (context, state) {
return SizedBox(
Expand All @@ -60,12 +65,12 @@ class FlowyPaneGroup extends StatelessWidget {
);
return Stack(
children: [
_resolveFlowyPanes(paneLayout, indexNode),
_resizeBar(
indexNode,
context,
_resolveFlowyPanes(
paneLayout,
)
indexNode,
state.resizeOffset[indexNode.$1],
),
_resizeBar(indexNode, context, paneLayout),
],
);
}).toList(),
Expand All @@ -91,19 +96,21 @@ class FlowyPaneGroup extends StatelessWidget {
cursor: paneLayout.resizeCursorType,
child: GestureDetector(
dragStartBehavior: DragStartBehavior.down,
onHorizontalDragUpdate: (details) =>
context.read<PaneNodeCubit>().resize(
paneLayout.childPaneWidth,
indexNode.$1,
details.delta.dx,
),
onVerticalDragUpdate: (details) =>
context.read<PaneNodeCubit>().resize(
paneLayout.childPaneHeight,
indexNode.$1,
details.delta.dy,
),
behavior: HitTestBehavior.opaque,
onHorizontalDragUpdate: (details) {
context
.read<PaneNodeCubit>()
.paneResized(indexNode.$1, details.delta.dx, groupWidth);
},
onVerticalDragUpdate: (details) {
context
.read<PaneNodeCubit>()
.paneResized(indexNode.$1, details.delta.dy, groupHeight);
},
onHorizontalDragStart: (_) =>
context.read<PaneNodeCubit>().resizeStart(),
onVerticalDragStart: (_) =>
context.read<PaneNodeCubit>().resizeStart(),
behavior: HitTestBehavior.translucent,
child: Container(
width: paneLayout.resizerWidth,
height: paneLayout.resizerHeight,
Expand All @@ -123,20 +130,20 @@ class FlowyPaneGroup extends StatelessWidget {
Widget _resolveFlowyPanes(
PaneLayout paneLayout,
(int, PaneNode) indexNode,
double position,
) {
return Positioned(
left: paneLayout.childPaneLPosition,
top: paneLayout.childPaneTPosition,
child: SizedBox(
child: FlowyPaneGroup(
node: indexNode.$2,
groupWidth: paneLayout.childPaneWidth,
groupHeight: paneLayout.childPaneHeight,
delegate: delegate,
layout: layout,
).constrained(
width: paneLayout.childPaneWidth,
height: paneLayout.childPaneHeight,
child: FlowyPaneGroup(
node: indexNode.$2,
groupWidth: paneLayout.childPaneWidth,
groupHeight: paneLayout.childPaneHeight,
delegate: delegate,
layout: layout,
),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:appflowy/workspace/application/panes/panes.dart';
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

Expand Down Expand Up @@ -44,11 +45,12 @@ class PaneLayout {
childPaneTPosition =
parentPane.axis == Axis.horizontal ? accumulatedHeight : null;

resizerWidth =
parentPane.axis == Axis.vertical ? 3 : parentPaneConstraints.maxWidth;
resizerWidth = parentPane.axis == Axis.vertical
? HomeSizes.resizeBarThickness
: parentPaneConstraints.maxWidth;

resizerHeight = parentPane.axis == Axis.horizontal
? 3
? HomeSizes.resizeBarThickness
: parentPaneConstraints.maxHeight;

resizeCursorType = parentPane.axis == Axis.vertical
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ class _DraggabletabItemState extends State<DraggableTabItem> {
final threshold = size.width / 2;
if (offset.dx < threshold) {
return TabDraggableHoverPosition.left;
} else {
return TabDraggableHoverPosition.right;
}
return TabDraggableHoverPosition.right;
}
return TabDraggableHoverPosition.none;
}
Expand Down

0 comments on commit d8d46d3

Please sign in to comment.