Skip to content

Commit a4b08e4

Browse files
authored
Merge pull request #1155 from AppFlowy-IO/fix/1126
fix: auto resize Action list
2 parents ae3a68e + 42995b6 commit a4b08e4

File tree

6 files changed

+70
-60
lines changed

6 files changed

+70
-60
lines changed

frontend/app_flowy/lib/plugins/doc/document.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ class ShareActions with ActionList<ShareActionWrapper>, FlowyOverlayDelegate {
195195

196196
ShareActions({required this.onSelected});
197197

198-
@override
199-
double get maxWidth => 130;
200-
201198
@override
202199
double get itemHeight => 22;
203200

frontend/app_flowy/lib/workspace/presentation/home/menu/app/header/add_button.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ class ActionList {
6161
itemBuilder: (context, index) => items[index],
6262
anchorContext: anchorContext,
6363
anchorDirection: AnchorDirection.bottomRight,
64-
width: 120,
65-
height: 80,
64+
constraints: BoxConstraints.tight(const Size(120, 80)),
6665
);
6766
}
6867
}

frontend/app_flowy/lib/workspace/presentation/widgets/float_bubble/question_bubble.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ class QuestionBubbleActionSheet
111111
required this.onSelected,
112112
});
113113

114-
@override
115-
double get maxWidth => 170;
116-
117114
@override
118115
double get itemHeight => 22;
119116

