Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions site/test-coverage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
actionSheet: { statements: '100%', branches: '96.55%', functions: '100%', lines: '100%' },
actionSheet: { statements: '98.48%', branches: '89.18%', functions: '100%', lines: '98.43%' },
avatar: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
backTop: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
badge: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
Expand All @@ -24,21 +24,21 @@ module.exports = {
form: { statements: '2.79%', branches: '0%', functions: '0%', lines: '2.95%' },
grid: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
guide: { statements: '99.43%', branches: '94.49%', functions: '100%', lines: '100%' },
hooks: { statements: '70.7%', branches: '45.88%', functions: '73.68%', lines: '70.66%' },
hooks: { statements: '67.74%', branches: '43%', functions: '71.73%', lines: '67.79%' },
image: { statements: '97.72%', branches: '100%', functions: '92.3%', lines: '97.61%' },
imageViewer: { statements: '8.33%', branches: '2.83%', functions: '0%', lines: '8.69%' },
indexes: { statements: '95.65%', branches: '69.81%', functions: '100%', lines: '96.94%' },
indexes: { statements: '96.37%', branches: '77.35%', functions: '100%', lines: '96.94%' },
input: { statements: '100%', branches: '98.18%', functions: '100%', lines: '100%' },
layout: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
link: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
list: { statements: '92%', branches: '77.77%', functions: '100%', lines: '100%' },
loading: { statements: '98.43%', branches: '96.07%', functions: '100%', lines: '98.3%' },
locale: { statements: '74.07%', branches: '62.5%', functions: '83.33%', lines: '75%' },
message: { statements: '100%', branches: '94.44%', functions: '100%', lines: '100%' },
navbar: { statements: '12.9%', branches: '0%', functions: '0%', lines: '13.79%' },
navbar: { statements: '9.3%', branches: '0%', functions: '0%', lines: '9.75%' },
noticeBar: { statements: '6.38%', branches: '0%', functions: '0%', lines: '6.52%' },
overlay: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
picker: { statements: '51.71%', branches: '29.69%', functions: '57.31%', lines: '52.51%' },
picker: { statements: '51.71%', branches: '29.09%', functions: '57.31%', lines: '52.51%' },
popover: { statements: '100%', branches: '96.55%', functions: '100%', lines: '100%' },
popup: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
progress: { statements: '100%', branches: '97.36%', functions: '100%', lines: '100%' },
Expand All @@ -55,9 +55,9 @@ module.exports = {
steps: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
sticky: { statements: '100%', branches: '90%', functions: '100%', lines: '100%' },
swipeCell: { statements: '100%', branches: '98.7%', functions: '100%', lines: '100%' },
swiper: { statements: '57.55%', branches: '37.1%', functions: '67.6%', lines: '59.74%' },
swiper: { statements: '96.78%', branches: '92.05%', functions: '100%', lines: '99.39%' },
switch: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
tabBar: { statements: '100%', branches: '93.18%', functions: '100%', lines: '100%' },
tabBar: { statements: '96.77%', branches: '87.5%', functions: '100%', lines: '96.55%' },
table: { statements: '100%', branches: '90%', functions: '100%', lines: '100%' },
tabs: { statements: '43.22%', branches: '18.75%', functions: '56%', lines: '45.07%' },
tag: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
Expand Down
26 changes: 19 additions & 7 deletions src/swiper/Swiper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ const Swiper = forwardRefWithStatics(
const enableNavigation = useMemo(() => {
if (isSwiperNavigation) {
const nav = navigation as SwiperNavigation;
return nav?.minShowNum ? items.current.length > nav?.minShowNum : true;
return nav?.minShowNum ? itemCount >= nav?.minShowNum : true;
}
return isObject(navigation);
}, [isSwiperNavigation, navigation]);
}, [isSwiperNavigation, navigation, itemCount]);

const isBottomPagination = useMemo(() => {
if (!isSwiperNavigation || !enableNavigation) return false;
Expand All @@ -137,9 +137,9 @@ const Swiper = forwardRefWithStatics(
className,
`${swiperClass}`,
`${swiperClass}--${type}`,
`${isBottomPagination && navPlacement ? `${swiperClass}--${navPlacement}` : ''}`,
`${navPlacement ? `${swiperClass}--${navPlacement}` : ''}`,
],
[swiperClass, type, isBottomPagination, navPlacement, className],
[swiperClass, type, navPlacement, className],
);

const intervalTimer = useRef<any>(null); // 轮播计时器
Expand Down Expand Up @@ -361,6 +361,7 @@ const Swiper = forwardRefWithStatics(

// 上一页
const goPrev = (source: SwiperChangeSource) => {
if (disabled) return;
navCtrlActive.current = true;
swiperSource.current = source;
nextIndex.current = previousIndex.current - 1;
Expand All @@ -369,13 +370,15 @@ const Swiper = forwardRefWithStatics(

// 下一页
const goNext = (source: SwiperChangeSource) => {
if (disabled) return;
navCtrlActive.current = true;
swiperSource.current = source;
nextIndex.current = previousIndex.current + 1;
enterSwitching(directionAxis, 1);
};

const onItemClick = () => {
if (disabled) return;
onClick?.(previousIndex.current ?? 0);
};

Expand Down Expand Up @@ -411,7 +414,7 @@ const Swiper = forwardRefWithStatics(
} else if (threshold < -SWIPE_THRESHOLD) {
goNext('touch');
} else {
enterSwitching(directionAxis, 0);
enterIdle(directionAxis);
}
},
});
Expand All @@ -433,6 +436,7 @@ const Swiper = forwardRefWithStatics(
}, [calculateItemIndex, current, directionAxis, enterSwitching, loop, currentIsNull]);

useEffect(() => {
if (disabled) return;
onChange?.(previousIndex.current, { source: swiperSource.current });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [itemChange]);
Expand Down Expand Up @@ -460,7 +464,7 @@ const Swiper = forwardRefWithStatics(
}
switch (swiperStatus) {
case SwiperStatus.IDLE:
if (autoplay) {
if (autoplay && !disabled) {
nextIndex.current = previousIndex.current + 1;
intervalTimer.current = setTimeout(() => {
enterSwitching(directionAxis, 1);
Expand All @@ -479,7 +483,7 @@ const Swiper = forwardRefWithStatics(
setSwiperStatus(SwiperStatus.IDLE);
break;
}
}, [autoplay, directionAxis, duration, enterIdle, enterSwitching, interval, quitSwitching, swiperStatus]);
}, [autoplay, directionAxis, duration, enterIdle, enterSwitching, interval, quitSwitching, swiperStatus, disabled]);

const changeProvide = () => {
if (props.disabled) return;
Expand Down Expand Up @@ -515,6 +519,14 @@ const Swiper = forwardRefWithStatics(
);

const swiperNav = () => {
// 如果 navigation 为 false,不显示导航
if (navigation === false) return null;

// 如果是字符串或函数,则调用 parseTNode
if (typeof navigation === 'string' || typeof navigation === 'function') {
return parseTNode(navigation);
}

// dots
const dots = (navigation: SwiperNavigation) => {
if (['dots', 'dots-bar'].includes(navigation?.type || '')) {
Expand Down
Loading
Loading