basic template

base core ui framework with placeholder template
This commit is contained in:
Pfeil, Scott Robert 2019-01-08 10:21:16 -05:00
parent 45b650cca7
commit 91260a0f98
9 changed files with 88 additions and 59 deletions

View File

@ -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 <MVMCoreViewControllerProtocol> *viewController = [[MVMCoreViewControllerMappingObject sharedViewControllerMappingObject] createMFViewControllerOfPageType:loadObject.pageType error:&error];
__block UIViewController <MVMCoreViewControllerProtocol> *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]];

View File

@ -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 <Foundation/Foundation.h>
#import <MVMCore/MVMCoreViewControllerProtocol.h>
@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 <NSObject>
// Creates and returns an mvm view controller.
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createViewController;
@end
@interface MVMCoreViewControllerMappingObject : NSObject
@property (nullable, strong, nonatomic) NSMutableDictionary *viewControllerMapping;
// The template based mapping.
@property (nullable, strong, nonatomic) NSMutableDictionary <NSString *,NSObject <MVMCoreViewControllerMappingProtocol>*> *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 <NSString *,NSObject <MVMCoreViewControllerMappingProtocol>*> *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 <MVMCoreViewControllerMappingProtocol>*)getViewControllerMappingForTemplate:(nonnull NSString *)templateID;
// Creates and returns an mvm view controller of the passed in template or page type using the mapping.
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createMFViewControllerOfTemplate:(nonnull NSString *)templateID;
// For pages external to the mobile first framework to be added to the view controller mapping.
- (void)addToViewControllerMapping:(nullable NSDictionary <NSString *,MVMCoreViewControllerMappingObject *>*)map;
- (void)addToTemplateViewControllerMapping:(nullable NSDictionary <NSString *,NSObject <MVMCoreViewControllerMappingProtocol>*>*)map;
// Creates and returns an mvm view controller of the passed in page type using the mapping.
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createMFViewControllerOfPageType:(nonnull NSString *)pageType error:(MVMCoreErrorObject *_Nullable *_Nullable)error;
// Transition function: A mix of new and legacy.
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)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<NSString*, NSArray<NSString*>*>*)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 <MVMCoreViewControllerMappingProtocol>*)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 <NSString *,NSObject <MVMCoreViewControllerMappingProtocol>*>*)map;
// Creates and returns an mvm view controller of the passed in template or page type using the mapping.
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createMFViewControllerOfPageType:(nonnull NSString *)pageType;
@end

View File

@ -31,57 +31,29 @@
#pragma mark - View Controller Mapping
- (nullable MVMCoreViewControllerMappingObject *)getViewControllerMappingForPageType:(nonnull NSString *)pageType {
return [self.viewControllerMapping objectForKey:pageType];
- (nullable NSObject <MVMCoreViewControllerMappingProtocol>*)getViewControllerMappingForTemplate:(nonnull NSString *)templateID {
return [self.viewControllerMapping objectForKey:templateID];
}
- (void)addToViewControllerMapping:(nullable NSDictionary <NSString *,MVMCoreViewControllerMappingObject *>*)map {
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createMFViewControllerOfTemplate:(nonnull NSString *)templateID {
return [[self getViewControllerMappingForTemplate:templateID] createViewController];
}
- (void)addToTemplateViewControllerMapping:(nullable NSDictionary <NSString *,NSObject <MVMCoreViewControllerMappingProtocol>*>*)map {
if (map) {
[self.viewControllerMapping addEntriesFromDictionary:map];
}
}
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createMFViewControllerOfPageType:(nonnull NSString *)pageType error:(MVMCoreErrorObject *_Nullable *_Nullable)error {
// Initialize the view controller using the pageType-ViewController mapping.
UIViewController <MVMCoreViewControllerProtocol> *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 <MVMCoreViewControllerProtocol> *)[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 <MVMCoreViewControllerProtocol> *)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 <MVMCoreViewControllerMappingProtocol>*)getViewControllerMappingForPageType:(nonnull NSString *)pageType {
return [self.pageTypeViewControllerMapping objectForKey:pageType];
}
- (void)addToPageTypeViewControllerMapping:(nullable NSDictionary <NSString *,NSObject <MVMCoreViewControllerMappingProtocol>*>*)map {
if (map) {
[self.pageTypeViewControllerMapping addEntriesFromDictionary:map];
}
}
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createMFViewControllerOfPageType:(nonnull NSString *)pageType {
return [[self getViewControllerMappingForPageType:pageType] createViewController];
}
@end

View File

@ -8,7 +8,7 @@
#import <MVMCore/MVMCoreViewControllerMappingObject.h>
@interface MVMCoreViewControllerNibMappingObject : MVMCoreViewControllerMappingObject
@interface MVMCoreViewControllerNibMappingObject : NSObject <MVMCoreViewControllerMappingProtocol>
// View Controller Class, for loading from a nib.
@property (nonnull, strong, nonatomic) Class viewControllerClass;

View File

@ -21,4 +21,9 @@
return self;
}
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createViewController {
// Initialize from nib
return [[self.viewControllerClass alloc] initWithNibName:self.nibName bundle:[NSBundle bundleWithIdentifier:self.bundleName]];
}
@end

View File

@ -8,7 +8,7 @@
#import <MVMCore/MVMCoreViewControllerMappingObject.h>
@interface MVMCoreViewControllerProgrammaticMappingObject : MVMCoreViewControllerMappingObject
@interface MVMCoreViewControllerProgrammaticMappingObject : NSObject <MVMCoreViewControllerMappingProtocol>
// View Controller Class, for loading by class.
@property (nonnull, strong, nonatomic) Class viewControllerClass;

View File

@ -19,4 +19,8 @@
return self;
}
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createViewController {
return [[self.viewControllerClass alloc] init];
}
@end

View File

@ -8,7 +8,7 @@
#import <MVMCore/MVMCoreViewControllerMappingObject.h>
@interface MVMCoreViewControllerStoryBoardMappingObject : MVMCoreViewControllerMappingObject
@interface MVMCoreViewControllerStoryBoardMappingObject : NSObject <MVMCoreViewControllerMappingProtocol>
// Initializes with a story board load.
- (nullable id)initWithStoryBoard:(nonnull NSString *)storyBoard storyBoardIdentifier:(nonnull NSString *)storyBoardIdentifier bundleName:(nonnull NSString *)bundleName;

View File

@ -21,4 +21,10 @@
return self;
}
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createViewController {
// Initialize from story board.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:self.storyBoard bundle:[NSBundle bundleWithIdentifier:self.bundleName]];
return [storyboard instantiateViewControllerWithIdentifier:self.storyBoardIdentifier];
}
@end