1 | import React from 'react';
|
2 |
|
3 | import {
|
4 | Text, TouchableWithoutFeedback, View,
|
5 | } from 'react-native';
|
6 |
|
7 | import PropTypes from 'prop-types';
|
8 |
|
9 | function noop() {}
|
10 |
|
11 | function Header({
|
12 | left, right,
|
13 | onPressLeft, onPressRight,
|
14 | children, style,
|
15 | }) {
|
16 | return (
|
17 | <View style={[Header.Style, style]}>
|
18 | {left || (
|
19 | <TouchableWithoutFeedback onPress={onPressLeft}>
|
20 | <Text>取消</Text>
|
21 | </TouchableWithoutFeedback>
|
22 | )}
|
23 | {children}
|
24 | {right || (
|
25 | <TouchableWithoutFeedback onPress={onPressRight}>
|
26 | <Text>确定</Text>
|
27 | </TouchableWithoutFeedback>
|
28 | )}
|
29 | </View>
|
30 | );
|
31 | }
|
32 |
|
33 | Header.Style = {
|
34 | flexDirection: 'row',
|
35 | justifyContent: 'space-between',
|
36 | alignItems: 'center',
|
37 | minHeight: 48,
|
38 | };
|
39 |
|
40 | Header.propTypes = {
|
41 | left: PropTypes.node,
|
42 | right: PropTypes.node,
|
43 | onPressLeft: PropTypes.func,
|
44 | onPressRight: PropTypes.func,
|
45 | children: PropTypes.node,
|
46 | style: View.propTypes.style,
|
47 | };
|
48 |
|
49 | Header.defaultProps = {
|
50 | left: null,
|
51 | right: null,
|
52 | onPressLeft: noop,
|
53 | onPressRight: noop,
|
54 | children: null,
|
55 | style: null,
|
56 | };
|
57 |
|
58 | export default Header;
|