diff --git a/nativescript-core/package.json b/nativescript-core/package.json index 400d4b0f6..32aa24e7d 100644 --- a/nativescript-core/package.json +++ b/nativescript-core/package.json @@ -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", diff --git a/nativescript-core/ui/tab-view/tab-view.ios.ts b/nativescript-core/ui/tab-view/tab-view.ios.ts index d6d61211d..6d2010240 100644 --- a/nativescript-core/ui/tab-view/tab-view.ios.ts +++ b/nativescript-core/ui/tab-view/tab-view.ios.ts @@ -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; - - public static initWithOwner(owner: WeakRef): UITabBarControllerImpl { - let handler = UITabBarControllerImpl.new(); - handler._owner = owner; - - return handler; - } - - 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; +const setupControllers = function () { + if (typeof UITabBarControllerImpl === 'undefined') { + class UITabBarControllerClass extends UITabBarController { + + private _owner: WeakRef; + + public static initWithOwner(owner: WeakRef): typeof UITabBarControllerImpl { + let handler = UITabBarControllerImpl.new(); + handler._owner = owner; + + return handler; } - - iosView.updateAutoAdjustScrollInsets(this, owner); - - if (!owner.parent) { - owner.callLoaded(); + + public viewDidLoad(): void { + super.viewDidLoad(); + + // 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); - - if (majorVersion >= 13) { + + iosView.updateAutoAdjustScrollInsets(this, owner); + + 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 }); + } } } } -} - -class UITabBarControllerDelegateImpl extends NSObject implements UITabBarControllerDelegate { - public static ObjCProtocols = [UITabBarControllerDelegate]; - - private _owner: WeakRef; - - public static initWithOwner(owner: WeakRef): UITabBarControllerDelegateImpl { - let delegate = 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); + UITabBarControllerImpl = UITabBarControllerClass; + + class UITabBarControllerDelegateClass extends NSObject implements UITabBarControllerDelegate { + public static ObjCProtocols = [UITabBarControllerDelegate]; + + private _owner: WeakRef; + + public static initWithOwner(owner: WeakRef): typeof UITabBarControllerDelegateImpl { + let delegate = UITabBarControllerDelegateImpl.new(); + delegate._owner = owner; + + 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 ((tabBarController).selectedViewController === viewController) { + return false; + } + + (tabBarController)._willSelectViewController = viewController; + + return true; } - - if ((tabBarController).selectedViewController === viewController) { - return false; - } - - (tabBarController)._willSelectViewController = 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); - } - - (tabBarController)._willSelectViewController = undefined; - } -} - -class UINavigationControllerDelegateImpl extends NSObject implements UINavigationControllerDelegate { - public static ObjCProtocols = [UINavigationControllerDelegate]; - - private _owner: WeakRef; - - public static initWithOwner(owner: WeakRef): UINavigationControllerDelegateImpl { - let delegate = 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); + + 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); + } + + (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; + + public static initWithOwner(owner: WeakRef): typeof UINavigationControllerDelegateImpl { + let delegate = 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() { diff --git a/tns-core-modules-package/package.json b/tns-core-modules-package/package.json index 04363456e..7d72415ff 100644 --- a/tns-core-modules-package/package.json +++ b/tns-core-modules-package/package.json @@ -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"