@@ -142,7 +139,7 @@ class QuestionBubbleActionSheet
142139
@override
143140
ListOverlayFooter? get footer => ListOverlayFooter(
144141
widget: const FlowyVersionDescription(),
145-
height: 30,
142+
height: 40,
146143
padding: const EdgeInsets.only(top: 6),
147144
);
148145
}
@@ -174,8 +171,11 @@ class FlowyVersionDescription extends StatelessWidget {
174171
children: [
175172
Divider(height: 1, color: theme.shader6, thickness: 1.0),
176173
const VSpace(6),
177-
FlowyText("$appName $version.$buildNumber",
178-
fontSize: 12, color: theme.shader4),
174+
FlowyText(
175+
"$appName $version.$buildNumber",
176+
fontSize: 12,
177+
color: theme.shader4,
178+
),
179179
],
180180
).padding(
181181
horizontal: ActionListSizes.itemHPadding + ActionListSizes.padding,

frontend/app_flowy/lib/workspace/presentation/widgets/pop_up_action.dart

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ abstract class ActionList<T extends ActionItem> {
1313

1414
String get identifier => toString();
1515

16-
double get maxWidth => 162;
16+
double get maxWidth => 300;
17+
18+
double get minWidth => 120;
1719

1820
double get itemHeight => ActionListSizes.itemHeight;
1921

@@ -29,28 +31,29 @@ abstract class ActionList<T extends ActionItem> {
2931
AnchorDirection anchorDirection = AnchorDirection.bottomRight,
3032
Offset? anchorOffset,
3133
}) {
32-
final widgets = items
33-
.map(
34-
(action) => ActionCell<T>(
35-
action: action,
36-
itemHeight: itemHeight,
37-
onSelected: (action) {
38-
FlowyOverlay.of(buildContext).remove(identifier);
39-
selectCallback(dartz.some(action));
40-
},
41-
),
42-
)
43-
.toList();
44-
4534
ListOverlay.showWithAnchor(
4635
buildContext,
4736
identifier: identifier,
48-
itemCount: widgets.length,
49-
itemBuilder: (context, index) => widgets[index],
37+
itemCount: items.length,
38+
itemBuilder: (context, index) {
39+
final action = items[index];
40+
return ActionCell<T>(
41+
action: action,
42+
itemHeight: itemHeight,
43+
onSelected: (action) {
44+
FlowyOverlay.of(buildContext).remove(identifier);
45+
selectCallback(dartz.some(action));
46+
},
47+
);
48+
},
5049
anchorContext: anchorContext ?? buildContext,
5150
anchorDirection: anchorDirection,
52-
width: maxWidth,
53-
height: widgets.length * (itemHeight + ActionListSizes.padding * 2),
51+
constraints: BoxConstraints(
52+
minHeight: items.length * (itemHeight + ActionListSizes.padding * 2),
53+
maxHeight: items.length * (itemHeight + ActionListSizes.padding * 2),
54+
maxWidth: maxWidth,
55+
minWidth: minWidth,
56+
),
5457
delegate: delegate,
5558
anchorOffset: anchorOffset,
5659
footer: footer,
@@ -93,7 +96,7 @@ class ActionCell<T extends ActionItem> extends StatelessWidget {
9396
child: SizedBox(
9497
height: itemHeight,
9598
child: Row(
96-
crossAxisAlignment: CrossAxisAlignment.center,
99+
crossAxisAlignment: CrossAxisAlignment.start,
97100
children: [
98101
if (icon != null) icon,
99102
HSpace(ActionListSizes.itemHPadding),

frontend/app_flowy/packages/flowy_infra_ui/example/lib/overlay/overlay_screen.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ class OverlayScreen extends StatelessWidget {
218218
overlapBehaviour: providerContext
219219
.read<OverlayDemoConfiguration>()
220220
.overlapBehaviour,
221-
width: 200.0,
222-
height: 200.0,
221+
constraints:
222+
BoxConstraints.tight(const Size(200, 200)),
223223
);
224224
},
225225
child: const Text('Show List Overlay'),

frontend/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/list_overlay.dart

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:math';
2+
13
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
24
import 'package:flutter/material.dart';
35
import 'package:flowy_infra/theme.dart';
@@ -19,46 +21,55 @@ class ListOverlay extends StatelessWidget {
1921
const ListOverlay({
2022
Key? key,
2123
required this.itemBuilder,
22-
this.itemCount,
24+
this.itemCount = 0,
2325
this.controller,
24-
this.width = double.infinity,
25-
this.height = double.infinity,
26+
this.constraints = const BoxConstraints(),
2627
this.footer,
2728
}) : super(key: key);
2829

2930
final IndexedWidgetBuilder itemBuilder;
30-
final int? itemCount;
31+
final int itemCount;
3132
final ScrollController? controller;
32-
final double width;
33-
final double height;
33+
final BoxConstraints constraints;
3434
final ListOverlayFooter? footer;
3535

3636
@override
3737
Widget build(BuildContext context) {
3838
const padding = EdgeInsets.symmetric(horizontal: 6, vertical: 6);
39-
double totalHeight = height + padding.vertical;
39+
double totalHeight = constraints.minHeight + padding.vertical;
4040
if (footer != null) {
4141
totalHeight = totalHeight + footer!.height + footer!.padding.vertical;
4242
}
4343

44+
final innerConstraints = BoxConstraints(
45+
minHeight: totalHeight,
46+
maxHeight: max(constraints.maxHeight, totalHeight),
47+
minWidth: constraints.minWidth,
48+
maxWidth: constraints.maxWidth,
49+
);
50+
51+
List<Widget> children = [];
52+
for (var i = 0; i < itemCount; i++) {
53+
children.add(itemBuilder(context, i));
54+
}
55+
4456
return OverlayContainer(
45-
constraints: BoxConstraints.tight(Size(width, totalHeight)),
57+
constraints: innerConstraints,
4658
padding: padding,
4759
child: SingleChildScrollView(
48-
child: Column(
49-
children: [
50-
ListView.builder(
51-
shrinkWrap: true,
52-
itemBuilder: itemBuilder,
53-
itemCount: itemCount,
54-
controller: controller,
55-
),
56-
if (footer != null)
57-
Padding(
58-
padding: footer!.padding,
59-
child: footer!.widget,
60-
),
61-
],
60+
scrollDirection: Axis.horizontal,
61+
child: IntrinsicWidth(
62+
child: Column(
63+
mainAxisSize: MainAxisSize.min,
64+
children: [
65+
...children,
66+
if (footer != null)
67+
Padding(
68+
padding: footer!.padding,
69+
child: footer!.widget,
70+
),
71+
],
72+
),
6273
),
6374
),
6475
);
@@ -68,10 +79,9 @@ class ListOverlay extends StatelessWidget {
6879
BuildContext context, {
6980
required String identifier,
7081
required IndexedWidgetBuilder itemBuilder,
71-
int? itemCount,
82+
int itemCount = 0,
7283
ScrollController? controller,
73-
double width = double.infinity,
74-
double height = double.infinity,
84+
BoxConstraints constraints = const BoxConstraints(),
7585
required BuildContext anchorContext,
7686
AnchorDirection? anchorDirection,
7787
FlowyOverlayDelegate? delegate,
@@ -85,8 +95,7 @@ class ListOverlay extends StatelessWidget {
8595
itemBuilder: itemBuilder,
8696
itemCount: itemCount,
8797
controller: controller,
88-
width: width,
89-
height: height,
98+
constraints: constraints,
9099
footer: footer,
91100
),
92101
identifier: identifier,
@@ -122,7 +131,9 @@ class OverlayContainer extends StatelessWidget {
122131
child: Container(
123132
padding: padding,
124133
decoration: FlowyDecoration.decoration(
125-
theme.surface, theme.shadowColor.withOpacity(0.15)),
134+
theme.surface,
135+
theme.shadowColor.withOpacity(0.15),
136+
),
126137
constraints: constraints,
127138
child: child,
128139
),

0 commit comments

Comments
 (0)