Skip to content

Commit

Permalink
TW-731: support copy/paste image for ios
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn committed Oct 11, 2023
1 parent 0de1d68 commit 031daee
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
4 changes: 3 additions & 1 deletion assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2764,5 +2764,7 @@
"paste": "Paste",
"cut": "Cut",
"pasteImageFailed": "Paste image failed",
"copyImageFailed": "Copy image failed"
"copyImageFailed": "Copy image failed",
"fileFormatNotSupported": "File format not supported",
"copyImageSuccess": "Copy image success"
}
10 changes: 8 additions & 2 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -787,15 +787,21 @@ class ChatController extends State<Chat>
);
if (event.messageType == MessageTypes.Image) {
if (matrixFile.filePath != null) {
Clipboard.instance.copyImageAsStream(
await Clipboard.instance.copyImageAsStream(
File(matrixFile.filePath!),
mimeType: event.mimeType,
);
if (!PlatformInfos.isAndroid) {
TwakeSnackBar.show(context, L10n.of(context)!.copyImageSuccess);
}
} else if (matrixFile.bytes != null) {
Clipboard.instance.copyImageAsBytes(
await Clipboard.instance.copyImageAsBytes(
matrixFile.bytes!,
mimeType: event.mimeType,
);
if (!PlatformInfos.isAndroid) {
TwakeSnackBar.show(context, L10n.of(context)!.copyImageSuccess);
}
} else {
TwakeSnackBar.show(context, L10n.of(context)!.copyImageFailed);
Logs().e(
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat/input_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ class InputBar extends StatelessWidget with PasteImageMixin {
// FIXME: need to handle the case when in draft chat
return;
}

await Clipboard.instance.initReader();
if (await Clipboard.instance
.isReadableImageFormat()) {
await pasteImage(context, room!);
Expand Down
26 changes: 14 additions & 12 deletions lib/pages/chat/send_file_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:fluffychat/presentation/extensions/send_file_web_extension.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:flutter/material.dart';

import 'package:flutter_gen/gen_l10n/l10n.dart';
Expand Down Expand Up @@ -43,18 +45,18 @@ class SendFileDialogState extends State<SendFileDialog> {
}
// ignore: unused_local_variable
final scaffoldMessenger = ScaffoldMessenger.of(context);
// widget.room
// .sendFileEvent(
// file,
// thumbnail: thumbnail,
// shrinkImageMaxDimension: origImage ? null : 1600,
// )
// .catchError((e) {
// scaffoldMessenger.showSnackBar(
// SnackBar(content: Text((e as Object).toLocalizedString(context))),
// );
// return null;
// });
widget.room
.sendFileOnWebEvent(
file,
thumbnail: thumbnail,
shrinkImageMaxDimension: origImage ? null : 1600,
)
.catchError((e) {
scaffoldMessenger.showSnackBar(
SnackBar(content: Text((e as Object).toLocalizedString(context))),
);
return null;
});
}
Navigator.of(context, rootNavigator: false).pop();

Expand Down
1 change: 1 addition & 0 deletions lib/presentation/mixins/paste_image_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mixin PasteImageMixin {
Future<void> pasteImage(BuildContext context, Room room) async {
await Clipboard.instance.initReader();
if (!(await Clipboard.instance.isReadableImageFormat())) {
TwakeSnackBar.show(context, L10n.of(context)!.fileFormatNotSupported);
Logs().e('PasteImageMixin::pasteImage(): not readable image format');
return;
}
Expand Down

0 comments on commit 031daee

Please sign in to comment.