@@ -11,7 +11,7 @@ import {
11
11
WhiteSpace ,
12
12
whiteSpaceProperty
13
13
} from 'tns-core-modules/ui/text-base/text-base' ;
14
- import { TextShadow } from './label' ;
14
+ import { TextShadow , verticalTextAlignmentProperty , VerticalTextAlignment } from './label' ;
15
15
import { isString } from 'tns-core-modules/utils/types' ;
16
16
17
17
export * from './label-common' ;
@@ -79,48 +79,7 @@ class ObserverClass extends NSObject {
79
79
if ( path === 'contentSize' ) {
80
80
const owner = this . _owner && this . _owner . get ( ) ;
81
81
if ( owner ) {
82
- const inset = owner . nativeViewProtected . textContainerInset ;
83
- const top = layout . toDeviceIndependentPixels ( owner . effectivePaddingTop + owner . effectiveBorderTopWidth ) ;
84
-
85
- switch ( owner . verticalTextAlignment ) {
86
- case 'initial' : // not supported
87
- case 'top' :
88
- owner . nativeViewProtected . textContainerInset = {
89
- top,
90
- left : inset . left ,
91
- bottom : inset . bottom ,
92
- right : inset . right
93
- } ;
94
- break ;
95
-
96
- case 'middle' : {
97
- const height = tv . sizeThatFits ( CGSizeMake ( tv . bounds . size . width , 10000 ) ) . height ;
98
- let topCorrect = ( tv . bounds . size . height - height * tv . zoomScale ) / 2.0 ;
99
- topCorrect = topCorrect < 0.0 ? 0.0 : topCorrect ;
100
- // tv.contentOffset = CGPointMake(0, -topCorrect);
101
- owner . nativeViewProtected . textContainerInset = {
102
- top : top + topCorrect ,
103
- left : inset . left ,
104
- bottom : inset . bottom ,
105
- right : inset . right
106
- } ;
107
- break ;
108
- }
109
-
110
- case 'bottom' : {
111
- const height = tv . sizeThatFits ( CGSizeMake ( tv . bounds . size . width , 10000 ) ) . height ;
112
- let bottomCorrect = tv . bounds . size . height - height * tv . zoomScale ;
113
- bottomCorrect = bottomCorrect < 0.0 ? 0.0 : bottomCorrect ;
114
- // tv.contentOffset = CGPointMake(0, -bottomCorrect);
115
- owner . nativeViewProtected . textContainerInset = {
116
- top : top + bottomCorrect ,
117
- left : inset . left ,
118
- bottom : inset . bottom ,
119
- right : inset . right
120
- } ;
121
- break ;
122
- }
123
- }
82
+ owner . updateVerticalAlignment ( ) ;
124
83
}
125
84
}
126
85
}
@@ -161,7 +120,8 @@ export class Label extends LabelBase {
161
120
162
121
public initNativeView ( ) {
163
122
super . initNativeView ( ) ;
164
- this . _observer = ObserverClass . alloc ( ) ;
123
+ console . log ( 'initNativeView' ) ;
124
+ this . _observer = ObserverClass . alloc ( ) . init ( ) ;
165
125
this . _observer [ '_owner' ] = new WeakRef ( this ) ;
166
126
this . nativeViewProtected . addObserverForKeyPathOptionsContext ( this . _observer , 'contentSize' , NSKeyValueObservingOptions . New , null ) ;
167
127
this . nativeViewProtected . attributedText = this . htmlText ;
@@ -180,6 +140,52 @@ export class Label extends LabelBase {
180
140
}
181
141
}
182
142
143
+ updateVerticalAlignment ( ) {
144
+ const tv = this . nativeTextViewProtected ;
145
+ const inset = this . nativeViewProtected . textContainerInset ;
146
+ const top = layout . toDeviceIndependentPixels ( this . effectivePaddingTop + this . effectiveBorderTopWidth ) ;
147
+ switch ( this . verticalTextAlignment ) {
148
+ case 'initial' : // not supported
149
+ case 'top' :
150
+ this . nativeViewProtected . textContainerInset = {
151
+ top,
152
+ left : inset . left ,
153
+ bottom : inset . bottom ,
154
+ right : inset . right
155
+ } ;
156
+ break ;
157
+
158
+ case 'middle' :
159
+ case 'center' : {
160
+ const height = tv . sizeThatFits ( CGSizeMake ( tv . bounds . size . width , 10000 ) ) . height ;
161
+ let topCorrect = ( tv . bounds . size . height - height * tv . zoomScale ) / 2.0 ;
162
+ topCorrect = topCorrect < 0.0 ? 0.0 : topCorrect ;
163
+ // tv.contentOffset = CGPointMake(0, -topCorrect);
164
+ this . nativeViewProtected . textContainerInset = {
165
+ top : top + topCorrect ,
166
+ left : inset . left ,
167
+ bottom : inset . bottom ,
168
+ right : inset . right
169
+ } ;
170
+ break ;
171
+ }
172
+
173
+ case 'bottom' : {
174
+ const height = tv . sizeThatFits ( CGSizeMake ( tv . bounds . size . width , 10000 ) ) . height ;
175
+ let bottomCorrect = tv . bounds . size . height - height * tv . zoomScale ;
176
+ bottomCorrect = bottomCorrect < 0.0 ? 0.0 : bottomCorrect ;
177
+ // tv.contentOffset = CGPointMake(0, -bottomCorrect);
178
+ this . nativeViewProtected . textContainerInset = {
179
+ top : top + bottomCorrect ,
180
+ left : inset . left ,
181
+ bottom : inset . bottom ,
182
+ right : inset . right
183
+ } ;
184
+ break ;
185
+ }
186
+ }
187
+ }
188
+
183
189
get ios ( ) : UITextView {
184
190
return this . nativeViewProtected ;
185
191
}
@@ -556,4 +562,7 @@ export class Label extends LabelBase {
556
562
// this.nativeViewProtected.textContainer.maximumNumberOfLines = value as number;
557
563
// }
558
564
// }
565
+ [ verticalTextAlignmentProperty . setNative ] ( value : VerticalTextAlignment ) {
566
+ this . updateVerticalAlignment ( ) ;
567
+ }
559
568
}
0 commit comments