1- import React from 'react' ;
2- import { StyleSheet , Text , TouchableOpacity , View } from 'react-native' ;
1+ import React , { useCallback } from 'react' ;
2+ import { Pressable , StyleSheet , Text , View } from 'react-native' ;
3+
4+ import { MessageComposerState } from 'stream-chat' ;
35
46import {
5- MessageInputContextValue ,
6- useMessageInputContext ,
7- } from '../../contexts/messageInputContext/MessageInputContext' ;
7+ ChannelContextValue ,
8+ useChannelContext ,
9+ } from '../../contexts/channelContext/ChannelContext' ;
10+ import { useMessageComposer } from '../../contexts/messageInputContext/hooks/useMessageComposer' ;
811import { useTheme } from '../../contexts/themeContext/ThemeContext' ;
912import { ThreadContextValue , useThreadContext } from '../../contexts/threadContext/ThreadContext' ;
1013import {
1114 TranslationContextValue ,
1215 useTranslationContext ,
1316} from '../../contexts/translationContext/TranslationContext' ;
17+ import { useStateStore } from '../../hooks/useStateStore' ;
1418import { Check } from '../../icons' ;
1519
16- const styles = StyleSheet . create ( {
17- checkBox : {
18- alignItems : 'center' ,
19- borderRadius : 3 ,
20- borderWidth : 2 ,
21- height : 16 ,
22- justifyContent : 'center' ,
23- width : 16 ,
24- } ,
25- container : {
26- flexDirection : 'row' ,
27- marginHorizontal : 2 ,
28- marginTop : 8 ,
29- } ,
30- innerContainer : {
31- flexDirection : 'row' ,
32- } ,
33- text : {
34- fontSize : 13 ,
35- marginLeft : 12 ,
36- } ,
20+ const stateSelector = ( state : MessageComposerState ) => ( {
21+ showReplyInChannel : state . showReplyInChannel ,
3722} ) ;
3823
3924export type ShowThreadMessageInChannelButtonWithContextProps = Pick <
40- MessageInputContextValue ,
41- 'sendThreadMessageInChannel' | 'setSendThreadMessageInChannel '
25+ ThreadContextValue ,
26+ 'allowThreadMessagesInChannel '
4227> &
43- Pick < ThreadContextValue , 'allowThreadMessagesInChannel' > &
44- Pick < TranslationContextValue , 't' > & {
45- threadList ?: boolean ;
46- } ;
28+ Pick < TranslationContextValue , 't' > &
29+ Pick < ChannelContextValue , 'threadList' > ;
4730
4831export const ShowThreadMessageInChannelButtonWithContext = (
4932 props : ShowThreadMessageInChannelButtonWithContextProps ,
5033) => {
51- const {
52- allowThreadMessagesInChannel,
53- sendThreadMessageInChannel,
54- setSendThreadMessageInChannel,
55- t,
56- threadList,
57- } = props ;
34+ const { allowThreadMessagesInChannel, t, threadList } = props ;
35+ const messageComposer = useMessageComposer ( ) ;
36+ const { showReplyInChannel } = useStateStore ( messageComposer . state , stateSelector ) ;
5837
5938 const {
6039 theme : {
@@ -72,20 +51,22 @@ export const ShowThreadMessageInChannelButtonWithContext = (
7251 } ,
7352 } = useTheme ( ) ;
7453
54+ const onPressHandler = useCallback ( ( ) => {
55+ messageComposer . toggleShowReplyInChannel ( ) ;
56+ } , [ messageComposer ] ) ;
57+
7558 if ( ! threadList || ! allowThreadMessagesInChannel ) {
7659 return null ;
7760 }
7861
7962 return (
8063 < View style = { [ styles . container , container ] } testID = 'show-thread-message-in-channel-button' >
81- < TouchableOpacity
82- onPress = { ( ) => setSendThreadMessageInChannel ( ( prevSendInChannel ) => ! prevSendInChannel ) }
83- >
64+ < Pressable onPress = { onPressHandler } style = { ( { pressed } ) => ( { opacity : pressed ? 0.8 : 1 } ) } >
8465 < View style = { [ styles . innerContainer , innerContainer ] } >
8566 < View
8667 style = { [
8768 styles . checkBox ,
88- sendThreadMessageInChannel
69+ showReplyInChannel
8970 ? {
9071 backgroundColor : accent_blue ,
9172 borderColor : accent_blue ,
@@ -94,15 +75,13 @@ export const ShowThreadMessageInChannelButtonWithContext = (
9475 : { borderColor : grey , ...checkBoxInactive } ,
9576 ] }
9677 >
97- { sendThreadMessageInChannel && (
98- < Check height = { 16 } pathFill = { white } width = { 16 } { ...check } />
99- ) }
78+ { showReplyInChannel && < Check height = { 16 } pathFill = { white } width = { 16 } { ...check } /> }
10079 </ View >
10180 < Text style = { [ styles . text , { color : grey } , text ] } >
10281 { t < string > ( 'Also send to channel' ) }
10382 </ Text >
10483 </ View >
105- </ TouchableOpacity >
84+ </ Pressable >
10685 </ View >
10786 ) ;
10887} ;
@@ -113,13 +92,11 @@ const areEqual = (
11392) => {
11493 const {
11594 allowThreadMessagesInChannel : prevAllowThreadMessagesInChannel ,
116- sendThreadMessageInChannel : prevSendThreadMessageInChannel ,
11795 t : prevT ,
11896 threadList : prevThreadList ,
11997 } = prevProps ;
12098 const {
12199 allowThreadMessagesInChannel : nextAllowThreadMessagesInChannel ,
122- sendThreadMessageInChannel : nexSendThreadMessageInChannel ,
123100 t : nextT ,
124101 threadList : nextThreadList ,
125102 } = nextProps ;
@@ -129,12 +106,6 @@ const areEqual = (
129106 return false ;
130107 }
131108
132- const sendThreadMessageInChannelEqual =
133- prevSendThreadMessageInChannel === nexSendThreadMessageInChannel ;
134- if ( ! sendThreadMessageInChannelEqual ) {
135- return false ;
136- }
137-
138109 const threadListEqual = prevThreadList === nextThreadList ;
139110 if ( ! threadListEqual ) {
140111 return false ;
@@ -158,17 +129,16 @@ export type ShowThreadMessageInChannelButtonProps =
158129 Partial < ShowThreadMessageInChannelButtonWithContextProps > ;
159130
160131export const ShowThreadMessageInChannelButton = ( props : ShowThreadMessageInChannelButtonProps ) => {
132+ const { threadList } = useChannelContext ( ) ;
161133 const { t } = useTranslationContext ( ) ;
162134 const { allowThreadMessagesInChannel } = useThreadContext ( ) ;
163- const { sendThreadMessageInChannel, setSendThreadMessageInChannel } = useMessageInputContext ( ) ;
164135
165136 return (
166137 < MemoizedShowThreadMessageInChannelButton
167138 { ...{
168139 allowThreadMessagesInChannel,
169- sendThreadMessageInChannel,
170- setSendThreadMessageInChannel,
171140 t,
141+ threadList,
172142 } }
173143 { ...props }
174144 />
@@ -177,3 +147,26 @@ export const ShowThreadMessageInChannelButton = (props: ShowThreadMessageInChann
177147
178148ShowThreadMessageInChannelButton . displayName =
179149 'ShowThreadMessageInChannelButton{messageInput{showThreadMessageInChannelButton}}' ;
150+
151+ const styles = StyleSheet . create ( {
152+ checkBox : {
153+ alignItems : 'center' ,
154+ borderRadius : 3 ,
155+ borderWidth : 2 ,
156+ height : 16 ,
157+ justifyContent : 'center' ,
158+ width : 16 ,
159+ } ,
160+ container : {
161+ flexDirection : 'row' ,
162+ marginHorizontal : 2 ,
163+ marginTop : 8 ,
164+ } ,
165+ innerContainer : {
166+ flexDirection : 'row' ,
167+ } ,
168+ text : {
169+ fontSize : 13 ,
170+ marginLeft : 12 ,
171+ } ,
172+ } ) ;
0 commit comments