1- import React , { useCallback , useMemo } from 'react' ;
1+ import React , { useCallback , useEffect , useMemo } from 'react' ;
22import { StyleSheet , Text , TextInput , View } from 'react-native' ;
33import { Gesture , GestureDetector } from 'react-native-gesture-handler' ;
44import Animated , {
@@ -11,6 +11,7 @@ import Animated, {
1111 useSharedValue ,
1212 withDelay ,
1313 withSpring ,
14+ withTiming ,
1415} from 'react-native-reanimated' ;
1516
1617import { PollComposerOption , PollComposerState } from 'stream-chat' ;
@@ -296,6 +297,19 @@ export const CreatePollOptions = ({ currentOptionPositions, options }: CreatePol
296297 // this will hold id for item which user started dragging
297298 const draggedItemId = useSharedValue < string | null > ( null ) ;
298299
300+ // holds the animated height of the option container
301+ const animatedOptionsContainerHeight = useSharedValue ( createPollOptionHeight * options . length ) ;
302+
303+ useEffect ( ( ) => {
304+ animatedOptionsContainerHeight . value = withTiming ( createPollOptionHeight * options . length , {
305+ duration : 200 ,
306+ } ) ;
307+ } , [ animatedOptionsContainerHeight , createPollOptionHeight , options . length ] ) ;
308+
309+ const animatedOptionsContainerStyle = useAnimatedStyle ( ( ) => ( {
310+ height : animatedOptionsContainerHeight . value ,
311+ } ) ) ;
312+
299313 const boundaries = useMemo (
300314 ( ) => ( { maxBound : ( options . length - 1 ) * createPollOptionHeight , minBound : 0 } ) ,
301315 [ createPollOptionHeight , options . length ] ,
@@ -333,7 +347,7 @@ export const CreatePollOptions = ({ currentOptionPositions, options }: CreatePol
333347 return (
334348 < View style = { [ styles . container , container ] } >
335349 < Text style = { [ styles . text , { color : black } , title ] } > { t < string > ( 'Options' ) } </ Text >
336- < View style = { { height : createPollOptionHeight * options . length } } >
350+ < Animated . View style = { animatedOptionsContainerStyle } >
337351 { options . map ( ( option , index ) => (
338352 < MemoizedCreatePollOption
339353 boundaries = { boundaries }
@@ -349,7 +363,7 @@ export const CreatePollOptions = ({ currentOptionPositions, options }: CreatePol
349363 option = { option }
350364 />
351365 ) ) }
352- </ View >
366+ </ Animated . View >
353367 </ View >
354368 ) ;
355369} ;
0 commit comments