@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
49 lines (35 loc) • 1.18 kB
JavaScript
/**
* 按照某个方向找到可用选项的下标
*/
const findAvailableOptionsIndex = (options, start, end) => {
const isNext = end - start >= 0;
for (let iii = start; isNext ? iii <= end : iii >= end; iii += isNext ? 1 : -1) {
const item = options[iii];
if (!item.disabled) {
return iii;
}
}
return -1;
};
export const findUsableOptionIndex = function (options, next, index) {
let reverse = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
const maxIndex = options.length - 1; // 两端的情况不能反转查找
if (reverse && (index === 0 || index === maxIndex)) {
reverse = false;
} // 顶端不能继续向上找
if (index === 0 && !next) {
next = true;
} // 末端不能继续向下找
if (index === maxIndex && next) {
next = false;
}
const getEnd = cNext => {
return cNext ? maxIndex : 0;
}; // 以当前为起点向某个方向找
let nIndex = findAvailableOptionsIndex(options, index, getEnd(next));
if (nIndex === -1 && reverse) {
nIndex = findAvailableOptionsIndex(options, index, getEnd(!next));
}
return nIndex;
};
//# sourceMappingURL=column.js.map