Skip to content

Commit df57488

Browse files
committed
fix: Apply Sortable.Flex alignItems before items are measured
Sortable.Flex forced `alignSelf: 'flex-start'` on every item to prevent stretching, but that also overrode a user-provided `alignItems` during the initial (pre-measurement) render phase. With items of different sizes this made them appear misaligned at first; they only snapped to the correct alignment after measuring, causing a visible jump. Only apply the `flex-start` override when `alignItems` is unset or `stretch` (the cases where items would otherwise stretch). For any other `alignItems` value, let it apply so items are aligned from the first render.
1 parent 92fe9da commit df57488

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,24 @@ function SortableFlexComponent({
235235
<SortableContainer
236236
{...rest}
237237
containerStyle={[baseContainerStyle, animatedContainerStyle]}
238-
itemStyle={styles.styleOverride}
238+
// `alignSelf: 'flex-start'` is only needed to prevent items from
239+
// stretching (the default when no `alignItems` is set). When a
240+
// specific `alignItems` is provided, let it apply so items are
241+
// aligned from the first render instead of only after measuring.
242+
itemStyle={
243+
alignItems === undefined || alignItems === 'stretch'
244+
? styles.styleOverride
245+
: undefined
246+
}
239247
onLayout={runOnUI(handleContainerMeasurement)}
240248
/>
241249
);
242250
}
243251

244252
const styles = StyleSheet.create({
245253
styleOverride: {
246-
// This is needed to prevent items from stretching (which is default behavior)
254+
// Prevents items from stretching (the default flex behavior when no
255+
// `alignItems` is set on the container)
247256
alignSelf: 'flex-start'
248257
}
249258
});

0 commit comments

Comments
 (0)