diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 7bce64d..b66c75a 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -780,11 +780,10 @@ return; } + // If we have an alert to show and a loaded view controller, allow the loaded view controller to be the delegate. + DelegateObject *delegateObject = [loadedViewController respondsToSelector:@selector(delegateObject)] ? [loadedViewController delegateObject] : loadObject.operation.delegateObject; // Show any alerts that we have been saving. if (loadObject.operation.alertToShow) { - - // If we have an alert to show and a loaded view controller, allow the loaded view controller to be the delegate. - DelegateObject *delegateObject = [loadedViewController respondsToSelector:@selector(delegateObject)] ? [loadedViewController delegateObject] : loadObject.operation.delegateObject; [MVMCoreLoadRequestOperation createAndShowAlertForLoadObject:loadObject error:loadObject.operation.errorForAlertToShow delegateObject:delegateObject]; } @@ -797,6 +796,7 @@ //make post load calls function [MVMCoreLoadRequestOperation loadPostCallActions:loadObject]; + [MVMCoreLoadRequestOperation loadPostAction:loadObject delegateObject:delegateObject]; [loadObject.operation markAsFinished]; } @@ -819,6 +819,13 @@ } } ++ (void)loadPostAction:(nonnull MVMCoreLoadObject *)loadObject delegateObject:(nullable DelegateObject *)delegateObject { + NSDictionary *actionDict = [loadObject.responseJSON dict:@"PostAction"]; + if (actionDict) { + [[MVMCoreActionHandler sharedActionHandler] handleActionWithDictionary:actionDict additionalData:nil delegateObject:delegateObject]; + } +} + + (void)removeCaches:(nullable NSDictionary *)cacheDictionary { if (cacheDictionary) { diff --git a/MVMCore/MVMCore/MVMCore.h b/MVMCore/MVMCore/MVMCore.h index fa613c5..ca0b8a0 100644 --- a/MVMCore/MVMCore/MVMCore.h +++ b/MVMCore/MVMCore/MVMCore.h @@ -62,6 +62,7 @@ FOUNDATION_EXPORT const unsigned char MVMCoreVersionString[]; #import #import #import +#import // Action Handling #import diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h index 02487e0..de0f25f 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h @@ -10,10 +10,16 @@ @interface MVMCoreViewControllerProgrammaticMappingObject : NSObject -// View Controller Class, for loading by class. +/// View Controller Class, for loading by class. @property (nonnull, strong, nonatomic) Class viewControllerClass; -// Initializes with the given class. +/// Configuration block executed on creation of the controller before loading. +@property (nullable, copy, nonatomic) void (^configureHandler)(UIViewController * _Nonnull); + +/// Initializes with the given class. - (nullable id)initWithClass:(nonnull Class)viewControllerClass; +/// Initializes with the given class. Assigns a configuration block triggered on intiailization which allows additional configuration of the view controller before its loaded, i.e. injecting top level dependencies. +- (nullable id)initWithClass:(nonnull Class)viewControllerClass configureHandler:(void(^_Nonnull)(UIViewController * _Nonnull))configureBlock; + @end diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m index 8547285..a47a583 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m @@ -19,8 +19,20 @@ return self; } +- (nullable id)initWithClass:(nonnull Class)viewControllerClass configureHandler:(void(^)(UIViewController * _Nonnull))configureBlock { + self = [self initWithClass:viewControllerClass]; + if (self) { + self.configureHandler = configureBlock; + } + return self; +} + - (nullable UIViewController *)createViewController { - return [[self.viewControllerClass alloc] init]; + UIViewController *newController = [[self.viewControllerClass alloc] init]; + if (self.configureHandler) { + self.configureHandler(newController); + } + return newController; } @end