Merge pull request #44 in BPHVB/mvm_core from feature/template to develop

* commit '1429fd1faeb3a94cb3c67834caec74a414b348d0':
  remove duplicate function Move back to delegate. Throw error when using exact class, don't throw error when using protocol. remove unused search path
  instance type checks
  moved some to ui framework
  Migration
  basic template base core ui framework with placeholder template
This commit is contained in:
Pfeil, Scott Robert 2019-01-22 15:50:56 -05:00
commit 839eee33e8
26 changed files with 139 additions and 159 deletions

View File

@ -38,8 +38,6 @@
8876D5F31FB50AB000EB2E3D /* UIFont+MFSpacing.m in Sources */ = {isa = PBXBuildFile; fileRef = 8876D5E51FB50AB000EB2E3D /* UIFont+MFSpacing.m */; };
8876D5F41FB50AB000EB2E3D /* UILabel+MFCustom.h in Headers */ = {isa = PBXBuildFile; fileRef = 8876D5E61FB50AB000EB2E3D /* UILabel+MFCustom.h */; settings = {ATTRIBUTES = (Public, ); }; };
8876D5F51FB50AB000EB2E3D /* UILabel+MFCustom.m in Sources */ = {isa = PBXBuildFile; fileRef = 8876D5E71FB50AB000EB2E3D /* UILabel+MFCustom.m */; };
88D1FBE11FCCCBA100338A3A /* MVMCoreMainSplitViewProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 88D1FBDF1FCCCADC00338A3A /* MVMCoreMainSplitViewProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
88D1FBE21FCCCBA500338A3A /* PanelProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 88D1FBE01FCCCB2C00338A3A /* PanelProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
A332F33F20C7231700DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h in Headers */ = {isa = PBXBuildFile; fileRef = A332F33E20C7231600DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h */; settings = {ATTRIBUTES = (Public, ); }; };
AF1201832108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
AF26DDAE1FCE6A37004E8F65 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = AF26DDB01FCE6A37004E8F65 /* Localizable.strings */; };
@ -165,8 +163,6 @@
8876D5E51FB50AB000EB2E3D /* UIFont+MFSpacing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIFont+MFSpacing.m"; sourceTree = "<group>"; };
8876D5E61FB50AB000EB2E3D /* UILabel+MFCustom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UILabel+MFCustom.h"; sourceTree = "<group>"; };
8876D5E71FB50AB000EB2E3D /* UILabel+MFCustom.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UILabel+MFCustom.m"; sourceTree = "<group>"; };
88D1FBDF1FCCCADC00338A3A /* MVMCoreMainSplitViewProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MVMCoreMainSplitViewProtocol.h; sourceTree = "<group>"; };
88D1FBE01FCCCB2C00338A3A /* PanelProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PanelProtocol.h; sourceTree = "<group>"; };
A332F33E20C7231600DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewControllerAnimatedTransitioning.h; sourceTree = "<group>"; };
AF1201812108C9B400E2F592 /* MVMCoreViewManagerViewControllerProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreViewManagerViewControllerProtocol.h; sourceTree = "<group>"; };
AF26DDAF1FCE6A37004E8F65 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
@ -318,7 +314,6 @@
AFBB96DE1FBA48CE0008D868 /* Singletons */,
AF43A70C1FC4F42B008E9347 /* Session */,
AFBB96D41FBA48240008D868 /* OtherHandlers */,
AF43A5941FBB700D008E9347 /* MainStructure */,
AF26DDAB1FCE5CF2004E8F65 /* Strings */,
8876D5CC1FB50A9E00EB2E3D /* MVMCore.h */,
8876D5CD1FB50A9E00EB2E3D /* Info.plist */,
@ -366,15 +361,6 @@
path = Strings;
sourceTree = "<group>";
};
AF43A5941FBB700D008E9347 /* MainStructure */ = {
isa = PBXGroup;
children = (
88D1FBE01FCCCB2C00338A3A /* PanelProtocol.h */,
88D1FBDF1FCCCADC00338A3A /* MVMCoreMainSplitViewProtocol.h */,
);
path = MainStructure;
sourceTree = "<group>";
};
AF43A6FC1FBE2F2A008E9347 /* Reachability */ = {
isa = PBXGroup;
children = (
@ -622,7 +608,6 @@
AF43A7201FC5D2BA008E9347 /* MVMCoreViewManagerProtocol.h in Headers */,
881D26951FCC9D180079C521 /* MVMCoreErrorObject.h in Headers */,
AFBB96341FBA34310008D868 /* MVMCoreErrorConstants.h in Headers */,
88D1FBE21FCCCBA500338A3A /* PanelProtocol.h in Headers */,
A332F33F20C7231700DCD9D9 /* MVMCoreViewControllerAnimatedTransitioning.h in Headers */,
AFBB968D1FBA3A9A0008D868 /* MVMCoreNavigationHandler.h in Headers */,
AFBB96A51FBA3A9A0008D868 /* MVMCoreTopAlertOperation.h in Headers */,
@ -647,7 +632,6 @@
AFEEE81E1FCDF3CA00B5EDD0 /* MVMCoreLoggingHandler.h in Headers */,
AF43A7011FC4B227008E9347 /* MVMCoreGlobalLoadProtocol.h in Headers */,
AF43A5771FBA5B7C008E9347 /* MVMCoreJSONConstants.h in Headers */,
88D1FBE11FCCCBA100338A3A /* MVMCoreMainSplitViewProtocol.h in Headers */,
AFBB96631FBA3A570008D868 /* MVMCoreLoadRequestOperation.h in Headers */,
AFC5FA1D1FFC39C700C244CF /* MVMCoreTopAlertViewProtocol.h in Headers */,
AFBB969D1FBA3A9A0008D868 /* MVMCoreAlertObject.h in Headers */,
@ -962,11 +946,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/MVMCore/EmbeddedLibaries/AdobeMobileLibrary",
"$(PROJECT_DIR)/MVMCore/EmbeddedLibraries/VZAnalytics",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCore;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
@ -991,11 +971,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/MVMCore/EmbeddedLibaries/AdobeMobileLibrary",
"$(PROJECT_DIR)/MVMCore/EmbeddedLibraries/VZAnalytics",
);
LIBRARY_SEARCH_PATHS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = com.vzw.MVMCore;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;

View File

@ -36,6 +36,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
@implementation MVMCoreActionHandler
+ (nullable instancetype)sharedActionHandler {
[MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].actionHandler.class otherClass:self throwException:YES];
return [MVMCoreObject sharedInstance].actionHandler;
}

