Swiftify Alert
This commit is contained in:
parent
f231ea26d7
commit
e55d9e14f6
@ -278,7 +278,6 @@
|
||||
AAE96FA225341F6A0037A989 /* ListStoreLocatorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE96FA125341F6A0037A989 /* ListStoreLocatorModel.swift */; };
|
||||
AAE96FA525341F7D0037A989 /* ListStoreLocator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE96FA425341F7D0037A989 /* ListStoreLocator.swift */; };
|
||||
AF1C33652883B5A4006B1001 /* ActionTopNotificationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF1C33642883B5A4006B1001 /* ActionTopNotificationHandler.swift */; };
|
||||
AF1C33672883B712006B1001 /* ActionPopupHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF1C33662883B712006B1001 /* ActionPopupHandler.swift */; };
|
||||
AF1C336928859778006B1001 /* ActionAlertHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF1C336828859778006B1001 /* ActionAlertHandler.swift */; };
|
||||
AF1C336B28859C73006B1001 /* ActionTopAlertHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF1C336A28859C73006B1001 /* ActionTopAlertHandler.swift */; };
|
||||
AF1C336D28859EE1006B1001 /* ActionOpenPanelHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF1C336C28859EE1006B1001 /* ActionOpenPanelHandler.swift */; };
|
||||
@ -291,6 +290,7 @@
|
||||
AF7E509929E477C1009DC2AD /* AlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF7E509729E477C0009DC2AD /* AlertController.swift */; };
|
||||
AFA4932029E5CA73001A9663 /* AlertOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA4931F29E5CA73001A9663 /* AlertOperation.swift */; };
|
||||
AFA4932229E5EF2E001A9663 /* TopNotificationHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA4932129E5EF2E001A9663 /* TopNotificationHandler.swift */; };
|
||||
AFA4933F29E874F0001A9663 /* MVMCoreUILoggingDelegateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA4933E29E874F0001A9663 /* MVMCoreUILoggingDelegateProtocol.swift */; };
|
||||
AFE4A1D127DFB5EE00C458D0 /* VDSColorTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = AFE4A1D027DFB5EE00C458D0 /* VDSColorTokens.xcframework */; };
|
||||
AFE4A1D627DFBB6F00C458D0 /* UINavigationController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFE4A1D527DFBB6F00C458D0 /* UINavigationController+Extension.swift */; };
|
||||
BB105859248DEFF70069D008 /* UICollectionViewLeftAlignedLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB105858248DEFF60069D008 /* UICollectionViewLeftAlignedLayout.swift */; };
|
||||
@ -560,7 +560,6 @@
|
||||
D2EC7BDD2527B83700F540AF /* SectionHeaderFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2EC7BDC2527B83700F540AF /* SectionHeaderFooterView.swift */; };
|
||||
D2ED27EB254B0CE700A1C293 /* UIAlertActionStyle+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2ED27E6254B0CE600A1C293 /* UIAlertActionStyle+Codable.swift */; };
|
||||
D2ED27EC254B0CE700A1C293 /* UIAlertControllerStyle+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2ED27E7254B0CE600A1C293 /* UIAlertControllerStyle+Extension.swift */; };
|
||||
D2ED27ED254B0CE700A1C293 /* ActionPopupModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2ED27E8254B0CE600A1C293 /* ActionPopupModel.swift */; };
|
||||
D2ED27EE254B0CE700A1C293 /* ActionAlertModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2ED27E9254B0CE600A1C293 /* ActionAlertModel.swift */; };
|
||||
D2ED27EF254B0CE700A1C293 /* AlertModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2ED27EA254B0CE700A1C293 /* AlertModel.swift */; };
|
||||
D2ED27FB254B0E0300A1C293 /* MVMCoreAlertDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D2ED27F2254B0E0200A1C293 /* MVMCoreAlertDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@ -573,7 +572,6 @@
|
||||
D2ED2811254B0EB800A1C293 /* MVMCoreTopAlertObject.h in Headers */ = {isa = PBXBuildFile; fileRef = D2ED280A254B0EB700A1C293 /* MVMCoreTopAlertObject.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
D2ED2812254B0EB800A1C293 /* MVMCoreTopAlertObject.m in Sources */ = {isa = PBXBuildFile; fileRef = D2ED280B254B0EB800A1C293 /* MVMCoreTopAlertObject.m */; };
|
||||
D2ED2815254B0EE400A1C293 /* MVMCoreGlobalTopAlertDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D2ED2814254B0EE400A1C293 /* MVMCoreGlobalTopAlertDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
D2ED2818254B115400A1C293 /* MVMCoreUIActionDelegateProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D2ED2817254B112900A1C293 /* MVMCoreUIActionDelegateProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
D2FA83D22513EA6900564112 /* NotificationXButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FA83D12513EA6900564112 /* NotificationXButton.swift */; };
|
||||
D2FA83D42514F80C00564112 /* CollapsableNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FA83D32514F80C00564112 /* CollapsableNotification.swift */; };
|
||||
D2FA83D62515021F00564112 /* CollapsableNotificationTopView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2FA83D52515021F00564112 /* CollapsableNotificationTopView.swift */; };
|
||||
@ -885,7 +883,6 @@
|
||||
AAE96FA125341F6A0037A989 /* ListStoreLocatorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListStoreLocatorModel.swift; sourceTree = "<group>"; };
|
||||
AAE96FA425341F7D0037A989 /* ListStoreLocator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListStoreLocator.swift; sourceTree = "<group>"; };
|
||||
AF1C33642883B5A4006B1001 /* ActionTopNotificationHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionTopNotificationHandler.swift; sourceTree = "<group>"; };
|
||||
AF1C33662883B712006B1001 /* ActionPopupHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionPopupHandler.swift; sourceTree = "<group>"; };
|
||||
AF1C336828859778006B1001 /* ActionAlertHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionAlertHandler.swift; sourceTree = "<group>"; };
|
||||
AF1C336A28859C73006B1001 /* ActionTopAlertHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionTopAlertHandler.swift; sourceTree = "<group>"; };
|
||||
AF1C336C28859EE1006B1001 /* ActionOpenPanelHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenPanelHandler.swift; sourceTree = "<group>"; };
|
||||
@ -898,6 +895,7 @@
|
||||
AF7E509729E477C0009DC2AD /* AlertController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertController.swift; sourceTree = "<group>"; };
|
||||
AFA4931F29E5CA73001A9663 /* AlertOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertOperation.swift; sourceTree = "<group>"; };
|
||||
AFA4932129E5EF2E001A9663 /* TopNotificationHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopNotificationHandler.swift; sourceTree = "<group>"; };
|
||||
AFA4933E29E874F0001A9663 /* MVMCoreUILoggingDelegateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MVMCoreUILoggingDelegateProtocol.swift; sourceTree = "<group>"; };
|
||||
AFE4A1D027DFB5EE00C458D0 /* VDSColorTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSColorTokens.xcframework; path = ../SharedFrameworks/VDSColorTokens.xcframework; sourceTree = "<group>"; };
|
||||
AFE4A1D527DFBB6F00C458D0 /* UINavigationController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationController+Extension.swift"; sourceTree = "<group>"; };
|
||||
BB105858248DEFF60069D008 /* UICollectionViewLeftAlignedLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UICollectionViewLeftAlignedLayout.swift; sourceTree = "<group>"; };
|
||||
@ -1168,7 +1166,6 @@
|
||||
D2EC7BDC2527B83700F540AF /* SectionHeaderFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionHeaderFooterView.swift; sourceTree = "<group>"; };
|
||||
D2ED27E6254B0CE600A1C293 /* UIAlertActionStyle+Codable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIAlertActionStyle+Codable.swift"; sourceTree = "<group>"; };
|
||||
D2ED27E7254B0CE600A1C293 /* UIAlertControllerStyle+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIAlertControllerStyle+Extension.swift"; sourceTree = "<group>"; };
|
||||
D2ED27E8254B0CE600A1C293 /* ActionPopupModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionPopupModel.swift; sourceTree = "<group>"; };
|
||||
D2ED27E9254B0CE600A1C293 /* ActionAlertModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionAlertModel.swift; sourceTree = "<group>"; };
|
||||
D2ED27EA254B0CE700A1C293 /* AlertModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertModel.swift; sourceTree = "<group>"; };
|
||||
D2ED27F2254B0E0200A1C293 /* MVMCoreAlertDelegateProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreAlertDelegateProtocol.h; sourceTree = "<group>"; };
|
||||
@ -1182,7 +1179,6 @@
|
||||
D2ED280A254B0EB700A1C293 /* MVMCoreTopAlertObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreTopAlertObject.h; sourceTree = "<group>"; };
|
||||
D2ED280B254B0EB800A1C293 /* MVMCoreTopAlertObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MVMCoreTopAlertObject.m; sourceTree = "<group>"; };
|
||||
D2ED2814254B0EE400A1C293 /* MVMCoreGlobalTopAlertDelegateProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreGlobalTopAlertDelegateProtocol.h; sourceTree = "<group>"; };
|
||||
D2ED2817254B112900A1C293 /* MVMCoreUIActionDelegateProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIActionDelegateProtocol.h; sourceTree = "<group>"; };
|
||||
D2FA83D12513EA6900564112 /* NotificationXButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationXButton.swift; sourceTree = "<group>"; };
|
||||
D2FA83D32514F80C00564112 /* CollapsableNotification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollapsableNotification.swift; sourceTree = "<group>"; };
|
||||
D2FA83D52515021F00564112 /* CollapsableNotificationTopView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollapsableNotificationTopView.swift; sourceTree = "<group>"; };
|
||||
@ -1522,8 +1518,6 @@
|
||||
D2ED27E9254B0CE600A1C293 /* ActionAlertModel.swift */,
|
||||
D2ED27EA254B0CE700A1C293 /* AlertModel.swift */,
|
||||
AF1C336828859778006B1001 /* ActionAlertHandler.swift */,
|
||||
D2ED27E8254B0CE600A1C293 /* ActionPopupModel.swift */,
|
||||
AF1C33662883B712006B1001 /* ActionPopupHandler.swift */,
|
||||
C6687440259D92D400F32D13 /* ActionTopNotificationModel.swift */,
|
||||
AF1C33642883B5A4006B1001 /* ActionTopNotificationHandler.swift */,
|
||||
AF1C33722885D481006B1001 /* MVMCoreUIActionOpenPageHandler.swift */,
|
||||
@ -2329,11 +2323,11 @@
|
||||
D29DF27821E7A533003B2FB9 /* MVMCoreUISession.m */,
|
||||
D29DF27321E79E81003B2FB9 /* MVMCoreUILoggingHandler.h */,
|
||||
D29DF27421E79E81003B2FB9 /* MVMCoreUILoggingHandler.m */,
|
||||
AFA4933E29E874F0001A9663 /* MVMCoreUILoggingDelegateProtocol.swift */,
|
||||
D2C5001621F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h */,
|
||||
D2C5001721F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.m */,
|
||||
D2092352244F7D630044AD09 /* MVMCoreUIViewControllerMappingObject+Extension.swift */,
|
||||
D296E14622A597490051EBE7 /* MVMCoreUIViewConstrainingProtocol.h */,
|
||||
D2ED2817254B112900A1C293 /* MVMCoreUIActionDelegateProtocol.h */,
|
||||
AF1C33702885AE76006B1001 /* MVMCoreUIActionHandler.swift */,
|
||||
D23A90672614B0B4007E14CE /* CoreUIModelMapping.swift */,
|
||||
);
|
||||
@ -2588,7 +2582,6 @@
|
||||
D2ED280F254B0EB800A1C293 /* MVMCoreTopAlertViewProtocol.h in Headers */,
|
||||
D2ED280C254B0EB800A1C293 /* MVMCoreTopAlertAnimationDelegateProtocol.h in Headers */,
|
||||
D2ED280D254B0EB800A1C293 /* MVMCoreTopAlertOperation.h in Headers */,
|
||||
D2ED2818254B115400A1C293 /* MVMCoreUIActionDelegateProtocol.h in Headers */,
|
||||
D2ED27FB254B0E0300A1C293 /* MVMCoreAlertDelegateProtocol.h in Headers */,
|
||||
D2ED2810254B0EB800A1C293 /* MVMCoreTopAlertDelegateProtocol.h in Headers */,
|
||||
D2ED2815254B0EE400A1C293 /* MVMCoreGlobalTopAlertDelegateProtocol.h in Headers */,
|
||||
@ -2784,7 +2777,6 @@
|
||||
AAB9C10A243496DD00151545 /* RadioSwatch.swift in Sources */,
|
||||
D29DF2B421E7B76D003B2FB9 /* MFLoadingSpinner.m in Sources */,
|
||||
011D9602240DA20A000E3791 /* FormRuleWatcherFieldProtocol.swift in Sources */,
|
||||
AF1C33672883B712006B1001 /* ActionPopupHandler.swift in Sources */,
|
||||
D23A900926125FFB007E14CE /* GetContactBehavior.swift in Sources */,
|
||||
D264FAA1243CF66B00D98315 /* ContainerCollectionReusableView.swift in Sources */,
|
||||
AA617AB22453012400910B8F /* ListDeviceComplexLinkSmallModel.swift in Sources */,
|
||||
@ -2846,7 +2838,6 @@
|
||||
D29DF2A221E7AF4E003B2FB9 /* MVMCoreUIUtility.m in Sources */,
|
||||
D23A8FF82612308D007E14CE /* PageBehaviorProtocolRequirer.swift in Sources */,
|
||||
D29DF12B21E6851E003B2FB9 /* MVMCoreUITopAlertExpandableView.m in Sources */,
|
||||
D2ED27ED254B0CE700A1C293 /* ActionPopupModel.swift in Sources */,
|
||||
94C2D9A723872DA90006CF46 /* LabelAttributeColorModel.swift in Sources */,
|
||||
943820842432382400B43AF3 /* WebView.swift in Sources */,
|
||||
0103B84E23D7E33A009C315C /* HeadlineBodyToggleModel.swift in Sources */,
|
||||
@ -2882,6 +2873,7 @@
|
||||
D28A838323CCBD3F00DFE4FC /* WheelModel.swift in Sources */,
|
||||
D268C70C2386DFFD007F2C1C /* MoleculeStackItemModel.swift in Sources */,
|
||||
0A9D091D2433796500D2E6C0 /* BarsCarouselIndicatorModel.swift in Sources */,
|
||||
AFA4933F29E874F0001A9663 /* MVMCoreUILoggingDelegateProtocol.swift in Sources */,
|
||||
DBEFFA04225A829700230692 /* Label.swift in Sources */,
|
||||
D2D6CD4022E78C1A00D701B8 /* Scroller.swift in Sources */,
|
||||
AF1C33712885AE76006B1001 /* MVMCoreUIActionHandler.swift in Sources */,
|
||||
|
||||
@ -40,7 +40,7 @@ public class AlertHandler {
|
||||
return !operation.isCancelled &&
|
||||
!operation.isFinished &&
|
||||
operation.isExecuting &&
|
||||
(operation as? AlertOperation)?.isGreedy ?? false
|
||||
(operation as? AlertOperation)?.alertObject.isGreedy ?? false
|
||||
})
|
||||
}
|
||||
|
||||
@ -71,14 +71,14 @@ public class AlertHandler {
|
||||
}
|
||||
|
||||
let alertController = createAlertController(with: alertObject.alertModel)
|
||||
let alertOperation = AlertOperation(with: alertController, isGreedy: alertObject.isGreedy, alertDelegate: alertObject.alertDelegate)
|
||||
let alertOperation = AlertOperation(with: alertController, alertObject: alertObject)
|
||||
|
||||
// If an existing greedy alert is showing, add it as a dependency.
|
||||
if let greedyAlertOperation = queue.operations.first(where: { operation in
|
||||
guard !operation.isFinished,
|
||||
!operation.isCancelled,
|
||||
let alertOperation = operation as? AlertOperation else { return false }
|
||||
return alertOperation.isGreedy
|
||||
return alertOperation.alertObject.isGreedy
|
||||
}) {
|
||||
alertOperation.addDependency((greedyAlertOperation as! AlertOperation))
|
||||
}
|
||||
|
||||
@ -30,14 +30,11 @@ public class AlertOperation: MVMCoreOperation {
|
||||
|
||||
public let alertController: AlertController
|
||||
|
||||
public let isGreedy: Bool
|
||||
public let alertObject: AlertObject
|
||||
|
||||
public weak var alertDelegate: MVMCoreAlertDelegateProtocol?
|
||||
|
||||
public init(with alert: AlertController, isGreedy: Bool = false, alertDelegate: MVMCoreAlertDelegateProtocol? = nil) {
|
||||
public init(with alert: AlertController, alertObject: AlertObject) {
|
||||
self.alertController = alert
|
||||
self.isGreedy = isGreedy
|
||||
self.alertDelegate = alertDelegate
|
||||
self.alertObject = alertObject
|
||||
}
|
||||
|
||||
deinit {
|
||||
@ -57,8 +54,11 @@ public class AlertOperation: MVMCoreOperation {
|
||||
// We finished but it was not displayed yet. It's possible that it was cancelled. Finish this task
|
||||
if await !self.properties.getIsDisplayed() {
|
||||
self.markAsFinished()
|
||||
} else if self.isCancelled {
|
||||
await self.dismissAlertView()
|
||||
} else {
|
||||
(CoreUIObject.sharedInstance()?.loggingDelegate as? MVMCoreUILoggingDelegateProtocol)?.logAlert(with: self.alertObject)
|
||||
if self.isCancelled {
|
||||
await self.dismissAlertView()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -67,7 +67,7 @@ public class AlertOperation: MVMCoreOperation {
|
||||
public override func cancel() {
|
||||
super.cancel()
|
||||
Task { @MainActor in
|
||||
self.alertDelegate?.alertCancelled?(self.alertController)
|
||||
self.alertObject.alertDelegate?.alertCancelled?(self.alertController)
|
||||
await self.dismissAlertView()
|
||||
}
|
||||
}
|
||||
@ -92,9 +92,9 @@ public class AlertOperation: MVMCoreOperation {
|
||||
Task { @MainActor in
|
||||
await self.properties.set(displayed: visible)
|
||||
if visible {
|
||||
self.alertDelegate?.alertShown?(self.alertController)
|
||||
self.alertObject.alertDelegate?.alertShown?(self.alertController)
|
||||
} else {
|
||||
self.alertDelegate?.alertDismissed?(self.alertController)
|
||||
self.alertObject.alertDelegate?.alertDismissed?(self.alertController)
|
||||
|
||||
// Is visible was set to NO, meaning that the alertview is no longer visible.
|
||||
self.stopObservingAlertView()
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
// Called for popup style alerts.
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
@class MVMCoreAlertObject;
|
||||
@class MVMCoreLoadObject;
|
||||
@class MVMCoreErrorObject;
|
||||
|
||||
@ -16,9 +15,6 @@
|
||||
|
||||
@optional
|
||||
|
||||
// helps tracking alert state
|
||||
- (nullable NSDictionary *)additionalAlertDataToTrackForAlertWithObject:(nullable MVMCoreAlertObject *)alertObject;
|
||||
|
||||
// All are performed on the main thread.
|
||||
- (void)alertShown:(nonnull UIAlertController *)alertController;
|
||||
- (void)alertCancelled:(nonnull UIAlertController *)alertController;
|
||||
@ -26,11 +22,10 @@
|
||||
- (void)alertPaused:(nonnull UIAlertController *)alertController;
|
||||
- (void)alertUnpaused:(nonnull UIAlertController *)alertController;
|
||||
|
||||
/** Get the alert object whose data will be presented. Overwrite this to alter how you want the alert to show.
|
||||
/** Overwrite this to alter how you want the alert to show.
|
||||
* @param loadObject The load object.
|
||||
* @param errorObject An error object if there was an error.
|
||||
* @return Returns the alert object.
|
||||
* Details: Gets the alert that will display to the screen. Easier to subclass here to avoid subclassing the displaying logic. */
|
||||
- (nullable MVMCoreAlertObject *)alertObjectToShow:(nonnull MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)errorObject;
|
||||
* Details: Easier to subclass here to avoid subclassing the displaying logic. */
|
||||
- (void)handleAlertFor:(nonnull MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)errorObject;
|
||||
|
||||
@end
|
||||
|
||||
@ -15,7 +15,7 @@ public struct AlertObject {
|
||||
public var isGreedy = false
|
||||
|
||||
/// The alert model for the alert to show.
|
||||
public let alertModel: AlertModel
|
||||
public var alertModel: AlertModel
|
||||
|
||||
public weak var alertDelegate: MVMCoreAlertDelegateProtocol?
|
||||
|
||||
|
||||
@ -156,16 +156,6 @@ public class TopNotificationHandler {
|
||||
let alertOperation = MVMCoreTopAlertOperation(topAlertObject: topAlertObject)!
|
||||
add(operation: alertOperation)
|
||||
}
|
||||
|
||||
public func showTopAlertError(with message: String) {
|
||||
let topAlertObject = MVMCoreTopAlertObject(type: ValueTypeError, message: message)!
|
||||
showTopAlert(with: topAlertObject)
|
||||
}
|
||||
|
||||
public func showTopAlertConfirmation(with message: String) {
|
||||
let topAlertObject = MVMCoreTopAlertObject(type: ValueTypeSuccess, message: message)!
|
||||
showTopAlert(with: topAlertObject)
|
||||
}
|
||||
|
||||
/// Cancel the current top alert view.
|
||||
public func hideTopAlertView() {
|
||||
|
||||
@ -1,121 +0,0 @@
|
||||
//
|
||||
// ActionPopupHandler.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 7/16/22.
|
||||
// Copyright © 2022 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import MVMCore
|
||||
|
||||
/// Shows a popup alert by grabbing the content from a Page in the cache using the pageType.
|
||||
open class ActionPopupHandler: MVMCoreActionHandlerProtocol {
|
||||
required public init() {}
|
||||
|
||||
public enum Error: MVMError, CustomStringConvertible {
|
||||
case jsonNotFound
|
||||
|
||||
public var description: String {
|
||||
switch self {
|
||||
case ActionPopupHandler.Error.jsonNotFound:
|
||||
return "JSON for popup not found."
|
||||
}
|
||||
}
|
||||
|
||||
public var errorCode: Int {
|
||||
ErrorCode.popupFailed.rawValue
|
||||
}
|
||||
}
|
||||
|
||||
open func execute(with model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
|
||||
guard let model = model as? ActionPopupModel else { return }
|
||||
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Swift.Error>) in
|
||||
MVMCoreCache.shared()?.fetchJSON(forPageType: model.pageType, queue: nil, waitUntilFinished: true, completionHandler: { json in
|
||||
guard let page = json else {
|
||||
continuation.resume(throwing: ActionPopupHandler.Error.jsonNotFound)
|
||||
return
|
||||
}
|
||||
Task(priority: .userInitiated) {
|
||||
do {
|
||||
try await self.showAlertObjectWithPage(page, isGreedy: false, additionalData: nil, delegateObject: delegateObject)
|
||||
continuation.resume()
|
||||
} catch {
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Find a way to wait for the actual alert to show? or finish?
|
||||
/// Shows the alert using the legacy page format.
|
||||
open func showAlertObjectWithPage(_ page: [AnyHashable: Any], isGreedy: Bool, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) async throws {
|
||||
let alertObject = try alertObjectWithPage(page, isGreedy: false, additionalData: additionalData, delegateObject: delegateObject)
|
||||
_ = await AlertHandler.shared().queueAlertToShow(with: alertObject)
|
||||
}
|
||||
|
||||
open func alertObjectWithPage(_ page: [AnyHashable: Any], isGreedy: Bool, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) throws -> AlertObject {
|
||||
let data = try JSONSerialization.data(withJSONObject: page)
|
||||
let decoder = JSONDecoder.create(with: delegateObject)
|
||||
let popupModel = try decoder.decode(LegacyAlertModel.self, from: data)
|
||||
let alert = AlertModel(title: popupModel.title ?? "", message: popupModel.message ?? "", actions: popupModel.buttonActions)
|
||||
return AlertObject(alertModel: alert, isGreedy: isGreedy)
|
||||
}
|
||||
}
|
||||
|
||||
private protocol ActionWithTitle: ActionModelProtocol {
|
||||
var title: String { get set }
|
||||
}
|
||||
|
||||
private struct LegacyAlertModel: Codable {
|
||||
var title: String?
|
||||
var message: String?
|
||||
var buttonActions: [UIAlertAction]
|
||||
private var buttonsForEncode: JSONValueArray
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Keys
|
||||
//--------------------------------------------------
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case title
|
||||
case message
|
||||
case Links
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Codec
|
||||
//--------------------------------------------------
|
||||
|
||||
struct TitleObject: Codable {
|
||||
var title: String
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
buttonsForEncode = try typeContainer.decode(JSONValueArray.self, forKey: .Links)
|
||||
title = try typeContainer.decode(String.self, forKey: .title)
|
||||
message = try typeContainer.decode(String.self, forKey: .message)
|
||||
if title?.count == 0 && message?.count == 0 {
|
||||
throw ModelRegistry.Error.decoderOther(message: "Popups must have either a title or a message")
|
||||
}
|
||||
|
||||
let buttonTitles = try typeContainer.decode([TitleObject].self, forKey: .Links).map({ object in
|
||||
return object.title
|
||||
})
|
||||
let delegateObject = try decoder.get()
|
||||
self.buttonActions = (try typeContainer.decodeModels(codingKey: .Links) as [ActionModelProtocol]).enumerated().map { (index, action) in
|
||||
return AlertButtonModel(buttonTitles[index], action)
|
||||
}.map({ alertButtonModel in
|
||||
return alertButtonModel.generateAction(delegateObject: delegateObject)
|
||||
})
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encodeIfPresent(title, forKey: .title)
|
||||
try container.encodeIfPresent(message, forKey: .message)
|
||||
try container.encode(buttonsForEncode, forKey: .Links)
|
||||
}
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
//
|
||||
// ActionPopupModel.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 12/16/19.
|
||||
// Copyright © 2019 myverizon. All rights reserved.
|
||||
//
|
||||
|
||||
import MVMCore
|
||||
|
||||
public struct ActionPopupModel: ActionModelProtocol {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
public static var identifier: String = "popup"
|
||||
public var actionType: String = ActionPopupModel.identifier
|
||||
public var pageType: String
|
||||
public var extraParameters: JSONValueDictionary?
|
||||
public var analyticsData: JSONValueDictionary?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializer
|
||||
//--------------------------------------------------
|
||||
|
||||
public init(pageType: String, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) {
|
||||
self.pageType = pageType
|
||||
self.extraParameters = extraParameters
|
||||
self.analyticsData = analyticsData
|
||||
}
|
||||
}
|
||||
@ -69,7 +69,7 @@ public struct AlertModel: Codable {
|
||||
public var message: String
|
||||
public var style: UIAlertController.Style = .alert
|
||||
public var actions: [UIAlertAction]
|
||||
private var alertActions: [AlertButtonModel]?
|
||||
public var alertActions: [AlertButtonModel]?
|
||||
public var analyticsData: JSONValueDictionary?
|
||||
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -20,7 +20,6 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[];
|
||||
#import <MVMCoreUI/MVMCoreUILoggingHandler.h>
|
||||
#import <MVMCoreUI/MVMCoreUIViewControllerMappingObject.h>
|
||||
#import <MVMCoreUI/MVMCoreUIViewConstrainingProtocol.h>
|
||||
#import <MVMCoreUI/MVMCoreUIActionDelegateProtocol.h>
|
||||
|
||||
// Alert Handling
|
||||
#import <MVMCoreUI/MVMCoreAlertDelegateProtocol.h>
|
||||
|
||||
@ -229,7 +229,6 @@ open class CoreUIModelMapping: ModelMapping {
|
||||
|
||||
open override class func registerActions() {
|
||||
super.registerActions()
|
||||
ModelRegistry.register(handler: ActionPopupHandler.self, for: ActionPopupModel.self)
|
||||
ModelRegistry.register(handler: ActionAlertHandler.self, for: ActionAlertModel.self)
|
||||
ModelRegistry.register(handler: ActionTopAlertHandler.self, for: ActionTopAlertModel.self)
|
||||
ModelRegistry.register(handler: ActionCollapseNotificationHandler.self, for: ActionCollapseNotificationModel.self)
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
//
|
||||
// MVMCoreUIActionDelegateProtocol.h
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 10/28/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
@import MVMCore.MVMCoreActionDelegateProtocol;
|
||||
@class MVMCoreAlertObject;
|
||||
|
||||
@protocol MVMCoreUIActionDelegateProtocol <MVMCoreActionDelegateProtocol>
|
||||
|
||||
// Gives the delegate a chance to alter the alert object
|
||||
- (void)willShowPopupWithAlertObject:(nonnull MVMCoreAlertObject *)alertObject alertJson:(nonnull NSDictionary *)alertJson;
|
||||
|
||||
@end
|
||||
@ -0,0 +1,13 @@
|
||||
//
|
||||
// MVMCoreUILoggingDelegateProtocol.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 4/13/23.
|
||||
// Copyright © 2023 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import MVMCore
|
||||
|
||||
public protocol MVMCoreUILoggingDelegateProtocol: MVMCoreLoggingDelegateProtocol {
|
||||
func logAlert(with alertObject: AlertObject)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user