Skip to content

Commit eed6c75

Browse files
authored
chore: add spacing between a popover and the edge of the window (#1625)
1 parent 436291c commit eed6c75

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

frontend/app_flowy/packages/appflowy_popover/lib/src/layout.dart

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ class PopoverLayoutDelegate extends SingleChildLayoutDelegate {
77
PopoverLink link;
88
PopoverDirection direction;
99
final Offset offset;
10+
final EdgeInsets windowPadding;
1011

1112
PopoverLayoutDelegate({
1213
required this.link,
1314
required this.direction,
1415
required this.offset,
16+
required this.windowPadding,
1517
});
1618

1719
@override
@@ -35,9 +37,21 @@ class PopoverLayoutDelegate extends SingleChildLayoutDelegate {
3537
return false;
3638
}
3739

40+
@override
41+
Size getSize(BoxConstraints constraints) {
42+
return Size(
43+
constraints.maxWidth - windowPadding.left - windowPadding.right,
44+
constraints.maxHeight - windowPadding.top - windowPadding.bottom,
45+
);
46+
}
47+
3848
@override
3949
BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
40-
return constraints.loosen();
50+
return BoxConstraints(
51+
maxWidth: constraints.maxWidth - windowPadding.left - windowPadding.right,
52+
maxHeight:
53+
constraints.maxHeight - windowPadding.top - windowPadding.bottom,
54+
);
4155
// assert(link.leaderSize != null);
4256
// // if (link.leaderSize == null) {
4357
// // return constraints.loosen();
@@ -274,8 +288,14 @@ class PopoverLayoutDelegate extends SingleChildLayoutDelegate {
274288
throw UnimplementedError();
275289
}
276290
return Offset(
277-
math.max(0.0, math.min(size.width - childSize.width, position.dx)),
278-
math.max(0.0, math.min(size.height - childSize.height, position.dy)),
291+
math.max(
292+
windowPadding.left,
293+
math.min(
294+
windowPadding.left + size.width - childSize.width, position.dx)),
295+
math.max(
296+
windowPadding.top,
297+
math.min(
298+
windowPadding.top + size.height - childSize.height, position.dy)),
279299
);
280300
}
281301
}

frontend/app_flowy/packages/appflowy_popover/lib/src/popover.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,19 @@ enum PopoverDirection {
4949
class Popover extends StatefulWidget {
5050
final PopoverController? controller;
5151

52+
/// The offset from the [child] where the popover will be drawn
5253
final Offset? offset;
5354

55+
/// Amount of padding between the edges of the window and the popover
56+
final EdgeInsets? windowPadding;
57+
5458
final Decoration? maskDecoration;
5559

5660
/// The function used to build the popover.
5761
final Widget? Function(BuildContext context) popupBuilder;
5862

63+
/// Specify how the popover can be triggered when interacting with the child
64+
/// by supplying a bitwise-OR combination of one or more [PopoverTriggerFlags]
5965
final int triggerActions;
6066

6167
/// If multiple popovers are exclusive,
@@ -84,6 +90,7 @@ class Popover extends StatefulWidget {
8490
this.triggerActions = 0,
8591
this.direction = PopoverDirection.rightWithTopAligned,
8692
this.mutex,
93+
this.windowPadding,
8794
this.onClose,
8895
this.asBarrier = false,
8996
}) : super(key: key);
@@ -126,6 +133,7 @@ class PopoverState extends State<Popover> {
126133
direction: widget.direction,
127134
popoverLink: popoverLink,
128135
offset: widget.offset ?? Offset.zero,
136+
windowPadding: widget.windowPadding ?? EdgeInsets.zero,
129137
popupBuilder: widget.popupBuilder,
130138
onClose: () => close(),
131139
onCloseAll: () => _removeRootOverlay(),
@@ -194,6 +202,7 @@ class PopoverContainer extends StatefulWidget {
194202
final PopoverDirection direction;
195203
final PopoverLink popoverLink;
196204
final Offset offset;
205+
final EdgeInsets windowPadding;
197206
final void Function() onClose;
198207
final void Function() onCloseAll;
199208

@@ -203,6 +212,7 @@ class PopoverContainer extends StatefulWidget {
203212
required this.direction,
204213
required this.popoverLink,
205214
required this.offset,
215+
required this.windowPadding,
206216
required this.onClose,
207217
required this.onCloseAll,
208218
}) : super(key: key);
@@ -228,6 +238,7 @@ class PopoverContainerState extends State<PopoverContainer> {
228238
direction: widget.direction,
229239
link: widget.popoverLink,
230240
offset: widget.offset,
241+
windowPadding: widget.windowPadding,
231242
),
232243
child: widget.popupBuilder(context),
233244
);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class AppFlowyPopover extends StatelessWidget {
1515
final Offset? offset;
1616
final bool asBarrier;
1717
final EdgeInsets margin;
18+
final EdgeInsets windowPadding;
1819

1920
const AppFlowyPopover({
2021
Key? key,
@@ -29,6 +30,7 @@ class AppFlowyPopover extends StatelessWidget {
2930
this.controller,
3031
this.asBarrier = false,
3132
this.margin = const EdgeInsets.all(6),
33+
this.windowPadding = const EdgeInsets.all(8.0),
3234
}) : super(key: key);
3335

3436
@override
@@ -40,6 +42,7 @@ class AppFlowyPopover extends StatelessWidget {
4042
mutex: mutex,
4143
asBarrier: asBarrier,
4244
triggerActions: triggerActions,
45+
windowPadding: windowPadding,
4346
popupBuilder: (context) {
4447
final child = popupBuilder(context);
4548
return _PopoverContainer(

0 commit comments

Comments
 (0)