View File

@ -17,4 +17,7 @@
- (void)topAlertViewShown:(nonnull id)topAlert topAlertObject:(nonnull MVMCoreTopAlertObject *)topAlertObject;
- (void)topAlertViewDismissed:(nonnull id)topAlert;
// Called when the top alert is pressed. Determines if we should load the option the default way or not.
- (BOOL)shouldLoadTopAlertAction:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData;
@end

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

@ -43,10 +43,6 @@ FOUNDATION_EXPORT const unsigned char MVMCoreVersionString[];
#import <MVMCore/MVMCoreViewControllerProgrammaticMappingObject.h>
#import <MVMCore/MVMCoreViewControllerStoryBoardMappingObject.h>
// Main Structure
#import <MVMCore/MVMCoreMainSplitViewProtocol.h>
#import <MVMCore/PanelProtocol.h>
// Load Handling
#import <MVMCore/MVMCoreLoadDelegateProtocol.h>
#import <MVMCore/MVMCoreRequestParameters.h>

View File

@ -12,24 +12,10 @@
@protocol MVMCoreViewControllerProtocol <NSObject>
// TODO: need to be moved out when core is completely finished
@property (nonatomic) BOOL masterShouldBeAccessible;
@property (nonatomic) BOOL supportShouldBeAccessible;
@property (nonatomic) BOOL cartShouldBeAccessible;
@property (nonatomic) BOOL communityShouldBeAccessible;
@property (nonatomic) BOOL closeButtonAccessible;
@property (nullable, nonatomic, readonly) NSDictionary *closeButtonActionMap;
@property (nullable, strong, nonatomic) NSString *pageType;
// This view controller should subclass this function and check the load to make sure it has all the needed data. Fills the error object if there are any errors. Returns if we should finish the load or not. Ideally error should use code ErrorCodeViewControllerProcessingJSON.
- (BOOL)shouldFinishProcessingLoad:(nonnull MVMCoreLoadObject *)loadObject error:(MVMCoreErrorObject *_Nonnull *_Nonnull)error;
@optional
// Called when the back button is pressed. Overwrite for special functionality. Default is to just popviewcontroller.
- (void)backButtonPressed;
@end

View File

