Skip to content

Commit

Permalink
fix: 🐛 fixed y position of reaction popup
Browse files Browse the repository at this point in the history
  • Loading branch information
vatsaltanna committed Jun 30, 2024
1 parent 2f530e0 commit ed9a288
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 26 deletions.
27 changes: 7 additions & 20 deletions lib/src/widgets/chat_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';

import '../../chatview.dart';
import 'reaction_popup.dart';
import 'reply_popup_widget.dart';

class ChatListWidget extends StatefulWidget {
Expand Down Expand Up @@ -115,8 +114,6 @@ class ChatListWidget extends StatefulWidget {
class _ChatListWidgetState extends State<ChatListWidget>
with SingleTickerProviderStateMixin {
final ValueNotifier<bool> _isNextPageLoading = ValueNotifier<bool>(false);
ValueNotifier<bool> showPopUp = ValueNotifier(false);
final GlobalKey<ReactionPopupState> _reactionPopupKey = GlobalKey();

ChatController get chatController => widget.chatController;

Expand Down Expand Up @@ -181,7 +178,7 @@ class _ChatListWidgetState extends State<ChatListWidget>
),
Expanded(
child: ValueListenableBuilder<bool>(
valueListenable: showPopUp,
valueListenable: provide!.showPopUp,
builder: (_, showPopupValue, child) {
return Stack(
children: [
Expand All @@ -201,14 +198,12 @@ class _ChatListWidgetState extends State<ChatListWidget>
typeIndicatorConfig: widget.typeIndicatorConfig,
onChatBubbleLongPress: (yCoordinate, xCoordinate, message) {
if (featureActiveConfig?.enableReactionPopup ?? false) {
_reactionPopupKey.currentState?.refreshWidget(
provide?.reactionPopupKey.currentState?.refreshWidget(
message: message,
xCoordinate: xCoordinate,
yCoordinate: yCoordinate < 0
? -(yCoordinate) - 5
: yCoordinate,
yCoordinate: yCoordinate,
);
showPopUp.value = true;
provide?.showPopUp.value = true;
}
if (featureActiveConfig?.enableReplySnackBar ?? false) {
_showReplyPopup(
Expand All @@ -219,14 +214,7 @@ class _ChatListWidgetState extends State<ChatListWidget>
},
onChatListTap: _onChatListTap,
),
if (featureActiveConfig?.enableReactionPopup ?? false)
ReactionPopup(
key: _reactionPopupKey,
reactionPopupConfig: widget.reactionPopupConfig,
onTap: _onChatListTap,
showPopUp: showPopupValue,
emojiPickerSheetConfig: widget.emojiPickerSheetConfig,
),

],
);
},
Expand Down Expand Up @@ -284,7 +272,7 @@ class _ChatListWidgetState extends State<ChatListWidget>
onReplyTap: () {
widget.assignReplyMessage(message);
if (featureActiveConfig?.enableReactionPopup ?? false) {
showPopUp.value = false;
provide?.showPopUp.value = false;
}
ScaffoldMessenger.of(context).hideCurrentSnackBar();
if (replyPopup?.onReplyTap != null) {
Expand All @@ -304,7 +292,7 @@ class _ChatListWidgetState extends State<ChatListWidget>
if (!kIsWeb && (Platform.isIOS || Platform.isAndroid)) {
FocusScope.of(context).unfocus();
}
showPopUp.value = false;
provide?.showPopUp.value = false;
ScaffoldMessenger.of(context).hideCurrentSnackBar();
}

Expand All @@ -313,7 +301,6 @@ class _ChatListWidgetState extends State<ChatListWidget>
chatController.messageStreamController.close();
scrollController.dispose();
_isNextPageLoading.dispose();
showPopUp.dispose();
super.dispose();
}
}
39 changes: 38 additions & 1 deletion lib/src/widgets/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import 'dart:io';

import 'package:chatview/chatview.dart';
import 'package:chatview/src/extensions/extensions.dart';
import 'package:chatview/src/widgets/chat_list_widget.dart';
import 'package:chatview/src/widgets/chat_view_inherited_widget.dart';
import 'package:chatview/src/widgets/chatview_state_widget.dart';
import 'package:chatview/src/widgets/reaction_popup.dart';
import 'package:chatview/src/widgets/suggestions/suggestions_config_inherited_widget.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:timeago/timeago.dart';
import '../values/custom_time_messages.dart';
Expand Down Expand Up @@ -209,7 +213,16 @@ class _ChatViewState extends State<ChatView>
margin: chatBackgroundConfig.margin,
child: Column(
children: [
if (widget.appBar != null) widget.appBar!,
if (widget.appBar != null) ...{
if (context.provide?.appBarKey == null) ...{
KeyedSubtree(
key: context.provide!.appBarKey,
child: widget.appBar!,
)
} else ...{
widget.appBar!
}
},
Expanded(
child: Stack(
children: [
Expand Down Expand Up @@ -285,6 +298,20 @@ class _ChatViewState extends State<ChatView>
messageConfig: widget.messageConfig,
replyMessageBuilder: widget.replyMessageBuilder,
),
if (featureActiveConfig.enableReactionPopup)
ValueListenableBuilder<bool>(
valueListenable: context.provide!.showPopUp,
builder: (_, showPopupValue, child) {
return ReactionPopup(
key: context.provide!.reactionPopupKey,
reactionPopupConfig: widget.reactionPopupConfig,
onTap: () => _onChatListTap(context),
showPopUp: showPopupValue,
emojiPickerSheetConfig:
widget.emojiPickerSheetConfig,
);
},
),
],
),
),
Expand All @@ -296,6 +323,15 @@ class _ChatViewState extends State<ChatView>
);
}

void _onChatListTap(BuildContext context) {
widget.onChatListTap?.call();
if (!kIsWeb && (Platform.isIOS || Platform.isAndroid)) {
FocusScope.of(context).unfocus();
}
context.provide?.showPopUp.value = false;
ScaffoldMessenger.of(context).hideCurrentSnackBar();
}

void _onSendTap(
String message,
ReplyMessage replyMessage,
Expand All @@ -321,6 +357,7 @@ class _ChatViewState extends State<ChatView>
@override
void dispose() {
replyMessage.dispose();
provide?.showPopUp.dispose();
super.dispose();
}
}
5 changes: 5 additions & 0 deletions lib/src/widgets/chat_view_inherited_widget.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:chatview/src/widgets/reaction_popup.dart';
import 'package:flutter/material.dart';
import 'package:chatview/chatview.dart';

Expand All @@ -15,6 +16,10 @@ class ChatViewInheritedWidget extends InheritedWidget {
final ProfileCircleConfiguration? profileCircleConfiguration;
final ChatController chatController;
final GlobalKey chatTextFieldViewKey = GlobalKey();
final ValueNotifier<bool> showPopUp = ValueNotifier(false);
final GlobalKey<ReactionPopupState> reactionPopupKey = GlobalKey();
final GlobalKey appBarKey = GlobalKey();


static ChatViewInheritedWidget? of(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<ChatViewInheritedWidget>();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/message_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class _MessageViewState extends State<MessageView>
void _onLongPressStart(LongPressStartDetails details) async {
await _animationController?.forward();
widget.onLongPress(
details.globalPosition.dy - 120 - 64,
details.globalPosition.dy,
details.globalPosition.dx,
);
}
Expand Down
15 changes: 11 additions & 4 deletions lib/src/widgets/reaction_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,17 @@ class ReactionPopupState extends State<ReactionPopup>
required double xCoordinate,
required double yCoordinate,
}) {
setState(() {
_message = message;
_xCoordinate = xCoordinate;
_yCoordinate = yCoordinate;
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
final appBarSize =
(provide!.appBarKey.currentContext?.size?.height ?? 0);
final popupYPosition = yCoordinate -
(provide!.reactionPopupKey.currentContext?.size?.height ?? 0) -
appBarSize;
_message = message;
_xCoordinate = xCoordinate;
_yCoordinate = popupYPosition < appBarSize ? 0 : popupYPosition;
});
});
}

Expand Down

0 comments on commit ed9a288

Please sign in to comment.