Skip to content

Commit

Permalink
add isReplyEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
lcsvcn committed Nov 19, 2024
1 parent fcd7f1a commit 46bb51e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
6 changes: 5 additions & 1 deletion lib/src/widgets/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ChatView extends StatefulWidget {
this.replyMessageBuilder,
this.replySuggestionsConfig,
this.scrollToBottomButtonConfig,
this.isReplyEnabled = true,
}) : chatBackgroundConfig = chatBackgroundConfig ?? const ChatBackgroundConfiguration(),
chatViewStateConfig = chatViewStateConfig ?? const ChatViewStateConfiguration(),
super(key: key);
Expand Down Expand Up @@ -148,6 +149,9 @@ class ChatView extends StatefulWidget {
/// Provides a configuration for scroll to bottom button config
final ScrollToBottomButtonConfig? scrollToBottomButtonConfig;

/// Determines if the reply feature is enabled.
final bool isReplyEnabled;

static void closeReplyMessageView(BuildContext context) {
final state = context.findAncestorStateOfType<_ChatViewState>();
if (state == null) return;
Expand Down Expand Up @@ -259,7 +263,7 @@ class _ChatViewState extends State<ChatView> with SingleTickerProviderStateMixin
);
},
),
if (featureActiveConfig.enableTextField)
if (featureActiveConfig.enableTextField && widget.isReplyEnabled)
SendMessageWidget(
key: _sendMessageKey,
sendMessageBuilder: widget.sendMessageBuilder,
Expand Down
14 changes: 10 additions & 4 deletions lib/src/widgets/reply_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ReplyIcon extends StatelessWidget {
Key? key,
required this.animationValue,
this.replyIconSize = 25,
this.isReplyEnabled = true,
}) : super(key: key);

/// Represents scale animation value of icon when user swipes for reply.
Expand All @@ -35,8 +36,15 @@ class ReplyIcon extends StatelessWidget {
/// Allow user to set color of icon which is appeared when user swipes for reply.
final double replyIconSize;

/// Determines if the reply feature is enabled.
final bool isReplyEnabled;

@override
Widget build(BuildContext context) {
if (!isReplyEnabled) {
return const SizedBox.shrink();
}

final swipeToReplyConfig = context.chatListConfig.swipeToReplyConfig;
return Stack(
alignment: Alignment.center,
Expand All @@ -45,8 +53,7 @@ class ReplyIcon extends StatelessWidget {
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(replyIconSize),
color: animationValue >= 1.0
? swipeToReplyConfig?.replyIconBackgroundColor ??
Colors.grey.shade300
? swipeToReplyConfig?.replyIconBackgroundColor ?? Colors.grey.shade300
: Colors.transparent,
),
height: replyIconSize,
Expand All @@ -55,8 +62,7 @@ class ReplyIcon extends StatelessWidget {
value: animationValue,
backgroundColor: Colors.transparent,
strokeWidth: 1.5,
color: swipeToReplyConfig?.replyIconProgressRingColor ??
Colors.grey.shade300,
color: swipeToReplyConfig?.replyIconProgressRingColor ?? Colors.grey.shade300,
),
),
Transform.scale(
Expand Down
12 changes: 4 additions & 8 deletions lib/src/widgets/swipe_to_reply.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SwipeToReply extends StatefulWidget {
required this.onSwipe,
required this.child,
this.isMessageByCurrentUser = true,
this.isReplyEnabled = true,
}) : super(key: key);

/// Provides callback when user swipes chat bubble from left side.
Expand Down Expand Up @@ -65,8 +66,7 @@ class _SwipeToReplyState extends State<SwipeToReply> {
return !(chatViewIW?.featureActiveConfig.enableSwipeToReply ?? true)
? widget.child
: GestureDetector(
onHorizontalDragStart: (details) =>
initialTouchPoint = details.globalPosition.dx,
onHorizontalDragStart: (details) => initialTouchPoint = details.globalPosition.dx,
onHorizontalDragEnd: (details) => setState(
() {
paddingValue = 0;
Expand All @@ -75,16 +75,12 @@ class _SwipeToReplyState extends State<SwipeToReply> {
),
onHorizontalDragUpdate: _onHorizontalDragUpdate,
child: Stack(
alignment: isMessageByCurrentUser
? Alignment.centerRight
: Alignment.centerLeft,
alignment: isMessageByCurrentUser ? Alignment.centerRight : Alignment.centerLeft,
fit: StackFit.passthrough,
children: [
ReplyIcon(
replyIconSize: replyIconSize,
animationValue: paddingValue > replyIconSize
? (paddingValue) / (paddingLimit)
: 0.0,
animationValue: paddingValue > replyIconSize ? (paddingValue) / (paddingLimit) : 0.0,
),
Padding(
padding: EdgeInsets.only(
Expand Down

0 comments on commit 46bb51e

Please sign in to comment.