Skip to content

Commit

Permalink
Adjust magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
angelosilvestre committed May 10, 2024
1 parent 70316cd commit cb9ccf4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,9 @@ class SuperEditorIosMagnifierOverlayManagerState extends State<SuperEditorIosMag
magnifierKey: magnifierKey,
leaderLink: magnifierFocalPoint,
show: visible,
offsetFromFocalPoint: const Offset(0, -230),
// The bottom of the magnifier sits above the focal point.
// Leave a few pixels between the bottom of the magnifier and the focal point.
offsetFromFocalPoint: const Offset(0, -20),
);
}
}
Expand Down Expand Up @@ -1853,3 +1855,4 @@ class SuperEditorIosHandlesDocumentLayerBuilder implements SuperEditorLayerBuild
const defaultIosMagnifierEnterAnimationDuration = Duration(milliseconds: 180);
const defaultIosMagnifierExitAnimationDuration = Duration(milliseconds: 150);
const defaultIosMagnifierAnimationCurve = Curves.easeInOut;
const defaultIosMagnifierSize = Size(133, 96);
28 changes: 14 additions & 14 deletions super_editor/lib/src/infrastructure/platforms/ios/magnifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,33 +112,33 @@ class _IOSFollowingMagnifierState extends State<IOSFollowingMagnifier> with Sing
animation: _animationController,
builder: (context, child) {
final percentage = _animationController.value;
final devicePixelRatio = MediaQuery.devicePixelRatioOf(context);

return Follower.withOffset(
link: widget.leaderLink,
// Center-align the magnifier with the focal point, so when the animation starts
// the magnifier is displayed in the same position as the focal point.
leaderAnchor: Alignment.center,
followerAnchor: Alignment.topLeft,
followerAnchor: Alignment.center,
offset: Offset(
widget.offsetFromFocalPoint.dx,
widget.offsetFromFocalPoint.dx * devicePixelRatio,
// Animate the magnfier up on entrance and down on exit.
widget.offsetFromFocalPoint.dy * percentage,
widget.offsetFromFocalPoint.dy * devicePixelRatio * percentage,
),
// Theoretically, we should be able to use a leaderAnchor and followerAnchor of "center"
// and avoid the following FractionalTranslation. However, when centering the follower,
// we don't get the expect focal point within the magnified area. It's off-center. I'm not
// sure why that happens, but using a followerAnchor of "topLeft" and then pulling back
// by 50% solve the problem.
// Translate the magnifier so it's displayed above the focal point
// when the animation ends.
child: FractionalTranslation(
translation: const Offset(-0.5, -0.5),
translation: Offset(0.0, -0.5 * percentage),
child: widget.magnifierBuilder(
context,
IosMagnifierViewModel(
// In theory, the offsetFromFocalPoint should either be `widget.offsetFromFocalPoint.dy` to match
// the actual offset, or it should be `widget.offsetFromFocalPoint.dy / magnificationLevel`. Neither
// of those align the focal point correctly. The following offset was found empirically to give the
// desired results.
// desired results. These values seem to work even with different pixel densities.
offsetFromFocalPoint: Offset(
widget.offsetFromFocalPoint.dx - 23,
(widget.offsetFromFocalPoint.dy + 140) * percentage,
-22 * percentage,
(-defaultIosMagnifierSize.height + 14) * percentage,
),
animationValue: _animationController.value,
animationDirection: _animationController.status,
Expand Down Expand Up @@ -189,8 +189,8 @@ class IOSRoundedRectangleMagnifyingGlass extends StatelessWidget {
Widget build(BuildContext context) {
final percent = defaultIosMagnifierAnimationCurve.transform(animationValue);

final height = lerpDouble(30, 96, percent)!;
final width = lerpDouble(4, 133, percent)!;
final height = lerpDouble(30, defaultIosMagnifierSize.height, percent)!;
final width = lerpDouble(4, defaultIosMagnifierSize.width, percent)!;
final size = Size(width, height);

final tintOpacity = 1.0 - Curves.easeIn.transform(animationValue);
Expand Down

0 comments on commit cb9ccf4

Please sign in to comment.