Skip to content

Commit 2367889

Browse files
authored
fix: animated-fab & animated-text ts issues (#4669)
1 parent 366e0d6 commit 2367889

File tree

2 files changed

+52
-48
lines changed

2 files changed

+52
-48
lines changed

src/components/FAB/AnimatedFAB.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
StyleSheet,
1818
View,
1919
ViewStyle,
20+
Text,
2021
} from 'react-native';
2122

2223
import color from 'color';
@@ -231,7 +232,7 @@ const AnimatedFAB = ({
231232
const isAnimatedFromRight = animateFrom === 'right';
232233
const isIconStatic = iconMode === 'static';
233234
const { isRTL } = I18nManager;
234-
const labelRef = React.useRef<HTMLElement | null>(null);
235+
const labelRef = React.useRef<Text & HTMLElement>(null);
235236
const { current: visibility } = React.useRef<Animated.Value>(
236237
new Animated.Value(visible ? 1 : 0)
237238
);

src/components/Typography/AnimatedText.tsx

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
StyleProp,
66
StyleSheet,
77
TextStyle,
8+
Text,
89
} from 'react-native';
910

1011
import type { VariantProp } from './types';
@@ -40,57 +41,59 @@ type Props<T> = React.ComponentPropsWithRef<typeof Animated.Text> & {
4041
*
4142
* @extends Text props https://reactnative.dev/docs/text#props
4243
*/
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';
4951

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+
/>
5793
);
5894
}
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-
);
9295
}
93-
});
96+
);
9497

9598
const styles = StyleSheet.create({
9699
text: {

0 commit comments

Comments
 (0)