Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

[infra_ui][overlar] Implement overlay insertion interface

Jaylen Bian58e4a4d5f175
diff --git a/app_flowy/packages/flowy_infra_ui/example/lib/overlay/overlay_screen.dart b/app_flowy/packages/flowy_infra_ui/example/lib/overlay/overlay_screen.dart
index 2b83902246..5c5738dc11 100644
--- a/app_flowy/packages/flowy_infra_ui/example/lib/overlay/overlay_screen.dart
+++ b/app_flowy/packages/flowy_infra_ui/example/lib/overlay/overlay_screen.dart
@@ -55,20 +55,22 @@ class OverlayScreen extends StatelessWidget {
child: const Text('Show Overlay'),
),
const SizedBox(height: 12.0),
- ElevatedButton(
- onPressed: () {
- FlowyOverlay.of(context).insertWithAnchor(
- widget: const FlutterLogo(
- size: 200,
- textColor: Colors.orange,
- ),
- identifier: 'overlay_flutter_logo',
- delegate: null,
- anchorContext: context,
- );
- },
- child: const Text('Show Anchored Overlay'),
- ),
+ Builder(builder: (buttonContext) {
+ return ElevatedButton(
+ onPressed: () {
+ FlowyOverlay.of(context).insertWithAnchor(
+ widget: const FlutterLogo(
+ size: 200,
+ textColor: Colors.orange,
+ ),
+ identifier: 'overlay_flutter_logo',
+ delegate: null,
+ anchorContext: buttonContext,
+ );
+ },
+ child: const Text('Show Anchored Overlay'),
+ );
+ }),
const SizedBox(height: 12.0),
ElevatedButton(
onPressed: () {
diff --git a/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/flowy_overlay.dart b/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/flowy_overlay.dart
index cc3c16a7d1..269eb8aa1f 100644
--- a/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/flowy_overlay.dart
+++ b/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/flowy_overlay.dart
@@ -201,17 +201,24 @@ class FlowyOverlayState extends State<FlowyOverlay> {
anchorPosition != null || anchorContext != null,
'Must provide `anchorPosition` or `anchorContext` to locating overlay.',
);
- var targetAnchorPosition = anchorPosition;
+ Offset targetAnchorPosition = anchorPosition ?? Offset.zero;
+ Size targetAnchorSize = anchorSize ?? Size.zero;
if (anchorContext != null) {
RenderObject renderObject = anchorContext.findRenderObject()!;
assert(
renderObject is RenderBox,
'Unexpect non-RenderBox render object caught.',
);
- final localOffset = (renderObject as RenderBox).localToGlobal(Offset.zero);
- targetAnchorPosition ??= localOffset;
+ final renderBox = renderObject as RenderBox;
+ targetAnchorPosition = renderBox.localToGlobal(Offset.zero);
+ targetAnchorSize = renderBox.size;
}
- final anchorRect = targetAnchorPosition! & (anchorSize ?? Size.zero);
+ final anchorRect = Rect.fromLTWH(
+ targetAnchorPosition.dx,
+ targetAnchorPosition.dy,
+ targetAnchorSize.width,
+ targetAnchorSize.height,
+ );
overlay = CustomSingleChildLayout(
delegate: OverlayLayoutDelegate(
anchorRect: anchorRect,
diff --git a/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/overlay_layout_delegate.dart b/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/overlay_layout_delegate.dart
index 34f63d7060..eaea7c17f8 100644
--- a/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/overlay_layout_delegate.dart
+++ b/app_flowy/packages/flowy_infra_ui/lib/src/flowy_overlay/overlay_layout_delegate.dart
@@ -19,20 +19,14 @@ class OverlayLayoutDelegate extends SingleChildLayoutDelegate {
return anchorRect != oldDelegate.anchorRect || anchorDirection != oldDelegate.anchorDirection;
}
- @override
- Size getSize(BoxConstraints constraints) {
- return super.getSize(constraints);
- }
-
@override
BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
- // TODO: junlin - calculate child constaints
- return super.getConstraintsForChild(constraints);
+ return constraints.loosen();
}
@override
Offset getPositionForChild(Size size, Size childSize) {
// TODO: junlin - calculate child position
- return Offset(size.width / 2, size.height / 2);
+ return Offset(anchorRect.width / 2, anchorRect.height / 2);
}
}