mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +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 {
|
export class ActionBar extends ActionBarBase {
|
||||||
|
|
||||||
get ios(): UIView {
|
get ios(): UIView {
|
||||||
const page = this.page;
|
const page = this.page;
|
||||||
if (!page || !page.parent) {
|
if (!page || !page.parent) {
|
||||||
@ -292,13 +291,21 @@ export class ActionBar extends ActionBarBase {
|
|||||||
this.setColor(navBar, color);
|
this.setColor(navBar, color);
|
||||||
|
|
||||||
const bgColor = <Color>this.backgroundColor;
|
const bgColor = <Color>this.backgroundColor;
|
||||||
navBar.barTintColor = bgColor ? bgColor.ios : null;
|
this.setBackgroundColor(navBar, bgColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private setColor(navBar: UINavigationBar, color?: Color) {
|
private setColor(navBar: UINavigationBar, color?: Color) {
|
||||||
|
if (!navBar) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (color) {
|
if (color) {
|
||||||
navBar.titleTextAttributes = <any>{ [NSForegroundColorAttributeName]: color.ios };
|
const titleTextColor = NSDictionary.dictionaryWithObjectForKey(color.ios, NSForegroundColorAttributeName);
|
||||||
navBar.largeTitleTextAttributes = <any>{ [NSForegroundColorAttributeName]: color.ios };
|
if (majorVersion >= 15) {
|
||||||
|
const appearance = navBar.standardAppearance ?? UINavigationBarAppearance.new();
|
||||||
|
appearance.titleTextAttributes = titleTextColor;
|
||||||
|
}
|
||||||
|
navBar.titleTextAttributes = titleTextColor;
|
||||||
|
navBar.largeTitleTextAttributes = titleTextColor;
|
||||||
navBar.tintColor = color.ios;
|
navBar.tintColor = color.ios;
|
||||||
} else {
|
} else {
|
||||||
navBar.titleTextAttributes = null;
|
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() {
|
public _onTitlePropertyChanged() {
|
||||||
const page = this.page;
|
const page = this.page;
|
||||||
if (!page) {
|
if (!page) {
|
||||||
@ -323,13 +349,34 @@ export class ActionBar extends ActionBarBase {
|
|||||||
|
|
||||||
private updateFlatness(navBar: UINavigationBar) {
|
private updateFlatness(navBar: UINavigationBar) {
|
||||||
if (this.flat) {
|
if (this.flat) {
|
||||||
navBar.setBackgroundImageForBarMetrics(UIImage.new(), UIBarMetrics.Default);
|
if (majorVersion >= 15) {
|
||||||
navBar.shadowImage = UIImage.new();
|
const appearance = navBar.standardAppearance ?? UINavigationBarAppearance.new();
|
||||||
navBar.translucent = false;
|
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 {
|
} else {
|
||||||
navBar.setBackgroundImageForBarMetrics(null, null);
|
if (majorVersion >= 15) {
|
||||||
navBar.shadowImage = null;
|
if(navBar.standardAppearance){ // Not flat and never been set do nothing.
|
||||||
navBar.translucent = true;
|
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.
|
// CssAnimationProperty use default value form their constructor.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
[backgroundColorProperty.setNative](value: UIColor | Color) {
|
[backgroundColorProperty.setNative](color: UIColor | Color) {
|
||||||
let navBar = this.navBar;
|
const navBar = this.navBar;
|
||||||
if (navBar) {
|
this.setBackgroundColor(navBar, color);
|
||||||
let color = value instanceof Color ? value.ios : value;
|
|
||||||
navBar.barTintColor = color;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[backgroundInternalProperty.getDefault](): UIColor {
|
[backgroundInternalProperty.getDefault](): UIColor {
|
||||||
|
Reference in New Issue
Block a user