Digital ACT-191 ONEAPP-10928 story: loading button data if provided

This commit is contained in:
Vasavi Kanamarlapudi 2024-09-27 17:05:19 +05:30
parent e71b94bc4f
commit 8a63ea5c75
3 changed files with 47 additions and 37 deletions

View File

@ -30,8 +30,7 @@ open class Modal: Control, ModalLaunchable {
public required init?(coder: NSCoder) { public required init?(coder: NSCoder) {
super.init(coder: coder) super.init(coder: coder)
} }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
@ -52,6 +51,12 @@ open class Modal: Control, ModalLaunchable {
/// UIView rendered for the content area of the modal /// UIView rendered for the content area of the modal
open var contentView: UIView? { didSet { setNeedsUpdate() } } open var contentView: UIView? { didSet { setNeedsUpdate() } }
///// Array of Buttonable Views that are shown as Modal Footer. Primary and Close button data for modal button group.
open var buttonData: [ButtonBase]? { didSet { setNeedsUpdate() } }
///// If provided, the Modal Dialog will render at full screen.
open var fullScreenDialog: Bool = false { didSet { setNeedsUpdate() } }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Overrides // MARK: - Overrides
//-------------------------------------------------- //--------------------------------------------------
@ -87,7 +92,7 @@ open class Modal: Control, ModalLaunchable {
return "Modal" return "Modal"
} }
} }
bridge_accessibilityHintBlock = { [weak self] in bridge_accessibilityHintBlock = { [weak self] in
guard let self else { return "" } guard let self else { return "" }
return isEnabled ? "Double tap to open." : "" return isEnabled ? "Double tap to open." : ""
@ -99,17 +104,18 @@ open class Modal: Control, ModalLaunchable {
modalModel: .init(closeButtonText: showModalButton.text ?? "", modalModel: .init(closeButtonText: showModalButton.text ?? "",
title: title, title: title,
content: content, content: content,
contentView: contentView), contentView: contentView,
buttonData: buttonData),
presenter: self) presenter: self)
} }
/// Used to make changes to the View based off a change events or from local properties. /// Used to make changes to the View based off a change events or from local properties.
open override func updateView() { open override func updateView() {
super.updateView() super.updateView()
showModalButton.surface = surface showModalButton.surface = surface
} }
public static func accessibleText(for title: String?, content: String?, closeButtonText: String) -> String { public static func accessibleText(for title: String?, content: String?, closeButtonText: String) -> String {
var label = "" var label = ""
if let title { if let title {
@ -132,5 +138,5 @@ extension Modal: AppleGuidelinesTouchable {
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool { override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
Self.acceptablyOutsideBounds(point: point, bounds: bounds) Self.acceptablyOutsideBounds(point: point, bounds: bounds)
} }
} }

View File

@ -51,7 +51,7 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
open var children: [any ViewProtocol] { [closeCrossButton, titleLabel, contentLabel, closeButton] } open var children: [any ViewProtocol] { [closeCrossButton, titleLabel, contentLabel, buttonGroupData] }
open var modalModel = Modal.ModalModel() { didSet { setNeedsUpdate() } } open var modalModel = Modal.ModalModel() { didSet { setNeedsUpdate() } }
@ -73,8 +73,11 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol {
$0.customContainerSize = UIDevice.isIPad ? 48 : 48 $0.customContainerSize = UIDevice.isIPad ? 48 : 48
$0.customIconSize = UIDevice.isIPad ? 32 : 32 $0.customIconSize = UIDevice.isIPad ? 32 : 32
} }
open lazy var closeButton = Button().with{ $0.use = .secondary; $0.text = "Close"}
open var buttonGroupData = ButtonGroup().with {
$0.alignment = .left
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Configuration // MARK: - Configuration
//-------------------------------------------------- //--------------------------------------------------
@ -123,14 +126,14 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol {
// Max Width: 70% of viewport width. // Max Width: 70% of viewport width.
// Maximum width is only applied to a provided width and not to the default. // Maximum width is only applied to a provided width and not to the default.
maxWidth = fullWidth * (70/100) maxWidth = UIDevice.isIPad ? fullWidth * (70/100): fullWidth
// Max Height: Total window height 70% of viewport height. // Max Height: Total window height 70% of viewport height.
// For Tablet: By default the model's height is dynamic and is based on the amount of content // For Tablet: By default the model's height is dynamic and is based on the amount of content
// it contains. it can expand between a minimum and maximum height. The minimum height is determined by the minimum // it contains. it can expand between a minimum and maximum height. The minimum height is determined by the minimum
// height of the content area plus the top and bottom padding. // height of the content area plus the top and bottom padding.
maxHeight = UIScreen.main.bounds.size.height * (70/100) maxHeight = UIDevice.isIPad ? UIScreen.main.bounds.size.height * (70/100) : UIScreen.main.bounds.size.height
titleLabel.accessibilityTraits = .header titleLabel.accessibilityTraits = .header
layer.cornerRadius = 12 layer.cornerRadius = 12
@ -140,10 +143,10 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol {
contentStackView.setCustomSpacing(contentLabelTopSpace, after: titleLabel) contentStackView.setCustomSpacing(contentLabelTopSpace, after: titleLabel)
scrollView.addSubview(contentStackView) scrollView.addSubview(contentStackView)
// Add crossButon, scrollView, closeButton. // Add crossButon, scrollView, buttonsData.
addSubview(closeCrossButton) addSubview(closeCrossButton)
addSubview(scrollView) addSubview(scrollView)
addSubview(closeButton) addSubview(buttonGroupData)
self.bringSubviewToFront(closeCrossButton) self.bringSubviewToFront(closeCrossButton)
let crossTopSpace = UIDevice.isIPad ? 0 : VDSLayout.space12X let crossTopSpace = UIDevice.isIPad ? 0 : VDSLayout.space12X
@ -161,21 +164,21 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol {
closeCrossButton.heightAnchor.constraint(equalToConstant: closeCrossButtonSize), closeCrossButton.heightAnchor.constraint(equalToConstant: closeCrossButtonSize),
// Constraints for the bottom button view // Constraints for the bottom button view
closeButton.leadingAnchor.constraint(equalTo: leadingAnchor, constant:containerViewInset), buttonGroupData.leadingAnchor.constraint(equalTo: leadingAnchor, constant:containerViewInset),
closeButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -containerViewInset), buttonGroupData.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -containerViewInset),
closeButton.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -containerViewInset), buttonGroupData.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -containerViewInset),
// Constraints for the scrollView // Constraints for the scrollView
scrollView.topAnchor.constraint(equalTo: topAnchor, constant: scrollTopSpace), scrollView.topAnchor.constraint(equalTo: topAnchor, constant: scrollTopSpace),
scrollView.leadingAnchor.constraint(equalTo: leadingAnchor, constant:containerViewInset), scrollView.leadingAnchor.constraint(equalTo: leadingAnchor, constant:containerViewInset),
scrollView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -contentTrailingSpace), scrollView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -contentTrailingSpace),
scrollView.bottomAnchor.constraint(equalTo: closeButton.topAnchor, constant: -contentLabelBottomSpace), scrollView.bottomAnchor.constraint(equalTo: buttonGroupData.topAnchor, constant: -contentLabelBottomSpace),
scrollView.widthAnchor.constraint(equalToConstant: (maxWidth - (containerViewInset + contentTrailingSpace))), scrollView.widthAnchor.constraint(equalToConstant: (maxWidth - (containerViewInset + contentTrailingSpace))),
// Constraints for the contentStackView // Constraints for the contentStackView
contentStackView.topAnchor.constraint(equalTo: scrollView.topAnchor), contentStackView.topAnchor.constraint(equalTo: scrollView.topAnchor),
contentStackView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor), contentStackView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),
contentStackView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor), contentStackView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor, constant: -contentTrailingSpace),
contentStackView.widthAnchor.constraint(equalTo: scrollView.widthAnchor, constant: -contentTrailingSpace), contentStackView.widthAnchor.constraint(equalTo: scrollView.widthAnchor, constant: -contentTrailingSpace),
contentStackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor) contentStackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor)
]) ])
@ -190,15 +193,14 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol {
open override func updateView() { open override func updateView() {
super.updateView() super.updateView()
heightConstraint?.deactivate() maxWidth = UIDevice.isIPad ? UIScreen.main.bounds.size.width * (70/100) : UIScreen.main.bounds.size.width
maxWidth = UIScreen.main.bounds.size.width * (70/100) maxHeight = UIDevice.isIPad ? UIScreen.main.bounds.size.height * (70/100) : UIScreen.main.bounds.size.height
maxHeight = UIScreen.main.bounds.size.height * (70/100)
// Update surface and background // Update surface and background
backgroundColor = backgroundColorConfiguration.getColor(self) backgroundColor = backgroundColorConfiguration.getColor(self)
scrollView.indicatorStyle = surface == .light ? .black : .white scrollView.indicatorStyle = surface == .light ? .black : .white
closeCrossButton.surface = surface closeCrossButton.surface = surface
closeButton.surface = surface buttonGroupData.surface = surface
titleLabel.surface = surface titleLabel.surface = surface
contentLabel.surface = surface contentLabel.surface = surface
@ -212,6 +214,15 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol {
titleLabel.sizeToFit() titleLabel.sizeToFit()
contentLabel.sizeToFit() contentLabel.sizeToFit()
// Add buttons data if provided
if let buttons = modalModel.buttonData, buttons.count > 0 {
buttonGroupData.buttons = buttons
let percent = UIDevice.isIPad ? 50.0 : 100.0
buttonGroupData.rowQuantityTablet = 2
buttonGroupData.rowQuantityPhone = 1
buttonGroupData.childWidth = .percentage(percent)
}
// Update title, content and contentview // Update title, content and contentview
var addedTitle = false var addedTitle = false
@ -237,26 +248,17 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol {
contentStackView.setCustomSpacing(contentLabelTopSpace, after: titleLabel) contentStackView.setCustomSpacing(contentLabelTopSpace, after: titleLabel)
} }
// Update closeButton
let textColor = textColorConfiguration.getColor(self)
closeButton.setTitleColor(textColor, for: .normal)
closeButton.setTitleColor(textColor, for: .highlighted)
closeButton.setTitle(modalModel.closeButtonText, for: .normal)
closeButton.accessibilityLabel = modalModel.closeButtonText
contentStackView.setNeedsLayout() contentStackView.setNeedsLayout()
contentStackView.layoutIfNeeded() contentStackView.layoutIfNeeded()
scrollView.setNeedsLayout() scrollView.setNeedsLayout()
scrollView.layoutIfNeeded() scrollView.layoutIfNeeded()
heightConstraint?.constant = maxHeight heightConstraint?.constant = maxHeight
heightConstraint?.activate()
} }
/// Used to update any Accessibility properties. /// Used to update any Accessibility properties.
open override func updateAccessibility() { open override func updateAccessibility() {
super.updateAccessibility() super.updateAccessibility()
primaryAccessibilityElement.accessibilityHint = "Double tap on the \(modalModel.closeButtonText) button to close." primaryAccessibilityElement.accessibilityHint = "Double tap on the cross button to close."
primaryAccessibilityElement.accessibilityFrameInContainerSpace = .init(origin: .zero, size: frame.size) primaryAccessibilityElement.accessibilityFrameInContainerSpace = .init(origin: .zero, size: frame.size)
} }
@ -264,8 +266,7 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol {
get { get {
var elements: [Any] = [primaryAccessibilityElement] var elements: [Any] = [primaryAccessibilityElement]
contentStackView.arrangedSubviews.forEach{ elements.append($0) } contentStackView.arrangedSubviews.forEach{ elements.append($0) }
elements.append(closeButton) elements.append(buttonGroupData)
return elements return elements
} }
set {} set {}

View File

@ -19,10 +19,12 @@ extension Modal {
public var contentView: UIView? public var contentView: UIView?
public var accessibleText: String? public var accessibleText: String?
public var contentViewAlignment: UIStackView.Alignment? public var contentViewAlignment: UIStackView.Alignment?
public var buttonData: [ButtonBase]?
public init(closeButtonText: String = "Close", public init(closeButtonText: String = "Close",
title: String? = nil, title: String? = nil,
content: String? = nil, content: String? = nil,
contentView: UIView? = nil, contentView: UIView? = nil,
buttonData: [ButtonBase]? = nil,
accessibleText: String? = "Modal", accessibleText: String? = "Modal",
contentViewAlignment: UIStackView.Alignment = .leading) { contentViewAlignment: UIStackView.Alignment = .leading) {
self.closeButtonText = closeButtonText self.closeButtonText = closeButtonText
@ -31,6 +33,7 @@ extension Modal {
self.contentView = contentView self.contentView = contentView
self.accessibleText = accessibleText self.accessibleText = accessibleText
self.contentViewAlignment = contentViewAlignment self.contentViewAlignment = contentViewAlignment
self.buttonData = buttonData
} }
} }
} }