Skip to content

Commit 073b7e0

Browse files
committed
fix: Respect Sortable.Flex alignItems before items are measured
Sortable.Flex put `alignSelf: 'flex-start'` on every item to stop them stretching (stretched items would be measured at the wrong size, which breaks the absolute layout). But `alignSelf` overrides the container's `alignItems`, so a user-provided `alignItems` (e.g. 'center') was ignored until the component switched to its absolute layout after measuring, causing a visible jump with differently-sized items. Prevent stretching on the container instead: fall back to `alignItems: 'flex-start'` when no `alignItems` is set (the default that would stretch), and drop the per-item `alignSelf` override. Any provided `alignItems` now applies from the first render.
1 parent 92fe9da commit 073b7e0

1 file changed

Lines changed: 2 additions & 10 deletions

File tree

packages/react-native-sortables/src/components/SortableFlex.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { memo, useMemo } from 'react';
22
import type { ViewStyle } from 'react-native';
3-
import { StyleSheet } from 'react-native';
43
import { runOnUI, useAnimatedStyle } from 'react-native-reanimated';
54

65
import { DEFAULT_SORTABLE_FLEX_PROPS } from '../constants';
@@ -224,7 +223,8 @@ function SortableFlexComponent({
224223
}
225224
: {
226225
alignContent,
227-
alignItems,
226+
// Avoid the default `stretch` so items keep their measured size
227+
alignItems: alignItems === undefined ? 'flex-start' : alignItems,
228228
flexDirection,
229229
flexWrap,
230230
justifyContent
@@ -235,17 +235,9 @@ function SortableFlexComponent({
235235
<SortableContainer
236236
{...rest}
237237
containerStyle={[baseContainerStyle, animatedContainerStyle]}
238-
itemStyle={styles.styleOverride}
239238
onLayout={runOnUI(handleContainerMeasurement)}
240239
/>
241240
);
242241
}
243242

244-
const styles = StyleSheet.create({
245-
styleOverride: {
246-
// This is needed to prevent items from stretching (which is default behavior)
247-
alignSelf: 'flex-start'
248-
}
249-
});
250-
251243
export default SortableFlex;

0 commit comments

Comments
 (0)