You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The library implements a `StyledText` component taking an HTML-like text and a styles object as input properties.
14
+
The library implements a `StyledText` component taking an HTML-like string in the `children` property and an optional text styles property.
15
15
16
16
## Installation
17
17
To install the library into your project, run yarn or npm:
@@ -39,9 +39,10 @@ import StyledText from 'react-native-styled-text';
39
39
40
40
...
41
41
<StyledText
42
-
text="Ha<i>pp</i>y <b>Styling</b>!"
43
42
style={styles.header}
44
-
/>
43
+
>
44
+
{"Ha<i>pp</i>y <b>Styling</b>!"}
45
+
</StyledText>
45
46
...
46
47
47
48
conststyles=StyleSheet.create({
@@ -70,10 +71,11 @@ import StyledText from 'react-native-styled-text';
70
71
71
72
...
72
73
<StyledText
73
-
text="Welcome to <b><u>React Native</u> <demo><i>Styled</i> Text</demo></b> demo!"
74
74
style={styles.welcome}
75
75
textStyles={textStyles}
76
-
/>
76
+
>
77
+
{"Welcome to <b><u>React Native</u> <demo><i>Styled</i> Text</demo></b> demo!"}
78
+
</StyledText>
77
79
...
78
80
79
81
conststyles=StyleSheet.create({
@@ -102,15 +104,16 @@ Renders as
102
104
103
105
## How it works
104
106
105
-
Internally, the `render` function of `StyledText` parses the value of the `text` property and returns a nested structure of React Native [`Text`](https://facebook.github.io/react-native/docs/text) components.
107
+
Internally, the `render` function of `StyledText` parses the value of the `children` property, which must be a string, and returns a nested structure of React Native [`Text`](https://facebook.github.io/react-native/docs/text) components.
106
108
107
109
From the example above:
108
110
109
111
```javascript
110
112
<StyledText
111
-
text="Ha<i>pp</i>y <b>Styling</b>!"
112
113
style={styles.header}
113
-
/>
114
+
>
115
+
{"Ha<i>pp</i>y <b>Styling</b>!"}
116
+
</StyledText>
114
117
```
115
118
would be transformed to:
116
119
@@ -125,11 +128,12 @@ So `StyledText` just provides a more compact, readable and flexible coding of ne
125
128
126
129
127
130
## API
128
-
In addition to the React Native `Text` properties, `StyledText` supports the following properties:
131
+
132
+
In addition to the React Native `Text` properties, `StyledText` supports the following properties, with a restriction on the `children` proerty:
129
133
130
134
| Name | Description |
131
135
| ---- | ----------- |
132
-
|text| String with style tags for mixed styling of the text. Each style tag must match one of the styles provided in textStyles or one of the default styles, see below. |
136
+
|children| String with style tags for mixed styling of the text. Each style tag must match one of the styles provided in textStyles or one of the default styles, see below. (Optional)|
133
137
| textStyles | Object (e.g. `StyleSheet`) containing definition of the styles used in the provided text. (Optional) |
0 commit comments