@@ -53,7 +53,7 @@ function onIsUserInteractionEnabledPropertyChanged(data: dependencyObservable.Pr
53
53
54
54
export class View extends viewCommon . View {
55
55
private _disableUserInteractionListener : android . view . View . OnTouchListener = new android . view . View . OnTouchListener ( {
56
- onTouch : function ( view : android . view . View , event : android . view . MotionEvent ) {
56
+ onTouch : function ( view : android . view . View , event : android . view . MotionEvent ) {
57
57
return true ;
58
58
}
59
59
} ) ;
@@ -116,7 +116,7 @@ export class View extends viewCommon.View {
116
116
this . _nativeView . setClickable ( true ) ;
117
117
}
118
118
this . _nativeView . setOnTouchListener ( new android . view . View . OnTouchListener ( {
119
- onTouch : function ( view : android . view . View , motionEvent : android . view . MotionEvent ) {
119
+ onTouch : function ( view : android . view . View , motionEvent : android . view . MotionEvent ) {
120
120
var owner = that . get ( ) ;
121
121
if ( ! owner ) {
122
122
return false ;
@@ -178,7 +178,7 @@ export class View extends viewCommon.View {
178
178
if ( this . _childrenCount > 0 ) {
179
179
// Notify each child for the _onAttached event
180
180
var that = this ;
181
- var eachChild = function ( child : View ) : boolean {
181
+ var eachChild = function ( child : View ) : boolean {
182
182
child . _onAttached ( context ) ;
183
183
if ( ! child . _isAddedToNativeVisualTree ) {
184
184
// 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 {
197
197
if ( this . _childrenCount > 0 ) {
198
198
// Detach children first
199
199
var that = this ;
200
- var eachChild = function ( child : View ) : boolean {
200
+ var eachChild = function ( child : View ) : boolean {
201
201
if ( child . _isAddedToNativeVisualTree ) {
202
202
that . _removeViewFromNativeVisualTree ( child ) ;
203
203
}
@@ -238,7 +238,7 @@ export class View extends viewCommon.View {
238
238
}
239
239
this . _createUI ( ) ;
240
240
// Ensure layout params
241
- if ( this . _nativeView && ! ( this . _nativeView . getLayoutParams ( ) instanceof org . nativescript . widgets . CommonLayoutParams ) ) {
241
+ if ( this . _nativeView && ! this . _nativeView . getLayoutParams ( ) ) {
242
242
this . _nativeView . setLayoutParams ( new org . nativescript . widgets . CommonLayoutParams ( ) ) ;
243
243
}
244
244
@@ -348,7 +348,7 @@ export class View extends viewCommon.View {
348
348
return {
349
349
x : utils . layout . toDeviceIndependentPixels ( nativeArray [ 0 ] ) ,
350
350
y : utils . layout . toDeviceIndependentPixels ( nativeArray [ 1 ] ) ,
351
- }
351
+ }
352
352
}
353
353
354
354
public getLocationOnScreen ( ) : viewDefinition . Point {
@@ -361,7 +361,7 @@ export class View extends viewCommon.View {
361
361
return {
362
362
x : utils . layout . toDeviceIndependentPixels ( nativeArray [ 0 ] ) ,
363
363
y : utils . layout . toDeviceIndependentPixels ( nativeArray [ 1 ] ) ,
364
- }
364
+ }
365
365
}
366
366
367
367
public getLocationRelativeTo ( otherView : viewDefinition . View ) : viewDefinition . Point {
@@ -378,7 +378,7 @@ export class View extends viewCommon.View {
378
378
return {
379
379
x : utils . layout . toDeviceIndependentPixels ( myArray [ 0 ] - otherArray [ 0 ] ) ,
380
380
y : utils . layout . toDeviceIndependentPixels ( myArray [ 1 ] - otherArray [ 1 ] ) ,
381
- }
381
+ }
382
382
}
383
383
384
384
public static resolveSizeAndState ( size : number , specSize : number , specMode : number , childMeasuredState : number ) : number {
@@ -500,35 +500,12 @@ export class ViewStyler implements style.Styler {
500
500
( < android . view . View > view . _nativeView ) . setMinimumHeight ( 0 ) ;
501
501
}
502
502
503
- private static getNativeLayoutParams ( nativeView : android . view . View ) : org . nativescript . widgets . CommonLayoutParams {
504
- var lp = < org . nativescript . widgets . CommonLayoutParams > nativeView . getLayoutParams ( ) ;
505
- if ( ! ( lp instanceof org . nativescript . widgets . CommonLayoutParams ) ) {
506
- lp = new org . nativescript . widgets . CommonLayoutParams ( ) ;
507
- }
508
-
509
- return lp ;
510
- }
511
-
512
503
private static setNativeLayoutParamsProperty ( view : View , params : CommonLayoutParams ) : void {
513
- var nativeView : android . view . View = view . _nativeView ;
514
- var lp = ViewStyler . getNativeLayoutParams ( nativeView ) ;
515
-
516
- lp . widthPercent = params . widthPercent ;
517
- lp . heightPercent = params . heightPercent ;
504
+ let nativeView : android . view . View = view . _nativeView ;
518
505
519
- lp . leftMarginPercent = params . leftMarginPercent ;
520
- lp . topMarginPercent = params . topMarginPercent ;
521
- lp . rightMarginPercent = params . rightMarginPercent ;
522
- lp . bottomMarginPercent = params . bottomMarginPercent ;
506
+ let width = params . width * utils . layout . getDisplayDensity ( ) ;
507
+ let height = params . height * utils . layout . getDisplayDensity ( ) ;
523
508
524
- lp . leftMargin = Math . round ( params . leftMargin * utils . layout . getDisplayDensity ( ) ) ;
525
- lp . topMargin = Math . round ( params . topMargin * utils . layout . getDisplayDensity ( ) ) ;
526
- lp . rightMargin = Math . round ( params . rightMargin * utils . layout . getDisplayDensity ( ) ) ;
527
- lp . bottomMargin = Math . round ( params . bottomMargin * utils . layout . getDisplayDensity ( ) ) ;
528
-
529
- var width = params . width * utils . layout . getDisplayDensity ( ) ;
530
- var height = params . height * utils . layout . getDisplayDensity ( ) ;
531
-
532
509
// If width is not specified set it as WRAP_CONTENT
533
510
if ( width < 0 ) {
534
511
width = - 2 ;
@@ -539,7 +516,7 @@ export class ViewStyler implements style.Styler {
539
516
height = - 2 ;
540
517
}
541
518
542
- var gravity = 0 ;
519
+ let gravity = 0 ;
543
520
switch ( params . horizontalAlignment ) {
544
521
case enums . HorizontalAlignment . left :
545
522
gravity |= android . view . Gravity . LEFT ;
@@ -591,10 +568,70 @@ export class ViewStyler implements style.Styler {
591
568
throw new Error ( "Invalid verticalAlignment value: " + params . verticalAlignment ) ;
592
569
}
593
570
594
- lp . gravity = gravity ;
571
+ let lp = nativeView . getLayoutParams ( ) ;
595
572
lp . width = Math . round ( width ) ;
596
573
lp . height = Math . round ( height ) ;
597
574
575
+ if ( lp instanceof org . nativescript . widgets . CommonLayoutParams ) {
576
+ lp . widthPercent = params . widthPercent ;
577
+ lp . heightPercent = params . heightPercent ;
578
+ lp . leftMarginPercent = params . leftMarginPercent ;
579
+ lp . topMarginPercent = params . topMarginPercent ;
580
+ lp . rightMarginPercent = params . rightMarginPercent ;
581
+ lp . bottomMarginPercent = params . bottomMarginPercent ;
582
+ lp . leftMargin = Math . round ( params . leftMargin * utils . layout . getDisplayDensity ( ) ) ;
583
+ lp . topMargin = Math . round ( params . topMargin * utils . layout . getDisplayDensity ( ) ) ;
584
+ lp . rightMargin = Math . round ( params . rightMargin * utils . layout . getDisplayDensity ( ) ) ;
585
+ lp . bottomMargin = Math . round ( params . bottomMargin * utils . layout . getDisplayDensity ( ) ) ;
586
+ lp . gravity = gravity ;
587
+ }
588
+ else {
589
+ let layoutParams : any = lp ;
590
+ if ( types . isDefined ( layoutParams . widthPercent ) ) {
591
+ layoutParams . widthPercent = params . widthPercent ;
592
+ }
593
+
594
+ if ( types . isDefined ( layoutParams . heightPercent ) ) {
595
+ layoutParams . heightPercent = params . heightPercent ;
596
+ }
597
+
598
+ if ( types . isDefined ( layoutParams . leftMarginPercent ) ) {
599
+ layoutParams . leftMarginPercent = params . leftMarginPercent ;
600
+ }
601
+
602
+ if ( types . isDefined ( layoutParams . topMarginPercent ) ) {
603
+ layoutParams . topMarginPercent = params . topMarginPercent ;
604
+ }
605
+
606
+ if ( types . isDefined ( layoutParams . rightMarginPercent ) ) {
607
+ layoutParams . rightMarginPercent = params . rightMarginPercent ;
608
+ }
609
+
610
+ if ( types . isDefined ( layoutParams . bottomMarginPercent ) ) {
611
+ layoutParams . bottomMarginPercent = params . bottomMarginPercent ;
612
+ }
613
+
614
+ if ( types . isDefined ( layoutParams . leftMargin ) ) {
615
+ layoutParams . leftMargin = Math . round ( params . leftMargin * utils . layout . getDisplayDensity ( ) ) ;
616
+ }
617
+
618
+ if ( types . isDefined ( layoutParams . topMargin ) ) {
619
+ layoutParams . topMargin = Math . round ( params . topMargin * utils . layout . getDisplayDensity ( ) ) ;
620
+ }
621
+
622
+ if ( types . isDefined ( layoutParams . rightMargin ) ) {
623
+ layoutParams . rightMargin = Math . round ( params . rightMargin * utils . layout . getDisplayDensity ( ) ) ;
624
+ }
625
+
626
+ if ( types . isDefined ( layoutParams . bottomMargin ) ) {
627
+ layoutParams . bottomMargin = Math . round ( params . bottomMargin * utils . layout . getDisplayDensity ( ) ) ;
628
+ }
629
+
630
+ if ( types . isDefined ( layoutParams . gravity ) ) {
631
+ layoutParams . gravity = gravity ;
632
+ }
633
+ }
634
+
598
635
nativeView . setLayoutParams ( lp ) ;
599
636
}
600
637
@@ -674,7 +711,7 @@ export class ViewStyler implements style.Styler {
674
711
if ( view . android . setZ ) {
675
712
view . android . setZ ( newValue ) ;
676
713
677
- if ( view . android instanceof android . widget . Button ) {
714
+ if ( view . android instanceof android . widget . Button ) {
678
715
view . android . setStateListAnimator ( null ) ;
679
716
}
680
717
}
0 commit comments