From 00caaa719d8acb4c22ab515be4d3151ee698d1aa Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Sat, 27 Nov 2021 10:33:21 +0100 Subject: [PATCH] fix: ChatView safearea on iPad --- lib/pages/chat/chat_view.dart | 325 +++++++++++++++++----------------- 1 file changed, 165 insertions(+), 160 deletions(-) diff --git a/lib/pages/chat/chat_view.dart b/lib/pages/chat/chat_view.dart index 68a726e7..1dd83e9b 100644 --- a/lib/pages/chat/chat_view.dart +++ b/lib/pages/chat/chat_view.dart @@ -177,172 +177,177 @@ class ChatView extends StatelessWidget { height: double.infinity, fit: BoxFit.cover, ), - Column( - children: [ - TombstoneDisplay(controller), - Expanded( - child: FutureBuilder( - future: controller.getTimeline(), - builder: (BuildContext context, snapshot) { - if (snapshot.hasError) { - SentryController.captureException( - snapshot.error, - StackTrace.current, - ); - } - if (controller.timeline == null) { - return const Center( - child: CircularProgressIndicator.adaptive( - strokeWidth: 2), - ); - } + SafeArea( + child: Column( + children: [ + TombstoneDisplay(controller), + Expanded( + child: FutureBuilder( + future: controller.getTimeline(), + builder: (BuildContext context, snapshot) { + if (snapshot.hasError) { + SentryController.captureException( + snapshot.error, + StackTrace.current, + ); + } + if (controller.timeline == null) { + return const Center( + child: CircularProgressIndicator.adaptive( + strokeWidth: 2), + ); + } - // create a map of eventId --> index to greatly improve performance of - // ListView's findChildIndexCallback - final thisEventsKeyMap = {}; - for (var i = 0; - i < controller.filteredEvents.length; - i++) { - thisEventsKeyMap[ - controller.filteredEvents[i].eventId] = i; - } - return ListView.custom( - padding: EdgeInsets.only( - top: 16, - bottom: 4, - left: horizontalPadding, - right: horizontalPadding, - ), - reverse: true, - controller: controller.scrollController, - keyboardDismissBehavior: PlatformInfos.isIOS - ? ScrollViewKeyboardDismissBehavior.onDrag - : ScrollViewKeyboardDismissBehavior.manual, - childrenDelegate: SliverChildBuilderDelegate( - (BuildContext context, int i) { - return i == controller.filteredEvents.length + 1 - ? controller.timeline.isRequestingHistory - ? const Center( - child: CircularProgressIndicator - .adaptive(strokeWidth: 2), - ) - : controller.canLoadMore - ? Center( - child: OutlinedButton( - style: OutlinedButton.styleFrom( - backgroundColor: Theme.of( - context) - .scaffoldBackgroundColor, + // create a map of eventId --> index to greatly improve performance of + // ListView's findChildIndexCallback + final thisEventsKeyMap = {}; + for (var i = 0; + i < controller.filteredEvents.length; + i++) { + thisEventsKeyMap[ + controller.filteredEvents[i].eventId] = i; + } + return ListView.custom( + padding: EdgeInsets.only( + top: 16, + bottom: 4, + left: horizontalPadding, + right: horizontalPadding, + ), + reverse: true, + controller: controller.scrollController, + keyboardDismissBehavior: PlatformInfos.isIOS + ? ScrollViewKeyboardDismissBehavior.onDrag + : ScrollViewKeyboardDismissBehavior.manual, + childrenDelegate: SliverChildBuilderDelegate( + (BuildContext context, int i) { + return i == controller.filteredEvents.length + 1 + ? controller.timeline.isRequestingHistory + ? const Center( + child: CircularProgressIndicator + .adaptive(strokeWidth: 2), + ) + : controller.canLoadMore + ? Center( + child: OutlinedButton( + style: + OutlinedButton.styleFrom( + backgroundColor: Theme.of( + context) + .scaffoldBackgroundColor, + ), + onPressed: + controller.requestHistory, + child: Text(L10n.of(context) + .loadMore), ), - onPressed: - controller.requestHistory, - child: Text( - L10n.of(context).loadMore), - ), - ) - : Container() - : i == 0 - ? Column( - mainAxisSize: MainAxisSize.min, - children: [ - SeenByRow(controller), - TypingIndicators(controller), - ], - ) - : AutoScrollTag( - key: ValueKey(controller - .filteredEvents[i - 1].eventId), - index: i - 1, - controller: - controller.scrollController, - child: Swipeable( + ) + : Container() + : i == 0 + ? Column( + mainAxisSize: MainAxisSize.min, + children: [ + SeenByRow(controller), + TypingIndicators(controller), + ], + ) + : AutoScrollTag( key: ValueKey(controller .filteredEvents[i - 1].eventId), - background: const Padding( - padding: EdgeInsets.symmetric( - horizontal: 12.0), - child: Center( - child: - Icon(Icons.reply_outlined), + index: i - 1, + controller: + controller.scrollController, + child: Swipeable( + key: ValueKey(controller + .filteredEvents[i - 1] + .eventId), + background: const Padding( + padding: EdgeInsets.symmetric( + horizontal: 12.0), + child: Center( + child: Icon( + Icons.reply_outlined), + ), ), - ), - direction: - SwipeDirection.endToStart, - onSwipe: (direction) => - controller.replyAction( - replyTo: controller - .filteredEvents[i - 1]), - child: Message( - controller - .filteredEvents[i - 1], - onInfoTab: - controller.showEventInfo, - onAvatarTab: (Event event) => - showModalBottomSheet( - context: context, - builder: (c) => - UserBottomSheet( - user: event.sender, - outerContext: context, - onMention: () => controller - .sendController - .text += - '${event.sender.mention} ', + direction: + SwipeDirection.endToStart, + onSwipe: (direction) => + controller.replyAction( + replyTo: controller + .filteredEvents[ + i - 1]), + child: Message( + controller + .filteredEvents[i - 1], + onInfoTab: + controller.showEventInfo, + onAvatarTab: (Event event) => + showModalBottomSheet( + context: context, + builder: (c) => + UserBottomSheet( + user: event.sender, + outerContext: context, + onMention: () => controller + .sendController + .text += + '${event.sender.mention} ', + ), ), - ), - unfold: controller.unfold, - onSelect: - controller.onSelectMessage, - scrollToEventId: (String eventId) => - controller.scrollToEventId( - eventId), - longPressSelect: controller - .selectedEvents.isEmpty, - selected: controller.selectedEvents.any((e) => - e.eventId == - controller - .filteredEvents[i - 1] - .eventId), - timeline: controller.timeline, - nextEvent: - i < controller.filteredEvents.length - ? controller - .filteredEvents[i] - : null), - ), - ); - }, - childCount: controller.filteredEvents.length + 2, - findChildIndexCallback: (key) => controller - .findChildIndexCallback(key, thisEventsKeyMap), - ), - ); - }, - ), - ), - if (controller.room.canSendDefaultMessages && - controller.room.membership == Membership.join) - Container( - margin: EdgeInsets.only( - bottom: bottomSheetPadding, - left: bottomSheetPadding, - right: bottomSheetPadding, + unfold: controller.unfold, + onSelect: controller + .onSelectMessage, + scrollToEventId: (String eventId) => controller + .scrollToEventId(eventId), + longPressSelect: controller + .selectedEvents.isEmpty, + selected: controller.selectedEvents.any((e) => + e.eventId == + controller + .filteredEvents[i - 1] + .eventId), + timeline: controller.timeline, + nextEvent: i < + controller + .filteredEvents + .length + ? controller.filteredEvents[i] + : null), + ), + ); + }, + childCount: controller.filteredEvents.length + 2, + findChildIndexCallback: (key) => + controller.findChildIndexCallback( + key, thisEventsKeyMap), + ), + ); + }, ), - constraints: const BoxConstraints( - maxWidth: FluffyThemes.columnWidth * 2.5), - alignment: Alignment.center, - child: Material( - borderRadius: const BorderRadius.only( - bottomLeft: Radius.circular(AppConfig.borderRadius), - bottomRight: Radius.circular(AppConfig.borderRadius), + ), + if (controller.room.canSendDefaultMessages && + controller.room.membership == Membership.join) + Container( + margin: EdgeInsets.only( + bottom: bottomSheetPadding, + left: bottomSheetPadding, + right: bottomSheetPadding, ), - elevation: 6, - shadowColor: Theme.of(context) - .secondaryHeaderColor - .withAlpha(100), - clipBehavior: Clip.hardEdge, - color: Theme.of(context).appBarTheme.backgroundColor, - child: SafeArea( + constraints: const BoxConstraints( + maxWidth: FluffyThemes.columnWidth * 2.5), + alignment: Alignment.center, + child: Material( + borderRadius: const BorderRadius.only( + bottomLeft: Radius.circular(AppConfig.borderRadius), + bottomRight: + Radius.circular(AppConfig.borderRadius), + ), + elevation: 6, + shadowColor: Theme.of(context) + .secondaryHeaderColor + .withAlpha(100), + clipBehavior: Clip.hardEdge, + color: Theme.of(context).appBarTheme.backgroundColor, child: Column( mainAxisSize: MainAxisSize.min, children: [ @@ -355,8 +360,8 @@ class ChatView extends StatelessWidget { ), ), ), - ), - ], + ], + ), ), ], ),