Skip to content

Commit e23b942

Browse files
committed
fix horizontal styles
1 parent 8000025 commit e23b942

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/components/CellDecorators.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React from "react";
2+
import { StyleSheet } from "react-native";
23
import Animated, {
34
interpolate,
45
interpolateNode,
56
multiply,
67
} from "react-native-reanimated";
8+
import { useDraggableFlatListContext } from "../context/draggableFlatListContext";
79
import { useNode } from "../hooks/useNode";
810
export { useOnCellActiveAnimation } from "../hooks/useOnCellActiveAnimation";
911
import { useOnCellActiveAnimation } from "../hooks/useOnCellActiveAnimation";
@@ -30,10 +32,14 @@ export const ScaleDecorator = ({ activeScale = 1.1, children }: ScaleProps) => {
3032
})
3133
);
3234

35+
const { horizontal } = useDraggableFlatListContext<any>();
3336
const scale = isActive ? animScale : 1;
3437
return (
3538
<Animated.View
36-
style={{ transform: [{ scaleX: scale }, { scaleY: scale }] }}
39+
style={[
40+
{ transform: [{ scaleX: scale }, { scaleY: scale }] },
41+
horizontal && styles.horizontal,
42+
]}
3743
>
3844
{children}
3945
</Animated.View>
@@ -56,6 +62,8 @@ export const ShadowDecorator = ({
5662
children,
5763
}: ShadowProps) => {
5864
const { isActive, onActiveAnim } = useOnCellActiveAnimation();
65+
const { horizontal } = useDraggableFlatListContext<any>();
66+
5967
const shadowOpacity = useNode(multiply(onActiveAnim, opacity));
6068

6169
const style = {
@@ -65,7 +73,11 @@ export const ShadowDecorator = ({
6573
shadowOpacity: isActive ? shadowOpacity : 0,
6674
};
6775

68-
return <Animated.View style={style}>{children}</Animated.View>;
76+
return (
77+
<Animated.View style={[style, horizontal && styles.horizontal]}>
78+
{children}
79+
</Animated.View>
80+
);
6981
};
7082

7183
type OpacityProps = {
@@ -78,6 +90,8 @@ export const OpacityDecorator = ({
7890
children,
7991
}: OpacityProps) => {
8092
const { isActive, onActiveAnim } = useOnCellActiveAnimation();
93+
const { horizontal } = useDraggableFlatListContext<any>();
94+
8195
const opacity = useNode(
8296
interpolateFn(onActiveAnim, {
8397
inputRange: [0, 1],
@@ -89,5 +103,16 @@ export const OpacityDecorator = ({
89103
opacity: isActive ? opacity : 1,
90104
};
91105

92-
return <Animated.View style={style}>{children}</Animated.View>;
106+
return (
107+
<Animated.View style={[style, horizontal && styles.horizontal]}>
108+
{children}
109+
</Animated.View>
110+
);
93111
};
112+
113+
const styles = StyleSheet.create({
114+
horizontal: {
115+
flexDirection: "row",
116+
flex: 1,
117+
},
118+
});

src/components/CellRendererComponent.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
findNodeHandle,
1010
LayoutChangeEvent,
1111
MeasureLayoutOnSuccessCallback,
12+
StyleProp,
13+
ViewStyle,
1214
} from "react-native";
1315
import Animated, { cond, useValue } from "react-native-reanimated";
1416
import { useDraggableFlatListContext } from "../context/draggableFlatListContext";
@@ -24,6 +26,7 @@ type Props<T> = {
2426
index: number;
2527
children: React.ReactNode;
2628
onLayout: (e: LayoutChangeEvent) => void;
29+
style?: StyleProp<ViewStyle>;
2730
};
2831

2932
function CellRendererComponent<T>(props: Props<T>) {
@@ -142,11 +145,17 @@ function CellRendererComponent<T>(props: Props<T>) {
142145
isAndroid && { elevation: isActive ? 1 : 0 },
143146
{ flexDirection: horizontal ? "row" : "column" },
144147
(isWeb || isIOS) && { zIndex: isActive ? 999 : 0 },
145-
style,
146148
]}
147149
pointerEvents={activeKey ? "none" : "auto"}
148150
>
149-
<CellProvider isActive={isActive}>{children}</CellProvider>
151+
<Animated.View
152+
{...props}
153+
// Including both animated styles and non-animated styles causes react-native-web
154+
// to ignore updates in non-animated styles. Solution is to separate animated styles from non-animated styles
155+
style={[props.style, style]}
156+
>
157+
<CellProvider isActive={isActive}>{children}</CellProvider>
158+
</Animated.View>
150159
</Animated.View>
151160
);
152161
}

0 commit comments

Comments
 (0)