11import { useMemo } from 'react' ;
2+ import type { DimensionValue } from 'react-native' ;
23import { StyleSheet } from 'react-native' ;
3- import type { AnimatedStyle , SharedValue } from 'react-native-reanimated' ;
4+ import type { SharedValue } from 'react-native-reanimated' ;
45import { runOnUI , useAnimatedStyle } from 'react-native-reanimated' ;
56
67import { DEFAULT_SORTABLE_GRID_PROPS , IS_WEB } from '../constants' ;
@@ -11,7 +12,6 @@ import {
1112 GridLayoutProvider ,
1213 OrderUpdaterComponent ,
1314 SharedProvider ,
14- useGridLayoutContext ,
1515 useMeasurementsContext ,
1616 useStrategyKey
1717} from '../providers' ;
@@ -175,67 +175,47 @@ function SortableGridInner<I>({
175175 rowHeight,
176176 ...containerProps
177177} : SortableGridInnerProps < I > ) {
178- const { mainGroupSize } = useGridLayoutContext ( ) ;
179178 const { handleContainerMeasurement } = useMeasurementsContext ( ) ;
180179
181- const animatedInnerStyle = useAnimatedStyle ( ( ) => ( {
182- flexDirection : isVertical ? 'row' : 'column' ,
183- height : isVertical
184- ? undefined
185- : groups * ( rowHeight + rowGap . value ) - rowGap . value ,
186- ...( IS_WEB || mainGroupSize . value
180+ const animatedInnerStyle = useAnimatedStyle ( ( ) =>
181+ isVertical
187182 ? {
188- columnGap : columnGap . value ,
189- marginHorizontal : 0 ,
190- marginVertical : 0 ,
183+ columnGap : IS_WEB ? columnGap . value : 0 ,
184+ flexDirection : 'row' ,
185+ marginHorizontal : IS_WEB ? 0 : - columnGap . value / 2 ,
191186 rowGap : rowGap . value
192187 }
193188 : {
194- marginHorizontal : - columnGap . value / 2 ,
195- marginVertical : - rowGap . value / 2
196- } )
197- } ) ) ;
198-
199- let animatedItemStyle : AnimatedStyle ;
200- if ( IS_WEB ) {
201- // eslint-disable-next-line react-hooks/rules-of-hooks
202- animatedItemStyle = useAnimatedStyle ( ( ) => ( {
203- [ isVertical ? 'width' : 'height' ] :
204- `calc((100% - ${ columnGap . value * ( groups - 1 ) } px) / ${ groups } )`
205- } ) ) ;
206- } else {
207- // eslint-disable-next-line react-hooks/rules-of-hooks
208- animatedItemStyle = useAnimatedStyle ( ( ) => {
209- if ( ! mainGroupSize . value ) {
210- return {
211- flexBasis : `${ 100 / groups } %` ,
212- paddingHorizontal : columnGap . value / 2 ,
213- paddingVertical : rowGap . value / 2
214- } ;
215- }
189+ columnGap : columnGap . value ,
190+ flexDirection : 'column' ,
191+ height : groups * ( rowHeight + rowGap . value ) - rowGap . value ,
192+ rowGap : rowGap . value
193+ }
194+ ) ;
216195
217- return {
218- flexBasis : 'auto' ,
219- [ isVertical ? 'width' : 'height' ] : mainGroupSize . value ,
220- paddingHorizontal : 0 ,
221- paddingVertical : 0
222- } ;
223- } ) ;
224- }
196+ const animatedItemStyle = useAnimatedStyle ( ( ) =>
197+ isVertical
198+ ? IS_WEB
199+ ? {
200+ width :
201+ `calc((100% - ${ columnGap . value * ( groups - 1 ) } px) / ${ groups } )` as DimensionValue
202+ }
203+ : {
204+ flexBasis : `${ 100 / groups } %` ,
205+ paddingHorizontal : columnGap . value / 2
206+ }
207+ : { height : rowHeight }
208+ ) ;
225209
226210 return (
227211 < SortableContainer
228212 { ...containerProps }
229213 style = { [ styles . gridContainer , animatedInnerStyle ] }
230214 onLayout = { runOnUI ( ( width , height ) => {
231- if ( IS_WEB || mainGroupSize . value ) {
232- handleContainerMeasurement ( width , height ) ;
233- } else {
234- handleContainerMeasurement (
235- width - columnGap . value ,
236- height - rowGap . value
237- ) ;
238- }
215+ handleContainerMeasurement (
216+ width - ( isVertical && ! IS_WEB ? columnGap . value : 0 ) ,
217+ height
218+ ) ;
239219 } ) } >
240220 { zipArrays ( data , itemKeys ) . map ( ( [ item , key ] , index ) => (
241221 < SortableGridItem
0 commit comments