Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve floating mobile toolbar animation for iOS #5309

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 [];
}
}
}