fix(ios): Objective-C class name "UITabBar..." already in use handling

This commit is contained in:
Nathan Walker
2020-09-07 10:50:24 -07:00
parent 5e4cd9865a
commit c8273931f3
3 changed files with 157 additions and 143 deletions

View File

@ -3,7 +3,7 @@
"main": "index",
"types": "index.d.ts",
"description": "NativeScript Core Modules",
"version": "6.5.17",
"version": "6.5.18",
"homepage": "https://www.nativescript.org",
"repository": {
"type": "git",

View File

@ -18,159 +18,173 @@ export * from "./tab-view-common";
const majorVersion = iosUtils.MajorVersion;
const isPhone = device.deviceType === "Phone";
class UITabBarControllerImpl extends UITabBarController {
let UITabBarControllerImpl;
let UITabBarControllerDelegateImpl;
let UINavigationControllerDelegateImpl;
private _owner: WeakRef<TabView>;
const setupControllers = function () {
if (typeof UITabBarControllerImpl === 'undefined') {
class UITabBarControllerClass extends UITabBarController {
public static initWithOwner(owner: WeakRef<TabView>): UITabBarControllerImpl {
let handler = <UITabBarControllerImpl>UITabBarControllerImpl.new();
handler._owner = owner;
private _owner: WeakRef<TabView>;
return handler;
}
public static initWithOwner(owner: WeakRef<TabView>): typeof UITabBarControllerImpl {
let handler = <typeof UITabBarControllerImpl>UITabBarControllerImpl.new();
handler._owner = owner;
public viewDidLoad(): void {
super.viewDidLoad();
// Unify translucent and opaque bars layout
// this.edgesForExtendedLayout = UIRectEdgeBottom;
this.extendedLayoutIncludesOpaqueBars = true;
}
@profile
public viewWillAppear(animated: boolean): void {
super.viewWillAppear(animated);
const owner = this._owner.get();
if (!owner) {
return;
return handler;
}
iosView.updateAutoAdjustScrollInsets(this, owner);
public viewDidLoad(): void {
super.viewDidLoad();
if (!owner.parent) {
owner.callLoaded();
// Unify translucent and opaque bars layout
// this.edgesForExtendedLayout = UIRectEdgeBottom;
this.extendedLayoutIncludesOpaqueBars = true;
}
}
@profile
public viewDidDisappear(animated: boolean): void {
super.viewDidDisappear(animated);
const owner = this._owner.get();
if (owner && !owner.parent && owner.isLoaded && !this.presentedViewController) {
owner.callUnloaded();
}
}
public viewWillTransitionToSizeWithTransitionCoordinator(size: CGSize, coordinator: UIViewControllerTransitionCoordinator): void {
super.viewWillTransitionToSizeWithTransitionCoordinator(size, coordinator);
coordinator.animateAlongsideTransitionCompletion(null, () => {
@profile
public viewWillAppear(animated: boolean): void {
super.viewWillAppear(animated);
const owner = this._owner.get();
if (owner && owner.items) {
owner.items.forEach(tabItem => tabItem._updateTitleAndIconPositions());
if (!owner) {
return;
}
});
}
// Mind implementation for other controllers
public traitCollectionDidChange(previousTraitCollection: UITraitCollection): void {
super.traitCollectionDidChange(previousTraitCollection);
iosView.updateAutoAdjustScrollInsets(this, owner);
if (majorVersion >= 13) {
if (!owner.parent) {
owner.callLoaded();
}
}
@profile
public viewDidDisappear(animated: boolean): void {
super.viewDidDisappear(animated);
const owner = this._owner.get();
if (owner &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner });
if (owner && !owner.parent && owner.isLoaded && !this.presentedViewController) {
owner.callUnloaded();
}
}
public viewWillTransitionToSizeWithTransitionCoordinator(size: CGSize, coordinator: UIViewControllerTransitionCoordinator): void {
super.viewWillTransitionToSizeWithTransitionCoordinator(size, coordinator);
coordinator.animateAlongsideTransitionCompletion(null, () => {
const owner = this._owner.get();
if (owner && owner.items) {
owner.items.forEach(tabItem => tabItem._updateTitleAndIconPositions());
}
});
}
// Mind implementation for other controllers
public traitCollectionDidChange(previousTraitCollection: UITraitCollection): void {
super.traitCollectionDidChange(previousTraitCollection);
if (majorVersion >= 13) {
const owner = this._owner.get();
if (owner &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner });
}
}
}
}
}
UITabBarControllerImpl = UITabBarControllerClass;
class UITabBarControllerDelegateImpl extends NSObject implements UITabBarControllerDelegate {
public static ObjCProtocols = [UITabBarControllerDelegate];
class UITabBarControllerDelegateClass extends NSObject implements UITabBarControllerDelegate {
public static ObjCProtocols = [UITabBarControllerDelegate];
private _owner: WeakRef<TabView>;
private _owner: WeakRef<TabView>;
public static initWithOwner(owner: WeakRef<TabView>): UITabBarControllerDelegateImpl {
let delegate = <UITabBarControllerDelegateImpl>UITabBarControllerDelegateImpl.new();
delegate._owner = owner;
public static initWithOwner(owner: WeakRef<TabView>): typeof UITabBarControllerDelegateImpl {
let delegate = <typeof UITabBarControllerDelegateImpl>UITabBarControllerDelegateImpl.new();
delegate._owner = owner;
return delegate;
}
public tabBarControllerShouldSelectViewController(tabBarController: UITabBarController, viewController: UIViewController): boolean {
if (traceEnabled()) {
traceWrite("TabView.delegate.SHOULD_select(" + tabBarController + ", " + viewController + ");", traceCategories.Debug);
return delegate;
}
let owner = this._owner.get();
if (owner) {
// "< More" cannot be visible after clicking on the main tab bar buttons.
let backToMoreWillBeVisible = false;
owner._handleTwoNavigationBars(backToMoreWillBeVisible);
public tabBarControllerShouldSelectViewController(tabBarController: UITabBarController, viewController: UIViewController): boolean {
if (traceEnabled()) {
traceWrite("TabView.delegate.SHOULD_select(" + tabBarController + ", " + viewController + ");", traceCategories.Debug);
}
let owner = this._owner.get();
if (owner) {
// "< More" cannot be visible after clicking on the main tab bar buttons.
let backToMoreWillBeVisible = false;
owner._handleTwoNavigationBars(backToMoreWillBeVisible);
}
if ((<any>tabBarController).selectedViewController === viewController) {
return false;
}
(<any>tabBarController)._willSelectViewController = viewController;
return true;
}
if ((<any>tabBarController).selectedViewController === viewController) {
return false;
}
public tabBarControllerDidSelectViewController(tabBarController: UITabBarController, viewController: UIViewController): void {
if (traceEnabled()) {
traceWrite("TabView.delegate.DID_select(" + tabBarController + ", " + viewController + ");", traceCategories.Debug);
}
(<any>tabBarController)._willSelectViewController = viewController;
const owner = this._owner.get();
if (owner) {
owner._onViewControllerShown(viewController);
}
return true;
}
public tabBarControllerDidSelectViewController(tabBarController: UITabBarController, viewController: UIViewController): void {
if (traceEnabled()) {
traceWrite("TabView.delegate.DID_select(" + tabBarController + ", " + viewController + ");", traceCategories.Debug);
}
const owner = this._owner.get();
if (owner) {
owner._onViewControllerShown(viewController);
}
(<any>tabBarController)._willSelectViewController = undefined;
}
}
class UINavigationControllerDelegateImpl extends NSObject implements UINavigationControllerDelegate {
public static ObjCProtocols = [UINavigationControllerDelegate];
private _owner: WeakRef<TabView>;
public static initWithOwner(owner: WeakRef<TabView>): UINavigationControllerDelegateImpl {
let delegate = <UINavigationControllerDelegateImpl>UINavigationControllerDelegateImpl.new();
delegate._owner = owner;
return delegate;
}
navigationControllerWillShowViewControllerAnimated(navigationController: UINavigationController, viewController: UIViewController, animated: boolean): void {
if (traceEnabled()) {
traceWrite("TabView.moreNavigationController.WILL_show(" + navigationController + ", " + viewController + ", " + animated + ");", traceCategories.Debug);
}
let owner = this._owner.get();
if (owner) {
// If viewController is one of our tab item controllers, then "< More" will be visible shortly.
// Otherwise viewController is the UIMoreListController which shows the list of all tabs beyond the 4th tab.
let backToMoreWillBeVisible = owner._ios.viewControllers.containsObject(viewController);
owner._handleTwoNavigationBars(backToMoreWillBeVisible);
(<any>tabBarController)._willSelectViewController = undefined;
}
}
UITabBarControllerDelegateImpl = UITabBarControllerDelegateClass;
navigationControllerDidShowViewControllerAnimated(navigationController: UINavigationController, viewController: UIViewController, animated: boolean): void {
if (traceEnabled()) {
traceWrite("TabView.moreNavigationController.DID_show(" + navigationController + ", " + viewController + ", " + animated + ");", traceCategories.Debug);
class UINavigationControllerDelegateClass extends NSObject implements UINavigationControllerDelegate {
public static ObjCProtocols = [UINavigationControllerDelegate];
private _owner: WeakRef<TabView>;
public static initWithOwner(owner: WeakRef<TabView>): typeof UINavigationControllerDelegateImpl {
let delegate = <typeof UINavigationControllerDelegateImpl>UINavigationControllerDelegateImpl.new();
delegate._owner = owner;
return delegate;
}
// We don't need Edit button in More screen.
navigationController.navigationBar.topItem.rightBarButtonItem = null;
let owner = this._owner.get();
if (owner) {
owner._onViewControllerShown(viewController);
navigationControllerWillShowViewControllerAnimated(navigationController: UINavigationController, viewController: UIViewController, animated: boolean): void {
if (traceEnabled()) {
traceWrite("TabView.moreNavigationController.WILL_show(" + navigationController + ", " + viewController + ", " + animated + ");", traceCategories.Debug);
}
let owner = this._owner.get();
if (owner) {
// If viewController is one of our tab item controllers, then "< More" will be visible shortly.
// Otherwise viewController is the UIMoreListController which shows the list of all tabs beyond the 4th tab.
let backToMoreWillBeVisible = owner._ios.viewControllers.containsObject(viewController);
owner._handleTwoNavigationBars(backToMoreWillBeVisible);
}
}
navigationControllerDidShowViewControllerAnimated(navigationController: UINavigationController, viewController: UIViewController, animated: boolean): void {
if (traceEnabled()) {
traceWrite("TabView.moreNavigationController.DID_show(" + navigationController + ", " + viewController + ", " + animated + ");", traceCategories.Debug);
}
// We don't need Edit button in More screen.
navigationController.navigationBar.topItem.rightBarButtonItem = null;
let owner = this._owner.get();
if (owner) {
owner._onViewControllerShown(viewController);
}
}
}
}
UINavigationControllerDelegateImpl = UINavigationControllerDelegateClass;
}
};
setupControllers();
function updateTitleAndIconPositions(tabItem: TabViewItem, tabBarItem: UITabBarItem, controller: UIViewController) {
if (!tabItem || !tabBarItem) {
@ -256,11 +270,11 @@ export class TabViewItem extends TabViewItemBase {
}
export class TabView extends TabViewBase {
public viewController: UITabBarControllerImpl;
public viewController: typeof UITabBarControllerImpl;
public items: TabViewItem[];
public _ios: UITabBarControllerImpl;
private _delegate: UITabBarControllerDelegateImpl;
private _moreNavigationControllerDelegate: UINavigationControllerDelegateImpl;
public _ios: typeof UITabBarControllerImpl;
private _delegate: typeof UITabBarControllerDelegateImpl;
private _moreNavigationControllerDelegate: typeof UINavigationControllerDelegateImpl;
private _iconsCache = {};
constructor() {

View File

@ -3,7 +3,7 @@
"main": "index",
"types": "index.d.ts",
"description": "NativeScript Core Modules",
"version": "6.5.17",
"version": "6.5.18",
"homepage": "https://www.nativescript.org",
"repository": {
"type": "git",
@ -11,7 +11,7 @@
},
"license": "Apache-2.0",
"dependencies": {
"@nativescript/core": "6.5.17"
"@nativescript/core": "6.5.18"
},
"devDependencies": {
"tns-platform-declarations": "6.5.15"