view will appear tab change

thread protection
This commit is contained in:
Pfeil, Scott Robert 2020-06-01 13:53:08 -04:00
parent 40240f4501
commit 5227f53776
3 changed files with 26 additions and 16 deletions

View File

@ -76,14 +76,18 @@ import Foundation
// MARK: - TabBarProtocol
public func highlightTab(at index: Int) {
guard let newSelectedItem = items?[model.selectedTab] else { return }
selectedItem = newSelectedItem
MVMCoreDispatchUtility.performBlock(onMainThread: {
guard let newSelectedItem = self.items?[index] else { return }
self.selectedItem = newSelectedItem
})
}
public func selectTab(at index: Int) {
guard let newSelectedItem = items?[model.selectedTab] else { return }
selectedItem = newSelectedItem
tabBar(self, didSelect: newSelectedItem)
MVMCoreDispatchUtility.performBlock(onMainThread: {
guard let newSelectedItem = self.items?[index] else { return }
self.selectedItem = newSelectedItem
self.tabBar(self, didSelect: newSelectedItem)
})
}
}

View File

@ -314,6 +314,11 @@ import UIKit
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Select tab if needed.
if let tab: Int = loadObject?.pageJSON?["tabBarIndex"] as? Int {
MVMCoreUISplitViewController.main()?.tabBar.highlightTab(at: tab)
}
// Update the navigation bar ui when view is appearing. Can remove check in the future, see viewControllerReady
if manager == nil {
setNavigationController()
@ -383,12 +388,13 @@ import UIKit
MVMCoreUISession.sharedGlobal()?.splitViewController?.showRightPanel(animated: true)
}
// Selects the tab if needed.
if let tab: Int = loadObject?.pageJSON?["tabBarIndex"] as? Int {
MVMCoreUISplitViewController.main()?.tabBar.highlightTab(at: tab)
} else if let tab: Int = loadObject?.requestParameters?.actionMap?["tabBarIndex"] as? Int,
error == nil {
MVMCoreUISplitViewController.main()?.tabBar.highlightTab(at: tab)
// Selects the tab if needed. Page driven takes priority over action driven (see viewWillAppear)
if let tab: Int = loadObject?.requestParameters?.actionMap?["tabBarIndex"] as? Int,
error == nil,
loadObject?.pageJSON?["tabBarIndex"] == nil {
MVMCoreDispatchUtility.performBlock(onMainThread: {
MVMCoreUISplitViewController.main()?.tabBar.highlightTab(at: tab)
})
}
}

View File

@ -718,7 +718,7 @@ CGFloat const PanelAnimationDuration = 0.2;
self.leftPanelWidth = leftPanelWidth;
[NSLayoutConstraint constraintWithItem:self.mainView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.leftView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:self.leftView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:self.leftView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.leftView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES;
if ([panel respondsToSelector:@selector(buttonForPanel)]) {
self.leftPanelButton = [panel buttonForPanel];
@ -753,7 +753,7 @@ CGFloat const PanelAnimationDuration = 0.2;
self.rightPanelWidth = rightPanelWidth;
[NSLayoutConstraint constraintWithItem:self.rightView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:self.rightView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:self.rightView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.rightView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES;
if ([panel respondsToSelector:@selector(buttonForPanel)]) {
self.rightPanelButton = [panel buttonForPanel];
@ -780,7 +780,7 @@ CGFloat const PanelAnimationDuration = 0.2;
}
- (void)addTabBar:(nonnull UIView <TabBarProtocol>*)tabBar {
[self.view addSubview:tabBar];
[self.view insertSubview:tabBar atIndex:0];
[tabBar.topAnchor constraintEqualToAnchor:self.mainView.bottomAnchor].active = YES;
[NSLayoutConstraint constraintWithItem:tabBar attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:tabBar attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.mainView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES;
@ -887,8 +887,8 @@ CGFloat const PanelAnimationDuration = 0.2;
self.mainViewCoverView = coverView;
[NSLayoutConstraint constraintWithItem:coverView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:coverView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:coverView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:coverView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:mainView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:coverView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:coverView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES;
[self setupPanels];
}