refactored to use new popover

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-06-20 18:24:21 -05:00
parent 0a2e6c88b6
commit ce6aad5540

View File

@ -5,7 +5,7 @@ import Combine
/// A dropdown select is an expandable menu of predefined options that allows a customer to make a single selection.
@objc(VDSDatePicker)
open class DatePicker: EntryFieldBase, DatePickerViewControllerDelegate, UIPopoverPresentationControllerDelegate {
open class DatePicker: EntryFieldBase {
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
@ -31,7 +31,7 @@ open class DatePicker: EntryFieldBase, DatePickerViewControllerDelegate, UIPopov
// MARK: - Private Properties
//--------------------------------------------------
internal var minWidthDefault = 186.0
internal var bottomStackView: UIStackView = {
return UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
@ -114,6 +114,16 @@ open class DatePicker: EntryFieldBase, DatePickerViewControllerDelegate, UIPopov
}
}
.store(in: &subscribers)
NotificationCenter.default
.publisher(for: UIDevice.orientationDidChangeNotification).sink { [weak self] _ in
guard let self, let popoverController else { return }
popoverController.dismiss(animated: true){ [weak self] in
guard let self else { return }
}
}
.store(in: &subscribers)
}
open override func getFieldContainer() -> UIView {
@ -153,31 +163,46 @@ open class DatePicker: EntryFieldBase, DatePickerViewControllerDelegate, UIPopov
selectedDateLabel.text = formatter.string(from: date)
}
internal func togglePicker() {
let calendarVC = DatePickerViewController(calendarModel, delegate: self)
calendarVC.modalPresentationStyle = .popover
calendarVC.selectedDate = selectedDate ?? Date()
if let popoverController = calendarVC.popoverPresentationController {
popoverController.delegate = self
popoverController.sourceView = containerView
popoverController.sourceRect = containerView.bounds
popoverController.permittedArrowDirections = .up
}
if let viewController = UIApplication.topViewController() {
viewController.present(calendarVC, animated: true, completion: nil)
}
}
internal var popoverController: UIViewController?
internal func didSelectDate(_ controller: DatePickerViewController, date: Date) {
func didSelect(_ date: Date) {
selectedDate = date
controller.dismiss(animated: true) { [weak self] in
sendActions(for: .valueChanged)
UIAccessibility.post(notification: .layoutChanged, argument: self.containerView)
popoverController?.dismiss(animated: true){ [weak self] in
guard let self else { return }
self.sendActions(for: .valueChanged)
UIAccessibility.post(notification: .layoutChanged, argument: self.containerView)
popoverController = nil
}
}
public func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
internal func togglePicker() {
let calendar = CalendarBase()
calendar.activeDates = calendarModel.activeDates
calendar.hideContainerBorder = calendarModel.hideContainerBorder
calendar.hideCurrentDateIndicator = calendarModel.hideCurrentDateIndicator
calendar.inactiveDates = calendarModel.inactiveDates
calendar.indicators = calendarModel.indicators
calendar.maxDate = calendarModel.maxDate
calendar.minDate = calendarModel.minDate
calendar.surface = calendarModel.surface
calendar.setNeedsLayout()
calendar.layoutIfNeeded()
calendar.onChange = { [weak self] control in
guard let self else { return }
didSelect(control.selectedDate)
}
popoverController = ClearPopoverViewController(contentView: calendar,
arrow: .up,
sourceView: containerView,
sourceRect: containerView.bounds,
spacing: VDSLayout.space1X)
if let viewController = UIApplication.topViewController(), let popoverController {
viewController.present(popoverController,
animated: true,
completion: nil)
}
}
}