Skip to content

Commit

Permalink
TW-1369: Add Pinned Msg Bottom Sheet on Long press for Mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian KOUNE committed Feb 7, 2024
1 parent d5ed02d commit 35c1e06
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/pages/chat/chat_event_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class ChatEventList extends StatelessWidget {
path: 'rooms',
),
onSelect: controller.onSelectMessage,
onLongPress: controller.onSelectMessage,
selectMode: controller.selectMode,
scrollToEventId: (String eventId) =>
controller.scrollToEventId(eventId),
Expand Down
22 changes: 22 additions & 0 deletions lib/pages/chat/chat_pinned_events/pinned_messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:fluffychat/pages/chat/chat_view_style.dart';
import 'package:fluffychat/pages/chat/context_item_chat_action.dart';
import 'package:fluffychat/presentation/model/forward/forward_argument.dart';
import 'package:fluffychat/resource/image_paths.dart';
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
import 'package:fluffychat/utils/extension/build_context_extension.dart';
import 'package:fluffychat/utils/extension/value_notifier_extension.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
Expand Down Expand Up @@ -168,6 +169,14 @@ class PinnedMessagesController extends State<PinnedMessages>
);
}

void onLongPress(Event event) async {
if (PlatformInfos.isMobile) {
await _showBottomSheetMobile(event);
} else {
onSelectMessage(event);
}
}

void onSelectMessage(Event event) {
if (!event.redacted) {
if (selectedEvents.value.contains(event)) {
Expand All @@ -179,6 +188,19 @@ class PinnedMessagesController extends State<PinnedMessages>
}
}

Future<void> _showBottomSheetMobile(Event event) async {
await showAdaptiveBottomSheet(
context: context,
showDragHandle: true,
builder: (context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: pinnedMessagesActionsList(context, event),
);
},
);
}

void _initPinnedEvents() {
if (widget.pinnedEvents.isNotEmpty) {
eventsNotifier.value = widget.pinnedEvents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class PinnedMessagesScreen extends StatelessWidget {
controller.onHover(isHover, index, event),
selectMode: selectedEvents.isNotEmpty,
onSelect: controller.onSelectMessage,
onLongPress: controller.onLongPress,
selected: controller.isSelected(event),
menuChildren: (context) => controller
.pinnedMessagesActionsList(context, event),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ class PinnedMessagesStyle {

static const double paddingAllContextMenuItem = 12;
static const double heightContextMenuItem = 48;
}
}
3 changes: 3 additions & 0 deletions lib/pages/chat/events/message/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Message extends StatelessWidget {
final Event? nextEvent;
final String? markedUnreadLocation;
final void Function(Event)? onSelect;
final void Function(Event)? onLongPress;
final void Function(Event)? onAvatarTap;
final void Function(String)? scrollToEventId;
final void Function(SwipeDirection)? onSwipe;
Expand All @@ -53,6 +54,7 @@ class Message extends StatelessWidget {
this.previousEvent,
this.nextEvent,
this.onSelect,
this.onLongPress,
this.onAvatarTap,
this.onHover,
this.scrollToEventId,
Expand Down Expand Up @@ -125,6 +127,7 @@ class Message extends StatelessWidget {
event: event,
nextEvent: nextEvent,
onSelect: onSelect,
onLongPress: onLongPress,
scrollToEventId: scrollToEventId,
selected: selected,
selectMode: selectMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MessageContentWithTimestampBuilder extends StatelessWidget {
final Event event;
final Event? nextEvent;
final void Function(Event)? onSelect;
final void Function(Event)? onLongPress;
final void Function(String)? scrollToEventId;
final ValueNotifier<String?> isHoverNotifier;
final bool selected;
Expand All @@ -38,6 +39,7 @@ class MessageContentWithTimestampBuilder extends StatelessWidget {
required this.event,
this.nextEvent,
this.onSelect,
this.onLongPress,
this.scrollToEventId,
this.selected = false,
this.selectMode = true,
Expand Down Expand Up @@ -88,7 +90,7 @@ class MessageContentWithTimestampBuilder extends StatelessWidget {
child: MultiPlatformSelectionMode(
event: event,
isClickable: responsiveUtils.isMobileOrTablet(context),
onSelect: onSelect,
onLongPress: onLongPress,
child: Stack(
alignment: event.isOwnMessage
? AlignmentDirectional.bottomStart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MultiPlatformsMessageContainer extends StatelessWidget {
}

class MultiPlatformSelectionMode extends StatelessWidget {
final void Function(Event event)? onSelect;
final void Function(Event event)? onLongPress;

final Event event;

Expand All @@ -48,7 +48,7 @@ class MultiPlatformSelectionMode extends StatelessWidget {

const MultiPlatformSelectionMode({
super.key,
this.onSelect,
this.onLongPress,
this.isClickable = true,
required this.event,
required this.child,
Expand All @@ -61,7 +61,7 @@ class MultiPlatformSelectionMode extends StatelessWidget {
}

return GestureDetector(
onLongPress: () => onSelect?.call(event),
onLongPress: () => onLongPress?.call(event),
child: child,
);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/adaptive_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ Future<T?> showAdaptiveBottomSheet<T>({
required Widget Function(BuildContext) builder,
bool isDismissible = true,
bool isScrollControlled = false,
bool showDragHandle = false,
}) =>
showModalBottomSheet(
context: context,
showDragHandle: showDragHandle,
builder: builder,
useRootNavigator: !PlatformInfos.isMobile,
isDismissible: isDismissible,
Expand Down

0 comments on commit 35c1e06

Please sign in to comment.