Digital ACT-191 ONEAPP-7013 story: add corner radius to slot, supporting to dynamic pagination inset
This commit is contained in:
parent
a829df86e5
commit
0a27c27189
@ -161,8 +161,9 @@ open class Carousel: View {
|
||||
open var paginationInset: CGFloat {
|
||||
get { return _paginationInset }
|
||||
set {
|
||||
_paginationInset = newValue
|
||||
setNeedsUpdate()
|
||||
let minValue = UIDevice.isIPad ? VDSLayout.space3X : VDSLayout.space2X
|
||||
_paginationInset = (newValue < minValue) ? minValue : newValue
|
||||
updatePaginationInset()
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,7 +181,7 @@ open class Carousel: View {
|
||||
|
||||
/// If provided, will set the alignment for slot content when the slots has different heights.
|
||||
open var slotAlignment: [CarouselSlotAlignmentModel] = [] { didSet { setNeedsUpdate() } }
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
//--------------------------------------------------
|
||||
@ -254,7 +255,9 @@ open class Carousel: View {
|
||||
private var selectedGroupIndex: Int? { didSet { setNeedsUpdate() } }
|
||||
private var containerStackHeightConstraint: NSLayoutConstraint?
|
||||
private var containerViewHeightConstraint: NSLayoutConstraint?
|
||||
|
||||
private var prevButtonLeadingConstraint: NSLayoutConstraint?
|
||||
private var nextButtonTrailingConstraint: NSLayoutConstraint?
|
||||
|
||||
// The scrollbar has top 5X space. So the expected top space is adjusted for tablet and mobile.
|
||||
let scrollbarTopSpace = UIDevice.isIPad ? VDSLayout.space3X : VDSLayout.space1X
|
||||
|
||||
@ -292,12 +295,12 @@ open class Carousel: View {
|
||||
// add pagination button icons
|
||||
scrollContainerView.addSubview(previousButton)
|
||||
previousButton
|
||||
.pinLeading(paginationInset)
|
||||
.pinLeadingGreaterThanOrEqualTo()
|
||||
.pinCenterY()
|
||||
|
||||
scrollContainerView.addSubview(nextButton)
|
||||
nextButton
|
||||
.pinTrailing(paginationInset)
|
||||
.pinTrailingLessThanOrEqualTo()
|
||||
.pinCenterY()
|
||||
|
||||
// add scroll container view & carousel scrollbar
|
||||
@ -314,10 +317,9 @@ open class Carousel: View {
|
||||
|
||||
addlisteners()
|
||||
}
|
||||
|
||||
|
||||
open override func updateView() {
|
||||
super.updateView()
|
||||
|
||||
carouselScrollBar.numberOfSlides = data.count
|
||||
carouselScrollBar.layout = _layout
|
||||
carouselScrollBar.position = (carouselScrollBar.position == 0 || carouselScrollBar.position > carouselScrollBar.numberOfSlides) ? 1 : carouselScrollBar.position
|
||||
@ -327,7 +329,7 @@ open class Carousel: View {
|
||||
if peek == .none {
|
||||
paginationDisplay = .persistent
|
||||
}
|
||||
|
||||
|
||||
containerViewHeightConstraint?.isActive = false
|
||||
containerStackHeightConstraint?.isActive = false
|
||||
updatePaginationControls()
|
||||
@ -354,6 +356,7 @@ open class Carousel: View {
|
||||
.pinLeading(xPos)
|
||||
.width(minimumSlotWidth)
|
||||
.height(slotHeight)
|
||||
carouselSlot.layer.cornerRadius = 12.0
|
||||
xPos = xPos + minimumSlotWidth + gutter.value
|
||||
}
|
||||
scrollView.contentSize = CGSize(width: xPos - gutter.value, height: slotHeight)
|
||||
@ -388,13 +391,7 @@ open class Carousel: View {
|
||||
func addlisteners() {
|
||||
nextButton.onClick = { _ in self.nextButtonClick() }
|
||||
previousButton.onClick = { _ in self.previousButtonClick() }
|
||||
|
||||
//setup test page to show scrubber id was changed
|
||||
// carouselScrollBar.onScrubberDrag = { [weak self] scrubberId in
|
||||
// guard let self else { return }
|
||||
// updateScrollPosition(position: scrubberId, callbackText:"onScrubberDrag")
|
||||
// }
|
||||
|
||||
|
||||
/// will be called when the thumb move forward.
|
||||
carouselScrollBar.onMoveForward = { [weak self] scrubberId in
|
||||
guard let self else { return }
|
||||
@ -431,6 +428,15 @@ open class Carousel: View {
|
||||
nextButton.surface = surface
|
||||
}
|
||||
|
||||
func updatePaginationInset() {
|
||||
prevButtonLeadingConstraint?.isActive = false
|
||||
nextButtonTrailingConstraint?.isActive = false
|
||||
prevButtonLeadingConstraint = previousButton.leadingAnchor.constraint(equalTo: scrollContainerView.leadingAnchor, constant: paginationInset)
|
||||
nextButtonTrailingConstraint = nextButton.trailingAnchor.constraint(equalTo: scrollContainerView.trailingAnchor, constant: -paginationInset)
|
||||
prevButtonLeadingConstraint?.isActive = true
|
||||
nextButtonTrailingConstraint?.isActive = true
|
||||
}
|
||||
|
||||
func getSlotWidth() {
|
||||
let actualWidth = containerView.frame.size.width
|
||||
minimumSlotWidth = actualWidth - (CGFloat(layout.value) * gutter.value)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user