Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 74 additions & 37 deletions tns-core-modules/ui/core/view.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function onIsUserInteractionEnabledPropertyChanged(data: dependencyObservable.Pr

export class View extends viewCommon.View {
private _disableUserInteractionListener: android.view.View.OnTouchListener = new android.view.View.OnTouchListener({
onTouch: function(view: android.view.View, event: android.view.MotionEvent) {
onTouch: function (view: android.view.View, event: android.view.MotionEvent) {
return true;
}
});
Expand Down Expand Up @@ -116,7 +116,7 @@ export class View extends viewCommon.View {
this._nativeView.setClickable(true);
}
this._nativeView.setOnTouchListener(new android.view.View.OnTouchListener({
onTouch: function(view: android.view.View, motionEvent: android.view.MotionEvent) {
onTouch: function (view: android.view.View, motionEvent: android.view.MotionEvent) {
var owner = that.get();
if (!owner) {
return false;
Expand Down Expand Up @@ -178,7 +178,7 @@ export class View extends viewCommon.View {
if (this._childrenCount > 0) {
// Notify each child for the _onAttached event
var that = this;
var eachChild = function(child: View): boolean {
var eachChild = function (child: View): boolean {
child._onAttached(context);
if (!child._isAddedToNativeVisualTree) {
// since we have lazy loading of the android widgets, we need to add the native instances at this point.
Expand All @@ -197,7 +197,7 @@ export class View extends viewCommon.View {
if (this._childrenCount > 0) {
// Detach children first
var that = this;
var eachChild = function(child: View): boolean {
var eachChild = function (child: View): boolean {
if (child._isAddedToNativeVisualTree) {
that._removeViewFromNativeVisualTree(child);
}
Expand Down Expand Up @@ -238,7 +238,7 @@ export class View extends viewCommon.View {
}
this._createUI();
// Ensure layout params
if (this._nativeView && !(this._nativeView.getLayoutParams() instanceof org.nativescript.widgets.CommonLayoutParams)) {
if (this._nativeView && !this._nativeView.getLayoutParams()) {
this._nativeView.setLayoutParams(new org.nativescript.widgets.CommonLayoutParams());
}

Expand Down Expand Up @@ -348,7 +348,7 @@ export class View extends viewCommon.View {
return {
x: utils.layout.toDeviceIndependentPixels(nativeArray[0]),
y: utils.layout.toDeviceIndependentPixels(nativeArray[1]),
}
}
}

public getLocationOnScreen(): viewDefinition.Point {
Expand All @@ -361,7 +361,7 @@ export class View extends viewCommon.View {
return {
x: utils.layout.toDeviceIndependentPixels(nativeArray[0]),
y: utils.layout.toDeviceIndependentPixels(nativeArray[1]),
}
}
}

public getLocationRelativeTo(otherView: viewDefinition.View): viewDefinition.Point {
Expand All @@ -378,7 +378,7 @@ export class View extends viewCommon.View {
return {
x: utils.layout.toDeviceIndependentPixels(myArray[0] - otherArray[0]),
y: utils.layout.toDeviceIndependentPixels(myArray[1] - otherArray[1]),
}
}
}

public static resolveSizeAndState(size: number, specSize: number, specMode: number, childMeasuredState: number): number {
Expand Down Expand Up @@ -500,35 +500,12 @@ export class ViewStyler implements style.Styler {
(<android.view.View>view._nativeView).setMinimumHeight(0);
}

private static getNativeLayoutParams(nativeView: android.view.View): org.nativescript.widgets.CommonLayoutParams {
var lp = <org.nativescript.widgets.CommonLayoutParams>nativeView.getLayoutParams();
if (!(lp instanceof org.nativescript.widgets.CommonLayoutParams)) {
lp = new org.nativescript.widgets.CommonLayoutParams();
}

return lp;
}

private static setNativeLayoutParamsProperty(view: View, params: CommonLayoutParams): void {
var nativeView: android.view.View = view._nativeView;
var lp = ViewStyler.getNativeLayoutParams(nativeView);

lp.widthPercent = params.widthPercent;
lp.heightPercent = params.heightPercent;
let nativeView: android.view.View = view._nativeView;

lp.leftMarginPercent = params.leftMarginPercent;
lp.topMarginPercent = params.topMarginPercent;
lp.rightMarginPercent = params.rightMarginPercent;
lp.bottomMarginPercent = params.bottomMarginPercent;
let width = params.width * utils.layout.getDisplayDensity();
let height = params.height * utils.layout.getDisplayDensity();

lp.leftMargin = Math.round(params.leftMargin * utils.layout.getDisplayDensity());
lp.topMargin = Math.round(params.topMargin * utils.layout.getDisplayDensity());
lp.rightMargin = Math.round(params.rightMargin * utils.layout.getDisplayDensity());
lp.bottomMargin = Math.round(params.bottomMargin * utils.layout.getDisplayDensity());

var width = params.width * utils.layout.getDisplayDensity();
var height = params.height * utils.layout.getDisplayDensity();

// If width is not specified set it as WRAP_CONTENT
if (width < 0) {
width = -2;
Expand All @@ -539,7 +516,7 @@ export class ViewStyler implements style.Styler {
height = -2;
}

var gravity = 0;
let gravity = 0;
switch (params.horizontalAlignment) {
case enums.HorizontalAlignment.left:
gravity |= android.view.Gravity.LEFT;
Expand Down Expand Up @@ -591,10 +568,70 @@ export class ViewStyler implements style.Styler {
throw new Error("Invalid verticalAlignment value: " + params.verticalAlignment);
}

lp.gravity = gravity;
let lp = nativeView.getLayoutParams();
lp.width = Math.round(width);
lp.height = Math.round(height);

if (lp instanceof org.nativescript.widgets.CommonLayoutParams) {
lp.widthPercent = params.widthPercent;
lp.heightPercent = params.heightPercent;
lp.leftMarginPercent = params.leftMarginPercent;
lp.topMarginPercent = params.topMarginPercent;
lp.rightMarginPercent = params.rightMarginPercent;
lp.bottomMarginPercent = params.bottomMarginPercent;
lp.leftMargin = Math.round(params.leftMargin * utils.layout.getDisplayDensity());
lp.topMargin = Math.round(params.topMargin * utils.layout.getDisplayDensity());
lp.rightMargin = Math.round(params.rightMargin * utils.layout.getDisplayDensity());
lp.bottomMargin = Math.round(params.bottomMargin * utils.layout.getDisplayDensity());
lp.gravity = gravity;
}
else {
let layoutParams: any = lp;
if (types.isDefined(layoutParams.widthPercent)) {
layoutParams.widthPercent = params.widthPercent;
}

if (types.isDefined(layoutParams.heightPercent)) {
layoutParams.heightPercent = params.heightPercent;
}

if (types.isDefined(layoutParams.leftMarginPercent)) {
layoutParams.leftMarginPercent = params.leftMarginPercent;
}

if (types.isDefined(layoutParams.topMarginPercent)) {
layoutParams.topMarginPercent = params.topMarginPercent;
}

if (types.isDefined(layoutParams.rightMarginPercent)) {
layoutParams.rightMarginPercent = params.rightMarginPercent;
}

if (types.isDefined(layoutParams.bottomMarginPercent)) {
layoutParams.bottomMarginPercent = params.bottomMarginPercent;
}

if (types.isDefined(layoutParams.leftMargin)) {
layoutParams.leftMargin = Math.round(params.leftMargin * utils.layout.getDisplayDensity());
}

if (types.isDefined(layoutParams.topMargin)) {
layoutParams.topMargin = Math.round(params.topMargin * utils.layout.getDisplayDensity());
}

if (types.isDefined(layoutParams.rightMargin)) {
layoutParams.rightMargin = Math.round(params.rightMargin * utils.layout.getDisplayDensity());
}

if (types.isDefined(layoutParams.bottomMargin)) {
layoutParams.bottomMargin = Math.round(params.bottomMargin * utils.layout.getDisplayDensity());
}

if (types.isDefined(layoutParams.gravity)) {
layoutParams.gravity = gravity;
}
}

nativeView.setLayoutParams(lp);
}

Expand Down Expand Up @@ -674,7 +711,7 @@ export class ViewStyler implements style.Styler {
if (view.android.setZ) {
view.android.setZ(newValue);

if(view.android instanceof android.widget.Button){
if (view.android instanceof android.widget.Button) {
view.android.setStateListAnimator(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ function setNativeProperty(data: PropertyChangeData, setter: (lp: org.nativescri
var view = data.object;
if (view instanceof View) {
var nativeView: android.view.View = view._nativeView;

var lp = <org.nativescript.widgets.CommonLayoutParams>nativeView.getLayoutParams();
if (!(lp instanceof org.nativescript.widgets.CommonLayoutParams)) {
lp = new org.nativescript.widgets.CommonLayoutParams();
var lp = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
if (lp instanceof org.nativescript.widgets.CommonLayoutParams) {
setter(lp);
nativeView.setLayoutParams(lp);
}
setter(lp);
nativeView.setLayoutParams(lp);
}
}

Expand Down
43 changes: 20 additions & 23 deletions tns-core-modules/ui/layouts/dock-layout/dock-layout.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,27 @@ function setNativeDockProperty(data: PropertyChangeData) {
var view = data.object;
if (view instanceof View) {
var nativeView: android.view.View = view._nativeView;

var lp = <org.nativescript.widgets.CommonLayoutParams>nativeView.getLayoutParams();
if (!(lp instanceof org.nativescript.widgets.CommonLayoutParams)) {
lp = new org.nativescript.widgets.CommonLayoutParams();
}

switch (data.newValue) {
case Dock.left:
lp.dock = org.nativescript.widgets.Dock.left;
break;
case Dock.top:
lp.dock = org.nativescript.widgets.Dock.top;
break;
case Dock.right:
lp.dock = org.nativescript.widgets.Dock.right;
break;
case Dock.bottom:
lp.dock = org.nativescript.widgets.Dock.bottom;
break;
default:
throw new Error("Invalid dock value: " + data.newValue + " on element: " + view);
var lp = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
if (lp instanceof org.nativescript.widgets.CommonLayoutParams) {
switch (data.newValue) {
case Dock.left:
lp.dock = org.nativescript.widgets.Dock.left;
break;
case Dock.top:
lp.dock = org.nativescript.widgets.Dock.top;
break;
case Dock.right:
lp.dock = org.nativescript.widgets.Dock.right;
break;
case Dock.bottom:
lp.dock = org.nativescript.widgets.Dock.bottom;
break;
default:
throw new Error("Invalid dock value: " + data.newValue + " on element: " + view);
}

nativeView.setLayoutParams(lp);
}

nativeView.setLayoutParams(lp);
}
}

Expand Down
10 changes: 4 additions & 6 deletions tns-core-modules/ui/layouts/grid-layout/grid-layout.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ function setNativeProperty(data: PropertyChangeData, setter: (lp: org.nativescri
let view = data.object;
if (view instanceof View) {
let nativeView: android.view.View = view._nativeView;

let lp = <org.nativescript.widgets.CommonLayoutParams>nativeView.getLayoutParams();
if (!(lp instanceof org.nativescript.widgets.CommonLayoutParams)) {
lp = new org.nativescript.widgets.CommonLayoutParams();
var lp = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
if (lp instanceof org.nativescript.widgets.CommonLayoutParams) {
setter(lp);
nativeView.setLayoutParams(lp);
}
setter(lp);
nativeView.setLayoutParams(lp);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/ui/tab-view/tab-view.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class TabView extends common.TabView {
}

this._viewPager = new android.support.v4.view.ViewPager(this._context);
var lp = new org.nativescript.widgets.CommonLayoutParams()
var lp = new org.nativescript.widgets.CommonLayoutParams();
lp.row = 1;
this._viewPager.setLayoutParams(lp);
this._grid.addView(this._viewPager);
Expand Down