Merge pull request #3744 from NativeScript/status-bar-30

Status bar style for modules 3.0
This commit is contained in:
Alexander Vakrilov
2017-03-07 17:39:19 +02:00
committed by GitHub
2 changed files with 17 additions and 27 deletions

View File

@@ -1,6 +1,7 @@
import { Page as PageDefinition, NavigatedData, ShownModallyData } from "ui/page"; import { Page as PageDefinition, NavigatedData, ShownModallyData } from "ui/page";
import { import {
ContentView, View, eachDescendant, Property, Color, isIOS, booleanConverter, resetCSSProperties ContentView, View, eachDescendant, Property, CssProperty, Color, isIOS,
booleanConverter, resetCSSProperties, Style
} from "ui/content-view"; } from "ui/content-view";
import { Frame, topmost as topmostFrame, resolvePageFromEntry } from "ui/frame"; import { Frame, topmost as topmostFrame, resolvePageFromEntry } from "ui/frame";
import { ActionBar } from "ui/action-bar"; import { ActionBar } from "ui/action-bar";
@@ -303,11 +304,12 @@ enableSwipeBackNavigationProperty.register(PageBase);
/** /**
* Property backing statusBarStyle. * Property backing statusBarStyle.
*/ */
export const statusBarStyleProperty = new Property<PageBase, "light" | "dark">({ name: "statusBarStyle" }); export const statusBarStyleProperty = new CssProperty<Style, "light" | "dark">({ name: "statusBarStyle", cssName: "status-bar-style" });
statusBarStyleProperty.register(PageBase); statusBarStyleProperty.register(Style);
/** /**
* Property backing androidStatusBarBackground. * Property backing androidStatusBarBackground.
*/ */
export const androidStatusBarBackgroundProperty = new Property<PageBase, Color>({ name: "androidStatusBarBackground", equalityComparer: Color.equals, valueConverter: (v) => new Color(v) }); export const androidStatusBarBackgroundProperty = new CssProperty<Style, Color>({ name: "androidStatusBarBackground", cssName:"android-status-bar-background",
androidStatusBarBackgroundProperty.register(PageBase); equalityComparer: Color.equals, valueConverter: (v) => new Color(v) });
androidStatusBarBackgroundProperty.register(Style);

View File

@@ -17,7 +17,7 @@ export module ad {
return SDK; return SDK;
} }
let _defaultBackgrounds = new Map<string, android.graphics.drawable.Drawable>(); let _defaultBackgrounds = new Map<string, android.graphics.drawable.Drawable.ConstantState>();
function isSetColorFilterOnlyWidget(nativeView: android.view.View): boolean { function isSetColorFilterOnlyWidget(nativeView: android.view.View): boolean {
return ( return (
@@ -37,6 +37,12 @@ export module ad {
let background = view.style.backgroundInternal; let background = view.style.backgroundInternal;
let backgroundDrawable = nativeView.getBackground(); let backgroundDrawable = nativeView.getBackground();
let cache = <CacheLayerType>view._nativeView; let cache = <CacheLayerType>view._nativeView;
let viewClass = getClass(view);
// always cache the default background constant state.
if (!_defaultBackgrounds.has(viewClass) && !isNullOrUndefined(backgroundDrawable)) {
_defaultBackgrounds.set(viewClass, backgroundDrawable.getConstantState());
}
if (isSetColorFilterOnlyWidget(nativeView) if (isSetColorFilterOnlyWidget(nativeView)
&& !isNullOrUndefined(backgroundDrawable) && !isNullOrUndefined(backgroundDrawable)
@@ -54,19 +60,9 @@ export module ad {
} }
else if (!background.isEmpty()) { else if (!background.isEmpty()) {
if (!(backgroundDrawable instanceof org.nativescript.widgets.BorderDrawable)) { if (!(backgroundDrawable instanceof org.nativescript.widgets.BorderDrawable)) {
let viewClass = getClass(view);
if (!isSetColorFilterOnlyWidget(nativeView) && !_defaultBackgrounds.has(viewClass)) {
_defaultBackgrounds.set(viewClass, nativeView.getBackground());
}
backgroundDrawable = new org.nativescript.widgets.BorderDrawable(layout.getDisplayDensity(), view.toString()); backgroundDrawable = new org.nativescript.widgets.BorderDrawable(layout.getDisplayDensity(), view.toString());
refreshBorderDrawable(view, <org.nativescript.widgets.BorderDrawable>backgroundDrawable); refreshBorderDrawable(view, <org.nativescript.widgets.BorderDrawable>backgroundDrawable);
org.nativescript.widgets.ViewHelper.setBackground(nativeView, backgroundDrawable);
if (getSDK() >= 16) {
nativeView.setBackground(backgroundDrawable);
} else {
nativeView.setBackgroundDrawable(backgroundDrawable);
}
} }
else { else {
refreshBorderDrawable(view, <org.nativescript.widgets.BorderDrawable>backgroundDrawable); refreshBorderDrawable(view, <org.nativescript.widgets.BorderDrawable>backgroundDrawable);
@@ -83,16 +79,8 @@ export module ad {
} }
} }
else { else {
// reset the value with the default native value
if (nativeView instanceof android.widget.Button) {
let nativeButton = new android.widget.Button(nativeView.getContext());
org.nativescript.widgets.ViewHelper.setBackground(nativeView, nativeButton.getBackground());
}
else {
let viewClass = getClass(view);
if (_defaultBackgrounds.has(viewClass)) { if (_defaultBackgrounds.has(viewClass)) {
org.nativescript.widgets.ViewHelper.setBackground(nativeView, _defaultBackgrounds.get(viewClass)); org.nativescript.widgets.ViewHelper.setBackground(nativeView, _defaultBackgrounds.get(viewClass).newDrawable());
}
} }
if (cache.layerType !== undefined) { if (cache.layerType !== undefined) {