Skip to content

Commit a203913

Browse files
committed
chore: starting verticalTextAlignment support
1 parent c287c69 commit a203913

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

src/textfield/textfield.android.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { VerticalTextAlignment, verticalTextAlignmentProperty } from '@nativescript-community/text';
12
import { getLayout, stateSets } from '@nativescript-community/ui-material-core/android/utils';
23
import {
34
counterMaxLengthProperty,
@@ -62,7 +63,6 @@ export class TextField extends TextFieldBase {
6263
return this.editText;
6364
}
6465

65-
drawingBackground = false;
6666
// @ts-ignore
6767
get nativeViewProtected() {
6868
return this.layoutView;
@@ -318,5 +318,23 @@ export class TextField extends TextFieldBase {
318318
[paddingLeftProperty.setNative](value: Length) {
319319
org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0));
320320
}
321+
[verticalTextAlignmentProperty.setNative](value: VerticalTextAlignment) {
322+
// TODO: not working for now
323+
const view = this.nativeTextViewProtected;
324+
const horizontalGravity = view.getGravity() & android.view.Gravity.HORIZONTAL_GRAVITY_MASK;
325+
switch (value) {
326+
case 'initial':
327+
case 'top':
328+
view.setGravity(android.view.Gravity.TOP | horizontalGravity);
329+
break;
330+
case 'middle':
331+
view.setGravity(android.view.Gravity.CENTER_VERTICAL | horizontalGravity);
332+
break;
333+
334+
case 'bottom':
335+
view.setGravity(android.view.Gravity.BOTTOM | horizontalGravity);
336+
break;
337+
}
338+
}
321339
}
322340
//

src/textfield/textfield.common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CSSType, Color, TextField as NTextField } from '@nativescript/core';
22
import { cssProperty } from '@nativescript-community/ui-material-core';
3+
import { VerticalTextAlignment } from '@nativescript-community/text';
34

45
@CSSType('MDTextField')
56
export abstract class TextFieldBase extends NTextField {
@@ -25,4 +26,5 @@ export abstract class TextFieldBase extends NTextField {
2526
@cssProperty floatingInactiveColor: Color;
2627
@cssProperty buttonColor: Color;
2728
@cssProperty digits: string;
29+
@cssProperty verticalTextAlignment: VerticalTextAlignment;
2830
}

src/textfield/textfield.ios.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { VerticalTextAlignment, verticalTextAlignmentProperty } from '@nativescript-community/text';
12
import { themer } from '@nativescript-community/ui-material-core';
23
import {
34
buttonColorProperty,
@@ -12,26 +13,23 @@ import {
1213
helperProperty,
1314
strokeColorProperty,
1415
strokeDisabledColorProperty,
15-
strokeInactiveColorProperty,
16+
strokeInactiveColorProperty
1617
} from '@nativescript-community/ui-material-core/textbase/cssproperties';
1718
import {
1819
Background,
1920
Color,
2021
Font,
21-
Property,
22-
Screen,
2322
Style,
2423
Utils,
2524
_updateCharactersInRangeReplacementString,
2625
backgroundInternalProperty,
2726
editableProperty,
2827
fontInternalProperty,
29-
isAndroid,
3028
paddingBottomProperty,
3129
paddingLeftProperty,
3230
paddingRightProperty,
3331
paddingTopProperty,
34-
placeholderColorProperty,
32+
placeholderColorProperty
3533
} from '@nativescript/core';
3634
import { textProperty } from '@nativescript/core/ui/text-base';
3735
import { TextFieldBase } from './textfield.common';
@@ -180,7 +178,6 @@ export class TextField extends TextFieldBase {
180178

181179
_getTextInsetsForBounds(insets: UIEdgeInsets): UIEdgeInsets {
182180
const style = this.style;
183-
184181
if (this.variant === 'underline' && this._controller.underlineHeightNormal === 0) {
185182
// if no underline/custom background, remove all insets like on android
186183
insets.top = 0;
@@ -358,4 +355,24 @@ export class TextField extends TextFieldBase {
358355
const font = value instanceof Font ? value.getUIFont(this._controller.inlinePlaceholderFont) : value;
359356
this._controller.inlinePlaceholderFont = font;
360357
}
358+
359+
[verticalTextAlignmentProperty.setNative](value: VerticalTextAlignment) {
360+
// TODO: not working for now
361+
const view = this.nativeTextViewProtected;
362+
view.backgroundColor = UIColor.redColor;
363+
switch (value) {
364+
case 'initial':
365+
case 'top':
366+
view.contentVerticalAlignment = UIControlContentVerticalAlignment.Top;
367+
break;
368+
case 'middle':
369+
view.contentVerticalAlignment = UIControlContentVerticalAlignment.Center;
370+
371+
break;
372+
373+
case 'bottom':
374+
view.contentVerticalAlignment = UIControlContentVerticalAlignment.Bottom;
375+
break;
376+
}
377+
}
361378
}

0 commit comments

Comments
 (0)