mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
fix(ios): proper UITabBarAppearance handling
This commit is contained in:
@ -14,23 +14,18 @@ import { profile } from '../../profiling';
|
|||||||
import { Frame } from '../frame';
|
import { Frame } from '../frame';
|
||||||
import { layout, iOSNativeHelper } from '../../utils';
|
import { layout, iOSNativeHelper } from '../../utils';
|
||||||
import { Device } from '../../platform';
|
import { Device } from '../../platform';
|
||||||
|
import { Transparent } from 'color/known-colors';
|
||||||
export * from './tab-view-common';
|
export * from './tab-view-common';
|
||||||
|
|
||||||
const majorVersion = iOSNativeHelper.MajorVersion;
|
const majorVersion = iOSNativeHelper.MajorVersion;
|
||||||
const isPhone = Device.deviceType === 'Phone';
|
const isPhone = Device.deviceType === 'Phone';
|
||||||
|
|
||||||
let UITabBarControllerImpl;
|
@NativeClass
|
||||||
let UITabBarControllerDelegateImpl;
|
class UITabBarControllerImpl extends UITabBarController {
|
||||||
let UINavigationControllerDelegateImpl;
|
|
||||||
|
|
||||||
const setupControllers = function () {
|
|
||||||
if (typeof UITabBarControllerImpl === 'undefined') {
|
|
||||||
@NativeClass
|
|
||||||
class UITabBarControllerClass extends UITabBarController {
|
|
||||||
private _owner: WeakRef<TabView>;
|
private _owner: WeakRef<TabView>;
|
||||||
|
|
||||||
public static initWithOwner(owner: WeakRef<TabView>): typeof UITabBarControllerImpl {
|
public static initWithOwner(owner: WeakRef<TabView>): UITabBarControllerImpl {
|
||||||
const handler = <typeof UITabBarControllerImpl>UITabBarControllerImpl.new();
|
const handler = <UITabBarControllerImpl>UITabBarControllerImpl.new();
|
||||||
handler._owner = owner;
|
handler._owner = owner;
|
||||||
|
|
||||||
return handler;
|
return handler;
|
||||||
@ -92,17 +87,16 @@ const setupControllers = function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UITabBarControllerImpl = UITabBarControllerClass;
|
|
||||||
|
|
||||||
@NativeClass
|
@NativeClass
|
||||||
class UITabBarControllerDelegateClass extends NSObject implements UITabBarControllerDelegate {
|
class UITabBarControllerDelegateImpl extends NSObject implements UITabBarControllerDelegate {
|
||||||
public static ObjCProtocols = [UITabBarControllerDelegate];
|
public static ObjCProtocols = [UITabBarControllerDelegate];
|
||||||
|
|
||||||
private _owner: WeakRef<TabView>;
|
private _owner: WeakRef<TabView>;
|
||||||
|
|
||||||
public static initWithOwner(owner: WeakRef<TabView>): typeof UITabBarControllerDelegateImpl {
|
public static initWithOwner(owner: WeakRef<TabView>): UITabBarControllerDelegateImpl {
|
||||||
const delegate = <typeof UITabBarControllerDelegateImpl>UITabBarControllerDelegateImpl.new();
|
const delegate = <UITabBarControllerDelegateImpl>UITabBarControllerDelegateImpl.new();
|
||||||
delegate._owner = owner;
|
delegate._owner = owner;
|
||||||
|
|
||||||
return delegate;
|
return delegate;
|
||||||
@ -141,17 +135,16 @@ const setupControllers = function () {
|
|||||||
|
|
||||||
(<any>tabBarController)._willSelectViewController = undefined;
|
(<any>tabBarController)._willSelectViewController = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UITabBarControllerDelegateImpl = UITabBarControllerDelegateClass;
|
|
||||||
|
|
||||||
@NativeClass
|
@NativeClass
|
||||||
class UINavigationControllerDelegateClass extends NSObject implements UINavigationControllerDelegate {
|
class UINavigationControllerDelegateImpl extends NSObject implements UINavigationControllerDelegate {
|
||||||
public static ObjCProtocols = [UINavigationControllerDelegate];
|
public static ObjCProtocols = [UINavigationControllerDelegate];
|
||||||
|
|
||||||
private _owner: WeakRef<TabView>;
|
private _owner: WeakRef<TabView>;
|
||||||
|
|
||||||
public static initWithOwner(owner: WeakRef<TabView>): typeof UINavigationControllerDelegateImpl {
|
public static initWithOwner(owner: WeakRef<TabView>): UINavigationControllerDelegateImpl {
|
||||||
const delegate = <typeof UINavigationControllerDelegateImpl>UINavigationControllerDelegateImpl.new();
|
const delegate = <UINavigationControllerDelegateImpl>UINavigationControllerDelegateImpl.new();
|
||||||
delegate._owner = owner;
|
delegate._owner = owner;
|
||||||
|
|
||||||
return delegate;
|
return delegate;
|
||||||
@ -182,12 +175,7 @@ const setupControllers = function () {
|
|||||||
owner._onViewControllerShown(viewController);
|
owner._onViewControllerShown(viewController);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UINavigationControllerDelegateImpl = UINavigationControllerDelegateClass;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
setupControllers();
|
|
||||||
|
|
||||||
function updateTitleAndIconPositions(tabItem: TabViewItem, tabBarItem: UITabBarItem, controller: UIViewController) {
|
function updateTitleAndIconPositions(tabItem: TabViewItem, tabBarItem: UITabBarItem, controller: UIViewController) {
|
||||||
if (!tabItem || !tabBarItem) {
|
if (!tabItem || !tabBarItem) {
|
||||||
@ -286,11 +274,11 @@ export class TabViewItem extends TabViewItemBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class TabView extends TabViewBase {
|
export class TabView extends TabViewBase {
|
||||||
public viewController: typeof UITabBarControllerImpl;
|
public viewController: UITabBarControllerImpl;
|
||||||
public items: TabViewItem[];
|
public items: TabViewItem[];
|
||||||
public _ios: typeof UITabBarControllerImpl;
|
public _ios: UITabBarControllerImpl;
|
||||||
private _delegate: typeof UITabBarControllerDelegateImpl;
|
private _delegate: UITabBarControllerDelegateImpl;
|
||||||
private _moreNavigationControllerDelegate: typeof UINavigationControllerDelegateImpl;
|
private _moreNavigationControllerDelegate: UINavigationControllerDelegateImpl;
|
||||||
private _iconsCache = {};
|
private _iconsCache = {};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -534,6 +522,17 @@ export class TabView extends TabViewBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _getAppearance(tabBar: UITabBar) {
|
||||||
|
return tabBar.standardAppearance ?? UITabBarAppearance.new();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _updateAppearance(tabBar: UITabBar, appearance: UITabBarAppearance) {
|
||||||
|
tabBar.standardAppearance = appearance;
|
||||||
|
if (majorVersion >= 15) {
|
||||||
|
tabBar.scrollEdgeAppearance = appearance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[selectedIndexProperty.setNative](value: number) {
|
[selectedIndexProperty.setNative](value: number) {
|
||||||
if (Trace.isEnabled()) {
|
if (Trace.isEnabled()) {
|
||||||
Trace.write('TabView._onSelectedIndexPropertyChangedSetNativeValue(' + value + ')', Trace.categories.Debug);
|
Trace.write('TabView._onSelectedIndexPropertyChangedSetNativeValue(' + value + ')', Trace.categories.Debug);
|
||||||
@ -571,12 +570,11 @@ export class TabView extends TabViewBase {
|
|||||||
return this._ios.tabBar.barTintColor;
|
return this._ios.tabBar.barTintColor;
|
||||||
}
|
}
|
||||||
[tabBackgroundColorProperty.setNative](value: UIColor | Color) {
|
[tabBackgroundColorProperty.setNative](value: UIColor | Color) {
|
||||||
if (majorVersion >= 15) {
|
if (majorVersion >= 13) {
|
||||||
let appearance = UITabBarAppearance.new();
|
const appearance = this._getAppearance(this._ios.tabBar);
|
||||||
|
appearance.configureWithDefaultBackground();
|
||||||
appearance.backgroundColor = value instanceof Color ? value.ios : value;
|
appearance.backgroundColor = value instanceof Color ? value.ios : value;
|
||||||
|
this._updateAppearance(this._ios.tabBar, appearance);
|
||||||
this._ios.tabBar.scrollEdgeAppearance = appearance;
|
|
||||||
this._ios.tabBar.standardAppearance = appearance;
|
|
||||||
} else {
|
} else {
|
||||||
this._ios.tabBar.barTintColor = value instanceof Color ? value.ios : value;
|
this._ios.tabBar.barTintColor = value instanceof Color ? value.ios : value;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user