diff --git a/ACarouselDemo/ACarouselDemo.xcodeproj/project.pbxproj b/ACarouselDemo/ACarouselDemo.xcodeproj/project.pbxproj index 1b880d7..a75d179 100644 --- a/ACarouselDemo/ACarouselDemo.xcodeproj/project.pbxproj +++ b/ACarouselDemo/ACarouselDemo.xcodeproj/project.pbxproj @@ -326,7 +326,7 @@ COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_ASSET_PATHS = "\"ACarouselDemo iOS/Preview Content\""; - DEVELOPMENT_TEAM = FJ92PFEJWW; + DEVELOPMENT_TEAM = 2E2G8B343X; ENABLE_PREVIEWS = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -402,7 +402,7 @@ COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = "\"ACarouselDemo iOS/Preview Content\""; - DEVELOPMENT_TEAM = FJ92PFEJWW; + DEVELOPMENT_TEAM = 2E2G8B343X; ENABLE_NS_ASSERTIONS = NO; ENABLE_PREVIEWS = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -474,7 +474,7 @@ COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_ASSET_PATHS = "\"ACarouselDemo macOS/Preview Content\""; - DEVELOPMENT_TEAM = FJ92PFEJWW; + DEVELOPMENT_TEAM = 2E2G8B343X; ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -552,7 +552,7 @@ COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = "\"ACarouselDemo macOS/Preview Content\""; - DEVELOPMENT_TEAM = FJ92PFEJWW; + DEVELOPMENT_TEAM = 2E2G8B343X; ENABLE_HARDENED_RUNTIME = YES; ENABLE_NS_ASSERTIONS = NO; ENABLE_PREVIEWS = YES; diff --git a/Sources/ACarousel/ACarouselViewModel.swift b/Sources/ACarousel/ACarouselViewModel.swift index 79199ef..88515f3 100644 --- a/Sources/ACarousel/ACarouselViewModel.swift +++ b/Sources/ACarousel/ACarouselViewModel.swift @@ -245,16 +245,31 @@ extension ACarouselViewModel { /// Defines the maximum value of the drag /// Avoid dragging more than the values of multiple subviews at the end of the drag, /// and still only one subview is toggled + ///Support RTL + if UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft { + var offset: CGFloat = itemActualWidth if value.translation.width > 0 { - offset = min(offset, value.translation.width) + offset = -min(offset, value.translation.width) } else { - offset = max(-offset, value.translation.width) + offset = -max(-offset, value.translation.width) } /// set drag offset dragOffset = offset + }else{ + var offset: CGFloat = itemActualWidth + if value.translation.width > 0 { + offset = min(offset, value.translation.width) + } else { + offset = max(-offset, value.translation.width) + } + + /// set drag offset + dragOffset = offset + + } /// stop active timer isTimerActive = false } @@ -272,16 +287,32 @@ extension ACarouselViewModel { /// At the end of the drag, if the drag value exceeds the drag threshold, /// the active view will be toggled /// default is one third of subview - let dragThreshold: CGFloat = itemWidth / 3 - - var activeIndex = self.activeIndex - if value.translation.width > dragThreshold { - activeIndex -= 1 - } - if value.translation.width < -dragThreshold { - activeIndex += 1 + if UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft { + + let dragThreshold: CGFloat = itemWidth / 3 + + var activeIndex = self.activeIndex + if value.translation.width > dragThreshold { + activeIndex += 1 + } + if value.translation.width < -dragThreshold { + activeIndex -= 1 + } + self.activeIndex = max(0, min(activeIndex, data.count - 1)) + }else{ + + let dragThreshold: CGFloat = itemWidth / 3 + + var activeIndex = self.activeIndex + if value.translation.width > dragThreshold { + activeIndex -= 1 + } + if value.translation.width < -dragThreshold { + activeIndex += 1 + } + self.activeIndex = max(0, min(activeIndex, data.count - 1)) + } - self.activeIndex = max(0, min(activeIndex, data.count - 1)) } }