change: Click on background to clear selected events

This commit is contained in:
S1m 2022-01-03 16:12:09 +00:00 committed by Krille Fear
parent 5ab514cc6f
commit fd7bb7f46c
2 changed files with 159 additions and 141 deletions

View File

@ -682,6 +682,12 @@ class ChatController extends State<Chat> {
showEmojiPicker = false; showEmojiPicker = false;
}); });
void clearSingleSelectedEvent() {
if (selectedEvents.length <= 1) {
clearSelectedEvents();
}
}
void editSelectedEventAction() { void editSelectedEventAction() {
final client = currentRoomBundle.firstWhere( final client = currentRoomBundle.firstWhere(
(cl) => selectedEvents.first.senderId == cl.userID, (cl) => selectedEvents.first.senderId == cl.userID,

View File

@ -188,6 +188,8 @@ class ChatView extends StatelessWidget {
children: <Widget>[ children: <Widget>[
TombstoneDisplay(controller), TombstoneDisplay(controller),
Expanded( Expanded(
child: GestureDetector(
onTap: controller.clearSingleSelectedEvent,
child: FutureBuilder<bool>( child: FutureBuilder<bool>(
future: controller.getTimeline(), future: controller.getTimeline(),
builder: (BuildContext context, snapshot) { builder: (BuildContext context, snapshot) {
@ -224,38 +226,46 @@ class ChatView extends StatelessWidget {
controller: controller.scrollController, controller: controller.scrollController,
keyboardDismissBehavior: PlatformInfos.isIOS keyboardDismissBehavior: PlatformInfos.isIOS
? ScrollViewKeyboardDismissBehavior.onDrag ? ScrollViewKeyboardDismissBehavior.onDrag
: ScrollViewKeyboardDismissBehavior.manual, : ScrollViewKeyboardDismissBehavior
.manual,
childrenDelegate: SliverChildBuilderDelegate( childrenDelegate: SliverChildBuilderDelegate(
(BuildContext context, int i) { (BuildContext context, int i) {
return i == return i ==
controller.filteredEvents.length + 1 controller.filteredEvents.length +
? controller.timeline.isRequestingHistory 1
? controller
.timeline.isRequestingHistory
? const Center( ? const Center(
child: CircularProgressIndicator child:
.adaptive(strokeWidth: 2), CircularProgressIndicator
.adaptive(
strokeWidth: 2),
) )
: controller.canLoadMore : controller.canLoadMore
? Center( ? Center(
child: OutlinedButton( child: OutlinedButton(
style: OutlinedButton style: OutlinedButton
.styleFrom( .styleFrom(
backgroundColor: Theme.of( backgroundColor: Theme
context) .of(context)
.scaffoldBackgroundColor, .scaffoldBackgroundColor,
), ),
onPressed: controller onPressed: controller
.requestHistory, .requestHistory,
child: Text(L10n.of(context) child: Text(
L10n.of(context)
.loadMore), .loadMore),
), ),
) )
: Container() : Container()
: i == 0 : i == 0
? Column( ? Column(
mainAxisSize: MainAxisSize.min, mainAxisSize:
MainAxisSize.min,
children: [ children: [
SeenByRow(controller), SeenByRow(controller),
TypingIndicators(controller), TypingIndicators(
controller),
], ],
) )
: AutoScrollTag( : AutoScrollTag(
@ -263,30 +273,31 @@ class ChatView extends StatelessWidget {
.filteredEvents[i - 1] .filteredEvents[i - 1]
.eventId), .eventId),
index: i - 1, index: i - 1,
controller: controller: controller
controller.scrollController, .scrollController,
child: Swipeable( child: Swipeable(
key: ValueKey(controller key: ValueKey(controller
.filteredEvents[i - 1] .filteredEvents[i - 1]
.eventId), .eventId),
background: const Padding( background: const Padding(
padding: EdgeInsets.symmetric( padding:
EdgeInsets.symmetric(
horizontal: 12.0), horizontal: 12.0),
child: Center( child: Center(
child: Icon( child: Icon(Icons
Icons.reply_outlined), .reply_outlined),
), ),
), ),
direction: direction: SwipeDirection
SwipeDirection.endToStart, .endToStart,
onSwipe: (direction) => onSwipe: (direction) =>
controller.replyAction( controller.replyAction(
replyTo: controller replyTo: controller
.filteredEvents[ .filteredEvents[
i - 1]), i - 1]),
child: Message( child: Message(
controller controller.filteredEvents[
.filteredEvents[i - 1], i - 1],
onInfoTab: controller onInfoTab: controller
.showEventInfo, .showEventInfo,
onAvatarTab: (Event event) => onAvatarTab: (Event event) =>
@ -294,7 +305,8 @@ class ChatView extends StatelessWidget {
context: context, context: context,
builder: (c) => builder: (c) =>
UserBottomSheet( UserBottomSheet(
user: event.sender, user: event
.sender,
outerContext: outerContext:
context, context,
onMention: () => controller onMention: () => controller
@ -303,22 +315,22 @@ class ChatView extends StatelessWidget {
'${event.sender.mention} ', '${event.sender.mention} ',
), ),
), ),
unfold: controller.unfold, unfold:
controller.unfold,
onSelect: controller onSelect: controller
.onSelectMessage, .onSelectMessage,
scrollToEventId: scrollToEventId:
(String eventId) => (String eventId) =>
controller.scrollToEventId( controller
.scrollToEventId(
eventId), eventId),
longPressSelect: controller longPressSelect:
.selectedEvents.isEmpty, controller
.selectedEvents
.isEmpty,
selected: controller selected: controller
.selectedEvents .selectedEvents
.any((e) => .any((e) => e.eventId == controller.filteredEvents[i - 1].eventId),
e.eventId ==
controller
.filteredEvents[i - 1]
.eventId),
timeline: controller.timeline, timeline: controller.timeline,
nextEvent: i < controller.filteredEvents.length ? controller.filteredEvents[i] : null), nextEvent: i < controller.filteredEvents.length ? controller.filteredEvents[i] : null),
), ),
@ -332,7 +344,7 @@ class ChatView extends StatelessWidget {
), ),
); );
}, },
), )),
), ),
if (controller.room.canSendDefaultMessages && if (controller.room.canSendDefaultMessages &&
controller.room.membership == Membership.join) controller.room.membership == Membership.join)