Pārlūkot izejas kodu

[RN] Render bold text in WaitForOwnerDialog

j8
Lyubo Marinov 8 gadus atpakaļ
vecāks
revīzija
e08d240a89

+ 3
- 3
react/features/authentication/components/LoginDialog.native.js Parādīt failu

@@ -159,15 +159,15 @@ class LoginDialog extends Component {
159 159
                         autoCorrect = { false }
160 160
                         onChangeText = { this._onUsernameChange }
161 161
                         placeholder = { 'user@domain.com' }
162
-                        style = { styles.loginDialogTextInput }
162
+                        style = { styles.dialogTextInput }
163 163
                         value = { this.state.username } />
164 164
                     <TextInput
165 165
                         onChangeText = { this._onPasswordChange }
166 166
                         placeholder = { t('dialog.userPassword') }
167 167
                         secureTextEntry = { true }
168
-                        style = { styles.loginDialogTextInput }
168
+                        style = { styles.dialogTextInput }
169 169
                         value = { this.state.password } />
170
-                    <Text style = { styles.loginDialogText }>
170
+                    <Text style = { styles.dialogText }>
171 171
                         {
172 172
                             messageKey
173 173
                                 ? t(messageKey, messageOptions || {})

+ 40
- 4
react/features/authentication/components/WaitForOwnerDialog.native.js Parādīt failu

@@ -104,13 +104,49 @@ class WaitForOwnerDialog extends Component {
104 104
      *
105 105
      * @param {string} html - The <tt>string</tt> which may contain HTML to
106 106
      * render.
107
-     * @returns {string}
107
+     * @returns {ReactElement[]|string}
108 108
      */
109 109
     _renderHTML(html) {
110 110
         if (typeof html === 'string') {
111
-            // TODO Limited styling may easily be provided by utilizing Text
112
-            // with style.
113
-            return html.replace(/<\/?b>/gi, '');
111
+            // At the time of this writing, the specified HTML contains a couple
112
+            // of spaces one after the other. They do not cause a visible
113
+            // problem on Web, because the specified HTML is rendered as, well,
114
+            // HTML. However, we're not rendering HTML here.
115
+
116
+            // eslint-disable-next-line no-param-reassign
117
+            html = html.replace(/\s{2,}/gi, ' ');
118
+
119
+            // Render text in <b>text</b> in bold.
120
+            const opening = /<\s*b\s*>/gi;
121
+            const closing = /<\s*\/\s*b\s*>/gi;
122
+            let o;
123
+            let c;
124
+            let prevClosingLastIndex = 0;
125
+            const r = [];
126
+
127
+            // eslint-disable-next-line no-cond-assign
128
+            while (o = opening.exec(html)) {
129
+                closing.lastIndex = opening.lastIndex;
130
+
131
+                // eslint-disable-next-line no-cond-assign
132
+                if (c = closing.exec(html)) {
133
+                    r.push(html.substring(prevClosingLastIndex, o.index));
134
+                    r.push(
135
+                        <Text style = { styles.boldDialogText }>
136
+                            { html.substring(opening.lastIndex, c.index) }
137
+                        </Text>);
138
+                    opening.lastIndex
139
+                        = prevClosingLastIndex
140
+                        = closing.lastIndex;
141
+                } else {
142
+                    break;
143
+                }
144
+            }
145
+            if (prevClosingLastIndex < html.length) {
146
+                r.push(html.substring(prevClosingLastIndex));
147
+            }
148
+
149
+            return r;
114 150
         }
115 151
 
116 152
         return html;

+ 20
- 9
react/features/authentication/components/styles.js Parādīt failu

@@ -20,31 +20,42 @@ const text = {
20 20
  */
21 21
 export default createStyleSheet({
22 22
     /**
23
-     * The style of <tt>LoginDialog</tt>.
23
+     * The style of bold <tt>Text</tt> rendered by the <tt>Dialog</tt>s of the
24
+     * feature authentication.
24 25
      */
25
-    loginDialog: {
26
-        ...dialog,
27
-        flex: 0,
28
-        flexDirection: 'column'
26
+    boldDialogText: {
27
+        ...text,
28
+        fontWeight: 'bold'
29 29
     },
30 30
 
31 31
     /**
32
-     * The style of <tt>Text</tt> rendered by <tt>LoginDialog</tt>.
32
+     * The style of <tt>Text</tt> rendered by the <tt>Dialog</tt>s of the
33
+     * feature authentication.
33 34
      */
34
-    loginDialogText: {
35
+    dialogText: {
35 36
         ...text
36 37
     },
37 38
 
38 39
     /**
39
-     * The style of <tt>TextInput</tt> rendered by <tt>LoginDialog</tt>.
40
+     * The style of <tt>TextInput</tt> rendered by the <tt>Dialog</tt>s of the
41
+     * feature authentication.
40 42
      */
41
-    loginDialogTextInput: {
43
+    dialogTextInput: {
42 44
         // XXX Matches react-native-prompt's dialogInput because base/dialog's
43 45
         // Dialog is implemented using react-native-prompt.
44 46
         fontSize: 18,
45 47
         height: 50
46 48
     },
47 49
 
50
+    /**
51
+     * The style of <tt>LoginDialog</tt>.
52
+     */
53
+    loginDialog: {
54
+        ...dialog,
55
+        flex: 0,
56
+        flexDirection: 'column'
57
+    },
58
+
48 59
     /**
49 60
      * The style of <tt>WaitForOwnerDialog</tt>.
50 61
      */

Notiek ielāde…
Atcelt
Saglabāt