feat: aciton sheet

This commit is contained in:
Vincent Chan 2022-08-26 15:25:35 +08:00
parent e9b215ebbd
commit 5cdd1d38c4
5 changed files with 36 additions and 53 deletions

View File

@ -54,11 +54,12 @@ class GridFieldCell extends StatelessWidget {
void _showActionSheet(BuildContext context) { void _showActionSheet(BuildContext context) {
final state = context.read<FieldCellBloc>().state; final state = context.read<FieldCellBloc>().state;
GridFieldCellActionSheet( GridFieldCellActionSheetPopover.show(
context,
cellContext: cellContext:
GridFieldCellContext(gridId: state.gridId, field: state.field), GridFieldCellContext(gridId: state.gridId, field: state.field),
onEdited: () => _showFieldEditor(context), onEdited: () => _showFieldEditor(context),
).show(context); );
} }
void _showFieldEditor(BuildContext context) { void _showFieldEditor(BuildContext context) {

View File

@ -21,19 +21,6 @@ class GridFieldCellActionSheet extends StatelessWidget
{required this.cellContext, required this.onEdited, Key? key}) {required this.cellContext, required this.onEdited, Key? key})
: super(key: key); : super(key: key);
void show(BuildContext overlayContext) {
FlowyOverlay.of(overlayContext).insertWithAnchor(
widget: OverlayContainer(
child: this,
constraints: BoxConstraints.loose(const Size(240, 200)),
),
identifier: GridFieldCellActionSheet.identifier(),
anchorContext: overlayContext,
anchorDirection: AnchorDirection.bottomWithLeftAligned,
delegate: this,
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider( return BlocProvider(
@ -213,3 +200,20 @@ extension _FieldActionExtension on FieldAction {
} }
} }
} }
class GridFieldCellActionSheetPopover {
static show(
BuildContext context, {
required GridFieldCellContext cellContext,
required VoidCallback onEdited,
}) {
FlowyPopover.show(context,
anchorContext: context,
anchorDirection: AnchorDirection.bottomWithLeftAligned,
constraints: BoxConstraints.loose(const Size(240, 200)),
builder: (BuildContext context) {
return GridFieldCellActionSheet(
cellContext: cellContext, onEdited: onEdited);
});
}
}

View File

@ -99,27 +99,7 @@ class _FieldNameCell extends StatelessWidget {
} }
} }
class FieldEditorPopOver extends StatelessWidget { class FieldEditorPopOver {
final String gridId;
final String fieldName;
final IFieldTypeOptionLoader typeOptionLoader;
const FieldEditorPopOver({
required this.gridId,
required this.fieldName,
required this.typeOptionLoader,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return FieldEditor(
gridId: gridId,
fieldName: fieldName,
typeOptionLoader: typeOptionLoader,
key: key);
}
static show( static show(
BuildContext context, { BuildContext context, {
required BuildContext anchorContext, required BuildContext anchorContext,
@ -132,7 +112,7 @@ class FieldEditorPopOver extends StatelessWidget {
context, context,
anchorContext: anchorContext, anchorContext: anchorContext,
builder: (BuildContext context) { builder: (BuildContext context) {
return FieldEditorPopOver( return FieldEditor(
gridId: gridId, gridId: gridId,
fieldName: fieldName, fieldName: fieldName,
typeOptionLoader: typeOptionLoader, typeOptionLoader: typeOptionLoader,

View File

@ -102,22 +102,15 @@ class _FieldTypeOptionEditorState extends State<FieldTypeOptionEditor> {
void _showOverlay(BuildContext context, Widget child, void _showOverlay(BuildContext context, Widget child,
{VoidCallback? onRemoved}) { {VoidCallback? onRemoved}) {
final identifier = child.toString(); FlowyPopover.show(
if (currentOverlayIdentifier != null) { context,
FlowyOverlay.of(context).remove(currentOverlayIdentifier!);
}
currentOverlayIdentifier = identifier;
FlowyOverlay.of(context).insertWithAnchor(
widget: OverlayContainer(
child: child,
constraints: BoxConstraints.loose(const Size(460, 440)), constraints: BoxConstraints.loose(const Size(460, 440)),
),
identifier: identifier,
anchorContext: context, anchorContext: context,
anchorDirection: AnchorDirection.leftWithCenterAligned, anchorDirection: AnchorDirection.rightWithCenterAligned,
style: FlowyOverlayStyle(blur: false), anchorOffset: const Offset(20, 0),
anchorOffset: const Offset(-20, 0), builder: (BuildContext context) {
return child;
},
); );
} }

View File

@ -13,6 +13,7 @@ class FlowyPopover extends StatefulWidget {
final Rect anchorRect; final Rect anchorRect;
final AnchorDirection? anchorDirection; final AnchorDirection? anchorDirection;
final EdgeInsets padding; final EdgeInsets padding;
final BoxConstraints? constraints;
FlowyPopover({ FlowyPopover({
Key? key, Key? key,
@ -21,6 +22,7 @@ class FlowyPopover extends StatefulWidget {
this.shape, this.shape,
this.padding = _overlayContainerPadding, this.padding = _overlayContainerPadding,
this.anchorDirection, this.anchorDirection,
this.constraints,
}) : super(key: key); }) : super(key: key);
static show( static show(
@ -31,6 +33,7 @@ class FlowyPopover extends StatefulWidget {
AnchorDirection? anchorDirection, AnchorDirection? anchorDirection,
Size? anchorSize, Size? anchorSize,
Offset? anchorOffset, Offset? anchorOffset,
BoxConstraints? constraints,
}) { }) {
final offset = anchorOffset ?? Offset.zero; final offset = anchorOffset ?? Offset.zero;
Offset targetAnchorPosition = anchorPosition ?? Offset.zero; Offset targetAnchorPosition = anchorPosition ?? Offset.zero;
@ -59,6 +62,7 @@ class FlowyPopover extends StatefulWidget {
return FlowyPopover( return FlowyPopover(
anchorRect: anchorRect, anchorRect: anchorRect,
anchorDirection: anchorDirection, anchorDirection: anchorDirection,
constraints: constraints,
builder: (BuildContext context) { builder: (BuildContext context) {
return builder(context); return builder(context);
}); });
@ -88,7 +92,8 @@ class _FlowyPopoverState extends State<FlowyPopover> {
), ),
child: Container( child: Container(
padding: widget.padding, padding: widget.padding,
constraints: BoxConstraints.loose(const Size(280, 400)), constraints: widget.constraints ??
BoxConstraints.loose(const Size(280, 400)),
decoration: FlowyDecoration.decoration( decoration: FlowyDecoration.decoration(
theme.surface, theme.shadowColor.withOpacity(0.15)), theme.surface, theme.shadowColor.withOpacity(0.15)),
key: preRenderKey, key: preRenderKey,