@@ -4,7 +4,7 @@ import { StyleSheet, Switch, Text, View } from 'react-native';
44import { ScrollView } from 'react-native-gesture-handler' ;
55import Animated , { LinearTransition , useSharedValue } from 'react-native-reanimated' ;
66
7- import { PollComposerState , VotingVisibility } from 'stream-chat' ;
7+ import { PollComposerState , StateStore , VotingVisibility } from 'stream-chat' ;
88
99import { CreatePollOptions , CurrentOptionPositionsCache } from './components' ;
1010
@@ -13,6 +13,7 @@ import { MultipleAnswersField } from './components/MultipleAnswersField';
1313import { NameField } from './components/NameField' ;
1414
1515import {
16+ CreatePollModalState ,
1617 CreatePollContentContextValue ,
1718 CreatePollContentProvider ,
1819 InputMessageInputContextValue ,
@@ -219,21 +220,23 @@ export const CreatePoll = ({
219220> &
220221 Pick < InputMessageInputContextValue , 'CreatePollContent' > ) => {
221222 const messageComposer = useMessageComposer ( ) ;
222- const [ isClosing , setIsClosing ] = useState ( false ) ;
223+ const [ modalStateStore ] = useState (
224+ ( ) => new StateStore < CreatePollModalState > ( { isClosing : false } ) ,
225+ ) ;
223226 const closeFrameRef = useRef < number | null > ( null ) ;
224227
225228 const closeCreatePollDialog = useCallback ( ( ) => {
226- if ( closeFrameRef . current !== null ) {
229+ if ( closeFrameRef . current !== null || modalStateStore . getLatestValue ( ) . isClosing ) {
227230 return ;
228231 }
229232
230- setIsClosing ( true ) ;
231233 // Let the modal render once with exit animations disabled before we dismiss it.
234+ modalStateStore . partialNext ( { isClosing : true } ) ;
232235 closeFrameRef . current = requestAnimationFrame ( ( ) => {
233236 closeFrameRef . current = null ;
234237 closePollCreationDialog ?.( ) ;
235238 } ) ;
236- } , [ closePollCreationDialog ] ) ;
239+ } , [ closePollCreationDialog , modalStateStore ] ) ;
237240
238241 useEffect ( ( ) => {
239242 return ( ) => {
@@ -261,7 +264,7 @@ export const CreatePoll = ({
261264 closePollCreationDialog : closeCreatePollDialog ,
262265 createAndSendPoll,
263266 createPollOptionGap,
264- isClosing ,
267+ modalStateStore ,
265268 sendMessage,
266269 } }
267270 >
0 commit comments