From c51093cfaf3788e567c4ee29c560e5b104a9125b Mon Sep 17 00:00:00 2001 From: Vasavi Kanamarlapudi Date: Fri, 28 Jun 2024 17:04:00 +0530 Subject: [PATCH] Digital ACT-191 ONEAPP-7013 story: update view as per aspect ratio --- VDS/Components/Carousel/Carousel.swift | 46 +++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/VDS/Components/Carousel/Carousel.swift b/VDS/Components/Carousel/Carousel.swift index 80c55b16..c5d0ab0e 100644 --- a/VDS/Components/Carousel/Carousel.swift +++ b/VDS/Components/Carousel/Carousel.swift @@ -355,6 +355,8 @@ open class Carousel: View { $0.backgroundColor = UIColor(red: CGFloat(216) / 255.0, green: CGFloat(218) / 255.0, blue: CGFloat(218) / 255.0, alpha: 1) } scrollView.addSubview(carouselSlot) + let size = ratioSize(for: minimumSlotWidth) + slotHeight = size.height carouselSlot .pinTop() .pinBottom() @@ -382,17 +384,51 @@ open class Carousel: View { } open override func reset() { - for subview in subviews { - for recognizer in subview.gestureRecognizers ?? [] { - subview.removeGestureRecognizer(recognizer) - } - } super.reset() + shouldUpdateView = false + aspectRatio = .ratio1x1 + layout = UIDevice.isIPad ? .threeUP : .oneUP + pagination = .init(kind: .lowContrast, floating: true) + paginationDisplay = .none + paginationInset = UIDevice.isIPad ? VDSLayout.space3X : VDSLayout.space2X + gutter = UIDevice.isIPad ? .twentyFourPX : .twelvePX + peek = .standard + width = nil } //-------------------------------------------------- // MARK: - Private Methods //-------------------------------------------------- + private func ratioSize(for width: CGFloat) -> CGSize { + var height: CGFloat = width + + switch aspectRatio { + case .ratio1x1: + break; + case .ratio3x4: + height = (4 / 3) * width + case .ratio4x3: + height = (3 / 4) * width + case .ratio2x3: + height = (3 / 2) * width + case .ratio3x2: + height = (2 / 3) * width + case .ratio9x16: + height = (16 / 9) * width + case .ratio16x9: + height = (9 / 16) * width + case .ratio1x2: + height = (2 / 1) * width + case .ratio2x1: + height = (1 / 2) * width + + default: + break + } + + return CGSize(width: width, height: height) + } + func addlisteners() { nextButton.onClick = { _ in self.nextButtonClick() } previousButton.onClick = { _ in self.previousButtonClick() }