@ -1,18 +0,0 @@
//
// MainSplitViewProtocol.h
// MVMCore
//
// Created by Pfeil, Scott Robert on 11/14/17.
// Copyright © 2017 myverizon. All rights reserved.
//
#import <MVMCore/PanelProtocol.h>
#import <MVMCore/MVMCoreViewControllerProtocol.h>
@protocol MVMCoreMainSplitViewProtocol<NSObject>
// Provide the panels that you would like to use.
- (nullable UIViewController <MVMCoreViewControllerProtocol,PanelProtocol> *)getLeftPanel;
- (nullable UIViewController <MVMCoreViewControllerProtocol,PanelProtocol> *)getRightPanel;
@end

View File

@ -1,35 +0,0 @@
//
// PanelProtocol.h
// mobilefirst
//
// Created by Seshamani, Shreyas on 6/2/17.
// Copyright © 2017 Verizon Wireless. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <MVMCore/MVMCoreViewControllerProtocol.h>
@protocol PanelProtocol <NSObject>
#pragma mark - life cycle
@optional
// The panel can return if it should be available or not.
- (BOOL)panelAvailable;
- (void)panel:(UIViewController <MVMCoreViewControllerProtocol> *_Nullable)panel viewWillAppear:(BOOL)animated;
- (void)panel:(UIViewController <MVMCoreViewControllerProtocol> *_Nullable)panel viewDidAppear:(BOOL)animated;
- (void)panel:(UIViewController <MVMCoreViewControllerProtocol> *_Nullable)panel viewWillDisappear:(BOOL)animated;
- (void)panel:(UIViewController <MVMCoreViewControllerProtocol> *_Nullable)panel viewDidDisappear:(BOOL)animated;
- (void)showArrow;
- (void)hideArrow;
- (void)willOpenWithActionInformation:(nullable NSDictionary *)actionInformation;
- (void)clearData;
- (void)resetIconToDefault;
- (void)getCurrentDetailViewController:(nullable UIViewController *)currentViewController;//in menu
@end

View File

@ -14,6 +14,7 @@
#import "MVMCoreGetterUtility.h"
#import "MVMCoreObject.h"
#import "MVMCoreConstants.h"
#import "MVMCoreActionUtility.h"
@interface MVMCoreCache ()
@ -41,6 +42,7 @@
static NSString * const STATIC_CACHE_COMPONENT = @"StaticCache.txt";
+ (nullable instancetype)sharedCache {
[MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].cache.class otherClass:self throwException:YES];
return [MVMCoreObject sharedInstance].cache;
}

View File

@ -17,6 +17,8 @@
@interface MVMCoreLoggingHandler : NSObject
+ (nullable instancetype)sharedLoggingHandler;
+ (void)addErrorToLog:(nonnull MVMCoreErrorObject *)errorObject;
+ (void)logDebugMessageWithDelegate:(nullable NSString *)message;
+ (void)logWithDelegateWithObject:(nullable id)object withName:(nullable NSString *)name withExtraInfo:(nullable NSDictionary *)extra;

View File

@ -8,9 +8,18 @@
#import "MVMCoreLoggingHandler.h"
#import "MVMCoreObject.h"
#import "MVMCoreActionUtility.h"
@implementation MVMCoreLoggingHandler
+ (nullable instancetype)sharedLoggingHandler {
if ([MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].loggingDelegate.class otherClass:self throwException:NO]) {
return (MVMCoreLoggingHandler *)[MVMCoreObject sharedInstance].loggingDelegate;
} else {
return nil;
}
}
+ (void)addErrorToLog:(nonnull MVMCoreErrorObject *)errorObject {
if (errorObject && [[MVMCoreObject sharedInstance].loggingDelegate respondsToSelector:@selector(addErrorToLog:)]) {
[[MVMCoreObject sharedInstance].loggingDelegate addErrorToLog:errorObject];

View File

@ -8,10 +8,12 @@
#import "MVMCoreSessionObject.h"
#import "MVMCoreObject.h"
#import "MVMCoreActionUtility.h"
@implementation MVMCoreSessionObject
+ (nullable instancetype)sharedGlobal {
[MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].session.class otherClass:self throwException:YES];
return [MVMCoreObject sharedInstance].session;
}

View File

@ -18,6 +18,7 @@
#import "MVMCoreRequestParameters.h"
#import "NSDictionary+MFConvenience.h"
#import "MVMCoreObject.h"
#import "MVMCoreActionUtility.h"
@interface MVMCoreSessionTimeHandler ()
@ -46,6 +47,7 @@
@implementation MVMCoreSessionTimeHandler
+ (nullable instancetype)sharedSessionHandler {
[MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].sessionHandler.class otherClass:self throwException:YES];
return [MVMCoreObject sharedInstance].sessionHandler;
}

