Skip to content

Commit

Permalink
fix: fix with zindex
Browse files Browse the repository at this point in the history
  • Loading branch information
dohooo committed Dec 29, 2021
1 parent c8054f1 commit f3b28cc
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/layouts/StackLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import Animated, {
runOnJS,
useAnimatedReaction,
useAnimatedStyle,
useSharedValue,
withTiming,
} from 'react-native-reanimated';
import { log } from '../utils/log';
import { useOffsetX } from '../hooks/useOffsetX';
import type { IVisibleRanges } from '../hooks/useVisibleRanges';
import { LazyView } from '../LazyView';
Expand All @@ -35,18 +32,9 @@ export const StackLayout: React.FC<{
children,
visibleRanges,
vertical,
handlerOffsetX,
} = props;

const handlerOffsetX = useSharedValue(0);

useAnimatedReaction(
() => props.handlerOffsetX.value,
(value) => {
handlerOffsetX.value = withTiming(value, { duration: 0 });
},
[]
);

const [shouldUpdate, setShouldUpdate] = React.useState(false);

const size = vertical ? height : width;
Expand All @@ -66,7 +54,7 @@ export const StackLayout: React.FC<{

const offsetXStyle = useAnimatedStyle(() => {
const startPosition = (x.value - index * size) / size;
runOnJS(log)(-x.value, ',', startPosition, `【${index}】`);

return {
transform: [
{
Expand All @@ -79,7 +67,7 @@ export const StackLayout: React.FC<{
{
scale: interpolate(
startPosition,
[-(index + 1), -index, 0, data.length - index],
[-index - 1, -index, 0, data.length - index],
[
1,
1,
Expand All @@ -91,14 +79,14 @@ export const StackLayout: React.FC<{
{
rotateZ: `${interpolate(
startPosition,
[-(index + 1), -index, 0],
[-index - 1, -index, 0],
[-135, 0, 0]
)}deg`,
},
{
translateY: interpolate(
startPosition,
[-(index + 1), -index, 0, data.length - index],
[-index - 1, -index, 0, data.length - index],
[
0,
0,
Expand All @@ -108,7 +96,17 @@ export const StackLayout: React.FC<{
),
},
],
zIndex: -x.value,
zIndex: -interpolate(
startPosition,
[-index - 1, -index - 0.5, -index, 0, data.length - index],
[
Number.MAX_VALUE,
Number.MIN_VALUE,
0,
index * size * 0.12,
(data.length - index) * size * 0.12,
]
),
};
}, [loop, vertical]);

Expand Down

0 comments on commit f3b28cc

Please sign in to comment.