Skip to content

Commit abd6283

Browse files
committed
fix: Corrected text alignment when layout direction is rtl
1 parent f7193ac commit abd6283

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

packages/core/ui/button/index.android.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { ButtonBase } from './button-common';
2-
import { AndroidHelper, PseudoClassHandler } from '../core/view';
2+
import { PseudoClassHandler } from '../core/view';
33
import { paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, Length, zIndexProperty, minWidthProperty, minHeightProperty } from '../styling/style-properties';
44
import { textAlignmentProperty } from '../text-base';
55
import { CoreTypes } from '../../core-types';
66
import { profile } from '../../profiling';
77
import { TouchGestureEventData, TouchAction, GestureTypes } from '../gestures';
8-
import { Device } from '../../platform';
98
import { SDK_VERSION } from '../../utils/constants';
10-
import type { Background } from '../styling/background';
11-
import { NativeScriptAndroidView } from '../utils';
129

1310
export * from './button-common';
1411

packages/core/ui/button/index.ios.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,19 @@ export class Button extends ButtonBase {
214214
this.nativeViewProtected.titleLabel.textAlignment = NSTextAlignment.Left;
215215
this.nativeViewProtected.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Left;
216216
break;
217-
case 'initial':
218-
case 'center':
219-
this.nativeViewProtected.titleLabel.textAlignment = NSTextAlignment.Center;
220-
this.nativeViewProtected.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Center;
221-
break;
222217
case 'right':
223218
this.nativeViewProtected.titleLabel.textAlignment = NSTextAlignment.Right;
224219
this.nativeViewProtected.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Right;
225220
break;
221+
case 'justify':
222+
this.nativeViewProtected.titleLabel.textAlignment = NSTextAlignment.Justified;
223+
this.nativeViewProtected.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Center;
224+
break;
225+
default:
226+
// initial | center
227+
this.nativeViewProtected.titleLabel.textAlignment = NSTextAlignment.Center;
228+
this.nativeViewProtected.contentHorizontalAlignment = UIControlContentHorizontalAlignment.Center;
229+
break;
226230
}
227231
}
228232

packages/core/ui/text-base/index.android.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,18 @@ export class TextBase extends TextBaseCommon {
307307
[textAlignmentProperty.setNative](value: CoreTypes.TextAlignmentType) {
308308
const verticalGravity = this.nativeTextViewProtected.getGravity() & android.view.Gravity.VERTICAL_GRAVITY_MASK;
309309
switch (value) {
310+
case 'left':
311+
this.nativeTextViewProtected.setGravity(android.view.Gravity.LEFT | verticalGravity);
312+
break;
310313
case 'center':
311314
this.nativeTextViewProtected.setGravity(android.view.Gravity.CENTER_HORIZONTAL | verticalGravity);
312315
break;
313316
case 'right':
314317
this.nativeTextViewProtected.setGravity(android.view.Gravity.RIGHT | verticalGravity);
315318
break;
316319
default:
317-
// initial | left | justify
318-
this.nativeTextViewProtected.setGravity(android.view.Gravity.LEFT | verticalGravity);
320+
// initial | justify
321+
this.nativeTextViewProtected.setGravity(android.view.Gravity.START | verticalGravity);
319322
break;
320323
}
321324

packages/core/ui/text-base/index.ios.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ export class TextBase extends TextBaseCommon {
248248
[textAlignmentProperty.setNative](value: CoreTypes.TextAlignmentType) {
249249
const nativeView = <UITextField | UITextView | UILabel>this.nativeTextViewProtected;
250250
switch (value) {
251-
case 'initial':
252251
case 'left':
253252
nativeView.textAlignment = NSTextAlignment.Left;
254253
break;
@@ -261,6 +260,9 @@ export class TextBase extends TextBaseCommon {
261260
case 'justify':
262261
nativeView.textAlignment = NSTextAlignment.Justified;
263262
break;
263+
default:
264+
nativeView.textAlignment = NSTextAlignment.Natural;
265+
break;
264266
}
265267
}
266268

0 commit comments

Comments
 (0)