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
8 changes: 4 additions & 4 deletions ACarouselDemo/ACarouselDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
53 changes: 42 additions & 11 deletions Sources/ACarousel/ACarouselViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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))
}
}

Expand Down