chore: improve floating mobile toolbar animation for iOS (#5309)

This commit is contained in:
Richard Shiue 2024-05-13 14:58:28 +08:00 committed by GitHub
parent 39f8c47758
commit 38fa9f7942
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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';
@ -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,
@ -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 [];
}
}
}