Skip to content
Open
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
2 changes: 1 addition & 1 deletion site/test-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = {
steps: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
sticky: { statements: '67.85%', branches: '30%', functions: '85.71%', lines: '69.09%' },
swipeCell: { statements: '4.42%', branches: '0%', functions: '0%', lines: '4.67%' },
swiper: { statements: '3.77%', branches: '0.9%', functions: '1.4%', lines: '3.89%' },
swiper: { statements: '97.68%', branches: '94.73%', functions: '100%', lines: '99.67%' },
switch: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
tabBar: { statements: '10%', branches: '0%', functions: '0%', lines: '10.81%' },
table: { statements: '100%', branches: '90%', functions: '100%', lines: '100%' },
Expand Down
34 changes: 21 additions & 13 deletions src/swiper/Swiper.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { RefObject, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { isNumber, isObject } from 'lodash-es';
import { isNumber } from 'lodash-es';
import classNames from 'classnames';
import { Property } from 'csstype';
import useDefaultProps from '../hooks/useDefaultProps';
Expand All @@ -23,7 +23,6 @@ enum SwiperStatus {
IDLE = 'idle', // 空闲状态
SWITCHING = 'switching', // 切换状态
STARTDRAG = 'startdrag', // 开始拖拽
ENDDRAG = 'enddrag', // 结束拖拽
}

// swiper组件的动态style
Expand Down Expand Up @@ -113,7 +112,7 @@ const Swiper = forwardRefWithStatics(
const nav = navigation as SwiperNavigation;
return nav?.minShowNum ? items.current.length > nav?.minShowNum : true;
}
return isObject(navigation);
return typeof navigation === 'string';
}, [isSwiperNavigation, navigation]);

const isBottomPagination = useMemo(() => {
Expand Down Expand Up @@ -475,9 +474,6 @@ const Swiper = forwardRefWithStatics(
case SwiperStatus.STARTDRAG:
nextIndex.current = previousIndex.current;
break;
case SwiperStatus.ENDDRAG:
setSwiperStatus(SwiperStatus.IDLE);
break;
}
}, [autoplay, directionAxis, duration, enterIdle, enterSwitching, interval, quitSwitching, swiperStatus]);

Expand Down Expand Up @@ -573,14 +569,26 @@ const Swiper = forwardRefWithStatics(

if (!enableNavigation) return '';
if (isSwiperNavigation) {
return (
<>
{controlsNav(navigation as SwiperNavigation)}
{typeNav(navigation as SwiperNavigation)}
</>
);
const controls = controlsNav(navigation as SwiperNavigation);
const type = typeNav(navigation as SwiperNavigation);
if (controls || type) {
return (
<span
className={classNames(
swiperNavClass,
`${swiperNavClass}--${direction}`,
`${swiperNavClass}--${(navigation as SwiperNavigation)?.paginationPosition || 'bottom'}`,
`${isBottomPagination && (navigation as SwiperNavigation)?.placement ? `${swiperNavClass}--${(navigation as SwiperNavigation)?.placement} ` : ''}`,
)}
>
{controls}
{type}
</span>
);
}
return '';
}
return isObject(navigation) ? '' : parseTNode(navigation);
return parseTNode(navigation as any);
};

return (
Expand Down
Loading
Loading