mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
[infra_ui][overlar] Implement overlay insertion interface
This commit is contained in:
parent
a6a350a831
commit
58e4a4d5f1
@ -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: () {
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user