Fix nativeView issues

Fix Listeners base class
This commit is contained in:
Hristo Hristov
2016-12-15 10:46:20 +02:00
parent e97fd105e3
commit b20fd7fd4c
17 changed files with 151 additions and 123 deletions

View File

@ -3,31 +3,31 @@
export * from "./activity-indicator-common"; export * from "./activity-indicator-common";
export class ActivityIndicator extends ActivityIndicatorBase { export class ActivityIndicator extends ActivityIndicatorBase {
nativeView: android.widget.ProgressBar; _progressBar: android.widget.ProgressBar;
public _createUI() { public _createUI() {
this.nativeView = new android.widget.ProgressBar(this._context); this._progressBar = new android.widget.ProgressBar(this._context);
this.nativeView.setVisibility(android.view.View.INVISIBLE); this._progressBar.setVisibility(android.view.View.INVISIBLE);
this.nativeView.setIndeterminate(true); this._progressBar.setIndeterminate(true);
} }
get android(): android.widget.ProgressBar { get android(): android.widget.ProgressBar {
return this.nativeView; return this._progressBar;
} }
get [busyProperty.native](): boolean { get [busyProperty.native](): boolean {
return this.nativeView.getVisibility() === android.view.View.VISIBLE; return this._progressBar.getVisibility() === android.view.View.VISIBLE;
} }
set [busyProperty.native](value: boolean) { set [busyProperty.native](value: boolean) {
this.nativeView.setVisibility(value ? android.view.View.VISIBLE : android.view.View.INVISIBLE); this._progressBar.setVisibility(value ? android.view.View.VISIBLE : android.view.View.INVISIBLE);
} }
get [visibilityProperty.native](): number { get [visibilityProperty.native](): number {
return this.nativeView.getVisibility(); return this._progressBar.getVisibility();
} }
set [visibilityProperty.native](value: number) { set [visibilityProperty.native](value: number) {
this.busy = value === android.view.View.VISIBLE; this.busy = value === android.view.View.VISIBLE;
this.nativeView.setVisibility(value); this._progressBar.setVisibility(value);
} }
get [colorProperty.native](): number { get [colorProperty.native](): number {
@ -35,10 +35,10 @@ export class ActivityIndicator extends ActivityIndicatorBase {
} }
set [colorProperty.native](value: number) { set [colorProperty.native](value: number) {
if (value < 0) { if (value < 0) {
this.nativeView.getIndeterminateDrawable().clearColorFilter(); this._progressBar.getIndeterminateDrawable().clearColorFilter();
} }
else { else {
this.nativeView.getIndeterminateDrawable().setColorFilter(value, android.graphics.PorterDuff.Mode.SRC_IN); this._progressBar.getIndeterminateDrawable().setColorFilter(value, android.graphics.PorterDuff.Mode.SRC_IN);
} }
} }
} }

View File

@ -6,8 +6,9 @@
export * from "./button-common"; export * from "./button-common";
@Interfaces([android.view.View.OnClickListener]) @Interfaces([android.view.View.OnClickListener])
class ClickListener implements android.view.View.OnClickListener { class ClickListener extends java.lang.Object implements android.view.View.OnClickListener {
constructor(public owner: WeakRef<Button>) { constructor(public owner: WeakRef<Button>) {
super();
return global.__native(this); return global.__native(this);
} }
@ -20,19 +21,19 @@ class ClickListener implements android.view.View.OnClickListener {
} }
export class Button extends ButtonBase { export class Button extends ButtonBase {
nativeView: android.widget.Button; _button: android.widget.Button;
private _isPressed: boolean; private _isPressed: boolean;
private _transformationMethod; private _transformationMethod;
private _highlightedHandler: (args: TouchGestureEventData) => void; private _highlightedHandler: (args: TouchGestureEventData) => void;
get android(): android.widget.Button { get android(): android.widget.Button {
return this.nativeView; return this._button;
} }
public _createUI() { public _createUI() {
let weakRef = new WeakRef(this); let weakRef = new WeakRef(this);
this.nativeView = new android.widget.Button(this._context); this._button = new android.widget.Button(this._context);
this.nativeView.setOnClickListener(new ClickListener(weakRef)); this._button.setOnClickListener(new ClickListener(weakRef));
} }
public _setFormattedTextPropertyToNative(value: FormattedString) { public _setFormattedTextPropertyToNative(value: FormattedString) {
@ -48,7 +49,7 @@ export class Button extends ButtonBase {
} }
} }
this.nativeView.setText(newText); this._button.setText(newText);
} }
@PseudoClassHandler("normal", "highlighted", "pressed", "active") @PseudoClassHandler("normal", "highlighted", "pressed", "active")

View File

@ -10,6 +10,20 @@ let cssSymbolPropertyMap = {};
let inheritableProperties = new Array<InheritedProperty<any, any>>(); let inheritableProperties = new Array<InheritedProperty<any, any>>();
let inheritableCssProperties = new Array<InheritedCssProperty<any, any>>(); let inheritableCssProperties = new Array<InheritedCssProperty<any, any>>();
function print(map) {
let symbols = (<any>Object).getOwnPropertySymbols(map);
for (let symbol of symbols) {
const prop = map[symbol];
if (!prop.registered) {
console.log(`Property ${prop.name} not Registered!!!!!`);
}
}
}
export function printUnregisteredProperties(): void {
print(symbolPropertyMap);
print(cssSymbolPropertyMap)
}
const enum ValueSource { const enum ValueSource {
Default = 0, Default = 0,
Inherited = 1, Inherited = 1,
@ -650,6 +664,7 @@ export class InheritedCssProperty<T extends Style, U> extends CssProperty<T, U>
} }
export class ShorthandProperty<T extends Style> { export class ShorthandProperty<T extends Style> {
private registered: boolean;
private readonly setLocalValue: (value: string) => void; private readonly setLocalValue: (value: string) => void;
private readonly setCssValue: (value: string) => void; private readonly setCssValue: (value: string) => void;
@ -721,6 +736,10 @@ export class ShorthandProperty<T extends Style> {
} }
public register(cls: { prototype: T }): void { public register(cls: { prototype: T }): void {
if (this.registered) {
throw new Error(`Property ${this.name} already registered.`);
}
this.registered = true;
Object.defineProperty(cls.prototype, this.name, this.localValueDescriptor); Object.defineProperty(cls.prototype, this.name, this.localValueDescriptor);
Object.defineProperty(cls.prototype, this.cssName, this.cssValueDescriptor); Object.defineProperty(cls.prototype, this.cssName, this.cssValueDescriptor);
} }

View File

@ -6,7 +6,7 @@ import { Background } from "ui/styling/background";
import { import {
ViewBase, getEventOrGestureName, Observable, EventData, Style, ViewBase, getEventOrGestureName, Observable, EventData, Style,
Property, InheritedProperty, CssProperty, ShorthandProperty, InheritedCssProperty, Property, InheritedProperty, CssProperty, ShorthandProperty, InheritedCssProperty,
gestureFromString, isIOS, traceEnabled, traceWrite, traceCategories, traceNotifyEvent gestureFromString, isIOS, traceEnabled, traceWrite, traceCategories, traceNotifyEvent, printUnregisteredProperties
} from "./view-base"; } from "./view-base";
import { observe as gestureObserve, GesturesObserver, GestureTypes, GestureEventData } from "ui/gestures"; import { observe as gestureObserve, GesturesObserver, GestureTypes, GestureEventData } from "ui/gestures";
import { Font, parseFont } from "ui/styling/font"; import { Font, parseFont } from "ui/styling/font";
@ -931,11 +931,6 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
return undefined; return undefined;
} }
public _shouldApplyStyleHandlers() {
// If we have native view we are ready to apply style handelr;
return !!this._nativeView;
}
public focus(): boolean { public focus(): boolean {
return undefined; return undefined;
} }
@ -1456,10 +1451,12 @@ function convertToTransform(value: string): [CssProperty<any, any>, any][] {
// Background properties. // Background properties.
export const backgroundInternalProperty = new CssProperty<Style, Background>({ name: "backgroundInternal", cssName: "_backgroundInternal", defaultValue: Background.default }); export const backgroundInternalProperty = new CssProperty<Style, Background>({ name: "backgroundInternal", cssName: "_backgroundInternal", defaultValue: Background.default });
backgroundInternalProperty.register(Style);
let pattern: RegExp = /url\(('|")(.*?)\1\)/; let pattern: RegExp = /url\(('|")(.*?)\1\)/;
export const backgroundImageProperty = new CssProperty<Style, string>({ export const backgroundImageProperty = new CssProperty<Style, string>({
name: "backgroundImage", cssName: "background-image", valueChanged: (target, oldValue, newValue) => { name: "backgroundImage", cssName: "background-image", valueChanged: (target, oldValue, newValue) => {
let style = target; let style = target;
let currentBackground = target.backgroundInternal; let currentBackground = target.backgroundInternal;
let url: string = newValue; let url: string = newValue;
@ -1505,6 +1502,7 @@ backgroundImageProperty.register(Style);
export const backgroundColorProperty = new CssProperty<Style, Color>({ export const backgroundColorProperty = new CssProperty<Style, Color>({
name: "backgroundColor", cssName: "background-color", valueChanged: (target, newValue) => { name: "backgroundColor", cssName: "background-color", valueChanged: (target, newValue) => {
printUnregisteredProperties();
let background = target.backgroundInternal; let background = target.backgroundInternal;
target.backgroundInternal = background.withColor(newValue); target.backgroundInternal = background.withColor(newValue);
}, equalityComparer: Color.equals, valueConverter: (value) => new Color(value) }, equalityComparer: Color.equals, valueConverter: (value) => new Color(value)

View File

@ -23,8 +23,9 @@ const VIEW_GROUP = "_viewGroup";
// TODO: Move this class into widgets. // TODO: Move this class into widgets.
@Interfaces([android.view.View.OnTouchListener]) @Interfaces([android.view.View.OnTouchListener])
class DisableUserInteractionListener implements android.view.View.OnTouchListener { class DisableUserInteractionListener extends java.lang.Object implements android.view.View.OnTouchListener {
constructor() { constructor() {
super();
return global.__native(this); return global.__native(this);
} }
@ -34,8 +35,9 @@ class DisableUserInteractionListener implements android.view.View.OnTouchListene
} }
@Interfaces([android.view.View.OnTouchListener]) @Interfaces([android.view.View.OnTouchListener])
class TouchListener implements android.view.View.OnTouchListener { class TouchListener extends java.lang.Object implements android.view.View.OnTouchListener {
constructor(private owner: WeakRef<View>) { constructor(private owner: WeakRef<View>) {
super();
return global.__native(this); return global.__native(this);
} }
@ -223,6 +225,8 @@ export class View extends ViewCommon {
this._nativeView.setLayoutParams(new org.nativescript.widgets.CommonLayoutParams()); this._nativeView.setLayoutParams(new org.nativescript.widgets.CommonLayoutParams());
} }
this.nativeView = this._nativeView;
if (traceEnabled) { if (traceEnabled) {
traceNotifyEvent(this, "_onContextChanged"); traceNotifyEvent(this, "_onContextChanged");
} }
@ -1079,11 +1083,11 @@ export class CustomLayoutView extends View implements CustomLayoutViewDefinition
public _addViewToNativeVisualTree(child: ViewCommon, atIndex: number = -1): boolean { public _addViewToNativeVisualTree(child: ViewCommon, atIndex: number = -1): boolean {
super._addViewToNativeVisualTree(child); super._addViewToNativeVisualTree(child);
if (this.nativeView && child.nativeView) { if (this._nativeView && child.nativeView) {
if (traceEnabled) { if (traceEnabled) {
traceWrite(`${this}.nativeView.addView(${child}.nativeView, ${atIndex})`, traceCategories.VisualTreeEvents); traceWrite(`${this}.nativeView.addView(${child}.nativeView, ${atIndex})`, traceCategories.VisualTreeEvents);
} }
this._nativeView.addView(child._nativeView, atIndex); this._nativeView.addView(child.nativeView, atIndex);
return true; return true;
} }

View File

@ -126,11 +126,6 @@ declare module "ui/core/view" {
* A View occupies a rectangular area on the screen and is responsible for drawing and layouting of all UI components within. * A View occupies a rectangular area on the screen and is responsible for drawing and layouting of all UI components within.
*/ */
export abstract class View extends ViewBase implements ApplyXmlAttributes { export abstract class View extends ViewBase implements ApplyXmlAttributes {
/**
* Get the nativeView created for this object.
*/
public nativeView: any;
/** /**
* Gets the android-specific native instance that lies behind this proxy. Will be available if running on an Android platform. * Gets the android-specific native instance that lies behind this proxy. Will be available if running on an Android platform.
*/ */
@ -609,9 +604,6 @@ declare module "ui/core/view" {
_onDetached(force?: boolean): void; _onDetached(force?: boolean): void;
_createUI(): void; _createUI(): void;
_shouldApplyStyleHandlers();
// _checkMetadataOnPropertyChanged(metadata: dependencyObservable.PropertyMetadata);
_updateLayout(): void; _updateLayout(): void;
/** /**

View File

@ -6,8 +6,9 @@
export * from "./date-picker-common"; export * from "./date-picker-common";
@Interfaces([android.widget.DatePicker.OnDateChangedListener]) @Interfaces([android.widget.DatePicker.OnDateChangedListener])
class DateChangedListener implements android.widget.DatePicker.OnDateChangedListener { class DateChangedListener extends java.lang.Object implements android.widget.DatePicker.OnDateChangedListener {
constructor(public owner: WeakRef<DatePicker>) { constructor(public owner: WeakRef<DatePicker>) {
super()
return global.__native(this); return global.__native(this);
} }
@ -42,7 +43,7 @@ class DateChangedListener implements android.widget.DatePicker.OnDateChangedList
export class DatePicker extends DatePickerBase { export class DatePicker extends DatePickerBase {
private _android: android.widget.DatePicker; private _android: android.widget.DatePicker;
public _listener: android.widget.DatePicker.OnDateChangedListener; public _listener: android.widget.DatePicker.OnDateChangedListener;
public nativeView: android.widget.DatePicker; public _datePicker: android.widget.DatePicker;
get android(): android.widget.DatePicker { get android(): android.widget.DatePicker {
return this._android; return this._android;
@ -56,48 +57,48 @@ export class DatePicker extends DatePickerBase {
} }
private updateNativeDate(): void { private updateNativeDate(): void {
let year = typeof this.year === "number" ? this.year : this.nativeView.getYear(); let year = typeof this.year === "number" ? this.year : this._datePicker.getYear();
let month = typeof this.month === "number" ? (this.month - 1) : this.nativeView.getMonth(); let month = typeof this.month === "number" ? (this.month - 1) : this._datePicker.getMonth();
let day = typeof this.day === "number" ? this.day : this.nativeView.getDayOfMonth(); let day = typeof this.day === "number" ? this.day : this._datePicker.getDayOfMonth();
this.date = new Date(year, month, day); this.date = new Date(year, month, day);
} }
get [yearProperty.native](): number { get [yearProperty.native](): number {
return this.nativeView.getYear(); return this._datePicker.getYear();
} }
set [yearProperty.native](value: number) { set [yearProperty.native](value: number) {
let picker = this.nativeView; let picker = this._datePicker;
if (picker.getYear() !== value) { if (picker.getYear() !== value) {
this.updateNativeDate(); this.updateNativeDate();
} }
} }
get [monthProperty.native](): number { get [monthProperty.native](): number {
return this.nativeView.getMonth(); return this._datePicker.getMonth();
} }
set [monthProperty.native](value: number) { set [monthProperty.native](value: number) {
let picker = this.nativeView; let picker = this._datePicker;
if (picker.getMonth() !== (value - 1)) { if (picker.getMonth() !== (value - 1)) {
this.updateNativeDate(); this.updateNativeDate();
} }
} }
get [dayProperty.native](): number { get [dayProperty.native](): number {
return this.nativeView.getDayOfMonth(); return this._datePicker.getDayOfMonth();
} }
set [dayProperty.native](value: number) { set [dayProperty.native](value: number) {
let picker = this.nativeView; let picker = this._datePicker;
if (picker.getDayOfMonth() !== value) { if (picker.getDayOfMonth() !== value) {
this.updateNativeDate(); this.updateNativeDate();
} }
} }
get [dateProperty.native](): Date { get [dateProperty.native](): Date {
let picker = this.nativeView; let picker = this._datePicker;
return new Date(picker.getYear(), picker.getMonth(), picker.getDayOfMonth()); return new Date(picker.getYear(), picker.getMonth(), picker.getDayOfMonth());
} }
set [dateProperty.native](value: Date) { set [dateProperty.native](value: Date) {
let picker = this.nativeView; let picker = this._datePicker;
if (picker.getDayOfMonth() !== value.getDay() if (picker.getDayOfMonth() !== value.getDay()
|| picker.getMonth() !== value.getMonth() || picker.getMonth() !== value.getMonth()
|| picker.getYear() !== value.getFullYear()) { || picker.getYear() !== value.getFullYear()) {
@ -106,10 +107,10 @@ export class DatePicker extends DatePickerBase {
} }
get [maxDateProperty.native](): Date { get [maxDateProperty.native](): Date {
return this.nativeView.getMaxDate(); return this._datePicker.getMaxDate();
} }
set [maxDateProperty.native](value: Date) { set [maxDateProperty.native](value: Date) {
let picker = this.nativeView; let picker = this._datePicker;
let newValue = value.getTime(); let newValue = value.getTime();
if (picker.getMaxDate() !== newValue) { if (picker.getMaxDate() !== newValue) {
picker.setMaxDate(newValue); picker.setMaxDate(newValue);
@ -117,10 +118,10 @@ export class DatePicker extends DatePickerBase {
} }
get [minDateProperty.native](): Date { get [minDateProperty.native](): Date {
return this.nativeView.getMinDate(); return this._datePicker.getMinDate();
} }
set [minDateProperty.native](value: Date) { set [minDateProperty.native](value: Date) {
let picker = this.nativeView; let picker = this._datePicker;
let newValue = value.getTime(); let newValue = value.getTime();
if (picker.getMinDate() !== newValue) { if (picker.getMinDate() !== newValue) {
picker.setMinDate(newValue); picker.setMinDate(newValue);

View File

@ -8,8 +8,9 @@
import { ad } from "utils/utils"; import { ad } from "utils/utils";
@Interfaces([android.text.TextWatcher]) @Interfaces([android.text.TextWatcher])
class TextWatcher implements android.text.TextWatcher { class TextWatcher extends java.lang.Object implements android.text.TextWatcher {
constructor(private owner: WeakRef<EditableTextBase>) { constructor(private owner: WeakRef<EditableTextBase>) {
super();
return global.__native(this); return global.__native(this);
} }
@ -56,8 +57,9 @@ class TextWatcher implements android.text.TextWatcher {
let dismissKeyboardTimeoutId: number; let dismissKeyboardTimeoutId: number;
@Interfaces([android.view.View.OnFocusChangeListener]) @Interfaces([android.view.View.OnFocusChangeListener])
class FocusChangeListener implements android.view.View.OnFocusChangeListener { class FocusChangeListener extends java.lang.Object implements android.view.View.OnFocusChangeListener {
constructor(private owner: WeakRef<EditableTextBase>) { constructor(private owner: WeakRef<EditableTextBase>) {
super();
return global.__native(this); return global.__native(this);
} }
@ -92,8 +94,9 @@ class FocusChangeListener implements android.view.View.OnFocusChangeListener {
} }
@Interfaces([android.widget.TextView.OnEditorActionListener]) @Interfaces([android.widget.TextView.OnEditorActionListener])
class EditorActionListener implements android.widget.TextView.OnEditorActionListener { class EditorActionListener extends java.lang.Object implements android.widget.TextView.OnEditorActionListener {
constructor(private owner: WeakRef<EditableTextBase>) { constructor(private owner: WeakRef<EditableTextBase>) {
super();
return global.__native(this); return global.__native(this);
} }
@ -133,7 +136,6 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
private _keyListenerCache: android.text.method.KeyListener; private _keyListenerCache: android.text.method.KeyListener;
private _focusChangeListener: android.view.View.OnFocusChangeListener; private _focusChangeListener: android.view.View.OnFocusChangeListener;
private _editorActionListener: android.widget.TextView.OnEditorActionListener; private _editorActionListener: android.widget.TextView.OnEditorActionListener;
public nativeView: android.widget.EditText;
get android(): android.widget.EditText { get android(): android.widget.EditText {
return this._android; return this._android;
@ -180,21 +182,21 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
} }
public dismissSoftInput() { public dismissSoftInput() {
ad.dismissSoftInput(this._nativeView); ad.dismissSoftInput(this._android);
} }
public focus(): boolean { public focus(): boolean {
let result = super.focus(); let result = super.focus();
if (result) { if (result) {
ad.showSoftInput(this._nativeView); ad.showSoftInput(this._android);
} }
return result; return result;
} }
private _setInputType(inputType): void { private _setInputType(inputType): void {
let nativeView = this.nativeView; let nativeView = this._android;
nativeView.setInputType(inputType); nativeView.setInputType(inputType);
// setInputType will change the keyListener so we should cache it again // setInputType will change the keyListener so we should cache it again
@ -210,15 +212,15 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
} }
get [textProperty.native](): string { get [textProperty.native](): string {
return this.nativeView.getText(); return this._android.getText();
} }
set [textProperty.native](value: string) { set [textProperty.native](value: string) {
let newValue = value + ''; let newValue = value + '';
this.nativeView.setText(newValue, android.widget.TextView.BufferType.EDITABLE); this._android.setText(newValue, android.widget.TextView.BufferType.EDITABLE);
} }
get [keyboardTypeProperty.native](): "datetime" | "phone" | "number" | "url" | "email" | string { get [keyboardTypeProperty.native](): "datetime" | "phone" | "number" | "url" | "email" | string {
let inputType = this.nativeView.getInputType(); let inputType = this._android.getInputType();
switch (inputType) { switch (inputType) {
case android.text.InputType.TYPE_CLASS_DATETIME | android.text.InputType.TYPE_DATETIME_VARIATION_NORMAL: case android.text.InputType.TYPE_CLASS_DATETIME | android.text.InputType.TYPE_DATETIME_VARIATION_NORMAL:
return "datetime"; return "datetime";
@ -276,7 +278,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
} }
get [returnKeyTypeProperty.native](): "done" | "next" | "go" | "search" | "send" | string { get [returnKeyTypeProperty.native](): "done" | "next" | "go" | "search" | "send" | string {
let ime = this.nativeView.getImeOptions(); let ime = this._android.getImeOptions();
switch (ime) { switch (ime) {
case android.view.inputmethod.EditorInfo.IME_ACTION_DONE: case android.view.inputmethod.EditorInfo.IME_ACTION_DONE:
return "done"; return "done";
@ -329,19 +331,19 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
} }
get [editableProperty.native](): boolean { get [editableProperty.native](): boolean {
return !!this.nativeView.getKeyListener(); return !!this._android.getKeyListener();
} }
set [editableProperty.native](value: boolean) { set [editableProperty.native](value: boolean) {
if (value) { if (value) {
this.nativeView.setKeyListener(this._keyListenerCache); this._android.setKeyListener(this._keyListenerCache);
} }
else { else {
this.nativeView.setKeyListener(null); this._android.setKeyListener(null);
} }
} }
get [autocapitalizationTypeProperty.native](): "none" | "words" | "sentences" | "allCharacters" | string { get [autocapitalizationTypeProperty.native](): "none" | "words" | "sentences" | "allCharacters" | string {
let inputType = this.nativeView.getInputType(); let inputType = this._android.getInputType();
if ((inputType & android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS) === android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS) { if ((inputType & android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS) === android.text.InputType.TYPE_TEXT_FLAG_CAP_WORDS) {
return "words"; return "words";
} else if ((inputType & android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) === android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) { } else if ((inputType & android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) === android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES) {
@ -353,7 +355,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
} }
} }
set [autocapitalizationTypeProperty.native](value: string) { set [autocapitalizationTypeProperty.native](value: string) {
let inputType = this.nativeView.getInputType(); let inputType = this._android.getInputType();
inputType = inputType & ~28672; //28672 (0x00070000) 13,14,15bits (111 0000 0000 0000) inputType = inputType & ~28672; //28672 (0x00070000) 13,14,15bits (111 0000 0000 0000)
switch (value) { switch (value) {
@ -384,7 +386,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
} }
get [autocorrectProperty.native](): boolean { get [autocorrectProperty.native](): boolean {
let autocorrect = this.nativeView.getInputType(); let autocorrect = this._android.getInputType();
if ((autocorrect & android.text.InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) === android.text.InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) { if ((autocorrect & android.text.InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) === android.text.InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) {
return true; return true;
} }
@ -392,7 +394,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
return false; return false;
} }
set [autocorrectProperty.native](value: boolean) { set [autocorrectProperty.native](value: boolean) {
let inputType = this.nativeView.getInputType(); let inputType = this._android.getInputType();
switch (value) { switch (value) {
case true: case true:
inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE; inputType = inputType | android.text.InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE;
@ -413,20 +415,20 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
} }
get [hintProperty.native](): string { get [hintProperty.native](): string {
return this.nativeView.getHint(); return this._android.getHint();
} }
set [hintProperty.native](value: string) { set [hintProperty.native](value: string) {
this.nativeView.setHint(value + ''); this._android.setHint(value + '');
} }
get [placeholderColorProperty.native](): android.content.res.ColorStateList { get [placeholderColorProperty.native](): android.content.res.ColorStateList {
return this.nativeView.getHintTextColors(); return this._android.getHintTextColors();
} }
set [placeholderColorProperty.native](value: Color | android.content.res.ColorStateList) { set [placeholderColorProperty.native](value: Color | android.content.res.ColorStateList) {
if (value instanceof Color) { if (value instanceof Color) {
this.nativeView.setHintTextColor(value.android); this._android.setHintTextColor(value.android);
} else { } else {
this.nativeView.setHintTextColor(value); this._android.setHintTextColor(value);
} }
} }
} }

View File

@ -161,8 +161,9 @@ export class Image extends ImageBase {
} }
@Interfaces([org.nativescript.widgets.image.Worker.OnImageLoadedListener]) @Interfaces([org.nativescript.widgets.image.Worker.OnImageLoadedListener])
class ImageLoadedListener implements org.nativescript.widgets.image.Worker.OnImageLoadedListener { class ImageLoadedListener extends java.lang.Object implements org.nativescript.widgets.image.Worker.OnImageLoadedListener {
constructor(private owner: WeakRef<Image>) { constructor(private owner: WeakRef<Image>) {
super();
return global.__native(this); return global.__native(this);
} }

View File

@ -4,8 +4,9 @@ import { ItemsSource } from "ui/list-picker";
export * from "./list-picker-common"; export * from "./list-picker-common";
@Interfaces([android.widget.NumberPicker.Formatter]) @Interfaces([android.widget.NumberPicker.Formatter])
class Formatter implements android.widget.NumberPicker.Formatter { class Formatter extends java.lang.Object implements android.widget.NumberPicker.Formatter {
constructor(private owner: WeakRef<ListPicker>) { constructor(private owner: WeakRef<ListPicker>) {
super();
return global.__native(this); return global.__native(this);
} }
@ -20,8 +21,9 @@ class Formatter implements android.widget.NumberPicker.Formatter {
} }
@Interfaces([android.widget.NumberPicker.OnValueChangeListener]) @Interfaces([android.widget.NumberPicker.OnValueChangeListener])
class ValueChangeListener implements android.widget.NumberPicker.OnValueChangeListener { class ValueChangeListener extends java.lang.Object implements android.widget.NumberPicker.OnValueChangeListener {
constructor(private owner: WeakRef<ListPicker>) { constructor(private owner: WeakRef<ListPicker>) {
super();
return global.__native(this); return global.__native(this);
} }

View File

@ -14,8 +14,9 @@ const LOADMOREITEMS = ListViewBase.loadMoreItemsEvent;
const ITEMTAP = ListViewBase.itemTapEvent; const ITEMTAP = ListViewBase.itemTapEvent;
@Interfaces([android.widget.AdapterView.OnItemClickListener]) @Interfaces([android.widget.AdapterView.OnItemClickListener])
class ItemClickListener implements android.widget.AdapterView.OnItemClickListener { class ItemClickListener extends java.lang.Object implements android.widget.AdapterView.OnItemClickListener {
constructor(private owner: WeakRef<ListView>) { constructor(private owner: WeakRef<ListView>) {
super();
return global.__native(this); return global.__native(this);
} }

View File

@ -10,8 +10,9 @@ const SEARCHTEXT = Symbol("searchText");
const QUERY = Symbol("query"); const QUERY = Symbol("query");
@Interfaces([android.widget.SearchView.OnQueryTextListener]) @Interfaces([android.widget.SearchView.OnQueryTextListener])
class QueryTextListener implements android.widget.SearchView.OnQueryTextListener { class QueryTextListener extends java.lang.Object implements android.widget.SearchView.OnQueryTextListener {
constructor(private owner: WeakRef<SearchBar>) { constructor(private owner: WeakRef<SearchBar>) {
super();
return global.__native(this); return global.__native(this);
} }
@ -44,8 +45,9 @@ class QueryTextListener implements android.widget.SearchView.OnQueryTextListener
} }
@Interfaces([android.widget.SearchView.OnCloseListener]) @Interfaces([android.widget.SearchView.OnCloseListener])
class CloseListener implements android.widget.SearchView.OnCloseListener { class CloseListener extends java.lang.Object implements android.widget.SearchView.OnCloseListener {
constructor(private owner: WeakRef<SearchBar>) { constructor(private owner: WeakRef<SearchBar>) {
super();
return global.__native(this); return global.__native(this);
} }

View File

@ -46,10 +46,10 @@ function setBackground(view: android.view.View, background: android.graphics.dra
} }
export class SegmentedBarItem extends SegmentedBarItemBase { export class SegmentedBarItem extends SegmentedBarItemBase {
private _nativeView: android.widget.TextView; private _textView: android.widget.TextView;
public setNativeView(textView: android.widget.TextView): void { public setNativeView(textView: android.widget.TextView): void {
this._nativeView = textView; this._textView = textView;
applyNativeSetters(this); applyNativeSetters(this);
if (this.titleDirty) { if (this.titleDirty) {
this._update(); this._update();
@ -67,7 +67,7 @@ export class SegmentedBarItem extends SegmentedBarItemBase {
// titleTextView.setText(this.title || ""); // titleTextView.setText(this.title || "");
// } // }
let tv = this._nativeView; let tv = this._textView;
if (tv) { if (tv) {
let title = this.title; let title = this.title;
title = (title === null || title === undefined) ? "" : title; title = (title === null || title === undefined) ? "" : title;
@ -79,22 +79,22 @@ export class SegmentedBarItem extends SegmentedBarItemBase {
} }
get [colorProperty.native](): number { get [colorProperty.native](): number {
return this._nativeView.getCurrentTextColor(); return this._textView.getCurrentTextColor();
} }
set [colorProperty.native](value: Color | number) { set [colorProperty.native](value: Color | number) {
let color = typeof value === "Color" ? value.android : value; let color = typeof value === "Color" ? value.android : value;
this._nativeView.setTextColor(color); this._textView.setTextColor(color);
} }
get [fontInternalProperty.native](): { typeface: android.graphics.Typeface, fontSize: number } { get [fontInternalProperty.native](): { typeface: android.graphics.Typeface, fontSize: number } {
let textView = this._nativeView; let textView = this._textView;
return { return {
typeface: textView.getTypeface(), typeface: textView.getTypeface(),
fontSize: textView.getTextSize() fontSize: textView.getTextSize()
}; };
} }
set [fontInternalProperty.native](value: Font | { typeface: android.graphics.Typeface, fontSize: number }) { set [fontInternalProperty.native](value: Font | { typeface: android.graphics.Typeface, fontSize: number }) {
let tv = this._nativeView; let tv = this._textView;
if (value instanceof Font) { if (value instanceof Font) {
tv.setTypeface(value.getAndroidTypeface()); tv.setTypeface(value.getAndroidTypeface());
tv.setTextSize(value.fontSize); tv.setTextSize(value.fontSize);
@ -105,11 +105,11 @@ export class SegmentedBarItem extends SegmentedBarItemBase {
} }
get [selectedBackgroundColorProperty.native](): android.graphics.drawable.Drawable { get [selectedBackgroundColorProperty.native](): android.graphics.drawable.Drawable {
let viewGroup = <android.view.ViewGroup>this._nativeView.getParent(); let viewGroup = <android.view.ViewGroup>this._textView.getParent();
return viewGroup.getBackground(); return viewGroup.getBackground();
} }
set [selectedBackgroundColorProperty.native](value: Color | android.graphics.drawable.Drawable) { set [selectedBackgroundColorProperty.native](value: Color | android.graphics.drawable.Drawable) {
let viewGroup = <android.view.ViewGroup>this._nativeView.getParent(); let viewGroup = <android.view.ViewGroup>this._textView.getParent();
if (value instanceof Color) { if (value instanceof Color) {
let color = value.android; let color = value.android;
let backgroundDrawable = viewGroup.getBackground(); let backgroundDrawable = viewGroup.getBackground();
@ -133,8 +133,9 @@ export class SegmentedBarItem extends SegmentedBarItemBase {
} }
@Interfaces([android.widget.TabHost.OnTabChangeListener]) @Interfaces([android.widget.TabHost.OnTabChangeListener])
class TabChangeListener implements android.widget.TabHost.OnTabChangeListener { class TabChangeListener extends java.lang.Object implements android.widget.TabHost.OnTabChangeListener {
constructor(private owner: WeakRef<SegmentedBar>) { constructor(private owner: WeakRef<SegmentedBar>) {
super();
return global.__native(this); return global.__native(this);
} }
@ -147,8 +148,9 @@ class TabChangeListener implements android.widget.TabHost.OnTabChangeListener {
} }
@Interfaces([android.widget.TabHost.TabContentFactory]) @Interfaces([android.widget.TabHost.TabContentFactory])
class TabContentFactory implements android.widget.TabHost.TabContentFactory { class TabContentFactory extends java.lang.Object implements android.widget.TabHost.TabContentFactory {
constructor(private owner: WeakRef<SegmentedBar>) { constructor(private owner: WeakRef<SegmentedBar>) {
super();
return global.__native(this); return global.__native(this);
} }

View File

@ -7,8 +7,9 @@
export * from "./slider-common"; export * from "./slider-common";
@Interfaces([android.widget.SeekBar.OnSeekBarChangeListener]) @Interfaces([android.widget.SeekBar.OnSeekBarChangeListener])
class SeekBarChangeListener implements android.widget.SeekBar.OnSeekBarChangeListener { class SeekBarChangeListener extends java.lang.Object implements android.widget.SeekBar.OnSeekBarChangeListener {
constructor(private owner: WeakRef<Slider>) { constructor(private owner: WeakRef<Slider>) {
super();
return global.__native(this); return global.__native(this);
} }

View File

@ -4,8 +4,9 @@ import { View, layout, Color, Property, colorProperty, backgroundColorProperty,
export * from "ui/core/view"; export * from "ui/core/view";
@Interfaces([android.widget.CompoundButton.OnCheckedChangeListener]) @Interfaces([android.widget.CompoundButton.OnCheckedChangeListener])
class CheckedChangeListener implements android.widget.CompoundButton.OnCheckedChangeListener { class CheckedChangeListener extends java.lang.Object implements android.widget.CompoundButton.OnCheckedChangeListener {
constructor(private owner: WeakRef<Switch>) { constructor(private owner: WeakRef<Switch>) {
super();
return global.__native(this); return global.__native(this);
} }

View File

@ -63,30 +63,30 @@ class TextTransformation extends android.text.method.ReplacementTransformationMe
export class TextBase extends TextBaseCommon { export class TextBase extends TextBaseCommon {
_transformationMethod: any; _transformationMethod: any;
nativeView: android.widget.TextView; _nativeView: android.widget.TextView;
public _setFormattedTextPropertyToNative(value: FormattedString) { public _setFormattedTextPropertyToNative(value: FormattedString) {
// TODO: Check if there is an option to force call the transformation method without // TODO: Check if there is an option to force call the transformation method without
// creating new native instance. // creating new native instance.
if (this.nativeView) { if (this._nativeView) {
this.nativeView.setTransformationMethod(new TextTransformation(this.text, value, this.style.textTransform)); this._nativeView.setTransformationMethod(new TextTransformation(this.text, value, this.style.textTransform));
} }
let newText = value ? value._formattedText : null; let newText = value ? value._formattedText : null;
if (this.nativeView) { if (this._nativeView) {
this.nativeView.setText(newText); this._nativeView.setText(newText);
} }
} }
get [textProperty.native](): string { get [textProperty.native](): string {
return this.nativeView.getText(); return this._nativeView.getText();
} }
set [textProperty.native](value: string) { set [textProperty.native](value: string) {
if (value === null || value === undefined) { if (value === null || value === undefined) {
value = ""; value = "";
} }
this.nativeView.setText(value); this._nativeView.setText(value);
} }
get [formattedTextProperty.native](): FormattedString { get [formattedTextProperty.native](): FormattedString {
@ -97,25 +97,25 @@ export class TextBase extends TextBaseCommon {
} }
get [colorProperty.native](): android.content.res.ColorStateList { get [colorProperty.native](): android.content.res.ColorStateList {
return this.nativeView.getTextColors(); return this._nativeView.getTextColors();
} }
set [colorProperty.native](value: Color | android.content.res.ColorStateList) { set [colorProperty.native](value: Color | android.content.res.ColorStateList) {
if (value instanceof Color) { if (value instanceof Color) {
this.nativeView.setTextColor(value.android); this._nativeView.setTextColor(value.android);
} else { } else {
this.nativeView.setTextColor(value); this._nativeView.setTextColor(value);
} }
} }
get [fontInternalProperty.native](): { typeface: android.graphics.Typeface, fontSize: number } { get [fontInternalProperty.native](): { typeface: android.graphics.Typeface, fontSize: number } {
let textView = this.nativeView; let textView = this._nativeView;
return { return {
typeface: textView.getTypeface(), typeface: textView.getTypeface(),
fontSize: textView.getTextSize() fontSize: textView.getTextSize()
}; };
} }
set [fontInternalProperty.native](value: Font | { typeface: android.graphics.Typeface, fontSize: number }) { set [fontInternalProperty.native](value: Font | { typeface: android.graphics.Typeface, fontSize: number }) {
let textView = this.nativeView; let textView = this._nativeView;
let typeface: android.graphics.Typeface; let typeface: android.graphics.Typeface;
let fontSize: number; let fontSize: number;
@ -131,7 +131,7 @@ export class TextBase extends TextBaseCommon {
} }
get [textAlignmentProperty.native](): string { get [textAlignmentProperty.native](): string {
let textGravity = this.nativeView.getGravity() & android.view.View.TEXT_ALIGNMENT_GRAVITY; let textGravity = this._nativeView.getGravity() & android.view.View.TEXT_ALIGNMENT_GRAVITY;
switch (textGravity) { switch (textGravity) {
case android.view.Gravity.LEFT: case android.view.Gravity.LEFT:
return "left"; return "left";
@ -147,16 +147,16 @@ export class TextBase extends TextBaseCommon {
} }
} }
set [textAlignmentProperty.native](value: string) { set [textAlignmentProperty.native](value: string) {
let verticalGravity = this.nativeView.getGravity() & android.view.Gravity.VERTICAL_GRAVITY_MASK; let verticalGravity = this._nativeView.getGravity() & android.view.Gravity.VERTICAL_GRAVITY_MASK;
switch (value) { switch (value) {
case "left": case "left":
this.nativeView.setGravity(android.view.Gravity.LEFT | verticalGravity); this._nativeView.setGravity(android.view.Gravity.LEFT | verticalGravity);
break; break;
case "center": case "center":
this.nativeView.setGravity(android.view.Gravity.CENTER_HORIZONTAL | verticalGravity); this._nativeView.setGravity(android.view.Gravity.CENTER_HORIZONTAL | verticalGravity);
break; break;
case "right": case "right":
this.nativeView.setGravity(android.view.Gravity.RIGHT | verticalGravity); this._nativeView.setGravity(android.view.Gravity.RIGHT | verticalGravity);
break; break;
default: default:
break; break;
@ -179,9 +179,9 @@ export class TextBase extends TextBaseCommon {
} }
if (values.indexOf("none") === -1) { if (values.indexOf("none") === -1) {
this.nativeView.setPaintFlags(flags); this._nativeView.setPaintFlags(flags);
} else { } else {
this.nativeView.setPaintFlags(0); this._nativeView.setPaintFlags(0);
} }
} }
@ -196,16 +196,16 @@ export class TextBase extends TextBaseCommon {
return "normal"; return "normal";
} }
set [whiteSpaceProperty.native](value: "normal" | "nowrap") { set [whiteSpaceProperty.native](value: "normal" | "nowrap") {
let nativeView = this.nativeView; let nativeView = this._nativeView;
let nowrap = value === "nowrap"; let nowrap = value === "nowrap";
nativeView.setSingleLine(nowrap); nativeView.setSingleLine(nowrap);
nativeView.setEllipsize(nowrap ? android.text.TextUtils.TruncateAt.END : null); nativeView.setEllipsize(nowrap ? android.text.TextUtils.TruncateAt.END : null);
} }
get [letterSpacingProperty.native](): number { get [letterSpacingProperty.native](): number {
return org.nativescript.widgets.ViewHelper.getLetterspacing(this.nativeView); return org.nativescript.widgets.ViewHelper.getLetterspacing(this._nativeView);
} }
set [letterSpacingProperty.native](value: number) { set [letterSpacingProperty.native](value: number) {
org.nativescript.widgets.ViewHelper.setLetterspacing(this.nativeView, value); org.nativescript.widgets.ViewHelper.setLetterspacing(this._nativeView, value);
} }
} }

View File

@ -3,8 +3,9 @@
export * from "./time-picker-common"; export * from "./time-picker-common";
@Interfaces([android.widget.TimePicker.OnTimeChangedListener]) @Interfaces([android.widget.TimePicker.OnTimeChangedListener])
class TimeChangedListener implements android.widget.TimePicker.OnTimeChangedListener { class TimeChangedListener extends java.lang.Object implements android.widget.TimePicker.OnTimeChangedListener {
constructor(public owner: WeakRef<TimePicker>) { constructor(public owner: WeakRef<TimePicker>) {
super();
return global.__native(this); return global.__native(this);
} }
@ -19,13 +20,13 @@ class TimeChangedListener implements android.widget.TimePicker.OnTimeChangedList
} }
export class TimePicker extends TimePickerBase { export class TimePicker extends TimePickerBase {
public nativeView: android.widget.TimePicker; public _timePicker: android.widget.TimePicker;
private _listener: android.widget.TimePicker.OnTimeChangedListener; private _listener: android.widget.TimePicker.OnTimeChangedListener;
public _createUI() { public _createUI() {
this.nativeView = new android.widget.TimePicker(this._context); this._timePicker = new android.widget.TimePicker(this._context);
this._listener = this._listener || new TimeChangedListener(new WeakRef(this)); this._listener = this._listener || new TimeChangedListener(new WeakRef(this));
this.nativeView.setOnTimeChangedListener(this._listener); this._timePicker.setOnTimeChangedListener(this._listener);
let c = java.util.Calendar.getInstance(); let c = java.util.Calendar.getInstance();
if (this.hour === 0) { if (this.hour === 0) {
@ -59,7 +60,7 @@ export class TimePicker extends TimePickerBase {
} }
get [timeProperty.native](): Date { get [timeProperty.native](): Date {
let nativeView = this.nativeView; let nativeView = this._timePicker;
return new Date(0, 0, 0, nativeView.getCurrentHour().intValue(), nativeView.getCurrentMinute().intValue()); return new Date(0, 0, 0, nativeView.getCurrentHour().intValue(), nativeView.getCurrentMinute().intValue());
} }
set [timeProperty.native](value: Date) { set [timeProperty.native](value: Date) {
@ -67,14 +68,14 @@ export class TimePicker extends TimePickerBase {
} }
get [minuteProperty.native](): number { get [minuteProperty.native](): number {
return this.nativeView.getCurrentMinute().intValue(); return this._timePicker.getCurrentMinute().intValue();
} }
set [minuteProperty.native](value: number) { set [minuteProperty.native](value: number) {
this._setNativeValueSilently(this.hour, value); this._setNativeValueSilently(this.hour, value);
} }
get [hourProperty.native](): number { get [hourProperty.native](): number {
return this.nativeView.getCurrentHour().intValue() return this._timePicker.getCurrentHour().intValue()
} }
set [hourProperty.native](value: number) { set [hourProperty.native](value: number) {
this._setNativeValueSilently(value, this.minute); this._setNativeValueSilently(value, this.minute);