Skip to content

Commit 4d261db

Browse files
authored
fix: Collapsible items implementation on the web (#485)
## Description This PR adjusts the example and the grid layout provider to work properly with on the web.
1 parent db586d7 commit 4d261db

4 files changed

Lines changed: 34 additions & 14 deletions

File tree

example/app/src/examples/SortableGrid/miscellaneous/CollapsibleItemsExample.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback, useState } from 'react';
22
import type { ViewStyle } from 'react-native';
3-
import { StyleSheet, Text } from 'react-native';
3+
import { StyleSheet, Text, View } from 'react-native';
44
import Animated, {
55
LinearTransition,
66
useAnimatedRef
@@ -46,6 +46,26 @@ function Example({ horizontal }: ExampleProps) {
4646

4747
const renderItem = useCallback<SortableGridRenderItem<string>>(
4848
({ item }) => {
49+
if (IS_WEB) {
50+
return (
51+
// The height/width of the outermost item container must be changed immediately
52+
// to the new final value so we set it here as well and change without animation
53+
<View style={[{ [dimension]: collapsed ? sizes.lg : sizes.xxxl }]}>
54+
<Animated.View
55+
style={[
56+
styles.card,
57+
{
58+
[dimension]: collapsed ? sizes.lg : sizes.xxxl,
59+
// Uses Reanimated 4 CSS transitions
60+
transitionDuration: 300
61+
}
62+
]}>
63+
<Text style={styles.text}>{item}</Text>
64+
</Animated.View>
65+
</View>
66+
);
67+
}
68+
4969
const layoutTransition = LinearTransition.delay(collapsed ? 0 : 50);
5070

5171
return (

example/app/src/examples/navigation/routes.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,22 @@ const routes: Routes = {
6969
}
7070
}
7171
},
72-
...(!IS_WEB && {
73-
Miscellaneous: {
74-
name: 'Miscellaneous',
75-
routes: {
72+
73+
Miscellaneous: {
74+
name: 'Miscellaneous',
75+
routes: {
76+
...(!IS_WEB && {
7677
StaggerAnimation: {
7778
Component: SortableGrid.miscellaneous.StaggerAnimationExample,
7879
name: 'Stagger Animation'
79-
},
80-
CollapsibleItems: {
81-
Component: SortableGrid.miscellaneous.CollapsibleItemsExample,
82-
name: 'Collapsible Items'
8380
}
81+
}),
82+
CollapsibleItems: {
83+
Component: SortableGrid.miscellaneous.CollapsibleItemsExample,
84+
name: 'Collapsible Items'
8485
}
8586
}
86-
}),
87+
},
8788
Tests: {
8889
name: 'Test examples',
8990
routes: {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ const { GridLayoutProvider, useGridLayoutContext } = createProvider(
158158
// GRID LAYOUT UPDATER
159159
useAnimatedReaction(
160160
() => ({
161-
_: layoutRequestId.value, // Helper to force layout re-calculation
162161
gaps: {
163162
cross: crossGap.value,
164163
main: mainGap.value
@@ -167,7 +166,8 @@ const { GridLayoutProvider, useGridLayoutContext } = createProvider(
167166
isVertical,
168167
itemHeights: itemHeights.value,
169168
itemWidths: itemWidths.value,
170-
numGroups
169+
numGroups,
170+
requestId: layoutRequestId.value // Helper to force layout re-calculation
171171
}),
172172
(props, prevProps) => {
173173
const adaptedProps: GridLayoutProps =
@@ -198,7 +198,7 @@ const { GridLayoutProvider, useGridLayoutContext } = createProvider(
198198

199199
if (adaptedProps.shouldAnimateLayout !== undefined) {
200200
shouldAnimateLayout.value = adaptedProps.shouldAnimateLayout;
201-
} else if (IS_WEB) {
201+
} else if (IS_WEB && props.requestId === prevProps?.requestId) {
202202
updateShouldAnimateWeb?.(adaptedProps, prevProps);
203203
} else {
204204
shouldAnimateLayout.value = true;

packages/react-native-sortables/src/providers/shared/AutoScrollProvider/AutoScrollProvider.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ function AutoScrollUpdater({
269269

270270
const distance = velocity * (cappedElapsedTime / 1000);
271271

272-
console.log('frameCallbackFunction', distance, ctx.progress);
273272
scrollBy(distance, animateScrollTo);
274273
},
275274
[

0 commit comments

Comments
 (0)