Skip to content

Commit

Permalink
fix(swiper): display abnormal when dir = 'rtl' (#2454)
Browse files Browse the repository at this point in the history
* fix(swiper): display abnormal when rtl

* fix: adjust
  • Loading branch information
Alex-huxiyang authored Jul 19, 2024
1 parent 4047426 commit 7bc7a46
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/packages/swiper/effects/default.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { ReactNode } from 'react'
import { animated, SpringValue } from '@react-spring/web'
import { useRtl } from '@/packages/configprovider'

type DefaultEffect = {
children: ReactNode
Expand Down Expand Up @@ -29,14 +30,16 @@ const getPerSlidePosition = (
export const defaultEffect = (args: DefaultEffect) => {
return React.Children.map(args.children, (child, index) => {
const { isVertical, getSpringsAxis, loop, count } = args
const rtl = useRtl()
const position = rtl ? 'right' : 'left'
return (
<animated.div
className="nut-swiper-slide"
style={{
[isVertical ? 'y' : 'x']: getSpringsAxis().to((position) => {
return getPerSlidePosition(index, position, loop, count)
}),
[isVertical ? 'top' : 'left']: `-${index * 100}%`,
[isVertical ? 'top' : position]: `-${index * 100}%`,
}}
>
{child}
Expand Down
5 changes: 4 additions & 1 deletion src/packages/swiper/effects/focus.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { ReactNode, useEffect } from 'react'
import { animated } from '@react-spring/web'
import { getRefValue, useRefState } from '@/utils/use-ref-state'
import { useRtl } from '@/packages/configprovider'

export interface FocusEffect {
name: 'focus'
Expand Down Expand Up @@ -39,6 +40,8 @@ const getPerSlidePosition = (
}
export const focusEffect = (args: DefaultEffect) => {
return React.Children.map(args.children, (child, index) => {
const rtl = useRtl()
const position = rtl ? 'right' : 'left'
const {
isVertical,
springs,
Expand All @@ -59,7 +62,7 @@ export const focusEffect = (args: DefaultEffect) => {
return getPerSlidePosition(index, position, loop, count)
}
),
[isVertical ? 'top' : 'left']: `-${index * 100}%`,
[isVertical ? 'top' : position]: `-${index * 100}%`,
scale: springs.s.to((ss: number) => {
const scales = getRefValue(transforms)
if (!scales) return 1
Expand Down

0 comments on commit 7bc7a46

Please sign in to comment.