feat(text): add css text-align justify (#9573)

Co-authored-by: Igor Randjelovic <rigor789@gmail.com>
Co-authored-by: Nathan Walker <walkerrunpdx@gmail.com>
This commit is contained in:
Juan de Dios Martínez Vallejo
2021-09-28 02:27:08 +02:00
committed by GitHub
parent 35fe4811bf
commit 1de5295ad9
5 changed files with 22 additions and 9 deletions

View File

@ -104,7 +104,7 @@ export namespace CoreTypes {
export const send: string;
}
export type TextAlignmentType = 'initial' | 'left' | 'center' | 'right';
export type TextAlignmentType = 'initial' | 'left' | 'center' | 'right' | 'justify';
/**
* Represents a text-align enumeration.
*/
@ -123,6 +123,11 @@ export namespace CoreTypes {
* Represents right text-align.
*/
export const right: TextAlignmentType;
/**
* Represents justify text-align.
*/
export const justify: TextAlignmentType;
}
export type OrientationType = 'horizontal' | 'vertical';

View File

@ -57,11 +57,12 @@ export namespace CoreTypes {
export const send = 'send';
}
export type TextAlignmentType = 'initial' | 'left' | 'center' | 'right';
export type TextAlignmentType = 'initial' | 'left' | 'center' | 'right' | 'justify';
export module TextAlignment {
export const left = 'left';
export const center = 'center';
export const right = 'right';
export const justify = 'justify';
}
export type TextDecorationType = 'none' | 'underline' | 'line-through' | 'underline line-through';

View File

@ -286,18 +286,22 @@ export class TextBase extends TextBaseCommon {
[textAlignmentProperty.setNative](value: CoreTypes.TextAlignmentType) {
const verticalGravity = this.nativeTextViewProtected.getGravity() & android.view.Gravity.VERTICAL_GRAVITY_MASK;
switch (value) {
case 'initial':
case 'left':
this.nativeTextViewProtected.setGravity(android.view.Gravity.START | verticalGravity);
break;
case 'center':
this.nativeTextViewProtected.setGravity(android.view.Gravity.CENTER_HORIZONTAL | verticalGravity);
break;
case 'right':
this.nativeTextViewProtected.setGravity(android.view.Gravity.END | verticalGravity);
break;
default: // initial | left | justify
this.nativeTextViewProtected.setGravity(android.view.Gravity.START | verticalGravity);
break;
}
if (android.os.Build.VERSION.SDK_INT >= 25) {
if (value === 'justify') {
this.nativeTextViewProtected.setJustificationMode(android.text.Layout.JUSTIFICATION_MODE_INTER_WORD);
} else {
this.nativeTextViewProtected.setJustificationMode(android.text.Layout.JUSTIFICATION_MODE_NONE);
}
}
}

View File

@ -171,6 +171,9 @@ export class TextBase extends TextBaseCommon {
case 'right':
nativeView.textAlignment = NSTextAlignment.Right;
break;
case 'justify':
nativeView.textAlignment = NSTextAlignment.Justified;
break;
}
}

View File

@ -246,7 +246,7 @@ export function getClosestPropertyValue<T>(property: CssProperty<any, T>, span:
}
}
const textAlignmentConverter = makeParser<CoreTypes.TextAlignmentType>(makeValidator<CoreTypes.TextAlignmentType>('initial', 'left', 'center', 'right'));
const textAlignmentConverter = makeParser<CoreTypes.TextAlignmentType>(makeValidator<CoreTypes.TextAlignmentType>('initial', 'left', 'center', 'right', 'justify'));
export const textAlignmentProperty = new InheritedCssProperty<Style, CoreTypes.TextAlignmentType>({
name: 'textAlignment',
cssName: 'text-align',