Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/FAB/AnimatedFAB.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
StyleSheet,
View,
ViewStyle,
Text,
} from 'react-native';

import color from 'color';
Expand Down Expand Up @@ -231,7 +232,7 @@ const AnimatedFAB = ({
const isAnimatedFromRight = animateFrom === 'right';
const isIconStatic = iconMode === 'static';
const { isRTL } = I18nManager;
const labelRef = React.useRef<HTMLElement | null>(null);
const labelRef = React.useRef<Text & HTMLElement>(null);
const { current: visibility } = React.useRef<Animated.Value>(
new Animated.Value(visible ? 1 : 0)
);
Expand Down
97 changes: 50 additions & 47 deletions src/components/Typography/AnimatedText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
StyleProp,
StyleSheet,
TextStyle,
Text,
} from 'react-native';

import type { VariantProp } from './types';
Expand Down Expand Up @@ -40,57 +41,59 @@ type Props<T> = React.ComponentPropsWithRef<typeof Animated.Text> & {
*
* @extends Text props https://reactnative.dev/docs/text#props
*/
const AnimatedText = forwardRef(function AnimatedText(
{ style, theme: themeOverrides, variant, ...rest }: Props<never>,
ref
) {
const theme = useInternalTheme(themeOverrides);
const writingDirection = I18nManager.getConstants().isRTL ? 'rtl' : 'ltr';
const AnimatedText = forwardRef<Text & HTMLElement, Props<never>>(
function AnimatedText(
{ style, theme: themeOverrides, variant, ...rest },
ref
) {
const theme = useInternalTheme(themeOverrides);
const writingDirection = I18nManager.getConstants().isRTL ? 'rtl' : 'ltr';

if (theme.isV3 && variant) {
const font = theme.fonts[variant];
if (typeof font !== 'object') {
throw new Error(
`Variant ${variant} was not provided properly. Valid variants are ${Object.keys(
theme.fonts
).join(', ')}.`
if (theme.isV3 && variant) {
const font = theme.fonts[variant];
if (typeof font !== 'object') {
throw new Error(
`Variant ${variant} was not provided properly. Valid variants are ${Object.keys(
theme.fonts
).join(', ')}.`
);
}

return (
<Animated.Text
ref={ref}
{...rest}
style={[
font,
styles.text,
{ writingDirection, color: theme.colors.onSurface },
style,
]}
/>
);
} else {
const font = !theme.isV3 ? theme.fonts.regular : theme.fonts.bodyMedium;
const textStyle = {
...font,
color: theme.isV3 ? theme.colors.onSurface : theme.colors.text,
};
return (
<Animated.Text
ref={ref}
{...rest}
style={[
styles.text,
textStyle,
{
writingDirection,
},
style,
]}
/>
);
}

return (
<Animated.Text
ref={ref}
{...rest}
style={[
font,
styles.text,
{ writingDirection, color: theme.colors.onSurface },
style,
]}
/>
);
} else {
const font = !theme.isV3 ? theme.fonts.regular : theme.fonts.bodyMedium;
const textStyle = {
...font,
color: theme.isV3 ? theme.colors.onSurface : theme.colors.text,
};
return (
<Animated.Text
ref={ref}
{...rest}
style={[
styles.text,
textStyle,
{
writingDirection,
},
style,
]}
/>
);
}
});
);

const styles = StyleSheet.create({
text: {
Expand Down