mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-10 22:47:02 +08:00
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
function getSceneIndicesForInterpolationInputRange(props) {
|
|
const { scene, scenes } = props;
|
|
const index = scene.index;
|
|
const lastSceneIndexInScenes = scenes.length - 1;
|
|
const isBack = !scenes[lastSceneIndexInScenes].isActive;
|
|
|
|
if (isBack) {
|
|
const currentSceneIndexInScenes = scenes.findIndex(item => item === scene);
|
|
const targetSceneIndexInScenes = scenes.findIndex(item => item.isActive);
|
|
const targetSceneIndex = scenes[targetSceneIndexInScenes].index;
|
|
const lastSceneIndex = scenes[lastSceneIndexInScenes].index;
|
|
|
|
if (
|
|
index !== targetSceneIndex &&
|
|
currentSceneIndexInScenes === lastSceneIndexInScenes
|
|
) {
|
|
return {
|
|
first: Math.min(targetSceneIndex, index - 1),
|
|
last: index + 1,
|
|
};
|
|
} else if (
|
|
index === targetSceneIndex &&
|
|
currentSceneIndexInScenes === targetSceneIndexInScenes
|
|
) {
|
|
return {
|
|
first: index - 1,
|
|
last: Math.max(lastSceneIndex, index + 1),
|
|
};
|
|
} else if (
|
|
index === targetSceneIndex ||
|
|
currentSceneIndexInScenes > targetSceneIndexInScenes
|
|
) {
|
|
return null;
|
|
} else {
|
|
return { first: index - 1, last: index + 1 };
|
|
}
|
|
} else {
|
|
return { first: index - 1, last: index + 1 };
|
|
}
|
|
}
|
|
|
|
export default getSceneIndicesForInterpolationInputRange;
|