Skip to main content

Text component

The text component is mainly based on the restyle package, replacing the react-native default Text component.

**Note: The Text component has removed the properties onLongPress/onPress/onPressIn/onPressOut (Why) . Therefore, you cannot use click events directly on the Text component. If necessary, please use components such as Pressable or Touchable* to wrap the Text component to achieve the same effect. **

Effect demonstration

1. Font size 32

<Text fontSize={32}>
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</Text>
text-ios1

2. The color is blue and the font is bold.

<Text fontSize={32} color="primaryColor" fontWeight="bold">
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
</Text>
text-ios2

3. Variant usage example

<Text variant="primaryBody">Hello, I am text</Text>

primaryBody is defined in src/themes as:

const extraVariants = {
...
primaryBody: {
fontSize: 16,
color: 'primaryTextColor',
}
}
export const lightTheme = {
...theme.lightTheme,
colors: {
...theme.lightTheme.colors,
...
primaryTextColor: theme.lightTheme.colors.primary200,
},
...
};
export const darkTheme: AppTheme = {
...theme.darkTheme,
colors: {
...theme.darkTheme.colors,
...
primaryTextColor: theme.lightTheme.colors.primary100,
},
...
};
text-ios3

API

Except for the style attributes, other attributes are consistent with TextProps. Style attributes are based on restyle, which flattens the properties originally wrapped in style and adopts the constraints defined in Theme.

Unique properties

PropertiesRequiredDescriptionTypeDefault Value
variantfalseThe value is the key value in the textVariants object defined in Themestring

Text attributes

For the definition, see: https://reactnative.dev/docs/text-style-props

PropertiesRequiredDescriptionTypeDefault Value
colorfalseText color. The value is colorsstring
opacityfalseTransparency. Value 0 -1number1
visiblefalseWhether it is visiblebooleantrue
fontFamilyfalse
fontSizefalse
fontStylefalse
fontWeightfalse
letterSpacingfalse
lineHeightfalse
textAlignfalse
textDecorationLinefalse
textDecorationStylefalse
textTransformfalse
textShadowOffsetfalse
textShadowRadiusfalse
textShadowColorfalseText shadow color. The value is colors in Theme

The value is spacing in Theme. For definition, see: https://reactnative.dev/docs/layout-props

PropertiesRequiredDescriptionTypeDefault Value
marginfalse
marginStartfalse
marginEndfalse
marginHorizontalfalse
marginVerticalfalse
marginLeftfalse
marginRightfalse
marginBottomfalse
marginTopfalse
paddingfalse
paddingStartfalse
paddingEndfalse
paddingHorizontalfalse
paddingVerticalfalse
paddingLeftfalse
paddingRightfalse
paddingBottomfalse
paddingTopfalse