|
5 | 5 | StyleProp, |
6 | 6 | StyleSheet, |
7 | 7 | TextStyle, |
| 8 | + Text, |
8 | 9 | } from 'react-native'; |
9 | 10 |
|
10 | 11 | import type { VariantProp } from './types'; |
@@ -40,57 +41,59 @@ type Props<T> = React.ComponentPropsWithRef<typeof Animated.Text> & { |
40 | 41 | * |
41 | 42 | * @extends Text props https://reactnative.dev/docs/text#props |
42 | 43 | */ |
43 | | -const AnimatedText = forwardRef(function AnimatedText( |
44 | | - { style, theme: themeOverrides, variant, ...rest }: Props<never>, |
45 | | - ref |
46 | | -) { |
47 | | - const theme = useInternalTheme(themeOverrides); |
48 | | - const writingDirection = I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'; |
| 44 | +const AnimatedText = forwardRef<Text & HTMLElement, Props<never>>( |
| 45 | + function AnimatedText( |
| 46 | + { style, theme: themeOverrides, variant, ...rest }, |
| 47 | + ref |
| 48 | + ) { |
| 49 | + const theme = useInternalTheme(themeOverrides); |
| 50 | + const writingDirection = I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'; |
49 | 51 |
|
50 | | - if (theme.isV3 && variant) { |
51 | | - const font = theme.fonts[variant]; |
52 | | - if (typeof font !== 'object') { |
53 | | - throw new Error( |
54 | | - `Variant ${variant} was not provided properly. Valid variants are ${Object.keys( |
55 | | - theme.fonts |
56 | | - ).join(', ')}.` |
| 52 | + if (theme.isV3 && variant) { |
| 53 | + const font = theme.fonts[variant]; |
| 54 | + if (typeof font !== 'object') { |
| 55 | + throw new Error( |
| 56 | + `Variant ${variant} was not provided properly. Valid variants are ${Object.keys( |
| 57 | + theme.fonts |
| 58 | + ).join(', ')}.` |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + return ( |
| 63 | + <Animated.Text |
| 64 | + ref={ref} |
| 65 | + {...rest} |
| 66 | + style={[ |
| 67 | + font, |
| 68 | + styles.text, |
| 69 | + { writingDirection, color: theme.colors.onSurface }, |
| 70 | + style, |
| 71 | + ]} |
| 72 | + /> |
| 73 | + ); |
| 74 | + } else { |
| 75 | + const font = !theme.isV3 ? theme.fonts.regular : theme.fonts.bodyMedium; |
| 76 | + const textStyle = { |
| 77 | + ...font, |
| 78 | + color: theme.isV3 ? theme.colors.onSurface : theme.colors.text, |
| 79 | + }; |
| 80 | + return ( |
| 81 | + <Animated.Text |
| 82 | + ref={ref} |
| 83 | + {...rest} |
| 84 | + style={[ |
| 85 | + styles.text, |
| 86 | + textStyle, |
| 87 | + { |
| 88 | + writingDirection, |
| 89 | + }, |
| 90 | + style, |
| 91 | + ]} |
| 92 | + /> |
57 | 93 | ); |
58 | 94 | } |
59 | | - |
60 | | - return ( |
61 | | - <Animated.Text |
62 | | - ref={ref} |
63 | | - {...rest} |
64 | | - style={[ |
65 | | - font, |
66 | | - styles.text, |
67 | | - { writingDirection, color: theme.colors.onSurface }, |
68 | | - style, |
69 | | - ]} |
70 | | - /> |
71 | | - ); |
72 | | - } else { |
73 | | - const font = !theme.isV3 ? theme.fonts.regular : theme.fonts.bodyMedium; |
74 | | - const textStyle = { |
75 | | - ...font, |
76 | | - color: theme.isV3 ? theme.colors.onSurface : theme.colors.text, |
77 | | - }; |
78 | | - return ( |
79 | | - <Animated.Text |
80 | | - ref={ref} |
81 | | - {...rest} |
82 | | - style={[ |
83 | | - styles.text, |
84 | | - textStyle, |
85 | | - { |
86 | | - writingDirection, |
87 | | - }, |
88 | | - style, |
89 | | - ]} |
90 | | - /> |
91 | | - ); |
92 | 95 | } |
93 | | -}); |
| 96 | +); |
94 | 97 |
|
95 | 98 | const styles = StyleSheet.create({ |
96 | 99 | text: { |
|
0 commit comments