Skip to content

Commit dc9c3cd

Browse files
authored
fix: Grid layout issues on web (#510)
## Description Fix applied in the #509 PR broke grid layout on web. This PR adds more necessary changes to ensure that web works as well.
1 parent 60089cb commit dc9c3cd

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

packages/react-native-sortables/src/components/shared/DraggableView/ItemCell.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import {
55
StyleSheet,
66
type ViewStyle
77
} from 'react-native';
8-
import type { SharedValue, TransformArrayItem } from 'react-native-reanimated';
8+
import type {
9+
AnimatedStyle,
10+
SharedValue,
11+
TransformArrayItem
12+
} from 'react-native-reanimated';
913
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
1014

11-
import { HIDDEN_X_OFFSET } from '../../../constants';
15+
import { HIDDEN_X_OFFSET, IS_WEB } from '../../../constants';
1216
import type {
1317
AnimatedStyleProp,
1418
LayoutAnimation
@@ -51,21 +55,27 @@ export default function ItemCell({
5155
);
5256

5357
const animatedCellStyle = useAnimatedStyle(() => ({
54-
...overriddenCellDimensions.value,
5558
...decorationStyleValue.value,
5659
...layoutStyleValue.value,
5760
transform: [
5861
...((layoutStyleValue.value.transform ?? []) as TransformsArray),
5962
...((decorationStyleValue.value.transform ?? []) as TransformsArray)
60-
]
63+
],
64+
...(!IS_WEB && overriddenCellDimensions.value)
6165
}));
6266

67+
let innerAnimatedStyle: AnimatedStyle | undefined;
68+
if (IS_WEB) {
69+
// eslint-disable-next-line react-hooks/rules-of-hooks
70+
innerAnimatedStyle = useAnimatedStyle(() => overriddenCellDimensions.value);
71+
}
72+
6373
return (
6474
<Animated.View style={[baseStyle, styles.decoration, animatedCellStyle]}>
6575
<AnimatedOnLayoutView
6676
entering={entering}
6777
exiting={exiting}
68-
style={hidden && styles.hidden}
78+
style={[styles.inner, innerAnimatedStyle, hidden && styles.hidden]}
6979
onLayout={onLayout}>
7080
{children}
7181
</AnimatedOnLayoutView>
@@ -93,5 +103,9 @@ const styles = StyleSheet.create({
93103
// affect item dimensions, etc., so the safest way is to put the item
94104
// far away from the viewport to hide it)
95105
left: HIDDEN_X_OFFSET
96-
}
106+
},
107+
inner: Platform.select<ViewStyle>({
108+
default: {},
109+
web: { flex: 1 }
110+
})
97111
});

packages/react-native-sortables/src/providers/grid/GridLayoutProvider/GridLayoutProvider.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ const { GridLayoutProvider, useGridLayoutContext } = createProvider(
135135

136136
if (isVertical) {
137137
itemWidths.value = value;
138-
overriddenCellDimensions.value = { width: value + mainGap.value };
138+
overriddenCellDimensions.value = {
139+
width: value + (IS_WEB ? 0 : mainGap.value)
140+
};
139141
} else {
140142
itemHeights.value = value;
141143
}

0 commit comments

Comments
 (0)