Digital ACT-191 ONEAPP-7013 story: Refactored code, removing redundant view and adding component to slot.

This commit is contained in:
Vasavi Kanamarlapudi 2024-07-18 17:28:40 +05:30
parent 559423f629
commit 93004f6e12

View File

@ -417,32 +417,29 @@ open class Carousel: View {
// Add received component // Add received component
let item : CarouselSlotItemModel = .init(component: views[x]) let item : CarouselSlotItemModel = .init(component: views[x])
let contentViewHeight = estimateHeightFor(item: item, with: minimumSlotWidth)
// Add subview for content to Carousel Slot
let contentView = View().with {
$0.clipsToBounds = true
}
carouselSlot.addSubview(contentView)
if let component = item.component { if let component = item.component {
carouselSlot.addSubview(component)
if slotAlignment != nil { if slotAlignment != nil {
// If slotAlignment exist, should use expected height // If slotAlignment exist, use component's own sizes
contentView.widthAnchor.constraint(equalToConstant: minimumSlotWidth).activate() component.widthAnchor.constraint(lessThanOrEqualTo: carouselSlot.widthAnchor).activate()
contentView.heightAnchor.constraint(equalToConstant: contentViewHeight).activate() setSlotAlignment(contentView: component, parentView: carouselSlot)
setSlotAlignment(contentView: contentView, parentView: carouselSlot)
} else { } else {
// If no slotAlignment, should use full slot // If no slotAlignment, should use full slot
contentView.pinToSuperView() component.pinToSuperView()
} }
carouselSlot.backgroundColor = .clear carouselSlot.backgroundColor = .clear
carouselSlot.layer.cornerRadius = 0 carouselSlot.layer.cornerRadius = 0
contentView.addSubview(component)
component.pinToSuperView()
if var surfacedView = component as? Surfaceable { if var surfacedView = component as? Surfaceable {
contentView.surface = surface
surfacedView.surface = surface surfacedView.surface = surface
} }
// TO BE REMOVED AFTER VQA - borderWidth and borderColor below did set only for Testing purpose to VQA
carouselSlot.layer.borderWidth = 1.0
carouselSlot.layer.borderColor = SurfaceColorConfiguration().with {
$0.lightColor = VDSColor.elementsPrimaryOnlight
$0.darkColor = VDSColor.elementsPrimaryOndark
}.getColor(self).cgColor
} }
} }
scrollView.contentSize = CGSize(width: xPos - gutter.value, height: slotHeight) scrollView.contentSize = CGSize(width: xPos - gutter.value, height: slotHeight)
@ -462,7 +459,7 @@ open class Carousel: View {
} }
// Set slot alignment if provided. Used only when slot content have different heights or widths. // Set slot alignment if provided. Used only when slot content have different heights or widths.
private func setSlotAlignment(contentView: View, parentView: View) { private func setSlotAlignment(contentView: UIView, parentView: View) {
parentView.backgroundColor = .clear parentView.backgroundColor = .clear
switch slotAlignment?.vertical { switch slotAlignment?.vertical {
case .top: case .top: