From 91260a0f983d0fd75c9172d1d27d43d4fa8413c2 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 8 Jan 2019 10:21:16 -0500 Subject: [PATCH] basic template base core ui framework with placeholder template --- .../MVMCoreLoadRequestOperation.m | 10 +-- .../MVMCoreViewControllerMappingObject.h | 44 ++++++++++-- .../MVMCoreViewControllerMappingObject.m | 72 ++++++++----------- .../MVMCoreViewControllerNibMappingObject.h | 2 +- .../MVMCoreViewControllerNibMappingObject.m | 5 ++ ...eViewControllerProgrammaticMappingObject.h | 2 +- ...eViewControllerProgrammaticMappingObject.m | 4 ++ ...oreViewControllerStoryBoardMappingObject.h | 2 +- ...oreViewControllerStoryBoardMappingObject.m | 6 ++ 9 files changed, 88 insertions(+), 59 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 7f00738..3938e8b 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -721,13 +721,13 @@ completionHandler(viewController,loadObject); } else { - // Initialize the view controller using the pageType-ViewController mapping. (on the main thread) + // Initialize the view controller using the ViewController mapping. (on the main thread) [MVMCoreDispatchUtility performBlockOnMainThread:^{ - __block MVMCoreErrorObject *error = nil; - __block UIViewController *viewController = [[MVMCoreViewControllerMappingObject sharedViewControllerMappingObject] createMFViewControllerOfPageType:loadObject.pageType error:&error]; + __block UIViewController *viewController = [[MVMCoreViewControllerMappingObject sharedViewControllerMappingObject] createMFViewControllerOfTemplate:[loadObject.pageJSON string:@"template"] pageType:loadObject.pageType]; [MVMCoreDispatchUtility performBlockInBackground:^{ + MVMCoreErrorObject *error = nil; BOOL shouldContinue = NO; if (viewController) { @@ -743,10 +743,6 @@ viewController = nil; } } - } else if (error) { - - // Sets the location for the error. - error.location = [[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]; } else { // Couldn't initialize view controller, serious error. error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeInitViewController domain:ErrorDomainNative location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]; diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.h b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.h index 0ba210c..27b6078 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.h +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.h @@ -5,31 +5,50 @@ // Created by Scott Pfeil on 12/2/13. // Copyright (c) 2013 Verizon Wireless. All rights reserved. // -// Any given pageType will map to a view controller. This object tells if it is loaded from a story board with the id in viewControllerString. If wish to load from nib, leave storyBoard nil, and viewControllerString the nib name. +// Singleton for using template id string to create view controllers based on mapping objects. Any given templateID will map to a view controller. #import #import @class MVMCoreErrorObject; +// Classes that use the protocol should be able to be added to the mapping and create a view controller when called upon. +@protocol MVMCoreViewControllerMappingProtocol + +// Creates and returns an mvm view controller. +- (nullable UIViewController *)createViewController; + +@end + @interface MVMCoreViewControllerMappingObject : NSObject -@property (nullable, strong, nonatomic) NSMutableDictionary *viewControllerMapping; +// The template based mapping. +@property (nullable, strong, nonatomic) NSMutableDictionary *> *viewControllerMapping; + +// The modules that the page can't survive without. Will throw an error if not all are found during loading. @property (nullable, strong, nonatomic) NSMutableDictionary *requiredModuleMapping; + +// The modules that the page will ask for but may not get. @property (nullable, strong, nonatomic) NSMutableDictionary *optionalModuleMapping; +// Legacy: page type based mapping +@property (nullable, strong, nonatomic) NSMutableDictionary *> *pageTypeViewControllerMapping; + // Returns the shared instance + (nullable instancetype)sharedViewControllerMappingObject; #pragma mark - View Controller Mapping -// Returns the mapping object which maps the given page type to how it's view controller is loaded. -- (nullable MVMCoreViewControllerMappingObject *)getViewControllerMappingForPageType:(nonnull NSString *)pageType; +// Returns the mapping object which maps the given template to how it's view controller is loaded. +- (nullable NSObject *)getViewControllerMappingForTemplate:(nonnull NSString *)templateID; + +// Creates and returns an mvm view controller of the passed in template or page type using the mapping. +- (nullable UIViewController *)createMFViewControllerOfTemplate:(nonnull NSString *)templateID; // For pages external to the mobile first framework to be added to the view controller mapping. -- (void)addToViewControllerMapping:(nullable NSDictionary *)map; +- (void)addToTemplateViewControllerMapping:(nullable NSDictionary *>*)map; -// Creates and returns an mvm view controller of the passed in page type using the mapping. -- (nullable UIViewController *)createMFViewControllerOfPageType:(nonnull NSString *)pageType error:(MVMCoreErrorObject *_Nullable *_Nullable)error; +// Transition function: A mix of new and legacy. +- (nullable UIViewController *)createMFViewControllerOfTemplate:(nullable NSString *)templateID pageType:(nullable NSString *)pageType; #pragma mark - Module PageType Mapping @@ -51,4 +70,15 @@ // Add optional modules for multiple pages. Used by external frameworks - (void)addOptionalModulesForPages:(nonnull NSDictionary*>*)optionalModulesForPages; +#pragma mark - Legacy PageType driven + +// Returns the mapping object which maps the given page type to how it's view controller is loaded. +- (nullable NSObject *)getViewControllerMappingForPageType:(nonnull NSString *)pageType; + +// For pages external to the mobile first framework to be added to the view controller mapping for pagetypes. +- (void)addToPageTypeViewControllerMapping:(nullable NSDictionary *>*)map; + +// Creates and returns an mvm view controller of the passed in template or page type using the mapping. +- (nullable UIViewController *)createMFViewControllerOfPageType:(nonnull NSString *)pageType; + @end diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.m b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.m index 1bc9fe0..da84cf2 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.m +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerMappingObject.m @@ -31,57 +31,29 @@ #pragma mark - View Controller Mapping -- (nullable MVMCoreViewControllerMappingObject *)getViewControllerMappingForPageType:(nonnull NSString *)pageType { - return [self.viewControllerMapping objectForKey:pageType]; +- (nullable NSObject *)getViewControllerMappingForTemplate:(nonnull NSString *)templateID { + return [self.viewControllerMapping objectForKey:templateID]; } -- (void)addToViewControllerMapping:(nullable NSDictionary *)map { +- (nullable UIViewController *)createMFViewControllerOfTemplate:(nonnull NSString *)templateID { + return [[self getViewControllerMappingForTemplate:templateID] createViewController]; +} + +- (void)addToTemplateViewControllerMapping:(nullable NSDictionary *>*)map { if (map) { [self.viewControllerMapping addEntriesFromDictionary:map]; } } -- (nullable UIViewController *)createMFViewControllerOfPageType:(nonnull NSString *)pageType error:(MVMCoreErrorObject *_Nullable *_Nullable)error { - - // Initialize the view controller using the pageType-ViewController mapping. - UIViewController *viewController = nil; - - MVMCoreViewControllerMappingObject *mapping = [self getViewControllerMappingForPageType:pageType]; - if ([mapping isKindOfClass:[MVMCoreViewControllerStoryBoardMappingObject class]]) { - - // Initialize from story board. - NSString *storyboardName = ((MVMCoreViewControllerStoryBoardMappingObject *)mapping).storyBoard; - NSString *viewIdentifier = ((MVMCoreViewControllerStoryBoardMappingObject *)mapping).storyBoardIdentifier; - NSString *bundleName = ((MVMCoreViewControllerStoryBoardMappingObject *)mapping).bundleName; - if (storyboardName.length != 0 && viewIdentifier.length != 0 && bundleName) { - UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:[NSBundle bundleWithIdentifier:bundleName]]; - viewController = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:viewIdentifier]; - } else if (error) { - - NSInteger code = 0; - if (storyboardName.length == 0) { - code = ErrorCodeNoStoryboardName; - } else if (viewIdentifier.length == 0) { - code = ErrorCodeNoStoryBoardIdentifier; - } - *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:code domain:ErrorDomainNative location:nil]; - } - } else if ([mapping isKindOfClass:[MVMCoreViewControllerNibMappingObject class]]) { - - // Initialize from nib - NSString *viewControllerNibName = ((MVMCoreViewControllerNibMappingObject *)mapping).nibName; - NSString *bundleName = ((MVMCoreViewControllerStoryBoardMappingObject *)mapping).bundleName; - if (viewControllerNibName.length != 0) { - viewController = [[((MVMCoreViewControllerNibMappingObject *)mapping).viewControllerClass alloc] initWithNibName:viewControllerNibName bundle:[NSBundle bundleWithIdentifier:bundleName]]; - } else if (error) { - *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorCritical] code:ErrorCodeNoNibName domain:ErrorDomainNative location:nil]; - } +// Transition function: A mix of new and legacy. +- (nullable UIViewController *)createMFViewControllerOfTemplate:(nullable NSString *)templateID pageType:(nullable NSString *)pageType { + if (templateID) { + return [self createMFViewControllerOfTemplate:templateID]; + } else if (pageType) { + return [self createMFViewControllerOfPageType:pageType]; } else { - // Initialize programmatically. - viewController = [[((MVMCoreViewControllerProgrammaticMappingObject *)mapping).viewControllerClass alloc] init]; + return nil; } - - return viewController; } #pragma mark - Module PageType Mapping @@ -128,5 +100,21 @@ [self.optionalModuleMapping addEntriesFromDictionary:optionalModulesForPages]; } } + +#pragma mark - Legacy PageType driven + +- (nullable NSObject *)getViewControllerMappingForPageType:(nonnull NSString *)pageType { + return [self.pageTypeViewControllerMapping objectForKey:pageType]; +} + +- (void)addToPageTypeViewControllerMapping:(nullable NSDictionary *>*)map { + if (map) { + [self.pageTypeViewControllerMapping addEntriesFromDictionary:map]; + } +} + +- (nullable UIViewController *)createMFViewControllerOfPageType:(nonnull NSString *)pageType { + return [[self getViewControllerMappingForPageType:pageType] createViewController]; +} @end diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.h b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.h index a862c1d..fa7c2d7 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.h +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.h @@ -8,7 +8,7 @@ #import -@interface MVMCoreViewControllerNibMappingObject : MVMCoreViewControllerMappingObject +@interface MVMCoreViewControllerNibMappingObject : NSObject // View Controller Class, for loading from a nib. @property (nonnull, strong, nonatomic) Class viewControllerClass; diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.m b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.m index 9d82eab..cb8d93c 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.m +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerNibMappingObject.m @@ -21,4 +21,9 @@ return self; } +- (nullable UIViewController *)createViewController { + // Initialize from nib + return [[self.viewControllerClass alloc] initWithNibName:self.nibName bundle:[NSBundle bundleWithIdentifier:self.bundleName]]; +} + @end diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h index be973b5..02487e0 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.h @@ -8,7 +8,7 @@ #import -@interface MVMCoreViewControllerProgrammaticMappingObject : MVMCoreViewControllerMappingObject +@interface MVMCoreViewControllerProgrammaticMappingObject : NSObject // View Controller Class, for loading by class. @property (nonnull, strong, nonatomic) Class viewControllerClass; diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m index b00a785..8547285 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerProgrammaticMappingObject.m @@ -19,4 +19,8 @@ return self; } +- (nullable UIViewController *)createViewController { + return [[self.viewControllerClass alloc] init]; +} + @end diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.h b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.h index 8847427..51fb398 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.h +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.h @@ -8,7 +8,7 @@ #import -@interface MVMCoreViewControllerStoryBoardMappingObject : MVMCoreViewControllerMappingObject +@interface MVMCoreViewControllerStoryBoardMappingObject : NSObject // Initializes with a story board load. - (nullable id)initWithStoryBoard:(nonnull NSString *)storyBoard storyBoardIdentifier:(nonnull NSString *)storyBoardIdentifier bundleName:(nonnull NSString *)bundleName; diff --git a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.m b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.m index 69744ab..55f0eb1 100644 --- a/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.m +++ b/MVMCore/MVMCore/ViewControllerMapping/MVMCoreViewControllerStoryBoardMappingObject.m @@ -21,4 +21,10 @@ return self; } +- (nullable UIViewController *)createViewController { + // Initialize from story board. + UIStoryboard *storyboard = [UIStoryboard storyboardWithName:self.storyBoard bundle:[NSBundle bundleWithIdentifier:self.bundleName]]; + return [storyboard instantiateViewControllerWithIdentifier:self.storyBoardIdentifier]; +} + @end