@@ -69,6 +69,10 @@ const styles = StyleSheet.create({
6969 fontWeight : '700' ,
7070 paddingTop : 16 ,
7171 } ,
72+ unseenItemContainer : {
73+ opacity : 0 ,
74+ position : 'absolute' ,
75+ } ,
7276} ) ;
7377
7478const reactionData : ReactionData [ ] = [
@@ -138,6 +142,8 @@ export const OverlayReactions: React.FC<OverlayReactionsProps> = (props) => {
138142 const layoutHeight = useSharedValue ( 0 ) ;
139143 const layoutWidth = useSharedValue ( 0 ) ;
140144
145+ const [ itemHeight , setItemHeight ] = React . useState ( 0 ) ;
146+
141147 const {
142148 theme : {
143149 colors : { accent_blue, black, grey_gainsboro, white } ,
@@ -159,7 +165,6 @@ export const OverlayReactions: React.FC<OverlayReactionsProps> = (props) => {
159165 } = useTheme ( ) ;
160166
161167 const width = useWindowDimensions ( ) . width ;
162- const height = useWindowDimensions ( ) . height ;
163168
164169 const supportedReactionTypes = supportedReactions . map (
165170 ( supportedReaction ) => supportedReaction . type ,
@@ -179,15 +184,6 @@ export const OverlayReactions: React.FC<OverlayReactionsProps> = (props) => {
179184 ( avatarSize + ( Number ( avatarContainer . padding || 0 ) || styles . avatarContainer . padding ) * 2 ) ,
180185 ) ;
181186
182- const maxHeight = Math . floor (
183- height -
184- overlayPadding * 2 -
185- ( ( Number ( flatListContainer . paddingVertical || 0 ) ||
186- styles . flatListContainer . paddingVertical ) +
187- ( Number ( avatarContainer . padding || 0 ) || styles . avatarContainer . padding ) ) *
188- 2 ,
189- ) ;
190-
191187 const renderItem = ( { item } : { item : Reaction } ) => {
192188 const { alignment = 'left' , name, type } = item ;
193189 const x = avatarSize / 2 - ( avatarSize / ( radius * 4 ) ) * ( alignment === 'left' ? 1 : - 1 ) ;
@@ -305,23 +301,48 @@ export const OverlayReactions: React.FC<OverlayReactionsProps> = (props) => {
305301 ) ;
306302
307303 return (
308- < Animated . View
309- onLayout = { ( { nativeEvent : { layout } } ) => {
310- layoutWidth . value = layout . width ;
311- layoutHeight . value = layout . height ;
312- } }
313- style = { [ styles . container , { backgroundColor : white } , container , showScreenStyle ] }
314- >
315- < Text style = { [ styles . title , { color : black } , titleStyle ] } > { title } </ Text >
316- < FlatList
317- contentContainerStyle = { styles . flatListContentContainer }
318- data = { filteredReactions }
319- keyExtractor = { ( { name } , index ) => `${ name } _${ index } ` }
320- numColumns = { numColumns }
321- renderItem = { renderItem }
322- style = { [ styles . flatListContainer , flatListContainer , { maxHeight : maxHeight / numColumns } ] }
323- />
324- </ Animated . View >
304+ < >
305+ < Animated . View
306+ onLayout = { ( { nativeEvent : { layout } } ) => {
307+ layoutWidth . value = layout . width ;
308+ layoutHeight . value = layout . height ;
309+ } }
310+ style = { [
311+ styles . container ,
312+ { backgroundColor : white , opacity : itemHeight ? 1 : 0 } ,
313+ container ,
314+ showScreenStyle ,
315+ ] }
316+ >
317+ < Text style = { [ styles . title , { color : black } , titleStyle ] } > { title } </ Text >
318+ < FlatList
319+ contentContainerStyle = { styles . flatListContentContainer }
320+ data = { filteredReactions }
321+ key = { numColumns }
322+ keyExtractor = { ( { name } , index ) => `${ name } _${ index } ` }
323+ numColumns = { numColumns }
324+ renderItem = { renderItem }
325+ style = { [
326+ styles . flatListContainer ,
327+ flatListContainer ,
328+ {
329+ // we show the item height plus a little extra to tease for scrolling if there are more than one row
330+ maxHeight :
331+ itemHeight + ( filteredReactions . length / numColumns > 1 ? itemHeight / 8 : 0 ) ,
332+ } ,
333+ ] }
334+ />
335+ { /* The below view is unseen by the user, we use it to compute the height that the item must be */ }
336+ < View
337+ onLayout = { ( { nativeEvent : { layout } } ) => {
338+ setItemHeight ( layout . height ) ;
339+ } }
340+ style = { [ styles . unseenItemContainer , styles . flatListContentContainer ] }
341+ >
342+ { renderItem ( { item : filteredReactions [ 0 ] } ) }
343+ </ View >
344+ </ Animated . View >
345+ </ >
325346 ) ;
326347} ;
327348
0 commit comments