Skip to content

Commit ce246ee

Browse files
committed
chore: update rtl text align props
1 parent 5c79554 commit ce246ee

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

packages/uikit-react-native-foundation/src/components/Text/index.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@ import useUIKitTheme from '../../theme/useUIKitTheme';
55
import type { TypoName, UIKitTheme } from '../../types';
66
import { isStartsWithRTL } from './isStartsWithRTL';
77

8+
export interface RTLTextAlignSupportProps {
9+
/**
10+
* If `I18nManager.isRTL` is `true` and this value is enabled, the text will be aligned according to RTL if it starts in an RTL language.
11+
* In the case of the `Text` component, the alignment value is calculated based on `I18nManager.doLeftAndRightSwapInRTL`.
12+
* For the `TextInput` component, the alignment value is calculated as a physical alignment, unaffected by `I18nManager.doLeftAndRightSwapInRTL`.
13+
*/
14+
supportRTLAlign?: boolean;
15+
/**
16+
* If you want to enable `supportRTLAlign` but are using nested `Text` components that are not simple text under the `Text` component, pass the original text here.
17+
*/
18+
originalText?: string;
19+
}
20+
821
type TypographyProps = Partial<Record<TypoName, boolean>>;
922
export type TextProps = RNTextProps &
10-
TypographyProps & {
11-
color?: ((colors: UIKitTheme['colors']) => string) | string;
12-
} & {
13-
supportRTLAlign?: boolean;
14-
originalText?: string;
15-
};
23+
TypographyProps & { color?: ((colors: UIKitTheme['colors']) => string) | string } & RTLTextAlignSupportProps;
1624

17-
const Text = ({ children, color, style, supportRTLAlign, originalText, ...props }: TextProps) => {
25+
const Text = ({ children, color, style, supportRTLAlign = true, originalText, ...props }: TextProps) => {
1826
const { colors } = useUIKitTheme();
1927
const typoStyle = useTypographyFilter(props);
2028

@@ -26,7 +34,10 @@ const Text = ({ children, color, style, supportRTLAlign, originalText, ...props
2634

2735
const textAlign = (() => {
2836
if (I18nManager.isRTL && supportRTLAlign) {
29-
if (originalText && isStartsWithRTL(originalText)) {
37+
if (
38+
(originalText && isStartsWithRTL(originalText)) ||
39+
(typeof children === 'string' && isStartsWithRTL(children))
40+
) {
3041
return I18nManager.doLeftAndRightSwapInRTL ? 'left' : 'right';
3142
}
3243
}

packages/uikit-react-native-foundation/src/components/TextInput/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { I18nManager, TextInput as RNTextInput, StyleSheet, TextInputProps, Text
44
import createStyleSheet from '../../styles/createStyleSheet';
55
import useUIKitTheme from '../../theme/useUIKitTheme';
66
import type { UIKitTheme } from '../../types';
7+
import { RTLTextAlignSupportProps } from '../Text';
78
import { isStartsWithRTL } from '../Text/isStartsWithRTL';
89

910
type Props = {
1011
variant?: keyof UIKitTheme['colors']['ui']['input'];
11-
originalText?: string;
12-
supportRTLAlign?: boolean;
13-
} & TextInputProps;
12+
} & TextInputProps &
13+
RTLTextAlignSupportProps;
1414
const TextInput = React.forwardRef<RNTextInput, Props>(function TextInput(
1515
{ children, style, variant = 'default', editable = true, originalText, supportRTLAlign, ...props },
1616
ref,

0 commit comments

Comments
 (0)