Merge pull request #1155 from AppFlowy-IO/fix/1126

fix: auto resize Action list
This commit is contained in:
Nathan.fooo 2022-09-25 15:28:37 +08:00 committed by GitHub
commit a4b08e4f46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 60 deletions

View File

@ -195,9 +195,6 @@ class ShareActions with ActionList<ShareActionWrapper>, FlowyOverlayDelegate {
ShareActions({required this.onSelected}); ShareActions({required this.onSelected});
@override
double get maxWidth => 130;
@override @override
double get itemHeight => 22; double get itemHeight => 22;

View File

@ -61,8 +61,7 @@ class ActionList {
itemBuilder: (context, index) => items[index], itemBuilder: (context, index) => items[index],
anchorContext: anchorContext, anchorContext: anchorContext,
anchorDirection: AnchorDirection.bottomRight, anchorDirection: AnchorDirection.bottomRight,
width: 120, constraints: BoxConstraints.tight(const Size(120, 80)),
height: 80,
); );
} }
} }

View File

@ -111,9 +111,6 @@ class QuestionBubbleActionSheet
required this.onSelected, required this.onSelected,
}); });
@override
double get maxWidth => 170;
@override @override
double get itemHeight => 22; double get itemHeight => 22;
@ -142,7 +139,7 @@ class QuestionBubbleActionSheet
@override @override
ListOverlayFooter? get footer => ListOverlayFooter( ListOverlayFooter? get footer => ListOverlayFooter(
widget: const FlowyVersionDescription(), widget: const FlowyVersionDescription(),
height: 30, height: 40,
padding: const EdgeInsets.only(top: 6), padding: const EdgeInsets.only(top: 6),
); );
} }
@ -174,8 +171,11 @@ class FlowyVersionDescription extends StatelessWidget {
children: [ children: [
Divider(height: 1, color: theme.shader6, thickness: 1.0), Divider(height: 1, color: theme.shader6, thickness: 1.0),
const VSpace(6), const VSpace(6),
FlowyText("$appName $version.$buildNumber", FlowyText(
fontSize: 12, color: theme.shader4), "$appName $version.$buildNumber",
fontSize: 12,
color: theme.shader4,
),
], ],
).padding( ).padding(
horizontal: ActionListSizes.itemHPadding + ActionListSizes.padding, horizontal: ActionListSizes.itemHPadding + ActionListSizes.padding,

View File

@ -13,7 +13,9 @@ abstract class ActionList<T extends ActionItem> {
String get identifier => toString(); String get identifier => toString();
double get maxWidth => 162; double get maxWidth => 300;
double get minWidth => 120;
double get itemHeight => ActionListSizes.itemHeight; double get itemHeight => ActionListSizes.itemHeight;
@ -29,28 +31,29 @@ abstract class ActionList<T extends ActionItem> {
AnchorDirection anchorDirection = AnchorDirection.bottomRight, AnchorDirection anchorDirection = AnchorDirection.bottomRight,
Offset? anchorOffset, Offset? anchorOffset,
}) { }) {
final widgets = items ListOverlay.showWithAnchor(
.map( buildContext,
(action) => ActionCell<T>( identifier: identifier,
itemCount: items.length,
itemBuilder: (context, index) {
final action = items[index];
return ActionCell<T>(
action: action, action: action,
itemHeight: itemHeight, itemHeight: itemHeight,
onSelected: (action) { onSelected: (action) {
FlowyOverlay.of(buildContext).remove(identifier); FlowyOverlay.of(buildContext).remove(identifier);
selectCallback(dartz.some(action)); selectCallback(dartz.some(action));
}, },
), );
) },
.toList();
ListOverlay.showWithAnchor(
buildContext,
identifier: identifier,
itemCount: widgets.length,
itemBuilder: (context, index) => widgets[index],
anchorContext: anchorContext ?? buildContext, anchorContext: anchorContext ?? buildContext,
anchorDirection: anchorDirection, anchorDirection: anchorDirection,
width: maxWidth, constraints: BoxConstraints(
height: widgets.length * (itemHeight + ActionListSizes.padding * 2), minHeight: items.length * (itemHeight + ActionListSizes.padding * 2),
maxHeight: items.length * (itemHeight + ActionListSizes.padding * 2),
maxWidth: maxWidth,
minWidth: minWidth,
),
delegate: delegate, delegate: delegate,
anchorOffset: anchorOffset, anchorOffset: anchorOffset,
footer: footer, footer: footer,
@ -93,7 +96,7 @@ class ActionCell<T extends ActionItem> extends StatelessWidget {
child: SizedBox( child: SizedBox(
height: itemHeight, height: itemHeight,
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
if (icon != null) icon, if (icon != null) icon,
HSpace(ActionListSizes.itemHPadding), HSpace(ActionListSizes.itemHPadding),

View File

@ -218,8 +218,8 @@ class OverlayScreen extends StatelessWidget {
overlapBehaviour: providerContext overlapBehaviour: providerContext
.read<OverlayDemoConfiguration>() .read<OverlayDemoConfiguration>()
.overlapBehaviour, .overlapBehaviour,
width: 200.0, constraints:
height: 200.0, BoxConstraints.tight(const Size(200, 200)),
); );
}, },
child: const Text('Show List Overlay'), child: const Text('Show List Overlay'),

View File

@ -1,3 +1,5 @@
import 'dart:math';
import 'package:flowy_infra_ui/flowy_infra_ui.dart'; import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flowy_infra/theme.dart'; import 'package:flowy_infra/theme.dart';
@ -19,40 +21,48 @@ class ListOverlay extends StatelessWidget {
const ListOverlay({ const ListOverlay({
Key? key, Key? key,
required this.itemBuilder, required this.itemBuilder,
this.itemCount, this.itemCount = 0,
this.controller, this.controller,
this.width = double.infinity, this.constraints = const BoxConstraints(),
this.height = double.infinity,
this.footer, this.footer,
}) : super(key: key); }) : super(key: key);
final IndexedWidgetBuilder itemBuilder; final IndexedWidgetBuilder itemBuilder;
final int? itemCount; final int itemCount;
final ScrollController? controller; final ScrollController? controller;
final double width; final BoxConstraints constraints;
final double height;
final ListOverlayFooter? footer; final ListOverlayFooter? footer;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
const padding = EdgeInsets.symmetric(horizontal: 6, vertical: 6); const padding = EdgeInsets.symmetric(horizontal: 6, vertical: 6);
double totalHeight = height + padding.vertical; double totalHeight = constraints.minHeight + padding.vertical;
if (footer != null) { if (footer != null) {
totalHeight = totalHeight + footer!.height + footer!.padding.vertical; totalHeight = totalHeight + footer!.height + footer!.padding.vertical;
} }
final innerConstraints = BoxConstraints(
minHeight: totalHeight,
maxHeight: max(constraints.maxHeight, totalHeight),
minWidth: constraints.minWidth,
maxWidth: constraints.maxWidth,
);
List<Widget> children = [];
for (var i = 0; i < itemCount; i++) {
children.add(itemBuilder(context, i));
}
return OverlayContainer( return OverlayContainer(
constraints: BoxConstraints.tight(Size(width, totalHeight)), constraints: innerConstraints,
padding: padding, padding: padding,
child: SingleChildScrollView( child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: IntrinsicWidth(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min,
children: [ children: [
ListView.builder( ...children,
shrinkWrap: true,
itemBuilder: itemBuilder,
itemCount: itemCount,
controller: controller,
),
if (footer != null) if (footer != null)
Padding( Padding(
padding: footer!.padding, padding: footer!.padding,
@ -61,6 +71,7 @@ class ListOverlay extends StatelessWidget {
], ],
), ),
), ),
),
); );
} }
@ -68,10 +79,9 @@ class ListOverlay extends StatelessWidget {
BuildContext context, { BuildContext context, {
required String identifier, required String identifier,
required IndexedWidgetBuilder itemBuilder, required IndexedWidgetBuilder itemBuilder,
int? itemCount, int itemCount = 0,
ScrollController? controller, ScrollController? controller,
double width = double.infinity, BoxConstraints constraints = const BoxConstraints(),
double height = double.infinity,
required BuildContext anchorContext, required BuildContext anchorContext,
AnchorDirection? anchorDirection, AnchorDirection? anchorDirection,
FlowyOverlayDelegate? delegate, FlowyOverlayDelegate? delegate,
@ -85,8 +95,7 @@ class ListOverlay extends StatelessWidget {
itemBuilder: itemBuilder, itemBuilder: itemBuilder,
itemCount: itemCount, itemCount: itemCount,
controller: controller, controller: controller,
width: width, constraints: constraints,
height: height,
footer: footer, footer: footer,
), ),
identifier: identifier, identifier: identifier,
@ -122,7 +131,9 @@ class OverlayContainer extends StatelessWidget {
child: Container( child: Container(
padding: padding, padding: padding,
decoration: FlowyDecoration.decoration( decoration: FlowyDecoration.decoration(
theme.surface, theme.shadowColor.withOpacity(0.15)), theme.surface,
theme.shadowColor.withOpacity(0.15),
),
constraints: constraints, constraints: constraints,
child: child, child: child,
), ),