mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: refactor grid cell expander
This commit is contained in:
parent
7071db65e9
commit
a568f6323d
@ -48,11 +48,19 @@ class BlankCell extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract class GridCellExpander implements Widget {
|
||||||
|
void onExpand(BuildContext context);
|
||||||
|
}
|
||||||
|
|
||||||
abstract class GridCellWidget implements FlowyHoverWidget {
|
abstract class GridCellWidget implements FlowyHoverWidget {
|
||||||
@override
|
@override
|
||||||
final ValueNotifier<bool> onFocus = ValueNotifier<bool>(false);
|
final ValueNotifier<bool> onFocus = ValueNotifier<bool>(false);
|
||||||
|
|
||||||
final GridCellRequestFocusNotifier requestFocus = GridCellRequestFocusNotifier();
|
final GridCellRequestFocusNotifier requestFocus = GridCellRequestFocusNotifier();
|
||||||
|
|
||||||
|
GridCellExpander? buildExpander() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GridCellRequestFocusNotifier extends ChangeNotifier {
|
class GridCellRequestFocusNotifier extends ChangeNotifier {
|
||||||
@ -125,7 +133,7 @@ class CellStateNotifier extends ChangeNotifier {
|
|||||||
|
|
||||||
class CellContainer extends StatelessWidget {
|
class CellContainer extends StatelessWidget {
|
||||||
final GridCellWidget child;
|
final GridCellWidget child;
|
||||||
final Widget? expander;
|
final GridCellExpander? expander;
|
||||||
final double width;
|
final double width;
|
||||||
final RegionStateNotifier rowStateNotifier;
|
final RegionStateNotifier rowStateNotifier;
|
||||||
const CellContainer({
|
const CellContainer({
|
||||||
@ -182,17 +190,33 @@ class CellContainer extends StatelessWidget {
|
|||||||
|
|
||||||
class CellEnterRegion extends StatelessWidget {
|
class CellEnterRegion extends StatelessWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
final Widget expander;
|
final GridCellExpander expander;
|
||||||
const CellEnterRegion({required this.child, required this.expander, Key? key}) : super(key: key);
|
const CellEnterRegion({required this.child, required this.expander, Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final theme = context.watch<AppTheme>();
|
||||||
|
|
||||||
return Selector<CellStateNotifier, bool>(
|
return Selector<CellStateNotifier, bool>(
|
||||||
selector: (context, notifier) => notifier.onEnter,
|
selector: (context, notifier) => notifier.onEnter,
|
||||||
builder: (context, onEnter, _) {
|
builder: (context, onEnter, _) {
|
||||||
List<Widget> children = [child];
|
List<Widget> children = [child];
|
||||||
if (onEnter) {
|
if (onEnter) {
|
||||||
children.add(expander.positioned(right: 0));
|
final hover = FlowyHover(
|
||||||
|
style: HoverStyle(hoverColor: theme.bg3, backgroundColor: theme.surface),
|
||||||
|
builder: (_, onHover) => Container(
|
||||||
|
width: 26,
|
||||||
|
height: 26,
|
||||||
|
padding: const EdgeInsets.all(3),
|
||||||
|
child: expander,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
children.add(GestureDetector(
|
||||||
|
child: hover,
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: () => expander.onExpand(context),
|
||||||
|
).positioned(right: 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return MouseRegion(
|
return MouseRegion(
|
||||||
|
@ -25,7 +25,10 @@ class URLCellEditor extends StatefulWidget {
|
|||||||
//
|
//
|
||||||
FlowyOverlay.of(context).insertWithAnchor(
|
FlowyOverlay.of(context).insertWithAnchor(
|
||||||
widget: OverlayContainer(
|
widget: OverlayContainer(
|
||||||
child: SizedBox(width: 200, child: editor),
|
child: SizedBox(
|
||||||
|
width: 200,
|
||||||
|
child: Padding(padding: const EdgeInsets.all(6), child: editor),
|
||||||
|
),
|
||||||
constraints: BoxConstraints.loose(const Size(300, 160)),
|
constraints: BoxConstraints.loose(const Size(300, 160)),
|
||||||
),
|
),
|
||||||
identifier: URLCellEditor.identifier(),
|
identifier: URLCellEditor.identifier(),
|
||||||
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
import 'package:app_flowy/workspace/application/grid/cell/url_cell_bloc.dart';
|
import 'package:app_flowy/workspace/application/grid/cell/url_cell_bloc.dart';
|
||||||
import 'package:flowy_infra/image.dart';
|
import 'package:flowy_infra/image.dart';
|
||||||
import 'package:flowy_infra/theme.dart';
|
import 'package:flowy_infra/theme.dart';
|
||||||
|
import 'package:flowy_infra_ui/style_widget/hover.dart';
|
||||||
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
|
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -36,6 +37,12 @@ class GridURLCell extends StatefulWidget with GridCellWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
State<GridURLCell> createState() => _GridURLCellState();
|
State<GridURLCell> createState() => _GridURLCellState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
GridCellExpander? buildExpander() {
|
||||||
|
final cellContext = cellContextBuilder.build() as GridURLCellContext;
|
||||||
|
return _EditURLCellIndicator(cellContext: cellContext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _GridURLCellState extends State<GridURLCell> {
|
class _GridURLCellState extends State<GridURLCell> {
|
||||||
@ -70,13 +77,7 @@ class _GridURLCellState extends State<GridURLCell> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return CellEnterRegion(
|
return Align(alignment: Alignment.centerLeft, child: richText);
|
||||||
child: Align(alignment: Alignment.centerLeft, child: richText),
|
|
||||||
expander: _EditCellIndicator(onTap: () {
|
|
||||||
final cellContext = widget.cellContextBuilder.build() as GridURLCellContext;
|
|
||||||
URLCellEditor.show(context, cellContext);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -115,20 +116,18 @@ class _GridURLCellState extends State<GridURLCell> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _EditCellIndicator extends StatelessWidget {
|
class _EditURLCellIndicator extends StatelessWidget with GridCellExpander {
|
||||||
final VoidCallback onTap;
|
final GridURLCellContext cellContext;
|
||||||
const _EditCellIndicator({required this.onTap, Key? key}) : super(key: key);
|
const _EditURLCellIndicator({required this.cellContext, Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = context.watch<AppTheme>();
|
final theme = context.watch<AppTheme>();
|
||||||
return FlowyIconButton(
|
return svgWidget("editor/edit", color: theme.iconColor);
|
||||||
width: 26,
|
}
|
||||||
onPressed: onTap,
|
|
||||||
hoverColor: theme.hover,
|
@override
|
||||||
radius: BorderRadius.circular(4),
|
void onExpand(BuildContext context) {
|
||||||
iconPadding: const EdgeInsets.all(5),
|
URLCellEditor.show(context, cellContext);
|
||||||
icon: svgWidget("editor/edit", color: theme.iconColor),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,6 @@ class _GridHeaderCellContainer extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = context.watch<AppTheme>();
|
final theme = context.watch<AppTheme>();
|
||||||
final borderSide = BorderSide(color: theme.shader5, width: 1.0);
|
final borderSide = BorderSide(color: theme.shader5, width: 1.0);
|
||||||
|
|
||||||
final decoration = BoxDecoration(
|
final decoration = BoxDecoration(
|
||||||
border: Border(
|
border: Border(
|
||||||
top: borderSide,
|
top: borderSide,
|
||||||
|
@ -170,14 +170,15 @@ class _RowCells extends StatelessWidget {
|
|||||||
List<Widget> _makeCells(BuildContext context, GridCellMap gridCellMap) {
|
List<Widget> _makeCells(BuildContext context, GridCellMap gridCellMap) {
|
||||||
return gridCellMap.values.map(
|
return gridCellMap.values.map(
|
||||||
(gridCell) {
|
(gridCell) {
|
||||||
Widget? expander;
|
final GridCellWidget child = buildGridCellWidget(gridCell, cellCache);
|
||||||
|
GridCellExpander? expander = child.buildExpander();
|
||||||
if (gridCell.field.isPrimary) {
|
if (gridCell.field.isPrimary) {
|
||||||
expander = _CellExpander(onExpand: onExpand);
|
expander = _PrimaryCellExpander(onTap: onExpand);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CellContainer(
|
return CellContainer(
|
||||||
width: gridCell.field.width.toDouble(),
|
width: gridCell.field.width.toDouble(),
|
||||||
child: buildGridCellWidget(gridCell, cellCache),
|
child: child,
|
||||||
rowStateNotifier: Provider.of<RegionStateNotifier>(context, listen: false),
|
rowStateNotifier: Provider.of<RegionStateNotifier>(context, listen: false),
|
||||||
expander: expander,
|
expander: expander,
|
||||||
);
|
);
|
||||||
@ -199,23 +200,19 @@ class RegionStateNotifier extends ChangeNotifier {
|
|||||||
bool get onEnter => _onEnter;
|
bool get onEnter => _onEnter;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CellExpander extends StatelessWidget {
|
class _PrimaryCellExpander extends StatelessWidget with GridCellExpander {
|
||||||
final VoidCallback onExpand;
|
final VoidCallback onTap;
|
||||||
const _CellExpander({required this.onExpand, Key? key}) : super(key: key);
|
const _PrimaryCellExpander({required this.onTap, Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = context.watch<AppTheme>();
|
final theme = context.watch<AppTheme>();
|
||||||
return FittedBox(
|
return svgWidget("grid/expander", color: theme.main1);
|
||||||
fit: BoxFit.contain,
|
}
|
||||||
child: FlowyIconButton(
|
|
||||||
width: 26,
|
@override
|
||||||
onPressed: onExpand,
|
void onExpand(BuildContext context) {
|
||||||
iconPadding: const EdgeInsets.all(5),
|
onTap();
|
||||||
radius: BorderRadius.circular(4),
|
|
||||||
icon: svgWidget("grid/expander", color: theme.main1),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class _FlowyHoverState extends State<FlowyHover> {
|
|||||||
child: child,
|
child: child,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return child;
|
return Container(child: child, color: widget.style.backgroundColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,12 +63,14 @@ class HoverStyle {
|
|||||||
final Color hoverColor;
|
final Color hoverColor;
|
||||||
final BorderRadius borderRadius;
|
final BorderRadius borderRadius;
|
||||||
final EdgeInsets contentMargin;
|
final EdgeInsets contentMargin;
|
||||||
|
final Color backgroundColor;
|
||||||
|
|
||||||
const HoverStyle(
|
const HoverStyle(
|
||||||
{this.borderColor = Colors.transparent,
|
{this.borderColor = Colors.transparent,
|
||||||
this.borderWidth = 0,
|
this.borderWidth = 0,
|
||||||
this.borderRadius = const BorderRadius.all(Radius.circular(6)),
|
this.borderRadius = const BorderRadius.all(Radius.circular(6)),
|
||||||
this.contentMargin = EdgeInsets.zero,
|
this.contentMargin = EdgeInsets.zero,
|
||||||
|
this.backgroundColor = Colors.transparent,
|
||||||
required this.hoverColor});
|
required this.hoverColor});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user