mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 01:43:14 +08:00
fix(action-bar): use appearance api on ios15+ (#9583)
Co-authored-by: Igor Randjelovic <rigor789@gmail.com>
This commit is contained in:
@ -85,7 +85,6 @@ export class NavigationButton extends ActionItem {
|
||||
}
|
||||
|
||||
export class ActionBar extends ActionBarBase {
|
||||
|
||||
get ios(): UIView {
|
||||
const page = this.page;
|
||||
if (!page || !page.parent) {
|
||||
@ -292,13 +291,21 @@ export class ActionBar extends ActionBarBase {
|
||||
this.setColor(navBar, color);
|
||||
|
||||
const bgColor = <Color>this.backgroundColor;
|
||||
navBar.barTintColor = bgColor ? bgColor.ios : null;
|
||||
this.setBackgroundColor(navBar, bgColor);
|
||||
}
|
||||
|
||||
private setColor(navBar: UINavigationBar, color?: Color) {
|
||||
if (!navBar) {
|
||||
return;
|
||||
}
|
||||
if (color) {
|
||||
navBar.titleTextAttributes = <any>{ [NSForegroundColorAttributeName]: color.ios };
|
||||
navBar.largeTitleTextAttributes = <any>{ [NSForegroundColorAttributeName]: color.ios };
|
||||
const titleTextColor = NSDictionary.dictionaryWithObjectForKey(color.ios, NSForegroundColorAttributeName);
|
||||
if (majorVersion >= 15) {
|
||||
const appearance = navBar.standardAppearance ?? UINavigationBarAppearance.new();
|
||||
appearance.titleTextAttributes = titleTextColor;
|
||||
}
|
||||
navBar.titleTextAttributes = titleTextColor;
|
||||
navBar.largeTitleTextAttributes = titleTextColor;
|
||||
navBar.tintColor = color.ios;
|
||||
} else {
|
||||
navBar.titleTextAttributes = null;
|
||||
@ -307,6 +314,25 @@ export class ActionBar extends ActionBarBase {
|
||||
}
|
||||
}
|
||||
|
||||
private setBackgroundColor(navBar: UINavigationBar, color?: UIColor | Color) {
|
||||
if (!navBar) {
|
||||
return;
|
||||
}
|
||||
|
||||
const color_ = color instanceof Color ? color.ios : color;
|
||||
if (majorVersion >= 15) {
|
||||
const appearance = navBar.standardAppearance ?? UINavigationBarAppearance.new();
|
||||
// appearance.configureWithOpaqueBackground();
|
||||
appearance.backgroundColor = color_;
|
||||
navBar.standardAppearance = appearance;
|
||||
navBar.compactAppearance = appearance;
|
||||
navBar.scrollEdgeAppearance = appearance;
|
||||
} else {
|
||||
// legacy styling
|
||||
navBar.barTintColor = color_;
|
||||
}
|
||||
}
|
||||
|
||||
public _onTitlePropertyChanged() {
|
||||
const page = this.page;
|
||||
if (!page) {
|
||||
@ -323,13 +349,34 @@ export class ActionBar extends ActionBarBase {
|
||||
|
||||
private updateFlatness(navBar: UINavigationBar) {
|
||||
if (this.flat) {
|
||||
navBar.setBackgroundImageForBarMetrics(UIImage.new(), UIBarMetrics.Default);
|
||||
navBar.shadowImage = UIImage.new();
|
||||
navBar.translucent = false;
|
||||
if (majorVersion >= 15) {
|
||||
const appearance = navBar.standardAppearance ?? UINavigationBarAppearance.new();
|
||||
appearance.shadowColor = UIColor.clearColor;
|
||||
|
||||
navBar.standardAppearance = appearance;
|
||||
navBar.compactAppearance = appearance;
|
||||
navBar.scrollEdgeAppearance = appearance;
|
||||
} else {
|
||||
|
||||
navBar.setBackgroundImageForBarMetrics(UIImage.new(), UIBarMetrics.Default);
|
||||
navBar.shadowImage = UIImage.new();
|
||||
navBar.translucent = false;
|
||||
}
|
||||
} else {
|
||||
navBar.setBackgroundImageForBarMetrics(null, null);
|
||||
navBar.shadowImage = null;
|
||||
navBar.translucent = true;
|
||||
if (majorVersion >= 15) {
|
||||
if(navBar.standardAppearance){ // Not flat and never been set do nothing.
|
||||
const appearance = navBar.standardAppearance;
|
||||
appearance.shadowColor = UINavigationBarAppearance.new().shadowColor;
|
||||
|
||||
navBar.standardAppearance = appearance;
|
||||
navBar.compactAppearance = appearance;
|
||||
navBar.scrollEdgeAppearance = appearance;
|
||||
}
|
||||
} else {
|
||||
navBar.setBackgroundImageForBarMetrics(null, null);
|
||||
navBar.shadowImage = null;
|
||||
navBar.translucent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -404,12 +451,9 @@ export class ActionBar extends ActionBarBase {
|
||||
// CssAnimationProperty use default value form their constructor.
|
||||
return null;
|
||||
}
|
||||
[backgroundColorProperty.setNative](value: UIColor | Color) {
|
||||
let navBar = this.navBar;
|
||||
if (navBar) {
|
||||
let color = value instanceof Color ? value.ios : value;
|
||||
navBar.barTintColor = color;
|
||||
}
|
||||
[backgroundColorProperty.setNative](color: UIColor | Color) {
|
||||
const navBar = this.navBar;
|
||||
this.setBackgroundColor(navBar, color);
|
||||
}
|
||||
|
||||
[backgroundInternalProperty.getDefault](): UIColor {
|
||||
|
Reference in New Issue
Block a user