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' ;
33
4- import {
5- MessageInputContextValue ,
6- useMessageInputContext ,
7- } from '../../contexts/messageInputContext/MessageInputContext ' ;
4+ import { MessageComposerState } from 'stream-chat' ;
5+
6+ import { ChannelContextValue } from '../../contexts/channelContext/ChannelContext' ;
7+ import { useMessageComposer } from '../../contexts/messageInputContext/hooks/useMessageComposer ' ;
88import { useTheme } from '../../contexts/themeContext/ThemeContext' ;
99import { ThreadContextValue , useThreadContext } from '../../contexts/threadContext/ThreadContext' ;
1010import {
1111 TranslationContextValue ,
1212 useTranslationContext ,
1313} from '../../contexts/translationContext/TranslationContext' ;
14+ import { useStateStore } from '../../hooks/useStateStore' ;
1415import { Check } from '../../icons' ;
1516
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- } ,
17+ const stateSelector = ( state : MessageComposerState ) => ( {
18+ showReplyInChannel : state . showReplyInChannel ,
3719} ) ;
3820
3921export type ShowThreadMessageInChannelButtonWithContextProps = Pick <
40- MessageInputContextValue ,
41- 'sendThreadMessageInChannel' | 'setSendThreadMessageInChannel '
22+ ThreadContextValue ,
23+ 'allowThreadMessagesInChannel '
4224> &
43- Pick < ThreadContextValue , 'allowThreadMessagesInChannel' > &
44- Pick < TranslationContextValue , 't' > & {
45- threadList ?: boolean ;
46- } ;
25+ Pick < TranslationContextValue , 't' > & { threadList ?: ChannelContextValue [ 'threadList' ] } ;
4726
4827export const ShowThreadMessageInChannelButtonWithContext = (
4928 props : ShowThreadMessageInChannelButtonWithContextProps ,
5029) => {
51- const {
52- allowThreadMessagesInChannel,
53- sendThreadMessageInChannel,
54- setSendThreadMessageInChannel,
55- t,
56- threadList,
57- } = props ;
30+ const { allowThreadMessagesInChannel, t, threadList } = props ;
31+ const messageComposer = useMessageComposer ( ) ;
32+ const { showReplyInChannel } = useStateStore ( messageComposer . state , stateSelector ) ;
5833
5934 const {
6035 theme : {
@@ -72,20 +47,22 @@ export const ShowThreadMessageInChannelButtonWithContext = (
7247 } ,
7348 } = useTheme ( ) ;
7449
50+ const onPressHandler = useCallback ( ( ) => {
51+ messageComposer . toggleShowReplyInChannel ( ) ;
52+ } , [ messageComposer ] ) ;
53+
7554 if ( ! threadList || ! allowThreadMessagesInChannel ) {
7655 return null ;
7756 }
7857
7958 return (
8059 < View style = { [ styles . container , container ] } testID = 'show-thread-message-in-channel-button' >
81- < TouchableOpacity
82- onPress = { ( ) => setSendThreadMessageInChannel ( ( prevSendInChannel ) => ! prevSendInChannel ) }
83- >
60+ < Pressable onPress = { onPressHandler } style = { ( { pressed } ) => ( { opacity : pressed ? 0.8 : 1 } ) } >
8461 < View style = { [ styles . innerContainer , innerContainer ] } >
8562 < View
8663 style = { [
8764 styles . checkBox ,
88- sendThreadMessageInChannel
65+ showReplyInChannel
8966 ? {
9067 backgroundColor : accent_blue ,
9168 borderColor : accent_blue ,
@@ -94,15 +71,13 @@ export const ShowThreadMessageInChannelButtonWithContext = (
9471 : { borderColor : grey , ...checkBoxInactive } ,
9572 ] }
9673 >
97- { sendThreadMessageInChannel && (
98- < Check height = { 16 } pathFill = { white } width = { 16 } { ...check } />
99- ) }
74+ { showReplyInChannel && < Check height = { 16 } pathFill = { white } width = { 16 } { ...check } /> }
10075 </ View >
10176 < Text style = { [ styles . text , { color : grey } , text ] } >
10277 { t < string > ( 'Also send to channel' ) }
10378 </ Text >
10479 </ View >
105- </ TouchableOpacity >
80+ </ Pressable >
10681 </ View >
10782 ) ;
10883} ;
@@ -113,13 +88,11 @@ const areEqual = (
11388) => {
11489 const {
11590 allowThreadMessagesInChannel : prevAllowThreadMessagesInChannel ,
116- sendThreadMessageInChannel : prevSendThreadMessageInChannel ,
11791 t : prevT ,
11892 threadList : prevThreadList ,
11993 } = prevProps ;
12094 const {
12195 allowThreadMessagesInChannel : nextAllowThreadMessagesInChannel ,
122- sendThreadMessageInChannel : nexSendThreadMessageInChannel ,
12396 t : nextT ,
12497 threadList : nextThreadList ,
12598 } = nextProps ;
@@ -129,12 +102,6 @@ const areEqual = (
129102 return false ;
130103 }
131104
132- const sendThreadMessageInChannelEqual =
133- prevSendThreadMessageInChannel === nexSendThreadMessageInChannel ;
134- if ( ! sendThreadMessageInChannelEqual ) {
135- return false ;
136- }
137-
138105 const threadListEqual = prevThreadList === nextThreadList ;
139106 if ( ! threadListEqual ) {
140107 return false ;
@@ -160,14 +127,11 @@ export type ShowThreadMessageInChannelButtonProps =
160127export const ShowThreadMessageInChannelButton = ( props : ShowThreadMessageInChannelButtonProps ) => {
161128 const { t } = useTranslationContext ( ) ;
162129 const { allowThreadMessagesInChannel } = useThreadContext ( ) ;
163- const { sendThreadMessageInChannel, setSendThreadMessageInChannel } = useMessageInputContext ( ) ;
164130
165131 return (
166132 < MemoizedShowThreadMessageInChannelButton
167133 { ...{
168134 allowThreadMessagesInChannel,
169- sendThreadMessageInChannel,
170- setSendThreadMessageInChannel,
171135 t,
172136 } }
173137 { ...props }
@@ -177,3 +141,26 @@ export const ShowThreadMessageInChannelButton = (props: ShowThreadMessageInChann
177141
178142ShowThreadMessageInChannelButton . displayName =
179143 'ShowThreadMessageInChannelButton{messageInput{showThreadMessageInChannelButton}}' ;
144+
145+ const styles = StyleSheet . create ( {
146+ checkBox : {
147+ alignItems : 'center' ,
148+ borderRadius : 3 ,
149+ borderWidth : 2 ,
150+ height : 16 ,
151+ justifyContent : 'center' ,
152+ width : 16 ,
153+ } ,
154+ container : {
155+ flexDirection : 'row' ,
156+ marginHorizontal : 2 ,
157+ marginTop : 8 ,
158+ } ,
159+ innerContainer : {
160+ flexDirection : 'row' ,
161+ } ,
162+ text : {
163+ fontSize : 13 ,
164+ marginLeft : 12 ,
165+ } ,
166+ } ) ;
0 commit comments