Back button fix

This commit is contained in:
Pfeil, Scott Robert 2020-05-20 11:00:02 -04:00
parent 5a55312c9d
commit 5bda356dc9
3 changed files with 38 additions and 16 deletions

View File

@ -34,7 +34,7 @@ public class NavigationItemButtonModel: Codable {
}
/// Convenience function that creates a BarButtonItem for the model.
public func createNavigationItem(delegateObject: MVMCoreUIDelegateObject? = nil, additionalData: [AnyHashable: Any]? = nil) -> BarButtonItem {
public func createNavigationItemButton(delegateObject: MVMCoreUIDelegateObject? = nil, additionalData: [AnyHashable: Any]? = nil) -> BarButtonItem {
let image = UIImage(named: imageName, in: MVMCoreCache.shared()?.bundleToUseForImages(), compatibleWith: nil)
return BarButtonItem.create(with: image, actionModel: action, delegateObject: delegateObject, additionalData: additionalData)
}

View File

@ -49,17 +49,17 @@ import UIKit
var items: [UIBarButtonItem] = []
if let backButtonModel = navigationItemModel.backButton,
navigationController.viewControllers.count > 1 {
items.append(backButtonModel.createNavigationItem(delegateObject: delegate, additionalData: nil))
items.append(backButtonModel.createNavigationItemButton(delegateObject: delegate, additionalData: nil))
}
if let itemModels = navigationItemModel.additionalLeftButtons {
for item in itemModels {
items.append(item.createNavigationItem(delegateObject: delegate, additionalData: nil))
items.append(item.createNavigationItemButton(delegateObject: delegate, additionalData: nil))
}
viewController.navigationItem.leftBarButtonItems = items
}
if let itemModels = navigationItemModel.additionalRightButtons {
for item in itemModels {
items.append(item.createNavigationItem(delegateObject: delegate, additionalData: nil))
items.append(item.createNavigationItemButton(delegateObject: delegate, additionalData: nil))
}
viewController.navigationItem.rightBarButtonItems = items
}

View File

@ -107,15 +107,13 @@ CGFloat const PanelAnimationDuration = 0.2;
return (width > 2000 ? MFTwoDrawer : (width > 1000 ? MFOneDrawer : MFNoDrawer));
}
- (nullable NSArray <UIBarButtonItem *>*)createNavigationItemsFrom:(nonnull NSArray <NSDictionary *>*)JSONlist delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject {
if (JSONlist.count == 0) { return nil; }
NSMutableArray *items = [NSMutableArray arrayWithCapacity:JSONlist.count];
for (NSDictionary *itemData in JSONlist) {
UIImage *image = [UIImage imageNamed:[itemData string:@"imageName"] inBundle:[[MVMCoreCache sharedCache] bundleToUseForImages] compatibleWithTraitCollection:nil];
BarButtonItem *item = [BarButtonItem createWith:image actionMap:[itemData dict:@"action"] delegateObject:delegateObject additionalData:nil];
[items addObject:item];
}
return items;
- (nullable UIBarButtonItem *)getBackButtonForViewController:(nonnull UIViewController *)viewController {
if (![viewController conformsToProtocol:@protocol(MVMCoreViewControllerProtocol)]) { return self.backButton; }
UIViewController <MVMCoreViewControllerProtocol>*controller = (UIViewController <MVMCoreViewControllerProtocol>*)viewController;
NSDictionary *item = [controller.loadObject.pageJSON dictWithChainOfKeysOrIndexes:@[@"navigationItem",@"backButton"]];
if (!item) { return self.backButton; }
DelegateObject *delegate = [controller delegateObject];
return [self createNavigationItemButtonFrom:item delegateObject:[delegate isKindOfClass:[MVMCoreUIDelegateObject class]] ? (MVMCoreUIDelegateObject *)delegate : nil];
}
- (nullable NSArray <UIBarButtonItem *>*)additionalLeftButtonsForViewController:(nonnull UIViewController *)viewController {
@ -123,7 +121,7 @@ CGFloat const PanelAnimationDuration = 0.2;
UIViewController <MVMCoreViewControllerProtocol>*controller = (UIViewController <MVMCoreViewControllerProtocol>*)viewController;
NSArray *items = [controller.loadObject.pageJSON arrayForChainOfKeysOrIndexes:@[@"navigationItem",@"additionalLeftButtons"]];
DelegateObject *delegate = [controller delegateObject];
return [self createNavigationItemsFrom:items delegateObject:[delegate isKindOfClass:[MVMCoreUIDelegateObject class]] ? (MVMCoreUIDelegateObject *)delegate : nil];
return [self createNavigationItemButtonsFrom:items delegateObject:[delegate isKindOfClass:[MVMCoreUIDelegateObject class]] ? (MVMCoreUIDelegateObject *)delegate : nil];
}
- (nullable NSArray <UIBarButtonItem *>*)additionalRightButtonsForViewController:(nonnull UIViewController *)viewController {
@ -131,7 +129,7 @@ CGFloat const PanelAnimationDuration = 0.2;
UIViewController <MVMCoreViewControllerProtocol>*controller = (UIViewController <MVMCoreViewControllerProtocol>*)viewController;
NSArray *items = [controller.loadObject.pageJSON arrayForChainOfKeysOrIndexes:@[@"navigationItem",@"additionalRightButtons"]];
DelegateObject *delegate = [controller delegateObject];
return [self createNavigationItemsFrom:items delegateObject:[delegate isKindOfClass:[MVMCoreUIDelegateObject class]] ? (MVMCoreUIDelegateObject *)delegate : nil];
return [self createNavigationItemButtonsFrom:items delegateObject:[delegate isKindOfClass:[MVMCoreUIDelegateObject class]] ? (MVMCoreUIDelegateObject *)delegate : nil];
}
- (CGFloat)leftPanelExtendedWidth {
@ -254,7 +252,13 @@ CGFloat const PanelAnimationDuration = 0.2;
- (void)setLeftNavigationItemForViewController:(UIViewController * _Nonnull)viewController accessible:(BOOL)accessible extended:(BOOL)extended {
NSMutableArray *leftBarButtonItems = [NSMutableArray array];
if ([viewController.navigationController.viewControllers count] > 1) {
[leftBarButtonItems addObject:self.backButton];
UIBarButtonItem *button = [self getBackButtonForViewController:viewController];
if (button) {
viewController.navigationItem.hidesBackButton = YES;
[leftBarButtonItems addObject:button];
} else {
viewController.navigationItem.hidesBackButton = NO;
}
}
if ((accessible && !extended) && self.leftPanelButton) {
[leftBarButtonItems addObject:self.leftPanelButton];
@ -621,6 +625,24 @@ CGFloat const PanelAnimationDuration = 0.2;
#pragma mark - Other Panel Functions
/// Convenience function, creates a BarButtonItem from button json
- (nonnull UIBarButtonItem *)createNavigationItemButtonFrom:(nonnull NSDictionary *)JSON delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject {
UIImage *image = [UIImage imageNamed:[JSON string:@"imageName"] inBundle:[[MVMCoreCache sharedCache] bundleToUseForImages] compatibleWithTraitCollection:nil];
BarButtonItem *item = [BarButtonItem createWith:image actionMap:[JSON dict:@"action"] delegateObject:delegateObject additionalData:nil];
return item;
}
/// Convenience function, creates a list of BarButtonItems list of json
- (nullable NSArray <UIBarButtonItem *>*)createNavigationItemButtonsFrom:(nullable NSArray <NSDictionary *>*)JSONlist delegateObject:(nullable MVMCoreUIDelegateObject *)delegateObject {
if (JSONlist.count == 0) { return nil; }
NSMutableArray *items = [NSMutableArray arrayWithCapacity:JSONlist.count];
for (NSDictionary *itemData in JSONlist) {
UIBarButtonItem *item = [self createNavigationItemButtonFrom:itemData delegateObject:delegateObject];
[items addObject:item];
}
return items;
}
- (void)forceHideBothDrawers {
[self hideBothDrawersShouldForceHide:YES];
}