fix padding on text-view & text-field (#3758)

* fix padding on text-view & text-field
text-base is now snapshotable
view.android is now snapshotable

* createNativeView returns the nativeView for android
Fix image tests
Implement test for image loaded from res://
EffectivePaddings updated when nativeView have some from its native theme
This commit is contained in:
Hristo Hristov
2017-03-09 16:09:53 +02:00
committed by GitHub
parent a4809fed16
commit 1d49f5f3c3
42 changed files with 269 additions and 236 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -86,7 +86,8 @@ application.on(application.lowMemoryEvent, function (args: application.Applicati
application.on(application.uncaughtErrorEvent, function (args: application.UnhandledErrorEventData) { application.on(application.uncaughtErrorEvent, function (args: application.UnhandledErrorEventData) {
console.log("NativeScriptError: " + args.error); console.log("NativeScriptError: " + args.error);
console.log(args.error.stack); console.log((<any>args.error).nativeException);
console.log((<any>args.error).stackTrace);
}); });
// Android activity events // Android activity events

View File

@ -16,10 +16,9 @@ import * as ImageSourceModule from "image-source";
import * as ViewModule from "ui/core/view"; import * as ViewModule from "ui/core/view";
import * as helper from "../helper"; import * as helper from "../helper";
import * as ObservableModule from "data/observable"; import * as ObservableModule from "data/observable";
import * as fs from "file-system";
import * as color from "color"; import * as color from "color";
const imagePath = fs.path.join(__dirname, "../../logo.png"); const imagePath = "~/logo.png";
if (isAndroid) { if (isAndroid) {
const imageModule = require("ui/image"); const imageModule = require("ui/image");
@ -33,19 +32,16 @@ export const test_Image_Members = function () {
TKUnit.assert(image.isLoading === false, "Image.isLoading is default value should be false."); TKUnit.assert(image.isLoading === false, "Image.isLoading is default value should be false.");
}; };
/* TODO: We need a way to programmatically add an image to resources and then load it from, otherwise we do not know if there is such resource in the target native app. export const test_setting_src_to_resource = function () {
export const test_settingImageSource = function () {
// >> img-create // >> img-create
const image = new ImageModule.Image(); const image = new ImageModule.Image();
image.imageSource = ImageSourceModule.fromResource("logo"); image.src = "res://icon";
// << img-create // << img-create
const testFunc = function (views: Array<ViewModule.View>) { const testFunc = function (views: Array<ViewModule.View>) {
const testImage = <ImageModule.Image> views[0]; TKUnit.waitUntilReady(() => image.isLayoutValid);
const width = image.getMeasuredWidth();
const desiredSize = testImage._measureNativeView(new geometry.Size(100, 100)); const height = image.getMeasuredHeight();
const width = desiredSize.width;
const height = desiredSize.height;
TKUnit.assert(width > 0, "Width should be greater than 0."); TKUnit.assert(width > 0, "Width should be greater than 0.");
TKUnit.assert(height > 0, "Height should be greater than 0."); TKUnit.assert(height > 0, "Height should be greater than 0.");
@ -53,7 +49,6 @@ export const test_settingImageSource = function () {
helper.buildUIAndRunTest(image, testFunc); helper.buildUIAndRunTest(image, testFunc);
} }
*/
const IMAGE_LOADED_EVENT = "isLoadingChange"; const IMAGE_LOADED_EVENT = "isLoadingChange";
@ -105,7 +100,7 @@ export const test_SettingImageSrcToURL_async = function (done) {
runImageTestAsync(image, image.src, done); runImageTestAsync(image, image.src, done);
}; };
export const test_SettingImageSrcToFileWithinApp_sync = function () { export const test_SettingImageSrcToFileWithinApp_sync = function () {
// >> img-create-local // >> img-create-local
const image = new ImageModule.Image(); const image = new ImageModule.Image();
image.src = "~/logo.png"; image.src = "~/logo.png";
@ -174,7 +169,6 @@ export const __test_SettingImageSrcTwiceMustNotMismatch = function (done) {
export const test_SettingStretch_AspectFit = function () { export const test_SettingStretch_AspectFit = function () {
// >> img-set-stretch // >> img-set-stretch
const image = new ImageModule.Image(); const image = new ImageModule.Image();
image.imageSource = ImageSourceModule.fromFile(imagePath);
// There are 4 modes of stretching none, fill, aspectFill, aspectFit // There are 4 modes of stretching none, fill, aspectFill, aspectFit
// The default value is aspectFit. // The default value is aspectFit.
// Image stretch can be set by using ImageModule.stretch enum. // Image stretch can be set by using ImageModule.stretch enum.
@ -182,17 +176,10 @@ export const test_SettingStretch_AspectFit = function () {
// << img-set-stretch // << img-set-stretch
const testFunc = function (views: Array<ViewModule.View>) { const testFunc = function (views: Array<ViewModule.View>) {
const testImage = <ImageModule.Image>views[0];
if (image.android) { if (image.android) {
const actualScaleType = testImage.android.getScaleType(); TKUnit.assertEqual(image.android.getScaleType(), android.widget.ImageView.ScaleType.FIT_CENTER);
const expectedScaleType = android.widget.ImageView.ScaleType.FIT_CENTER; } else if (image.ios) {
TKUnit.assertEqual(actualScaleType, expectedScaleType, "actualScaleType"); TKUnit.assertEqual(image.ios.contentMode, UIViewContentMode.ScaleAspectFit);
}
else if (image.ios) {
const actualContentMode = testImage.ios.contentMode;
const expectedContentMode = UIViewContentMode.ScaleAspectFit;
TKUnit.assertEqual(actualContentMode, expectedContentMode, "actualContentMode");
} }
}; };
@ -201,20 +188,11 @@ export const test_SettingStretch_AspectFit = function () {
export const test_SettingStretch_Default = function () { export const test_SettingStretch_Default = function () {
const image = new ImageModule.Image(); const image = new ImageModule.Image();
image.imageSource = ImageSourceModule.fromFile(imagePath);
const testFunc = function (views: Array<ViewModule.View>) { const testFunc = function (views: Array<ViewModule.View>) {
const testImage = <ImageModule.Image>views[0];
if (image.android) { if (image.android) {
const actualScaleType = testImage.android.getScaleType(); TKUnit.assertEqual(image.android.getScaleType(), android.widget.ImageView.ScaleType.FIT_CENTER);
const expectedScaleType = android.widget.ImageView.ScaleType.FIT_CENTER; } else if (image.ios) {
TKUnit.assert(actualScaleType === expectedScaleType, "Expected: " + expectedScaleType + ", Actual: " + actualScaleType); TKUnit.assertEqual(image.ios.contentMode, UIViewContentMode.ScaleAspectFit);
}
else if (image.ios) {
const actualContentMode = testImage.ios.contentMode;
const expectedContentMode = UIViewContentMode.ScaleAspectFit;
TKUnit.assert(actualContentMode === expectedContentMode, "Expected: " + expectedContentMode + ", Actual: " + actualContentMode);
} }
}; };
@ -223,21 +201,13 @@ export const test_SettingStretch_Default = function () {
export const test_SettingStretch_AspectFill = function () { export const test_SettingStretch_AspectFill = function () {
const image = new ImageModule.Image(); const image = new ImageModule.Image();
image.imageSource = ImageSourceModule.fromFile(imagePath);
image.stretch = "aspectFill"; image.stretch = "aspectFill";
const testFunc = function (views: Array<ViewModule.View>) { const testFunc = function (views: Array<ViewModule.View>) {
const testImage = <ImageModule.Image>views[0];
if (image.android) { if (image.android) {
const actualScaleType = testImage.android.getScaleType(); TKUnit.assertEqual(image.android.getScaleType(), android.widget.ImageView.ScaleType.CENTER_CROP);
const expectedScaleType = android.widget.ImageView.ScaleType.CENTER_CROP; } else if (image.ios) {
TKUnit.assert(actualScaleType === expectedScaleType, "Expected: " + expectedScaleType + ", Actual: " + actualScaleType); TKUnit.assertEqual(image.ios.contentMode, UIViewContentMode.ScaleAspectFill);
}
else if (image.ios) {
const actualContentMode = testImage.ios.contentMode;
const expectedContentMode = UIViewContentMode.ScaleAspectFill;
TKUnit.assert(actualContentMode === expectedContentMode, "Expected: " + expectedContentMode + ", Actual: " + actualContentMode);
} }
}; };
@ -246,21 +216,14 @@ export const test_SettingStretch_AspectFill = function () {
export const test_SettingStretch_Fill = function () { export const test_SettingStretch_Fill = function () {
const image = new ImageModule.Image(); const image = new ImageModule.Image();
image.imageSource = ImageSourceModule.fromFile(imagePath);
image.stretch = "fill"; image.stretch = "fill";
const testFunc = function (views: Array<ViewModule.View>) { const testFunc = function (views: Array<ViewModule.View>) {
const testImage = <ImageModule.Image>views[0];
if (image.android) { if (image.android) {
const actualScaleType = testImage.android.getScaleType(); TKUnit.assertEqual(image.android.getScaleType(), android.widget.ImageView.ScaleType.FIT_XY);
const expectedScaleType = android.widget.ImageView.ScaleType.FIT_XY; } else if (image.ios) {
TKUnit.assert(actualScaleType === expectedScaleType, "Expected: " + expectedScaleType + ", Actual: " + actualScaleType); TKUnit.assertEqual(image.ios.contentMode, UIViewContentMode.ScaleToFill);
}
else if (image.ios) {
const actualContentMode = testImage.ios.contentMode;
const expectedContentMode = UIViewContentMode.ScaleToFill;
TKUnit.assert(actualContentMode === expectedContentMode, "Expected: " + expectedContentMode + ", Actual: " + actualContentMode);
} }
}; };
@ -269,21 +232,13 @@ export const test_SettingStretch_Fill = function () {
export const test_SettingStretch_none = function () { export const test_SettingStretch_none = function () {
const image = new ImageModule.Image(); const image = new ImageModule.Image();
image.imageSource = ImageSourceModule.fromFile(imagePath);
image.stretch = "none"; image.stretch = "none";
const testFunc = function (views: Array<ViewModule.View>) { const testFunc = function (views: Array<ViewModule.View>) {
const testImage = <ImageModule.Image>views[0];
if (image.android) { if (image.android) {
const actualScaleType = testImage.android.getScaleType(); TKUnit.assertEqual(image.android.getScaleType(), android.widget.ImageView.ScaleType.MATRIX);
const expectedScaleType = android.widget.ImageView.ScaleType.MATRIX; } else if (image.ios) {
TKUnit.assert(actualScaleType === expectedScaleType, "Expected: " + expectedScaleType + ", Actual: " + actualScaleType); TKUnit.assertEqual(image.ios.contentMode, UIViewContentMode.TopLeft);
}
else if (image.ios) {
const actualContentMode = testImage.ios.contentMode;
const expectedContentMode = UIViewContentMode.TopLeft;
TKUnit.assert(actualContentMode === expectedContentMode, "Expected: " + expectedContentMode + ", Actual: " + actualContentMode);
} }
}; };
@ -375,7 +330,7 @@ export const test_DimensionsAreRoundedAfterScale = function () {
export const test_tintColor = function () { export const test_tintColor = function () {
const colorRed = new color.Color("red"); const colorRed = new color.Color("red");
const image = new ImageModule.Image(); const image = new ImageModule.Image();
image.imageSource = ImageSourceModule.fromFile(imagePath); image.src = imagePath;
const testFunc = function (views: Array<ViewModule.View>) { const testFunc = function (views: Array<ViewModule.View>) {
const testImage = <ImageModule.Image>views[0]; const testImage = <ImageModule.Image>views[0];

View File

@ -87,6 +87,7 @@ export class MyButton extends Button implements def.MyButton {
public _createNativeView() { public _createNativeView() {
this._layout = new NativeButton(this._context, this); this._layout = new NativeButton(this._context, this);
return this._layout;
} }
public measureCount: number = 0; public measureCount: number = 0;
@ -140,6 +141,7 @@ export class MyStackLayout extends StackLayout implements def.MyStackLayout {
public _createNativeView() { public _createNativeView() {
this._layout = new NativeStackLayout(this._context, this); this._layout = new NativeStackLayout(this._context, this);
return this._layout;
} }
public measureCount: number = 0; public measureCount: number = 0;
@ -193,6 +195,7 @@ export class MyGridLayout extends GridLayout implements def.MyGridLayout {
public _createNativeView() { public _createNativeView() {
this._layout = new NativeGridLayout(this._context, this); this._layout = new NativeGridLayout(this._context, this);
return this._layout;
} }
public measureCount: number = 0; public measureCount: number = 0;

View File

@ -137,9 +137,10 @@ export class ActionBar extends ActionBarBase {
public _createNativeView() { public _createNativeView() {
initializeMenuItemClickListener(); initializeMenuItemClickListener();
this._toolbar = new android.support.v7.widget.Toolbar(this._context); const toolbar = this._toolbar = new android.support.v7.widget.Toolbar(this._context);
this._menuItemClickListener = this._menuItemClickListener || new MenuItemClickListener(this); this._menuItemClickListener = this._menuItemClickListener || new MenuItemClickListener(this);
this._toolbar.setOnMenuItemClickListener(this._menuItemClickListener); this._toolbar.setOnMenuItemClickListener(this._menuItemClickListener);
return toolbar;
} }
public onLoaded() { public onLoaded() {

View File

@ -6,9 +6,10 @@ export class ActivityIndicator extends ActivityIndicatorBase {
_progressBar: android.widget.ProgressBar; _progressBar: android.widget.ProgressBar;
public _createNativeView() { public _createNativeView() {
this._progressBar = new android.widget.ProgressBar(this._context); const progressBar = this._progressBar = new android.widget.ProgressBar(this._context);
this._progressBar.setVisibility(android.view.View.INVISIBLE); this._progressBar.setVisibility(android.view.View.INVISIBLE);
this._progressBar.setIndeterminate(true); this._progressBar.setIndeterminate(true);
return progressBar;
} }
get android(): android.widget.ProgressBar { get android(): android.widget.ProgressBar {

View File

@ -36,7 +36,6 @@ function initializeClickListener(): void {
export class Button extends ButtonBase { export class Button extends ButtonBase {
_button: android.widget.Button; _button: android.widget.Button;
private _highlightedHandler: (args: TouchGestureEventData) => void; private _highlightedHandler: (args: TouchGestureEventData) => void;
private _defaultNativePadding: android.graphics.Rect;
get android(): android.widget.Button { get android(): android.widget.Button {
return this._button; return this._button;
@ -44,18 +43,9 @@ export class Button extends ButtonBase {
public _createNativeView() { public _createNativeView() {
initializeClickListener(); initializeClickListener();
this._button = new android.widget.Button(this._context); const button = this._button = new android.widget.Button(this._context);
this._button.setOnClickListener(new ClickListener(this)); this._button.setOnClickListener(new ClickListener(this));
return button;
// Unlike all other widgets, the Button has padding 30 36 30 36 in device pixels.
let result = new android.graphics.Rect();
this._button.getBackground().getPadding(result);
this._defaultNativePadding = result;
this.effectivePaddingTop = this._defaultNativePadding.top;
this.effectivePaddingRight = this._defaultNativePadding.right;
this.effectivePaddingBottom = this._defaultNativePadding.bottom;
this.effectivePaddingLeft = this._defaultNativePadding.left;
} }
@PseudoClassHandler("normal", "highlighted", "pressed", "active") @PseudoClassHandler("normal", "highlighted", "pressed", "active")
@ -77,33 +67,29 @@ export class Button extends ButtonBase {
} }
} }
//PaddingTop
get [paddingTopProperty.native](): Length { get [paddingTopProperty.native](): Length {
return { value: this._defaultNativePadding.top, unit: "px" } return { value: this._defaultPaddingTop, unit: "px" }
} }
set [paddingTopProperty.native](value: Length) { set [paddingTopProperty.native](value: Length) {
org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0)); org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0));
} }
//PaddingRight
get [paddingRightProperty.native](): Length { get [paddingRightProperty.native](): Length {
return { value: this._defaultNativePadding.right, unit: "px" } return { value: this._defaultPaddingRight, unit: "px" }
} }
set [paddingRightProperty.native](value: Length) { set [paddingRightProperty.native](value: Length) {
org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0)); org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0));
} }
//PaddingBottom
get [paddingBottomProperty.native](): Length { get [paddingBottomProperty.native](): Length {
return { value: this._defaultNativePadding.bottom, unit: "px" } return { value: this._defaultPaddingBottom, unit: "px" }
} }
set [paddingBottomProperty.native](value: Length) { set [paddingBottomProperty.native](value: Length) {
org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0)); org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0));
} }
//PaddingLeft
get [paddingLeftProperty.native](): Length { get [paddingLeftProperty.native](): Length {
return { value: this._defaultNativePadding.left, unit: "px" } return { value: this._defaultPaddingLeft, unit: "px" }
} }
set [paddingLeftProperty.native](value: Length) { set [paddingLeftProperty.native](value: Length) {
org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0)); org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0));

View File

@ -64,6 +64,10 @@ export abstract class ViewBase extends Observable {
_oldTop: number; _oldTop: number;
_oldRight: number; _oldRight: number;
_oldBottom: number; _oldBottom: number;
_defaultPaddingTop: number;
_defaultPaddingRight: number;
_defaultPaddingBottom: number;
_defaultPaddingLeft: number;
//@endprivate //@endprivate
public effectiveMinWidth: number; public effectiveMinWidth: number;
@ -200,7 +204,7 @@ export abstract class ViewBase extends Observable {
/** /**
* Creates a native view * Creates a native view
*/ */
_createNativeView(): void; _createNativeView(): Object;
/** /**
* Clean up references to the native view. * Clean up references to the native view.

View File

@ -3,14 +3,14 @@ import { ViewBase as ViewBaseDefinition } from "ui/core/view-base";
import { Page } from "ui/page"; import { Page } from "ui/page";
import { SelectorCore } from "ui/styling/css-selector"; import { SelectorCore } from "ui/styling/css-selector";
import { Order, FlexGrow, FlexShrink, FlexWrapBefore, AlignSelf } from "ui/layouts/flexbox-layout"; import { Order, FlexGrow, FlexShrink, FlexWrapBefore, AlignSelf } from "ui/layouts/flexbox-layout";
import { Length } from "../../styling/style-properties";
import { KeyframeAnimation } from "ui/animation/keyframe-animation"; import { KeyframeAnimation } from "ui/animation/keyframe-animation";
// Types. // Types.
import { Property, InheritedProperty, Style, clearInheritedProperties, propagateInheritableProperties, propagateInheritableCssProperties, resetCSSProperties, initNativeView, resetNativeView } from "../properties"; import { Property, InheritedProperty, Style, clearInheritedProperties, propagateInheritableProperties, propagateInheritableCssProperties, resetCSSProperties, initNativeView, resetNativeView, _isSet } from "../properties";
import { Binding, BindingOptions, Observable, WrappedValue, PropertyChangeData, traceEnabled, traceWrite, traceCategories, traceNotifyEvent } from "ui/core/bindable"; import { Binding, BindingOptions, Observable, WrappedValue, PropertyChangeData, traceEnabled, traceWrite, traceCategories, traceNotifyEvent } from "ui/core/bindable";
import { isIOS, isAndroid } from "platform"; import { isIOS, isAndroid } from "platform";
import { layout } from "utils/utils"; import { layout } from "utils/utils";
import { Length, paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty } from "../../styling/style-properties";
// TODO: Remove this import! // TODO: Remove this import!
import * as types from "utils/types"; import * as types from "utils/types";
@ -156,6 +156,11 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
public effectiveBorderBottomWidth: number; public effectiveBorderBottomWidth: number;
public effectiveBorderLeftWidth: number; public effectiveBorderLeftWidth: number;
public _defaultPaddingTop: number;
public _defaultPaddingRight: number;
public _defaultPaddingBottom: number;
public _defaultPaddingLeft: number;
constructor() { constructor() {
super(); super();
this._domId = viewIdCounter++; this._domId = viewIdCounter++;
@ -544,8 +549,8 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
} }
} }
public _createNativeView() { public _createNativeView(): Object {
// return undefined;
} }
public _disposeNativeView() { public _disposeNativeView() {
@ -575,9 +580,40 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
this._context = context; this._context = context;
traceNotifyEvent(this, "_onContextChanged"); traceNotifyEvent(this, "_onContextChanged");
// TODO: refactor createUI to return native view if (isAndroid) {
this._createNativeView(); const native: any = this._createNativeView();
this.nativeView = (<any>this)._nativeView; const nativeView: android.view.View = this.nativeView = native;
if (nativeView) {
let result: android.graphics.Rect = (<any>nativeView).defaultPaddings;
if (result === undefined) {
result = org.nativescript.widgets.ViewHelper.getPadding(nativeView);
(<any>nativeView).defaultPaddings = result;
}
this._defaultPaddingTop = result.top;
this._defaultPaddingRight = result.right;
this._defaultPaddingBottom = result.bottom;
this._defaultPaddingLeft = result.left;
const style = this.style;
if (!_isSet(paddingTopProperty, style)) {
this.effectivePaddingTop = this._defaultPaddingTop;
}
if (!_isSet(paddingRightProperty, style)) {
this.effectivePaddingRight = this._defaultPaddingRight;
}
if (!_isSet(paddingBottomProperty, style)) {
this.effectivePaddingBottom = this._defaultPaddingBottom;
}
if (!_isSet(paddingLeftProperty, style)) {
this.effectivePaddingLeft = this._defaultPaddingLeft;
}
}
} else {
// TODO: Implement _createNativeView for iOS
this._createNativeView();
this.nativeView = (<any>this)._nativeView;
}
this._initNativeView(); this._initNativeView();
@ -734,6 +770,10 @@ ViewBase.prototype.effectiveBorderTopWidth = 0;
ViewBase.prototype.effectiveBorderRightWidth = 0; ViewBase.prototype.effectiveBorderRightWidth = 0;
ViewBase.prototype.effectiveBorderBottomWidth = 0; ViewBase.prototype.effectiveBorderBottomWidth = 0;
ViewBase.prototype.effectiveBorderLeftWidth = 0; ViewBase.prototype.effectiveBorderLeftWidth = 0;
ViewBase.prototype._defaultPaddingTop = 0;
ViewBase.prototype._defaultPaddingRight = 0;
ViewBase.prototype._defaultPaddingBottom = 0;
ViewBase.prototype._defaultPaddingLeft = 0;
export const bindingContextProperty = new InheritedProperty<ViewBase, any>({ name: "bindingContext" }); export const bindingContextProperty = new InheritedProperty<ViewBase, any>({ name: "bindingContext" });
bindingContextProperty.register(ViewBase); bindingContextProperty.register(ViewBase);

View File

@ -662,10 +662,6 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
return { boundsChanged, sizeChanged }; return { boundsChanged, sizeChanged };
} }
public _createNativeView() {
//
}
public eachChild(callback: (child: ViewBase) => boolean): void { public eachChild(callback: (child: ViewBase) => boolean): void {
this.eachChildView(<any>callback); this.eachChildView(<any>callback);
} }

View File

@ -467,7 +467,8 @@ export class CustomLayoutView extends View implements CustomLayoutViewDefinition
} }
public _createNativeView() { public _createNativeView() {
this._viewGroup = new org.nativescript.widgets.ContentLayout(this._context); const viewGroup = this._viewGroup = new org.nativescript.widgets.ContentLayout(this._context);
return viewGroup;
} }
public _addViewToNativeVisualTree(child: ViewCommon, atIndex: number = -1): boolean { public _addViewToNativeVisualTree(child: ViewCommon, atIndex: number = -1): boolean {
@ -523,9 +524,17 @@ interface NativePercentLengthPropertyOptions {
setPixels: NativeSetter; setPixels: NativeSetter;
setPercent?: NativeSetter setPercent?: NativeSetter
} }
function createNativePercentLengthProperty({ key, auto = 0, getPixels, setPixels, setPercent = percentNotSupported }: NativePercentLengthPropertyOptions) { function createNativePercentLengthProperty(options: NativePercentLengthPropertyOptions) {
const { key, auto = 0 } = options;
let setPixels, getPixels, setPercent;
Object.defineProperty(View.prototype, key, { Object.defineProperty(View.prototype, key, {
get: function (this: View): PercentLength { get: function (this: View): PercentLength {
if (options) {
setPixels = options.setPixels;
getPixels = options.getPixels;
setPercent = options.setPercent || percentNotSupported;
options = null;
}
const value = getPixels(this.nativeView); const value = getPixels(this.nativeView);
if (value == auto) { // tslint:disable-line if (value == auto) { // tslint:disable-line
return "auto"; return "auto";
@ -534,6 +543,12 @@ function createNativePercentLengthProperty({ key, auto = 0, getPixels, setPixels
} }
}, },
set: function (this: View, length: PercentLength) { set: function (this: View, length: PercentLength) {
if (options) {
setPixels = options.setPixels;
getPixels = options.getPixels;
setPercent = options.setPercent || percentNotSupported;
options = null;
}
if (length == "auto") { // tslint:disable-line if (length == "auto") { // tslint:disable-line
setPixels(this.nativeView, auto); setPixels(this.nativeView, auto);
} else if (typeof length === "number") { } else if (typeof length === "number") {
@ -553,56 +568,56 @@ function createNativePercentLengthProperty({ key, auto = 0, getPixels, setPixels
createNativePercentLengthProperty({ createNativePercentLengthProperty({
key: marginTopProperty.native, key: marginTopProperty.native,
getPixels: org.nativescript.widgets.ViewHelper.getMarginTop, get getPixels() { return org.nativescript.widgets.ViewHelper.getMarginTop },
setPixels: org.nativescript.widgets.ViewHelper.setMarginTop, get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginTop },
setPercent: org.nativescript.widgets.ViewHelper.setMarginTopPercent get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginTopPercent }
}); });
createNativePercentLengthProperty({ createNativePercentLengthProperty({
key: marginRightProperty.native, key: marginRightProperty.native,
getPixels: org.nativescript.widgets.ViewHelper.getMarginRight, get getPixels() { return org.nativescript.widgets.ViewHelper.getMarginRight },
setPixels: org.nativescript.widgets.ViewHelper.setMarginRight, get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginRight },
setPercent: org.nativescript.widgets.ViewHelper.setMarginRightPercent get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginRightPercent }
}); });
createNativePercentLengthProperty({ createNativePercentLengthProperty({
key: marginBottomProperty.native, key: marginBottomProperty.native,
getPixels: org.nativescript.widgets.ViewHelper.getMarginBottom, get getPixels() { return org.nativescript.widgets.ViewHelper.getMarginBottom },
setPixels: org.nativescript.widgets.ViewHelper.setMarginBottom, get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginBottom },
setPercent: org.nativescript.widgets.ViewHelper.setMarginBottomPercent get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginBottomPercent }
}); });
createNativePercentLengthProperty({ createNativePercentLengthProperty({
key: marginLeftProperty.native, key: marginLeftProperty.native,
getPixels: org.nativescript.widgets.ViewHelper.getMarginLeft, get getPixels() { return org.nativescript.widgets.ViewHelper.getMarginLeft },
setPixels: org.nativescript.widgets.ViewHelper.setMarginLeft, get setPixels() { return org.nativescript.widgets.ViewHelper.setMarginLeft },
setPercent: org.nativescript.widgets.ViewHelper.setMarginLeftPercent get setPercent() { return org.nativescript.widgets.ViewHelper.setMarginLeftPercent }
}); });
createNativePercentLengthProperty({ createNativePercentLengthProperty({
key: widthProperty.native, key: widthProperty.native,
auto: android.view.ViewGroup.LayoutParams.MATCH_PARENT, auto: -1, //android.view.ViewGroup.LayoutParams.MATCH_PARENT,
getPixels: org.nativescript.widgets.ViewHelper.getWidth, get getPixels() { return org.nativescript.widgets.ViewHelper.getWidth },
setPixels: org.nativescript.widgets.ViewHelper.setWidth, get setPixels() { return org.nativescript.widgets.ViewHelper.setWidth },
setPercent: org.nativescript.widgets.ViewHelper.setWidthPercent get setPercent() { return org.nativescript.widgets.ViewHelper.setWidthPercent }
}); });
createNativePercentLengthProperty({ createNativePercentLengthProperty({
key: heightProperty.native, key: heightProperty.native,
auto: android.view.ViewGroup.LayoutParams.MATCH_PARENT, auto: -1, //android.view.ViewGroup.LayoutParams.MATCH_PARENT,
getPixels: org.nativescript.widgets.ViewHelper.getHeight, get getPixels() { return org.nativescript.widgets.ViewHelper.getHeight },
setPixels: org.nativescript.widgets.ViewHelper.setHeight, get setPixels() { return org.nativescript.widgets.ViewHelper.setHeight },
setPercent: org.nativescript.widgets.ViewHelper.setHeightPercent get setPercent() { return org.nativescript.widgets.ViewHelper.setHeightPercent }
}); });
createNativePercentLengthProperty({ createNativePercentLengthProperty({
key: "_minWidthNative", key: "_minWidthNative",
getPixels: org.nativescript.widgets.ViewHelper.getMinWidth, get getPixels() { return org.nativescript.widgets.ViewHelper.getMinWidth },
setPixels: org.nativescript.widgets.ViewHelper.setMinWidth get setPixels() { return org.nativescript.widgets.ViewHelper.setMinWidth }
}); });
createNativePercentLengthProperty({ createNativePercentLengthProperty({
key: "_minHeightNative", key: "_minHeightNative",
getPixels: org.nativescript.widgets.ViewHelper.getMinHeight, get getPixels() { return org.nativescript.widgets.ViewHelper.getMinHeight },
setPixels: org.nativescript.widgets.ViewHelper.setMinHeight get setPixels() { return org.nativescript.widgets.ViewHelper.setMinHeight }
}); });

View File

@ -60,10 +60,11 @@ export class DatePicker extends DatePickerBase {
public _createNativeView() { public _createNativeView() {
initializeDateChangedListener(); initializeDateChangedListener();
this._android = new android.widget.DatePicker(this._context); const picker = this._android = new android.widget.DatePicker(this._context);
this._android.setCalendarViewShown(false); picker.setCalendarViewShown(false);
this._listener = this._listener = new DateChangedListener(this); this._listener = this._listener = new DateChangedListener(this);
this._android.init(0, 0, 0, this._listener); picker.init(0, 0, 0, this._listener);
return picker;
} }
private updateNativeDate(): void { private updateNativeDate(): void {

View File

@ -134,14 +134,15 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
public _createNativeView() { public _createNativeView() {
initializeEditTextListeners(); initializeEditTextListeners();
this._android = new android.widget.EditText(this._context); const editText = this._android = new android.widget.EditText(this._context);
this._configureEditText(); this._configureEditText();
this._keyListenerCache = this.android.getKeyListener(); this._keyListenerCache = editText.getKeyListener();
this._editTextListeners = this._editTextListeners || new EditTextListeners(this); this._editTextListeners = this._editTextListeners || new EditTextListeners(this);
this._android.addTextChangedListener(this._editTextListeners); editText.addTextChangedListener(this._editTextListeners);
this._android.setOnFocusChangeListener(this._editTextListeners); editText.setOnFocusChangeListener(this._editTextListeners);
this._android.setOnEditorActionListener(this._editTextListeners); editText.setOnEditorActionListener(this._editTextListeners);
return editText;
} }
public _resetNativeView(force?: boolean) { public _resetNativeView(force?: boolean) {

View File

@ -297,7 +297,7 @@ export class Frame extends FrameBase {
} }
public _createNativeView() { public _createNativeView() {
let root = new org.nativescript.widgets.ContentLayout(this._context); const root = new org.nativescript.widgets.ContentLayout(this._context);
if (this._containerViewId < 0) { if (this._containerViewId < 0) {
this._containerViewId = android.view.View.generateViewId(); this._containerViewId = android.view.View.generateViewId();
} }
@ -305,6 +305,7 @@ export class Frame extends FrameBase {
this._android.rootViewGroup = root; this._android.rootViewGroup = root;
this._android.rootViewGroup.setId(this._containerViewId); this._android.rootViewGroup.setId(this._containerViewId);
this._android.rootViewGroup.addOnAttachStateChangeListener(this._listener); this._android.rootViewGroup.addOnAttachStateChangeListener(this._listener);
return root;
} }
private onNativeViewAttachedToWindow(view: android.view.View): void { private onNativeViewAttachedToWindow(view: android.view.View): void {

View File

@ -12,10 +12,11 @@ export class HtmlView extends HtmlViewBase {
} }
public _createNativeView() { public _createNativeView() {
this._android = new android.widget.TextView(this._context); const textView = this._android = new android.widget.TextView(this._context);
// This makes the html <a href...> work // This makes the html <a href...> work
this._android.setLinksClickable(true); textView.setLinksClickable(true);
this._android.setMovementMethod(android.text.method.LinkMovementMethod.getInstance()); textView.setMovementMethod(android.text.method.LinkMovementMethod.getInstance());
return textView;
} }
get [htmlProperty.native](): string { get [htmlProperty.native](): string {

View File

@ -65,7 +65,8 @@ export class Image extends ImageBase {
initImageCache(this._context); initImageCache(this._context);
} }
this._android = new org.nativescript.widgets.ImageView(this._context); const imageView = this._android = new org.nativescript.widgets.ImageView(this._context);
return imageView;
} }
public _createImageSourceFromSrc() { public _createImageSourceFromSrc() {

View File

@ -18,6 +18,7 @@ export class Label extends TextBase implements LabelDefinition {
} }
public _createNativeView() { public _createNativeView() {
this._android = new android.widget.TextView(this._context); const textView = this._android = new android.widget.TextView(this._context);
return textView;
} }
} }

View File

@ -52,6 +52,7 @@ export class AbsoluteLayout extends AbsoluteLayoutBase {
} }
public _createNativeView() { public _createNativeView() {
this._layout = new org.nativescript.widgets.AbsoluteLayout(this._context); const layout = this._layout = new org.nativescript.widgets.AbsoluteLayout(this._context);
return layout;
} }
} }

View File

@ -55,7 +55,8 @@ export class DockLayout extends DockLayoutBase {
} }
public _createNativeView() { public _createNativeView() {
this._layout = new org.nativescript.widgets.DockLayout(this._context); const layout = this._layout = new org.nativescript.widgets.DockLayout(this._context);
return layout;
} }
get [stretchLastChildProperty.native](): boolean { get [stretchLastChildProperty.native](): boolean {

View File

@ -135,7 +135,8 @@ export class FlexboxLayout extends FlexboxLayoutBase {
get _nativeView(): org.nativescript.widgets.FlexboxLayout { return this._layout; } get _nativeView(): org.nativescript.widgets.FlexboxLayout { return this._layout; }
public _createNativeView() { public _createNativeView() {
this._layout = new org.nativescript.widgets.FlexboxLayout(this._context); const layout = this._layout = new org.nativescript.widgets.FlexboxLayout(this._context);
return layout;
} }
get [flexDirectionProperty.native](): FlexDirection { get [flexDirectionProperty.native](): FlexDirection {

View File

@ -103,11 +103,12 @@ export class GridLayout extends GridLayoutBase {
} }
public _createNativeView() { public _createNativeView() {
this._layout = new org.nativescript.widgets.GridLayout(this._context); const layout = this._layout = new org.nativescript.widgets.GridLayout(this._context);
// Update native GridLayout // Update native GridLayout
this.getRows().forEach((itemSpec: ItemSpec, index, rows) => { this._onRowAdded(itemSpec); }, this); this.getRows().forEach((itemSpec: ItemSpec, index, rows) => { this._onRowAdded(itemSpec); }, this);
this.getColumns().forEach((itemSpec: ItemSpec, index, rows) => { this._onColumnAdded(itemSpec); }, this); this.getColumns().forEach((itemSpec: ItemSpec, index, rows) => { this._onColumnAdded(itemSpec); }, this);
return layout;
} }
public _onRowAdded(itemSpec: ItemSpec) { public _onRowAdded(itemSpec: ItemSpec) {

View File

@ -25,33 +25,29 @@ export class LayoutBase extends LayoutBaseCommon {
console.warn(`clipToBounds with value false is not supported on Android. You can use this.android.getParent().setClipChildren(false) as an alternative`); console.warn(`clipToBounds with value false is not supported on Android. You can use this.android.getParent().setClipChildren(false) as an alternative`);
} }
//PaddingTop
get [paddingTopProperty.native](): Length { get [paddingTopProperty.native](): Length {
return { value: org.nativescript.widgets.ViewHelper.getPaddingTop(this.nativeView), unit: "px" }; return { value: this._defaultPaddingTop, unit: "px" }
} }
set [paddingTopProperty.native](value: Length) { set [paddingTopProperty.native](value: Length) {
org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0)); org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0));
} }
//PaddingRight
get [paddingRightProperty.native](): Length { get [paddingRightProperty.native](): Length {
return { value: org.nativescript.widgets.ViewHelper.getPaddingRight(this.nativeView), unit: "px" }; return { value: this._defaultPaddingRight, unit: "px" }
} }
set [paddingRightProperty.native](value: Length) { set [paddingRightProperty.native](value: Length) {
org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0)); org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0));
} }
//PaddingBottom
get [paddingBottomProperty.native](): Length { get [paddingBottomProperty.native](): Length {
return { value: org.nativescript.widgets.ViewHelper.getPaddingBottom(this.nativeView), unit: "px" }; return { value: this._defaultPaddingBottom, unit: "px" }
} }
set [paddingBottomProperty.native](value: Length) { set [paddingBottomProperty.native](value: Length) {
org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0)); org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0));
} }
//PaddingLeft
get [paddingLeftProperty.native](): Length { get [paddingLeftProperty.native](): Length {
return { value: org.nativescript.widgets.ViewHelper.getPaddingLeft(this.nativeView), unit: "px" }; return { value: this._defaultPaddingLeft, unit: "px" }
} }
set [paddingLeftProperty.native](value: Length) { set [paddingLeftProperty.native](value: Length) {
org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0)); org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0));

View File

@ -51,8 +51,9 @@ export class Layout extends LayoutBase implements LayoutDefinition {
public _createNativeView() { public _createNativeView() {
initializeNativeViewGroup(); initializeNativeViewGroup();
this._viewGroup = new NativeViewGroup(this._context); const layout = this._viewGroup = new NativeViewGroup(this._context);
this._viewGroup[OWNER] = this; this._viewGroup[OWNER] = this;
return layout;
} }
public _disposeNativeView() { public _disposeNativeView() {

View File

@ -14,7 +14,8 @@ export class StackLayout extends StackLayoutBase {
} }
public _createNativeView() { public _createNativeView() {
this._layout = new org.nativescript.widgets.StackLayout(this._context); const layout = this._layout = new org.nativescript.widgets.StackLayout(this._context);
return layout;
} }
get [orientationProperty.native](): "horizontal" | "vertical" { get [orientationProperty.native](): "horizontal" | "vertical" {

View File

@ -14,7 +14,8 @@ export class WrapLayout extends WrapLayoutBase {
} }
public _createNativeView() { public _createNativeView() {
this._layout = new org.nativescript.widgets.WrapLayout(this._context); const layout = this._layout = new org.nativescript.widgets.WrapLayout(this._context);
return layout;
} }
get [orientationProperty.native](): "horizontal" | "vertical" { get [orientationProperty.native](): "horizontal" | "vertical" {

View File

@ -81,22 +81,21 @@ export class ListPicker extends ListPickerBase {
public _createNativeView() { public _createNativeView() {
initializeNativeClasses(); initializeNativeClasses();
this._android = new android.widget.NumberPicker(this._context); const picker = this._android = new android.widget.NumberPicker(this._context);
let editText = getEditText(this._android); let editText = getEditText(this._android);
this._editText = editText; this._editText = editText;
this._selectorWheelPaint = getSelectorWheelPaint(this._android); this._selectorWheelPaint = getSelectorWheelPaint(picker);
this._android.setDescendantFocusability(android.widget.NumberPicker.FOCUS_BLOCK_DESCENDANTS); picker.setDescendantFocusability(android.widget.NumberPicker.FOCUS_BLOCK_DESCENDANTS);
picker.setMinValue(0);
this._android.setMinValue(0); picker.setMaxValue(0);
this._android.setMaxValue(0); picker.setValue(0);
this._android.setValue(0);
this._formatter = this._formatter || new Formatter(this); this._formatter = this._formatter || new Formatter(this);
this._android.setFormatter(this._formatter); picker.setFormatter(this._formatter);
this._valueChangedListener = this._valueChangedListener || new ValueChangeListener(this); this._valueChangedListener = this._valueChangedListener || new ValueChangeListener(this);
this._android.setOnValueChangedListener(this._valueChangedListener); picker.setOnValueChangedListener(this._valueChangedListener);
if (editText) { if (editText) {
//Fix the disappearing selected item. //Fix the disappearing selected item.
@ -107,8 +106,8 @@ export class ListPicker extends ListPickerBase {
editText.setText(" ", android.widget.TextView.BufferType.NORMAL); editText.setText(" ", android.widget.TextView.BufferType.NORMAL);
} }
this._android.setWrapSelectorWheel(false); picker.setWrapSelectorWheel(false);
this.nativeView = this._android; return picker;
} }
private _fixNumberPickerRendering() { private _fixNumberPickerRendering() {
@ -119,7 +118,7 @@ export class ListPicker extends ListPickerBase {
this._editText.setFilters([]); this._editText.setFilters([]);
this._editText.invalidate(); //Force the EditText to redraw this._editText.invalidate(); //Force the EditText to redraw
} }
this.android.invalidate(); this._android.invalidate();
} }
get [selectedIndexProperty.native](): number { get [selectedIndexProperty.native](): number {

View File

@ -50,7 +50,7 @@ export class ListView extends ListViewBase {
public _createNativeView() { public _createNativeView() {
initializeItemClickListener(); initializeItemClickListener();
this._android = new android.widget.ListView(this._context); const listView = this._android = new android.widget.ListView(this._context);
this._android.setDescendantFocusability(android.view.ViewGroup.FOCUS_AFTER_DESCENDANTS); this._android.setDescendantFocusability(android.view.ViewGroup.FOCUS_AFTER_DESCENDANTS);
this.updateEffectiveRowHeight(); this.updateEffectiveRowHeight();
@ -66,6 +66,7 @@ export class ListView extends ListViewBase {
this._itemClickListener = this._itemClickListener || new ItemClickListener(this); this._itemClickListener = this._itemClickListener || new ItemClickListener(this);
this.android.setOnItemClickListener(this._itemClickListener); this.android.setOnItemClickListener(this._itemClickListener);
return listView;
} }
get android(): android.widget.ListView { get android(): android.widget.ListView {

View File

@ -1,4 +1,4 @@
import { View, PageBase, Color, actionBarHiddenProperty, statusBarStyleProperty, androidStatusBarBackgroundProperty, HorizontalAlignment, VerticalAlignment } from "./page-common"; import { View, PageBase, Color, actionBarHiddenProperty, statusBarStyleProperty, androidStatusBarBackgroundProperty } from "./page-common";
import { ActionBar } from "ui/action-bar"; import { ActionBar } from "ui/action-bar";
import { GridLayout } from "ui/layouts/grid-layout"; import { GridLayout } from "ui/layouts/grid-layout";
import { DIALOG_FRAGMENT_TAG } from "./constants"; import { DIALOG_FRAGMENT_TAG } from "./constants";
@ -35,8 +35,8 @@ function initializeDialogFragment() {
dialog.requestWindowFeature(android.view.Window.FEATURE_NO_TITLE); dialog.requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
// Hide actionBar and adjust alignment based on _fullscreen value. // Hide actionBar and adjust alignment based on _fullscreen value.
this._owner.horizontalAlignment = this._fullscreen ? HorizontalAlignment.STRETCH : HorizontalAlignment.CENTER; this._owner.horizontalAlignment = this._fullscreen ? "stretch" : "center";
this._owner.verticalAlignment = this._fullscreen ? VerticalAlignment.STRETCH : VerticalAlignment.MIDDLE; this._owner.verticalAlignment = this._fullscreen ? "stretch" : "middle";
this._owner.actionBarHidden = true; this._owner.actionBarHidden = true;
const nativeView = <android.view.View>this._owner._nativeView; const nativeView = <android.view.View>this._owner._nativeView;
@ -103,10 +103,11 @@ export class Page extends PageBase {
} }
public _createNativeView() { public _createNativeView() {
this._grid = new org.nativescript.widgets.GridLayout(this._context); const layout = this._grid = new org.nativescript.widgets.GridLayout(this._context);
this._grid.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.auto)); this._grid.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.auto));
this._grid.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.star)); this._grid.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.star));
this.nativeView.setBackgroundColor(new Color("white").android); this.nativeView.setBackgroundColor(new Color("white").android);
return layout;
} }
public _addViewToNativeVisualTree(child: View, atIndex?: number): boolean { public _addViewToNativeVisualTree(child: View, atIndex?: number): boolean {

View File

@ -9,7 +9,8 @@ export class Placeholder extends View implements PlaceholderDefinition {
public _createNativeView() { public _createNativeView() {
let args = <CreateViewEventData>{ eventName: Placeholder.creatingViewEvent, object: this, view: undefined, context: this._context }; let args = <CreateViewEventData>{ eventName: Placeholder.creatingViewEvent, object: this, view: undefined, context: this._context };
this.notify(args); this.notify(args);
this._android = <android.view.View>args.view; const view = this._android = <android.view.View>args.view;
return view;
} }
get android(): android.view.View { get android(): android.view.View {

View File

@ -11,7 +11,8 @@ export class Progress extends ProgressBase {
private _android: android.widget.ProgressBar; private _android: android.widget.ProgressBar;
public _createNativeView() { public _createNativeView() {
this._android = new android.widget.ProgressBar(this._context, null, R_ATTR_PROGRESS_BAR_STYLE_HORIZONTAL); const progressBar = this._android = new android.widget.ProgressBar(this._context, null, R_ATTR_PROGRESS_BAR_STYLE_HORIZONTAL);
return progressBar;
} }
get android(): android.widget.ProgressBar { get android(): android.widget.ProgressBar {

View File

@ -29,7 +29,7 @@ export class ProxyViewContainer extends LayoutBase implements ProxyViewContainer
} }
public _createNativeView() { public _createNativeView() {
// return undefined;
} }
public _getNativeViewsCount(): number { public _getNativeViewsCount(): number {

View File

@ -83,6 +83,7 @@ export class ScrollView extends ScrollViewBase {
} }
this._android.setId(this._androidViewId); this._android.setId(this._androidViewId);
return this._android;
} }
public _onOrientationChanged() { public _onOrientationChanged() {

View File

@ -104,6 +104,7 @@ export class SearchBar extends SearchBarBase {
this._closeListener = this._closeListener || new CloseListener(this); this._closeListener = this._closeListener || new CloseListener(this);
this._android.setOnCloseListener(this._closeListener); this._android.setOnCloseListener(this._closeListener);
return this._android;
} }
get android(): android.widget.SearchView { get android(): android.widget.SearchView {

View File

@ -211,6 +211,7 @@ export class SegmentedBar extends SegmentedBarBase {
this._android.addView(tabHostLayout); this._android.addView(tabHostLayout);
this._android.setup(); this._android.setup();
this._android.setOnTabChangedListener(this.listener); this._android.setOnTabChangedListener(this.listener);
return this._android;
} }
get android(): android.widget.TabHost { get android(): android.widget.TabHost {

View File

@ -54,6 +54,7 @@ export class Slider extends SliderBase {
this.changeListener = this.changeListener || new SeekBarChangeListener(this); this.changeListener = this.changeListener || new SeekBarChangeListener(this);
this._android = new android.widget.SeekBar(this._context); this._android = new android.widget.SeekBar(this._context);
this._android.setOnSeekBarChangeListener(this.changeListener); this._android.setOnSeekBarChangeListener(this.changeListener);
return this._android;
} }
get android(): android.widget.SeekBar { get android(): android.widget.SeekBar {

View File

@ -74,6 +74,7 @@ function loadCss(cssFile?: string): RuleSet[] {
application.on("cssChanged", onCssChanged); application.on("cssChanged", onCssChanged);
application.on("livesync", onLiveSync); application.on("livesync", onLiveSync);
application.on("launch", () => loadCss(application.getCssFileName()));
let pattern: RegExp = /('|")(.*?)\1/; let pattern: RegExp = /('|")(.*?)\1/;
@ -371,5 +372,3 @@ class InlineSelector extends SelectorCore {
public ruleset: RuleSet; public ruleset: RuleSet;
public match(node: Node): boolean { return true; } public match(node: Node): boolean { return true; }
} }
loadCss(application.getCssFileName());

View File

@ -45,6 +45,7 @@ export class Switch extends SwitchBase {
this._android = new android.widget.Switch(this._context); this._android = new android.widget.Switch(this._context);
this.listener = this.listener || new CheckedChangeListener(this); this.listener = this.listener || new CheckedChangeListener(this);
this._android.setOnCheckedChangeListener(this.listener); this._android.setOnCheckedChangeListener(this.listener);
return this._android;
} }
get [checkedProperty.native](): boolean { get [checkedProperty.native](): boolean {

View File

@ -307,6 +307,7 @@ export class TabView extends TabViewBase {
(<any>this._viewPager).addOnPageChangeListener(this._pageChagedListener); (<any>this._viewPager).addOnPageChangeListener(this._pageChagedListener);
this.nativeView = this._viewPager; this.nativeView = this._viewPager;
this._nativeView = this._viewPager; this._nativeView = this._viewPager;
return this._grid;
} }
private setElevation() { private setElevation() {

View File

@ -13,6 +13,59 @@ import { FontWeight, FontStyle } from "ui/styling/font";
export * from "./text-base-common"; export * from "./text-base-common";
interface TextTransformation {
new (owner: TextBase): android.text.method.TransformationMethod;
}
let TextTransformation: TextTransformation;
function initializeTextTransformation(): void {
if (TextTransformation) {
return;
}
@Interfaces([android.text.method.TransformationMethod])
class TextTransformationImpl extends android.text.method.ReplacementTransformationMethod implements android.text.method.TransformationMethod {
constructor(public textBase: TextBase) {
super();
return global.__native(this);
}
protected getOriginal(): native.Array<string> {
return convertStringToNativeCharArray(this.textBase.formattedText ? this.textBase.formattedText.toString() : this.textBase.text);
}
protected getReplacement(): native.Array<string> {
let replacementString: string = "";
const formattedText = this.textBase.formattedText;
const textTransform = this.textBase.textTransform;
if (formattedText) {
for (let i = 0, length = formattedText.spans.length; i < length; i++) {
let span = formattedText.spans.getItem(i);
replacementString += getTransformedText(span.text, textTransform);
}
}
else {
replacementString = getTransformedText(this.textBase.text, textTransform);
}
return convertStringToNativeCharArray(replacementString);
}
public getTransformation(charSeq: any, view: android.view.View): any {
const formattedText = this.textBase.formattedText;
if (formattedText) {
return createSpannableStringBuilder(formattedText);
}
else {
return getTransformedText(this.textBase.text, this.textBase.textTransform);
}
}
}
TextTransformation = TextTransformationImpl;
}
export class TextBase extends TextBaseCommon { export class TextBase extends TextBaseCommon {
_nativeView: android.widget.TextView; _nativeView: android.widget.TextView;
@ -30,6 +83,8 @@ export class TextBase extends TextBaseCommon {
return null; return null;
} }
set [formattedTextProperty.native](value: FormattedString) { set [formattedTextProperty.native](value: FormattedString) {
initializeTextTransformation();
let spannableStringBuilder = createSpannableStringBuilder(value); let spannableStringBuilder = createSpannableStringBuilder(value);
this._nativeView.setText(<any>spannableStringBuilder); this._nativeView.setText(<any>spannableStringBuilder);
textProperty.nativeValueChange(this, (value === null || value === undefined) ? '' : value.toString()); textProperty.nativeValueChange(this, (value === null || value === undefined) ? '' : value.toString());
@ -50,6 +105,7 @@ export class TextBase extends TextBaseCommon {
return this._nativeView.getTransformationMethod(); return this._nativeView.getTransformationMethod();
} }
set [textTransformProperty.native](value: TextTransform | android.text.method.TransformationMethod) { set [textTransformProperty.native](value: TextTransform | android.text.method.TransformationMethod) {
initializeTextTransformation();
if (typeof value === "string") { if (typeof value === "string") {
this._nativeView.setTransformationMethod(new TextTransformation(this)); this._nativeView.setTransformationMethod(new TextTransformation(this));
} else { } else {
@ -167,7 +223,6 @@ export class TextBase extends TextBaseCommon {
} }
} }
//LetterSpacing
get [letterSpacingProperty.native](): number { get [letterSpacingProperty.native](): number {
return org.nativescript.widgets.ViewHelper.getLetterspacing(this._nativeView); return org.nativescript.widgets.ViewHelper.getLetterspacing(this._nativeView);
} }
@ -175,78 +230,35 @@ export class TextBase extends TextBaseCommon {
org.nativescript.widgets.ViewHelper.setLetterspacing(this._nativeView, value); org.nativescript.widgets.ViewHelper.setLetterspacing(this._nativeView, value);
} }
//PaddingTop
get [paddingTopProperty.native](): Length { get [paddingTopProperty.native](): Length {
return { value: org.nativescript.widgets.ViewHelper.getPaddingTop(this.nativeView), unit: "px" }; return { value: this._defaultPaddingTop, unit: "px" }
} }
set [paddingTopProperty.native](value: Length) { set [paddingTopProperty.native](value: Length) {
org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0)); org.nativescript.widgets.ViewHelper.setPaddingTop(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderTopWidth, 0));
} }
//PaddingRight
get [paddingRightProperty.native](): Length { get [paddingRightProperty.native](): Length {
return { value: org.nativescript.widgets.ViewHelper.getPaddingRight(this.nativeView), unit: "px" }; return { value: this._defaultPaddingRight, unit: "px" }
} }
set [paddingRightProperty.native](value: Length) { set [paddingRightProperty.native](value: Length) {
org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0)); org.nativescript.widgets.ViewHelper.setPaddingRight(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderRightWidth, 0));
} }
//PaddingBottom
get [paddingBottomProperty.native](): Length { get [paddingBottomProperty.native](): Length {
return { value: org.nativescript.widgets.ViewHelper.getPaddingBottom(this.nativeView), unit: "px" }; return { value: this._defaultPaddingBottom, unit: "px" }
} }
set [paddingBottomProperty.native](value: Length) { set [paddingBottomProperty.native](value: Length) {
org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0)); org.nativescript.widgets.ViewHelper.setPaddingBottom(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderBottomWidth, 0));
} }
//PaddingLeft
get [paddingLeftProperty.native](): Length { get [paddingLeftProperty.native](): Length {
return { value: org.nativescript.widgets.ViewHelper.getPaddingLeft(this.nativeView), unit: "px" }; return { value: this._defaultPaddingLeft, unit: "px" }
} }
set [paddingLeftProperty.native](value: Length) { set [paddingLeftProperty.native](value: Length) {
org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0)); org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeView, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0));
} }
} }
@Interfaces([android.text.method.TransformationMethod])
class TextTransformation extends android.text.method.ReplacementTransformationMethod {
constructor(public textBase: TextBase) {
super();
return global.__native(this);
}
protected getOriginal(): native.Array<string> {
return convertStringToNativeCharArray(this.textBase.formattedText ? this.textBase.formattedText.toString() : this.textBase.text);
}
protected getReplacement(): native.Array<string> {
let replacementString: string = "";
const formattedText = this.textBase.formattedText;
const textTransform = this.textBase.textTransform;
if (formattedText) {
for (let i = 0, length = formattedText.spans.length; i < length; i++) {
let span = formattedText.spans.getItem(i);
replacementString += getTransformedText(span.text, textTransform);
}
}
else {
replacementString = getTransformedText(this.textBase.text, textTransform);
}
return convertStringToNativeCharArray(replacementString);
}
public getTransformation(charSeq: any, view: android.view.View): any {
const formattedText = this.textBase.formattedText;
if (formattedText) {
return createSpannableStringBuilder(formattedText);
}
else {
return getTransformedText(this.textBase.text, this.textBase.textTransform);
}
}
}
function getCapitalizedString(str: string): string { function getCapitalizedString(str: string): string {
let words = str.split(" "); let words = str.split(" ");
let newWords = []; let newWords = [];

View File

@ -52,6 +52,7 @@ export class TimePicker extends TimePickerBase {
let validTime = getValidTime(this, this.hour, this.minute); let validTime = getValidTime(this, this.hour, this.minute);
this._setNativeValueSilently(validTime.hour, validTime.minute); this._setNativeValueSilently(validTime.hour, validTime.minute);
return this._android;
} }
get android(): android.widget.TimePicker { get android(): android.widget.TimePicker {

View File

@ -102,6 +102,7 @@ export class WebView extends WebViewBase {
this._android.getSettings().setJavaScriptEnabled(true); this._android.getSettings().setJavaScriptEnabled(true);
this._android.getSettings().setBuiltInZoomControls(true); this._android.getSettings().setBuiltInZoomControls(true);
this._android.setWebViewClient(this._webViewClient); this._android.setWebViewClient(this._webViewClient);
return this._android;
} }
public _resetNativeView() { public _resetNativeView() {

View File

@ -454,7 +454,7 @@
public static getVerticalAlignment(view: android.view.View): string; public static getVerticalAlignment(view: android.view.View): string;
public static setVerticalAlignment(view: android.view.View, value: string): void; public static setVerticalAlignment(view: android.view.View, value: string): void;
public static getPadding(view: android.view.View): { left: number, top: number, right: number, bottom: number }; public static getPadding(view: android.view.View): android.graphics.Rect;
public static setPadding(view: android.view.View, left: number, top: number, right: number, bottom: number): void; public static setPadding(view: android.view.View, left: number, top: number, right: number, bottom: number): void;
public static getPaddingLeft(view: android.view.View): number; public static getPaddingLeft(view: android.view.View): number;