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

TW-729,730: swipe to close page, swipe images and videos #739

Merged
merged 11 commits into from
Oct 5, 2023
Merged
14 changes: 6 additions & 8 deletions lib/config/go_routes/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -352,34 +352,32 @@ abstract class AppRoutes {
switch (extra.type) {
case ChatRouterInputArgumentType.draft:
if (extra.data is String?) {
return NoTransitionPage(
return CupertinoPage(
child: Chat(
roomId: state.pathParameters['roomid']!,
key: Key(state.pathParameters['roomid']!),
roomName: extra.data as String?,
),
);
}
return NoTransitionPage(
return CupertinoPage(
child: Chat(
roomId: state.pathParameters['roomid']!,
key: Key(state.pathParameters['roomid']!),
),
);
case ChatRouterInputArgumentType.share:
return defaultPageBuilder(
context,
Chat(
return CupertinoPage(
child: Chat(
roomId: state.pathParameters['roomid']!,
key: Key(state.pathParameters['roomid']!),
shareFile: extra.data as MatrixFile?,
),
);
}
}
return defaultPageBuilder(
context,
Chat(
return CupertinoPage(
child: Chat(
roomId: state.pathParameters['roomid']!,
key: Key(state.pathParameters['roomid']!),
),
Expand Down
6 changes: 5 additions & 1 deletion lib/pages/chat/events/event_video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ class EventVideoPlayerState extends State<EventVideoPlayer>
icon: Icons.play_arrow,
onTap: () {
if (path != null) {
playVideoAction(context, path!);
playVideoAction(
context,
path!,
eventId: widget.event.eventId,
);
}
},
);
Expand Down
6 changes: 5 additions & 1 deletion lib/pages/chat/events/message_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ class MessageContent extends StatelessWidget with PlayVideoActionMixin {
handleDownloadVideoEvent: (event) {
return controller.handleDownloadVideoEvent(
event: event,
playVideoAction: (path) => playVideoAction(context, path),
playVideoAction: (path) => playVideoAction(
context,
path,
eventId: event.eventId,
),
);
},
);
Expand Down
121 changes: 67 additions & 54 deletions lib/pages/chat/events/sending_image_info_widget.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'dart:io';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pages/chat/events/message_content_style.dart';
import 'package:fluffychat/pages/image_viewer/image_viewer.dart';
import 'package:fluffychat/presentation/model/file/display_image_info.dart';
import 'package:fluffychat/utils/interactive_viewer_gallery.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
import 'package:fluffychat/widgets/hero_page_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_blurhash/flutter_blurhash.dart';
import 'package:linagora_design_flutter/colors/linagora_ref_colors.dart';
Expand All @@ -28,15 +32,17 @@ class SendingImageInfoWidget extends StatelessWidget {

void _onTap(BuildContext context) async {
if (onTapPreview != null) {
await showGeneralDialog(
context: context,
useRootNavigator: false,
barrierDismissible: true,
barrierLabel:
MaterialLocalizations.of(context).modalBarrierDismissLabel,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (_, animationOne, animationTwo) =>
ImageViewer(event, filePath: matrixFile.filePath),
Navigator.of(context).push(
drminh2807 marked this conversation as resolved.
Show resolved Hide resolved
HeroPageRoute(
builder: (context) {
return InteractiveViewerGallery(
itemBuilder: ImageViewer(
event,
filePath: matrixFile.filePath,
),
);
},
),
);
}
}
Expand All @@ -48,55 +54,62 @@ class SendingImageInfoWidget extends StatelessWidget {
sendingFileProgressNotifier.value = 1;
}

return ValueListenableBuilder<double>(
key: ValueKey(event.eventId),
valueListenable: sendingFileProgressNotifier,
builder: (context, value, child) {
return Stack(
alignment: Alignment.center,
children: [
child!,
if (sendingFileProgressNotifier.value != 1) ...[
CircularProgressIndicator(
strokeWidth: 2,
color: LinagoraRefColors.material().primary[100],
),
Icon(
Icons.close,
color: LinagoraRefColors.material().primary[100],
),
]
],
);
},
child: InkWell(
onTap: () => _onTap(context),
child: ClipRRect(
borderRadius: BorderRadius.circular(12.0),
child: Stack(
return Hero(
tag: event.eventId,
child: ValueListenableBuilder<double>(
key: ValueKey(event.eventId),
valueListenable: sendingFileProgressNotifier,
builder: (context, value, child) {
return Stack(
alignment: Alignment.center,
children: [
if (displayImageInfo.hasBlur)
SizedBox(
width: MessageContentStyle.imageBubbleWidth(
displayImageInfo.size.width,
),
height: MessageContentStyle.imageBubbleHeight(
displayImageInfo.size.height,
),
child:
const BlurHash(hash: MessageContentStyle.defaultBlurHash),
child!,
if (sendingFileProgressNotifier.value != 1) ...[
CircularProgressIndicator(
strokeWidth: 2,
color: LinagoraRefColors.material().primary[100],
),
Icon(
Icons.close,
color: LinagoraRefColors.material().primary[100],
),
Image.file(
File(matrixFile.filePath!),
width: displayImageInfo.size.width,
height: displayImageInfo.size.height,
cacheHeight: displayImageInfo.size.height.toInt(),
cacheWidth: displayImageInfo.size.width.toInt(),
fit: BoxFit.cover,
filterQuality: FilterQuality.medium,
)
]
],
);
},
child: Material(
borderRadius: MessageContentStyle.borderRadiusBubble,
child: InkWell(
onTap: () => _onTap(context),
child: ClipRRect(
borderRadius: MessageContentStyle.borderRadiusBubble,
child: Stack(
alignment: Alignment.center,
children: [
if (displayImageInfo.hasBlur)
SizedBox(
width: MessageContentStyle.imageBubbleWidth(
displayImageInfo.size.width,
),
height: MessageContentStyle.imageBubbleHeight(
displayImageInfo.size.height,
),
child: BlurHash(
hash: event.blurHash ?? AppConfig.defaultImageBlurHash,
),
),
Image.file(
File(matrixFile.filePath!),
width: displayImageInfo.size.width,
height: displayImageInfo.size.height,
cacheHeight: displayImageInfo.size.height.toInt(),
cacheWidth: displayImageInfo.size.width.toInt(),
fit: BoxFit.cover,
filterQuality: FilterQuality.medium,
)
],
),
),
),
),
),
Expand Down
17 changes: 12 additions & 5 deletions lib/pages/chat/events/sending_video_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ class SendingVideoWidget extends StatelessWidget with PlayVideoActionMixin {
),
);
}),
child: VideoWidget(
imageHeight: displayImageInfo.size.height,
imageWidth: displayImageInfo.size.width,
matrixFile: matrixFile,
child: Hero(
tag: event.eventId,
child: VideoWidget(
imageHeight: displayImageInfo.size.height,
imageWidth: displayImageInfo.size.width,
matrixFile: matrixFile,
),
),
);
}
Expand All @@ -89,7 +92,11 @@ class SendingVideoWidget extends StatelessWidget with PlayVideoActionMixin {
if (matrixFile.filePath == null) {
return;
}
playVideoAction(context, matrixFile.filePath!);
playVideoAction(
context,
matrixFile.filePath!,
eventId: event.eventId,
);
}

void _checkSendingFileStatus() {
Expand Down
6 changes: 5 additions & 1 deletion lib/pages/chat_details/chat_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,11 @@ class ChatDetailsController extends State<ChatDetails>
Future<String> _handleDownloadAndPlayVideo(Event event) {
return handleDownloadVideoEvent(
event: event,
playVideoAction: (path) => playVideoAction(context, path),
playVideoAction: (path) => playVideoAction(
context,
path,
eventId: event.eventId,
),
);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/pages/forward/forward.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:fluffychat/pages/chat/send_file_dialog.dart';
import 'package:fluffychat/pages/forward/forward_view.dart';
import 'package:fluffychat/presentation/enum/chat_list/chat_list_enum.dart';
import 'package:fluffychat/presentation/extensions/client_extension.dart';
import 'package:fluffychat/utils/extension/navigator_state_extension.dart';
import 'package:fluffychat/presentation/model/pop_result_from_forward.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart';
Expand Down Expand Up @@ -107,7 +107,9 @@ class ForwardController extends State<Forward> {
switch (success.runtimeType) {
case ForwardMessageSuccess:
final dataOnSuccess = success as ForwardMessageSuccess;
Navigator.of(context).popAllDialogs();
if (Navigator.of(context).canPop()) {
Navigator.of(context).pop(const PopResultFromForward());
}
context.go('/rooms/${dataOnSuccess.room.id}');
break;
case ForwardMessageIsShareFileState:
Expand Down
6 changes: 5 additions & 1 deletion lib/pages/image_viewer/image_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:typed_data';

import 'package:fluffychat/pages/forward/forward.dart';
import 'package:fluffychat/pages/image_viewer/image_viewer_view.dart';
import 'package:fluffychat/presentation/model/pop_result_from_forward.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/matrix.dart';
Expand Down Expand Up @@ -46,12 +47,15 @@ class ImageViewerController extends State<ImageViewer> {
/// Forward this image to another room.
void forwardAction() async {
Matrix.of(context).shareContent = widget.event.content;
await showDialog(
final result = await showDialog(
context: context,
useSafeArea: false,
useRootNavigator: false,
builder: (c) => const Forward(),
);
if (result is PopResultFromForward) {
Navigator.of(context).pop<PopResultFromForward>();
}
}

void toggleAppbarPreview() {
Expand Down
11 changes: 11 additions & 0 deletions lib/pages/image_viewer/image_viewer_style.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/material.dart';

class ImageViewerStyle {
static const double minScaleInteractiveViewer = 1.0;
static const double maxScaleInteractiveViewer = 10.0;
static double? appBarHeight = PlatformInfos.isWeb ? 56 : null;
static EdgeInsetsGeometry paddingTopAppBar = EdgeInsetsDirectional.only(
top: PlatformInfos.isWeb ? 0 : 56,
);
}
Loading