Skip to content

Commit

Permalink
chore: improve floating mobile toolbar animation for iOS (#5309)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardshiue committed May 13, 2024
1 parent 39f8c47 commit 38fa9f7
Showing 1 changed file with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
Expand Down Expand Up @@ -100,14 +102,7 @@ class CustomMobileFloatingToolbar extends StatelessWidget {
Widget build(BuildContext context) {
return Animate(
autoPlay: true,
effects: [
const FadeEffect(duration: SelectionOverlay.fadeDuration),
MoveEffect(
curve: Curves.easeOutCubic,
begin: const Offset(0, 16),
duration: 100.milliseconds,
),
],
effects: _getEffects(context),
child: AdaptiveTextSelectionToolbar.buttonItems(
buttonItems: buildMobileFloatingToolbarItems(
editorState,
Expand All @@ -120,4 +115,32 @@ class CustomMobileFloatingToolbar extends StatelessWidget {
),
);
}

List<Effect> _getEffects(BuildContext context) {
if (Platform.isIOS) {
final Size(:width, :height) = MediaQuery.of(context).size;
final alignmentX = (anchor.dx - width / 2) / (width / 2);
final alignmentY = (anchor.dy - height / 2) / (height / 2);
return [
ScaleEffect(
curve: Curves.easeInOut,
alignment: Alignment(alignmentX, alignmentY),
duration: 250.milliseconds,
),
];
} else if (Platform.isAndroid) {
return [
const FadeEffect(
duration: SelectionOverlay.fadeDuration,
),
MoveEffect(
curve: Curves.easeOutCubic,
begin: const Offset(0, 16),
duration: 100.milliseconds,
),
];
} else {
return [];
}
}
}

0 comments on commit 38fa9f7

Please sign in to comment.