@@ -10,7 +10,7 @@ import { useTranslationContext } from '../../../../contexts/translationContext/T
1010import { Mic } from '../../../../icons/Mic' ;
1111import { AudioRecordingReturnType , NativeHandlers } from '../../../../native' ;
1212
13- type AudioRecordingButtonPropsWithContext = Pick <
13+ type AudioRecordingButtonProps = Pick <
1414 MessageInputContextValue ,
1515 'asyncMessagesMinimumPressDuration'
1616> & {
@@ -40,16 +40,24 @@ type AudioRecordingButtonPropsWithContext = Pick<
4040 startVoiceRecording ?: ( ) => Promise < void > ;
4141} ;
4242
43- export const AudioRecordingButtonWithContext = ( props : AudioRecordingButtonPropsWithContext ) => {
43+ /**
44+ * Component to display the mic button on the Message Input.
45+ */
46+ export const AudioRecordingButton = ( props : AudioRecordingButtonProps ) => {
4447 const {
45- asyncMessagesMinimumPressDuration,
48+ asyncMessagesMinimumPressDuration : propAsyncMessagesMinimumPressDuration ,
4649 buttonSize,
4750 handleLongPress,
4851 handlePress,
4952 permissionsGranted,
5053 recording,
5154 startVoiceRecording,
5255 } = props ;
56+ const { asyncMessagesMinimumPressDuration : contextAsyncMessagesMinimumPressDuration } =
57+ useMessageInputContext ( ) ;
58+
59+ const asyncMessagesMinimumPressDuration =
60+ propAsyncMessagesMinimumPressDuration || contextAsyncMessagesMinimumPressDuration ;
5361
5462 const {
5563 theme : {
@@ -116,51 +124,6 @@ export const AudioRecordingButtonWithContext = (props: AudioRecordingButtonProps
116124 ) ;
117125} ;
118126
119- const areEqual = (
120- prevProps : AudioRecordingButtonPropsWithContext ,
121- nextProps : AudioRecordingButtonPropsWithContext ,
122- ) => {
123- const {
124- asyncMessagesMinimumPressDuration : prevAsyncMessagesMinimumPressDuration ,
125- recording : prevRecording ,
126- } = prevProps ;
127- const {
128- asyncMessagesMinimumPressDuration : nextAsyncMessagesMinimumPressDuration ,
129- recording : nextRecording ,
130- } = nextProps ;
131-
132- const asyncMessagesMinimumPressDurationEqual =
133- prevAsyncMessagesMinimumPressDuration === nextAsyncMessagesMinimumPressDuration ;
134- if ( ! asyncMessagesMinimumPressDurationEqual ) {
135- return false ;
136- }
137-
138- const recordingEqual = prevRecording === nextRecording ;
139- if ( ! recordingEqual ) {
140- return false ;
141- }
142-
143- return true ;
144- } ;
145-
146- const MemoizedAudioRecordingButton = React . memo (
147- AudioRecordingButtonWithContext ,
148- areEqual ,
149- ) as typeof AudioRecordingButtonWithContext ;
150-
151- export type AudioRecordingButtonProps = Partial < AudioRecordingButtonPropsWithContext > & {
152- recording : AudioRecordingReturnType ;
153- } ;
154-
155- /**
156- * Component to display the mic button on the Message Input.
157- */
158- export const AudioRecordingButton = ( props : AudioRecordingButtonProps ) => {
159- const { asyncMessagesMinimumPressDuration } = useMessageInputContext ( ) ;
160-
161- return < MemoizedAudioRecordingButton { ...{ asyncMessagesMinimumPressDuration } } { ...props } /> ;
162- } ;
163-
164127const styles = StyleSheet . create ( {
165128 container : {
166129 alignItems : 'center' ,
0 commit comments