Digital ACT-191 ONEAPP-7013 story: fixed observed issue on content scroll while changing peek, gutter and layout.
This commit is contained in:
parent
938364535b
commit
99fe7e22ac
@ -120,7 +120,7 @@ open class Carousel: View {
|
||||
open var peek: Peek = .standard { didSet { setNeedsUpdate() } }
|
||||
|
||||
/// The initial visible slide's index in the carousel.
|
||||
open var groupIndex: Int? { didSet { setNeedsUpdate() } }
|
||||
open var groupIndex: Int = 0 { didSet { setNeedsUpdate() } }
|
||||
|
||||
/// If provided, will set the alignment for slot content when the slots has different heights.
|
||||
open var slotAlignment: CarouselSlotAlignmentModel? = .init(vertical: .top, horizontal: .left) { didSet { setNeedsUpdate() } }
|
||||
@ -277,12 +277,6 @@ open class Carousel: View {
|
||||
|
||||
updatePaginationControls()
|
||||
addCarouselSlots()
|
||||
|
||||
// If groupIndex is received, the carousel should update its position.
|
||||
if let groupIndex {
|
||||
let totalPos = totalPositions()
|
||||
carouselScrollBar.position = groupIndex >= totalPos ? totalPos : groupIndex+1
|
||||
}
|
||||
}
|
||||
|
||||
/// Resets to default settings.
|
||||
@ -304,6 +298,12 @@ open class Carousel: View {
|
||||
nextButton.onClick = { _ in self.nextButtonClick() }
|
||||
previousButton.onClick = { _ in self.previousButtonClick() }
|
||||
|
||||
/// Will be called when the scrubber position changes.
|
||||
carouselScrollBar.onScrubberDrag = { [weak self] scrubberId in
|
||||
guard let self else { return }
|
||||
updateScrollPosition(position: scrubberId, callbackText:"onThumbPositionChange")
|
||||
}
|
||||
|
||||
/// Will be called when the scrollbar thumb move forward.
|
||||
carouselScrollBar.onMoveForward = { [weak self] scrubberId in
|
||||
guard let self else { return }
|
||||
@ -484,7 +484,7 @@ open class Carousel: View {
|
||||
break
|
||||
}
|
||||
}
|
||||
minimumSlotWidth = minimumSlotWidth / CGFloat(layout.value)
|
||||
minimumSlotWidth = ceil(minimumSlotWidth / CGFloat(layout.value))
|
||||
}
|
||||
|
||||
private func nextButtonClick() {
|
||||
@ -533,27 +533,18 @@ open class Carousel: View {
|
||||
let isScrollbarSuppressed = views.count > 0 && layout.value == views.count
|
||||
let isPeekMinimumOnTablet = UIDevice.isIPad && peek == .minimum
|
||||
if !isScrollbarSuppressed {
|
||||
let subpart = minimumSlotWidth + gutter.value
|
||||
let xPosition = CGFloat( Float(position-1) * Float(layout.value) * Float(subpart))
|
||||
switch peek {
|
||||
case .standard:
|
||||
if UIDevice.isIPad {
|
||||
xPos = xPosition - (minimumSlotWidth/(CGFloat(layout.value) + 3))/2
|
||||
} else if layout == .oneUP {
|
||||
xPos = xPosition - gutter.value - (minimumSlotWidth/4)/2
|
||||
}
|
||||
case .minimum:
|
||||
xPos = isPeekMinimumOnTablet ? xPosition : xPosition - peekMinimum
|
||||
case .none:
|
||||
xPos = xPosition
|
||||
}
|
||||
let slotWidthWithGutter = minimumSlotWidth + gutter.value
|
||||
let xPosition = CGFloat( Float(position-1) * Float(layout.value) * Float(slotWidthWithGutter))
|
||||
let peekWidth = (containerView.frame.size.width - gutter.value - (Double(layout.value) * (minimumSlotWidth + gutter.value)))/2
|
||||
xPos = (peek == .none || isPeekMinimumOnTablet) ? xPosition : xPosition - gutter.value - peekWidth
|
||||
}
|
||||
}
|
||||
carouselScrollBar.scrubberId = position+1
|
||||
let yPos = scrollView.contentOffset.y
|
||||
scrollView.setContentOffset(CGPoint(x: xPos, y: yPos), animated: true)
|
||||
scrollView.setContentOffset(CGPoint(x: xPos, y: yPos), animated: false)
|
||||
showPaginationControls()
|
||||
onChangePublisher.send(position-1)
|
||||
groupIndex = position-1
|
||||
onChangePublisher.send(groupIndex)
|
||||
}
|
||||
}
|
||||
|
||||
@ -571,9 +562,4 @@ extension Carousel: UIScrollViewDelegate {
|
||||
updateScrollbarPosition(targetContentOffsetXPos: targetContentOffset.pointee.x)
|
||||
}
|
||||
|
||||
public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
|
||||
var visibleRect = CGRect()
|
||||
visibleRect.origin = scrollView.contentOffset
|
||||
updateScrollbarPosition(targetContentOffsetXPos: visibleRect.origin.x)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user