Skip to content

Commit d9660d2

Browse files
authored
fix: Active item portal provider on web (#312)
## Description This PR fixes active item portal provider implementation on web.
1 parent 73ba0de commit d9660d2

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { PropsWithChildren, ReactNode } from 'react';
22
import { useEffect } from 'react';
3+
import type { ViewStyle } from 'react-native';
34
import type { SharedValue } from 'react-native-reanimated';
45
import {
56
runOnJS,
@@ -8,9 +9,20 @@ import {
89
useSharedValue
910
} from 'react-native-reanimated';
1011

12+
import { IS_WEB } from '../../../constants';
1113
import { usePortalContext, useTeleportedItemId } from '../../../providers';
1214
import type { AnimatedStyleProp, MeasureCallback } from '../../../types';
1315

16+
const TELEPORTED_ITEM_STYLE: ViewStyle = {
17+
maxHeight: 0,
18+
overflow: 'hidden'
19+
};
20+
21+
const NOT_TELEPORTED_ITEM_STYLE: ViewStyle = {
22+
maxHeight: IS_WEB ? 9999 : 'auto', // 'auto' doesn't trigger onLayout on web
23+
overflow: 'visible'
24+
};
25+
1426
type ActiveItemPortalProps = PropsWithChildren<{
1527
itemKey: string;
1628
activationAnimationProgress: SharedValue<number>;
@@ -75,10 +87,9 @@ export default function ActiveItemPortal({
7587
}
7688
};
7789

78-
const animatedItemStyle = useAnimatedStyle(() => ({
79-
maxHeight: isTeleported.value ? 0 : 'auto',
80-
overflow: isTeleported.value ? 'hidden' : 'visible'
81-
}));
90+
const animatedItemStyle = useAnimatedStyle(() =>
91+
isTeleported.value ? TELEPORTED_ITEM_STYLE : NOT_TELEPORTED_ITEM_STYLE
92+
);
8293

8394
useAnimatedReaction(
8495
() => activationAnimationProgress.value,

0 commit comments

Comments
 (0)