Explorar el Código

[RN] Extract header components for reuse

j8
Bettenbuk Zoltan hace 6 años
padre
commit
d7475a44e4

react/features/settings/components/native/BackButton.js → react/features/base/react/components/native/BackButton.js Ver fichero

@@ -3,8 +3,9 @@
3 3
 import React, { Component } from 'react';
4 4
 import { TouchableOpacity } from 'react-native';
5 5
 
6
-import { Icon } from '../../../base/font-icons';
7
-import { Header } from '../../../base/react';
6
+import { Icon } from '../../../font-icons';
7
+
8
+import styles from './styles';
8 9
 
9 10
 /**
10 11
  * The type of the React {@code Component} props of {@link BackButton}
@@ -40,7 +41,7 @@ export default class BackButton extends Component<Props> {
40 41
                 <Icon
41 42
                     name = { 'arrow_back' }
42 43
                     style = { [
43
-                        Header.buttonStyle,
44
+                        styles.headerButton,
44 45
                         this.props.style
45 46
                     ] } />
46 47
             </TouchableOpacity>

+ 48
- 0
react/features/base/react/components/native/HeaderLabel.js Ver fichero

@@ -0,0 +1,48 @@
1
+// @flow
2
+
3
+import React, { Component } from 'react';
4
+import { Text } from 'react-native';
5
+
6
+import { translate } from '../../../i18n';
7
+
8
+import styles from './styles';
9
+
10
+/**
11
+ * The type of the React {@code Component} props of {@link HeaderLabel}
12
+ */
13
+type Props = {
14
+
15
+    /**
16
+     * The i18n key of the label to be rendered.
17
+     */
18
+    labelKey: string,
19
+
20
+    /**
21
+     * The i18n translate function.
22
+     */
23
+    t: Function
24
+};
25
+
26
+/**
27
+ * A component rendering a standard label in the header.
28
+ */
29
+class HeaderLabel extends Component<Props> {
30
+    /**
31
+     * Implements React's {@link Component#render()}.
32
+     *
33
+     * @inheritdoc
34
+     * @returns {ReactElement}
35
+     */
36
+    render() {
37
+        return (
38
+            <Text
39
+                style = { [
40
+                    styles.headerText
41
+                ] }>
42
+                { this.props.t(this.props.labelKey) }
43
+            </Text>
44
+        );
45
+    }
46
+}
47
+
48
+export default translate(HeaderLabel);

+ 2
- 0
react/features/base/react/components/native/index.js Ver fichero

@@ -1,5 +1,7 @@
1
+export { default as BackButton } from './BackButton';
1 2
 export { default as Container } from './Container';
2 3
 export { default as Header } from './Header';
4
+export { default as HeaderLabel } from './HeaderLabel';
3 5
 export { default as Link } from './Link';
4 6
 export { default as LoadingIndicator } from './LoadingIndicator';
5 7
 export { default as NavigateSectionListEmptyComponent } from

+ 3
- 10
react/features/settings/components/native/SettingsView.js Ver fichero

@@ -7,25 +7,24 @@ import {
7 7
     SafeAreaView,
8 8
     ScrollView,
9 9
     Switch,
10
-    Text,
11 10
     TextInput,
12 11
     View
13 12
 } from 'react-native';
14 13
 import { connect } from 'react-redux';
15 14
 
16 15
 import { translate } from '../../../base/i18n';
17
-import { Header } from '../../../base/react';
16
+import { BackButton, Header } from '../../../base/react';
18 17
 
19 18
 import {
20 19
     AbstractSettingsView,
21 20
     _mapStateToProps
22 21
 } from '../AbstractSettingsView';
23 22
 import { setSettingsViewVisible } from '../../actions';
24
-import BackButton from './BackButton';
25 23
 import FormRow from './FormRow';
26 24
 import FormSectionHeader from './FormSectionHeader';
27 25
 import { normalizeUserInputURL } from '../../functions';
28 26
 import styles from './styles';
27
+import { HeaderLabel } from '../../../base/react/components/native';
29 28
 
30 29
 /**
31 30
  * The native container rendering the app settings page.
@@ -205,13 +204,7 @@ class SettingsView extends AbstractSettingsView {
205 204
         return (
206 205
             <Header>
207 206
                 <BackButton onPress = { this._onRequestClose } />
208
-                <Text
209
-                    style = { [
210
-                        styles.text,
211
-                        Header.textStyle
212
-                    ] }>
213
-                    { this.props.t('settingsView.header') }
214
-                </Text>
207
+                <HeaderLabel labelKey = 'settingsView.header' />
215 208
             </Header>
216 209
         );
217 210
     }

Loading…
Cancelar
Guardar