From fac4f42503da3eb5582d7936062f66193fada8fc Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Wed, 7 Dec 2016 22:18:32 +0200 Subject: [PATCH] adding features deleted from rebase --- .../ui/list-picker/list-picker.android.ts | 8 ++- .../ui/list-view/list-view.ios.ts | 10 +-- tns-core-modules/ui/page/page-common.ts | 14 +++++ tns-core-modules/ui/page/page.android.ts | 63 ++++++++++++++++--- tns-core-modules/ui/page/page.d.ts | 12 +++- tns-core-modules/ui/page/page.ios.ts | 20 +++++- .../ui/text-field/text-field.ios.ts | 14 ++--- 7 files changed, 117 insertions(+), 24 deletions(-) diff --git a/tns-core-modules/ui/list-picker/list-picker.android.ts b/tns-core-modules/ui/list-picker/list-picker.android.ts index 3f38cd723..2ed5ac32d 100644 --- a/tns-core-modules/ui/list-picker/list-picker.android.ts +++ b/tns-core-modules/ui/list-picker/list-picker.android.ts @@ -1,4 +1,4 @@ -import { ListPickerBase, selectedIndexProperty, itemsProperty } from "./list-picker-common"; +import { ListPickerBase, selectedIndexProperty, itemsProperty, colorProperty } from "./list-picker-common"; import { ItemsSource } from "ui/list-picker"; export * from "./list-picker-common"; @@ -121,4 +121,8 @@ export class ListPicker extends ListPickerBase { this.itemsSet = true; } } -} + + get [colorProperty.native](): number { + return + } +} \ No newline at end of file diff --git a/tns-core-modules/ui/list-view/list-view.ios.ts b/tns-core-modules/ui/list-view/list-view.ios.ts index 7ff84892d..3259c6102 100644 --- a/tns-core-modules/ui/list-view/list-view.ios.ts +++ b/tns-core-modules/ui/list-view/list-view.ios.ts @@ -370,17 +370,16 @@ export class ListView extends ListViewBase { } get [separatorColor.native](): UIColor { - return null; + return this._ios.separatorColor; } - set [separatorColor.native](value: Color) { - this._ios.separatorColor = value ? value.ios : null; + set [separatorColor.native](value: Color | UIColor) { + this._ios.separatorColor = value instanceof Color ? value.ios : value; } get [itemTemplatesProperty.native](): KeyedTemplate[] { return null; } set [itemTemplatesProperty.native](value: KeyedTemplate[]) { - this._itemTemplatesInternal = new Array(this._defaultTemplate); this._itemTemplatesInternal = new Array(this._defaultTemplate); if (value) { for (let i = 0, length = value.length; i < length; i++) { @@ -388,6 +387,7 @@ export class ListView extends ListViewBase { } this._itemTemplatesInternal = this._itemTemplatesInternal.concat(value); } + this.refresh(); } -} +} \ No newline at end of file diff --git a/tns-core-modules/ui/page/page-common.ts b/tns-core-modules/ui/page/page-common.ts index 8d179aab9..fe99754eb 100644 --- a/tns-core-modules/ui/page/page-common.ts +++ b/tns-core-modules/ui/page/page-common.ts @@ -35,6 +35,8 @@ export class PageBase extends ContentView implements PageDefinition { public actionBarHidden: boolean; public enableSwipeBackNavigation: boolean; public backgroundSpanUnderStatusBar: boolean; + public statusBarStyle: "light" | "dark"; + public androidStatusBarBackground: Color; constructor() { super(); @@ -307,3 +309,15 @@ backgroundSpanUnderStatusBarProperty.register(PageBase); */ export const enableSwipeBackNavigationProperty = new Property({ name: "enableSwipeBackNavigation", defaultValue: true, valueConverter: booleanConverter }); enableSwipeBackNavigationProperty.register(PageBase); + +/** + * Property backing statusBarStyle. + */ +export const statusBarStyleProperty = new Property({ name: "statusBarStyle" }); +statusBarStyleProperty.register(PageBase); + +/** + * Property backing androidStatusBarBackground. + */ +export const androidStatusBarBackgroundProperty = new Property({ name: "androidStatusBarBackground", equalityComparer: Color.equals, valueConverter: (v) => new Color(v) }); +androidStatusBarBackgroundProperty.register(PageBase); \ No newline at end of file diff --git a/tns-core-modules/ui/page/page.android.ts b/tns-core-modules/ui/page/page.android.ts index ed0f2ae4c..147aac84b 100644 --- a/tns-core-modules/ui/page/page.android.ts +++ b/tns-core-modules/ui/page/page.android.ts @@ -1,17 +1,18 @@ -import { View, PageBase, actionBarHiddenProperty, enableSwipeBackNavigationProperty, Color } from "./page-common"; +import { View, PageBase, Color, actionBarHiddenProperty, enableSwipeBackNavigationProperty, statusBarStyleProperty, androidStatusBarBackgroundProperty } from "./page-common"; import { ActionBar } from "ui/action-bar"; import { GridLayout } from "ui/layouts/grid-layout"; import { DIALOG_FRAGMENT_TAG } from "./constants"; +import { device } from "platform"; import * as trace from "trace"; export * from "./page-common"; const SYSTEM_UI_FLAG_LIGHT_STATUS_BAR = 0x00002000; -const STATUS_BAR_LIGHT_BCKG = "#F5F5F5"; -const STATUS_BAR_DARK_BCKG = "#66000000"; +const STATUS_BAR_LIGHT_BCKG = -657931; +const STATUS_BAR_DARK_BCKG = 1711276032; interface DialogFragmentClass { -new (owner: Page, fullscreen: boolean, shownCallback: () => void, dismissCallback: () => void): android.app.DialogFragment; + new (owner: Page, fullscreen: boolean, shownCallback: () => void, dismissCallback: () => void): android.app.DialogFragment; } var DialogFragmentClass: DialogFragmentClass; @@ -55,7 +56,7 @@ function ensureDialogFragmentClass() { super.onStart(); if (!this._owner.isLoaded) { this._owner.onLoaded(); - } + } this._shownCallback(); } @@ -160,7 +161,7 @@ export class Page extends PageBase { super._raiseShowingModallyEvent(); - this._dialogFragment.show(parent.frame.android.activity.getFragmentManager(), DIALOG_FRAGMENT_TAG); + this._dialogFragment.show(parent.frame.android.activity.getFragmentManager(), DIALOG_FRAGMENT_TAG); } protected _hideNativeModalView(parent: Page) { @@ -182,4 +183,52 @@ export class Page extends PageBase { set [actionBarHiddenProperty.native](value: boolean) { this.updateActionBar(value); } -} + + get [statusBarStyleProperty.native](): { color: number, systemUiVisibility: number } { + if (device.sdkVersion >= "21") { + let window = (this._context).getWindow(); + let decorView = window.getDecorView(); + + return { + color: (window).getStatusBarColor(), + systemUiVisibility: decorView.getSystemUiVisibility() + } + } + + return null; + } + set [statusBarStyleProperty.native](value: "dark" | "light" | { color: number, systemUiVisibility: number }) { + if (device.sdkVersion >= "21") { + let window = (this._context).getWindow(); + let decorView = window.getDecorView(); + + if (value === "light") { + (window).setStatusBarColor(STATUS_BAR_LIGHT_BCKG); + decorView.setSystemUiVisibility(SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); + + } else if (value === "dark") { + (window).setStatusBarColor(STATUS_BAR_DARK_BCKG); + decorView.setSystemUiVisibility(0); + } else { + (window).setStatusBarColor(value.color); + decorView.setSystemUiVisibility(value.systemUiVisibility); + } + } + } + + get [androidStatusBarBackgroundProperty.native](): number { + if (device.sdkVersion >= "21") { + let window = (this._context).getWindow(); + return (window).getStatusBarColor(); + } + + return null; + } + set [androidStatusBarBackgroundProperty.native](value: number | Color) { + if (device.sdkVersion >= "21") { + let window = (this._context).getWindow(); + let color = value instanceof Color ? value.android : value; + (window).setStatusBarColor(color); + } + } +} \ No newline at end of file diff --git a/tns-core-modules/ui/page/page.d.ts b/tns-core-modules/ui/page/page.d.ts index 33ccfc8d8..d9d594fb5 100644 --- a/tns-core-modules/ui/page/page.d.ts +++ b/tns-core-modules/ui/page/page.d.ts @@ -87,7 +87,7 @@ declare module "ui/page" { /** * Gets or sets the style of the status bar. */ - statusBarStyle: string; + statusBarStyle: "light" | "dark"; /** * Gets or sets the color of the status bar in Android. @@ -265,4 +265,14 @@ declare module "ui/page" { * This property is iOS sepecific. Default value: true */ export const enableSwipeBackNavigationProperty: Property; + + /** + * Property backing statusBarStyle. + */ + export const statusBarStyleProperty: Property; + + /** + * Property backing androidStatusBarBackground. + */ + export const androidStatusBarBackgroundProperty: Property; } diff --git a/tns-core-modules/ui/page/page.ios.ts b/tns-core-modules/ui/page/page.ios.ts index 9adc4ccc1..c906139cb 100644 --- a/tns-core-modules/ui/page/page.ios.ts +++ b/tns-core-modules/ui/page/page.ios.ts @@ -1,5 +1,6 @@ -import { PageBase, actionBarHiddenProperty, enableSwipeBackNavigationProperty, - View, layout, Color } from "./page-common"; +import { PageBase, View, layout, Color, + actionBarHiddenProperty, enableSwipeBackNavigationProperty, statusBarStyleProperty + } from "./page-common"; import { ios as iosApp } from "application"; import { device } from "platform"; import { ActionBar } from "ui/action-bar"; @@ -559,4 +560,19 @@ export class Page extends PageBase { set [actionBarHiddenProperty.native](value: boolean) { this._updateEnableSwipeBackNavigation(value); } + + get [statusBarStyleProperty.native](): UIBarStyle { + return UIBarStyle.Default; + } + set [statusBarStyleProperty.native](value: string | UIBarStyle) { + let frame = this.frame; + if (frame) { + let navigationBar = (frame.ios.controller).navigationBar; + if (typeof value === "string") { + navigationBar.barStyle = value === "dark" ? UIBarStyle.Black : UIBarStyle.Default; + } else { + navigationBar.barStyle = value; + } + } + } } diff --git a/tns-core-modules/ui/text-field/text-field.ios.ts b/tns-core-modules/ui/text-field/text-field.ios.ts index ad836ef2f..cbf559c43 100644 --- a/tns-core-modules/ui/text-field/text-field.ios.ts +++ b/tns-core-modules/ui/text-field/text-field.ios.ts @@ -1,4 +1,4 @@ -import { TextFieldBase, secureProperty, textProperty, hintProperty, colorProperty, placeholderColorProperty } from "./text-field-common"; +import { TextFieldBase, Color, secureProperty, textProperty, hintProperty, colorProperty, placeholderColorProperty } from "./text-field-common"; export * from "./text-field-common"; @@ -175,12 +175,12 @@ export class TextField extends TextFieldBase { } get [placeholderColorProperty.native](): UIColor { - return this.nativeView.attributedPlaceholder.attributeAtIndexEffectiveRange(NSForegroundColorAttributeName, 0, null); + return null; } - set [placeholderColorProperty.native](value: UIColor) { + set [placeholderColorProperty.native](value: UIColor | Color) { let nativeView = this.nativeView; - let colorAttibutes = NSMutableDictionary.alloc().init(); - colorAttibutes.setValueForKey(value, NSForegroundColorAttributeName); - nativeView.attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(nativeView.placeholder, colorAttibutes.copy()); + let colorAttibutes = NSMutableDictionary.new(); + colorAttibutes.setValueForKey(value instanceof Color ? value.ios : value, NSForegroundColorAttributeName); + nativeView.attributedPlaceholder = NSAttributedString.alloc().initWithStringAttributes(nativeView.placeholder || "", colorAttibutes); } -} +} \ No newline at end of file