Skip to content

Commit d4034d6

Browse files
authored
fix: Animated sortable container height not working (#243)
## Description This PR fixes issue with `animateHeight` not taking any effect after recent changes.
1 parent d74e419 commit d4034d6

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Animated, {
99
withTiming
1010
} from 'react-native-reanimated';
1111

12-
import { IS_WEB } from '../../constants';
12+
import { EMPTY_OBJECT, IS_WEB } from '../../constants';
1313
import {
1414
ItemContextProvider,
1515
useCommonValuesContext,
@@ -70,20 +70,34 @@ export default function DraggableView({
7070
return () => handleItemRemoval(key);
7171
}, [key, handleItemRemoval]);
7272

73-
const animatedStyle = useAnimatedStyle(() => {
73+
const animatedTranslationStyle = useAnimatedStyle(() => {
7474
if (!canSwitchToAbsoluteLayout.value) {
7575
return RELATIVE_STYLE;
7676
}
7777

78-
const layoutX = layoutPosition.x.value;
79-
const layoutY = layoutPosition.y.value;
8078
const translateX = translation.x.value;
8179
const translateY = translation.y.value;
8280

8381
if (translateX === null || translateY === null) {
8482
return NO_TRANSLATION_STYLE;
8583
}
8684

85+
return {
86+
opacity: 1,
87+
position: 'absolute',
88+
transform: [{ translateX }, { translateY }],
89+
zIndex: zIndex.value
90+
};
91+
});
92+
93+
const animatedLayoutStyle = useAnimatedStyle(() => {
94+
if (!canSwitchToAbsoluteLayout.value) {
95+
return EMPTY_OBJECT;
96+
}
97+
98+
const layoutX = layoutPosition.x.value;
99+
const layoutY = layoutPosition.y.value;
100+
87101
let left = layoutX;
88102
let top = layoutY;
89103

@@ -94,19 +108,15 @@ export default function DraggableView({
94108

95109
return {
96110
left,
97-
opacity: 1,
98-
position: 'absolute',
99-
top,
100-
transform: [{ translateX }, { translateY }],
101-
zIndex: zIndex.value
111+
top
102112
};
103113
});
104114

105115
return (
106116
<Animated.View
107117
{...viewProps}
108118
layout={IS_WEB ? undefined : LinearTransition}
109-
style={[style, animatedStyle]}>
119+
style={[style, animatedTranslationStyle, animatedLayoutStyle]}>
110120
<Animated.View entering={entering} exiting={exiting}>
111121
<GestureDetector gesture={gesture}>
112122
<ItemDecoration

packages/react-native-sortables/src/components/shared/SortableContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default function SortableContainer({
4040
}
4141
return {
4242
height:
43-
animateHeight && shouldAnimateLayout.value
43+
animateHeight && (!IS_WEB || shouldAnimateLayout.value)
4444
? withTiming(containerHeight.value)
4545
: containerHeight.value,
4646
overflow:

0 commit comments

Comments
 (0)