-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adjust AnimatedText, update Typography component and props desc…
…ription (#3082) * refactor: adjust AnimatedText, update component and props description * refactor: correct prop description
- Loading branch information
1 parent
32dcb73
commit be26644
Showing
9 changed files
with
258 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import * as React from 'react'; | ||
import { | ||
Animated, | ||
TextStyle, | ||
I18nManager, | ||
StyleProp, | ||
StyleSheet, | ||
} from 'react-native'; | ||
import { withTheme } from '../../core/theming'; | ||
import { Font, MD3TypescaleKey, Theme } from '../../types'; | ||
|
||
type Props = React.ComponentPropsWithRef<typeof Animated.Text> & { | ||
/** | ||
* Variant defines appropriate text styles for type role and its size. | ||
* Available variants: | ||
* | ||
* Display: `displayLarge`, `displayMedium`, `displaySmall` | ||
* | ||
* Headline: `headlineLarge`, `headlineMedium`, `headlineSmall` | ||
* | ||
* Title: `titleLarge`, `titleMedium`, `titleSmall` | ||
* | ||
* Label: `labelLarge`, `labelMedium`, `labelSmall` | ||
* | ||
* Body: `bodyLarge`, `bodyMedium`, `bodySmall` | ||
*/ | ||
variant?: keyof typeof MD3TypescaleKey; | ||
style?: StyleProp<TextStyle>; | ||
/** | ||
* @optional | ||
*/ | ||
theme: Theme; | ||
}; | ||
|
||
/** | ||
* Animated text component which follows styles from the theme. | ||
* | ||
* @extends Text props https://reactnative.dev/docs/text#props | ||
*/ | ||
function AnimatedText({ style, theme, variant, ...rest }: Props) { | ||
const writingDirection = I18nManager.isRTL ? 'rtl' : 'ltr'; | ||
|
||
if (theme.isV3 && variant) { | ||
const stylesByVariant = Object.keys(MD3TypescaleKey).reduce( | ||
(acc, key) => { | ||
const { size, weight, lineHeight, tracking } = | ||
theme.typescale[key as keyof typeof MD3TypescaleKey]; | ||
|
||
return { | ||
...acc, | ||
[key]: { | ||
fontSize: size, | ||
fontWeight: weight, | ||
lineHeight: lineHeight, | ||
letterSpacing: tracking, | ||
color: theme.colors.onSurface, | ||
}, | ||
}; | ||
}, | ||
{} as { | ||
[key in MD3TypescaleKey]: { | ||
fontSize: number; | ||
fontWeight: Font['fontWeight']; | ||
lineHeight: number; | ||
letterSpacing: number; | ||
}; | ||
} | ||
); | ||
|
||
const styleForVariant = stylesByVariant[variant]; | ||
|
||
return ( | ||
<Animated.Text | ||
{...rest} | ||
style={[styleForVariant, styles.text, { writingDirection }, style]} | ||
/> | ||
); | ||
} else { | ||
return ( | ||
<Animated.Text | ||
{...rest} | ||
style={[ | ||
styles.text, | ||
{ | ||
...theme.fonts.regular, | ||
color: theme.isV3 ? theme.colors.onSurface : theme.colors.text, | ||
writingDirection, | ||
}, | ||
style, | ||
]} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
text: { | ||
textAlign: 'left', | ||
}, | ||
}); | ||
|
||
export default withTheme(AnimatedText); |
Oops, something went wrong.