Files
react-navigation/packages/core/src/utils/getSceneIndicesForInterpolationInputRange.js
2018-10-11 13:50:01 -07:00

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;