mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
android LayoutParams are not overridden (#2383)
* LayoutParams are no longer overriden with CommonLayoutParams * Small code refactoring to get intellisense
This commit is contained in:
@ -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;
|
||||
}
|
||||
});
|
||||
@ -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;
|
||||
@ -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.
|
||||
@ -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);
|
||||
}
|
||||
@ -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());
|
||||
}
|
||||
|
||||
@ -500,34 +500,11 @@ 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);
|
||||
let nativeView: android.view.View = view._nativeView;
|
||||
|
||||
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());
|
||||
|
||||
var width = params.width * utils.layout.getDisplayDensity();
|
||||
var height = params.height * utils.layout.getDisplayDensity();
|
||||
let width = params.width * utils.layout.getDisplayDensity();
|
||||
let height = params.height * utils.layout.getDisplayDensity();
|
||||
|
||||
// If width is not specified set it as WRAP_CONTENT
|
||||
if (width < 0) {
|
||||
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -10,14 +10,12 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setNativeLeftProperty(data: PropertyChangeData) {
|
||||
|
@ -10,12 +10,8 @@ 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();
|
||||
}
|
||||
|
||||
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;
|
||||
@ -35,6 +31,7 @@ function setNativeDockProperty(data: PropertyChangeData) {
|
||||
|
||||
nativeView.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(<PropertyMetadata>common.DockLayout.dockProperty.metadata).onSetNativeValue = setNativeDockProperty;
|
||||
|
@ -10,14 +10,12 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setNativeRowProperty(data: PropertyChangeData) {
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user