View File

@ -14,9 +14,9 @@
#import <MVMCore/MVMCoreSessionTimeHandler.h>
#import <MVMCore/MVMCoreGlobalLoadProtocol.h>
#import <MVMCore/MVMCoreLoadingOverlayDelegateProtocol.h>
#import <MVMCore/MVMCoreMainSplitViewProtocol.h>
#import <MVMCore/MVMCoreLoggingDelegateProtocol.h>
#import <MVMCore/MVMCoreGlobalTopAlertDelegateProtocol.h>
#import <MVMCore/MVMCoreLoggingHandler.h>
@interface MVMCoreObject : NSObject
@ -27,10 +27,9 @@
@property (nullable, strong, nonatomic) MVMCoreSessionTimeHandler *sessionHandler;
// The delegates
@property (nullable, weak, nonatomic) NSObject <MVMCoreMainSplitViewProtocol> *splitViewDelegate;
@property (nullable, weak, nonatomic) id <MVMCoreGlobalLoadProtocol> globalLoadDelegate;
@property (nullable, weak, nonatomic) id <MVMCoreLoadingOverlayDelegateProtocol> loadingProtocol;
@property (nullable, weak, nonatomic) id <MVMCoreLoggingDelegateProtocol> loggingDelegate;
@property (nullable, weak, nonatomic) NSObject <MVMCoreLoggingDelegateProtocol> *loggingDelegate;
@property (nullable, weak, nonatomic) id <MVMCoreGlobalTopAlertDelegateProtocol> globalTopAlertDelegate;
// A reference to the calling application delegate that should be set. For a normal app, could be the UIApplicationDelegate. For watch, could be WKExtensionDelegate. For iMessage, could be MSMessagesAppViewController. etc, etc. Useful for the framework to call delegate specific functions.

View File

@ -23,4 +23,7 @@
// Can call to display a view controller based on the load object in the same way the architecture does it. Will check the presentation style of the page, action, and request. Will check if needs a view manager.
+ (void)displayViewController:(nonnull UIViewController <MVMCoreViewControllerProtocol> *)viewController forLoadObject:(nullable MVMCoreLoadObject *)loadObject presentationDelegate:(nullable NSObject<MVMCorePresentationDelegateProtocol>*)delegate completionHandler:(nullable void (^)(void))completionBlock;
// returns if the class is not the same or a subclass of the other class. Can pass throw an exception as well
+ (BOOL)classIsInstanceTypeOfClass:(Class)theClass otherClass:(Class)otherClass throwException:(BOOL)throwException;
@end

View File

@ -137,4 +137,14 @@
[[MVMCoreNavigationHandler sharedNavigationHandler] navigateWithLoadObject:loadObject viewController:(viewControllerToLoad ?: viewController) delegate:delegate completionHandler:completionBlock];
}
+ (BOOL)classIsInstanceTypeOfClass:(Class)theClass otherClass:(Class)otherClass throwException:(BOOL)throwException {
if (theClass != otherClass && ![theClass isSubclassOfClass:otherClass]) {
if (throwException) {
@throw([NSException exceptionWithName:@"NotInstanceType" reason:[NSString stringWithFormat:@"%@ is not an instance of %@",theClass,otherClass] userInfo:nil]);
}
return NO;
}
return YES;
}
@end

View File

@ -25,4 +25,7 @@
// Returns a UIColor
+ (nonnull UIColor *)getColorForHexString:(nonnull NSString *)hexString;
// Returns if the device is an ipad
+ (BOOL)isOnIPad;
@end

View File

@ -50,4 +50,12 @@
alpha:1];
}
+ (BOOL)isOnIPad {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
} else {
return NO;
}
}
@end

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

@ -18,6 +18,7 @@
#import "MVMCoreErrorConstants.h"
#import "MVMCoreHardcodedStringsConstants.h"
#import "MVMCoreObject.h"
#import "MVMCoreActionUtility.h"
@interface MVMCoreViewControllerMappingObject ()
@ -26,62 +27,35 @@
@implementation MVMCoreViewControllerMappingObject
+ (nullable instancetype)sharedViewControllerMappingObject {
[MVMCoreActionUtility classIsInstanceTypeOfClass:[MVMCoreObject sharedInstance].viewControllerMapping.class otherClass:self throwException:YES];
return [MVMCoreObject sharedInstance].viewControllerMapping;
}
#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 +102,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