瀏覽代碼

[RN] Extract header components for reuse

j8
Bettenbuk Zoltan 6 年之前
父節點
當前提交
d7475a44e4

react/features/settings/components/native/BackButton.js → react/features/base/react/components/native/BackButton.js 查看文件

3
 import React, { Component } from 'react';
3
 import React, { Component } from 'react';
4
 import { TouchableOpacity } from 'react-native';
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
  * The type of the React {@code Component} props of {@link BackButton}
11
  * The type of the React {@code Component} props of {@link BackButton}
40
                 <Icon
41
                 <Icon
41
                     name = { 'arrow_back' }
42
                     name = { 'arrow_back' }
42
                     style = { [
43
                     style = { [
43
-                        Header.buttonStyle,
44
+                        styles.headerButton,
44
                         this.props.style
45
                         this.props.style
45
                     ] } />
46
                     ] } />
46
             </TouchableOpacity>
47
             </TouchableOpacity>

+ 48
- 0
react/features/base/react/components/native/HeaderLabel.js 查看文件

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 查看文件

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

+ 3
- 10
react/features/settings/components/native/SettingsView.js 查看文件

7
     SafeAreaView,
7
     SafeAreaView,
8
     ScrollView,
8
     ScrollView,
9
     Switch,
9
     Switch,
10
-    Text,
11
     TextInput,
10
     TextInput,
12
     View
11
     View
13
 } from 'react-native';
12
 } from 'react-native';
14
 import { connect } from 'react-redux';
13
 import { connect } from 'react-redux';
15
 
14
 
16
 import { translate } from '../../../base/i18n';
15
 import { translate } from '../../../base/i18n';
17
-import { Header } from '../../../base/react';
16
+import { BackButton, Header } from '../../../base/react';
18
 
17
 
19
 import {
18
 import {
20
     AbstractSettingsView,
19
     AbstractSettingsView,
21
     _mapStateToProps
20
     _mapStateToProps
22
 } from '../AbstractSettingsView';
21
 } from '../AbstractSettingsView';
23
 import { setSettingsViewVisible } from '../../actions';
22
 import { setSettingsViewVisible } from '../../actions';
24
-import BackButton from './BackButton';
25
 import FormRow from './FormRow';
23
 import FormRow from './FormRow';
26
 import FormSectionHeader from './FormSectionHeader';
24
 import FormSectionHeader from './FormSectionHeader';
27
 import { normalizeUserInputURL } from '../../functions';
25
 import { normalizeUserInputURL } from '../../functions';
28
 import styles from './styles';
26
 import styles from './styles';
27
+import { HeaderLabel } from '../../../base/react/components/native';
29
 
28
 
30
 /**
29
 /**
31
  * The native container rendering the app settings page.
30
  * The native container rendering the app settings page.
205
         return (
204
         return (
206
             <Header>
205
             <Header>
207
                 <BackButton onPress = { this._onRequestClose } />
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
             </Header>
208
             </Header>
216
         );
209
         );
217
     }
210
     }

Loading…
取消
儲存