CommonTitleBar.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import React, {Component} from 'react';
  2. import Global from '../utils/Global';
  3. import Utils from '../utils/Utils';
  4. import {Button, Dimensions, Image, PixelRatio, StatusBar, StyleSheet, Text, TouchableOpacity, View, Platform} from 'react-native';
  5. const {width} = Dimensions.get('window');
  6. export default class CommonTitleBar extends Component {
  7. constructor(props) {
  8. super(props);
  9. }
  10. renderAndroid() {
  11. return (
  12. <View style={styles.container}>
  13. <StatusBar
  14. backgroundColor='#393A3E'
  15. barStyle="light-content"
  16. />
  17. <View style={styles.content}>
  18. <TouchableOpacity activeOpacity={0.5} onPress={this.handleBackClick}>
  19. <Image source={require('../../images/ic_back.png')} style={styles.backBtn}/>
  20. </TouchableOpacity>
  21. <View style={styles.btnDivider}/>
  22. <View style={styles.titleContainer}>
  23. <Text style={styles.title}>{this.props.title}</Text>
  24. {
  25. Utils.isEmpty(this.props.rightIcon) ? (null) : (
  26. <TouchableOpacity activeOpacity={0.6} onPress={() => this.handleRightClick()}>
  27. <Image style={styles.img} source={this.props.rightIcon}/>
  28. </TouchableOpacity>
  29. )
  30. }
  31. {
  32. Utils.isEmpty(this.props.rightBtnText) ? (null) : (
  33. <Button
  34. onPress={() => this.props.handleRightBtnClick()}
  35. title={this.props.rightBtnText}
  36. color="#19AD17"
  37. />
  38. )
  39. }
  40. </View>
  41. </View>
  42. </View>
  43. );
  44. }
  45. renderIOS() {
  46. return (
  47. <View style={styles.container}>
  48. <View style={{height: 20, backgroundColor: Global.titleBackgroundColor}}/>
  49. <View style={styles.content}>
  50. <TouchableOpacity activeOpacity={0.5} onPress={this.handleBackClick}>
  51. <Image source={require('../../images/ic_back.png')} style={styles.backBtn}/>
  52. </TouchableOpacity>
  53. <View style={styles.btnDivider}/>
  54. <View style={styles.titleContainer}>
  55. <Text style={styles.title}>{this.props.title}</Text>
  56. {
  57. Utils.isEmpty(this.props.rightIcon) ? (null) : (
  58. <TouchableOpacity activeOpacity={0.6} onPress={() => this.handleRightClick()}>
  59. <Image style={styles.img} source={this.props.rightIcon}/>
  60. </TouchableOpacity>
  61. )
  62. }
  63. {
  64. Utils.isEmpty(this.props.rightBtnText) ? (null) : (
  65. <Button
  66. onPress={() => this.props.handleRightBtnClick()}
  67. title={this.props.rightBtnText}
  68. color="#19AD17"
  69. />
  70. )
  71. }
  72. </View>
  73. </View>
  74. </View>
  75. );
  76. }
  77. render() {
  78. if (Platform.OS === 'ios') {
  79. return this.renderIOS();
  80. }
  81. return this.renderAndroid();
  82. }
  83. handleRightClick() {
  84. if (!Utils.isEmpty(this.props.handleRightClick)) {
  85. this.props.handleRightClick();
  86. }
  87. }
  88. handleBackClick = () => {
  89. this.props.nav.goBack();
  90. }
  91. }
  92. const styles = StyleSheet.create({
  93. container: {
  94. flexDirection: 'column',
  95. },
  96. content: {
  97. width: width,
  98. height: 50,
  99. backgroundColor: Global.titleBackgroundColor,
  100. flexDirection: 'row',
  101. alignItems: 'center'
  102. },
  103. backBtn: {
  104. marginLeft: 8,
  105. marginRight: 8,
  106. width: 30,
  107. height: 30,
  108. },
  109. btnDivider: {
  110. width: 1 / PixelRatio.get(),
  111. height: 30,
  112. marginTop: 10,
  113. marginBottom: 10,
  114. backgroundColor: '#888888'
  115. },
  116. titleContainer: {
  117. flex: 1,
  118. flexDirection: 'row',
  119. alignItems: 'center',
  120. paddingLeft: 10,
  121. paddingRight: 10,
  122. },
  123. title: {
  124. color: '#FFFFFF',
  125. fontSize: 16,
  126. flex: 1,
  127. },
  128. img: {
  129. width: 30,
  130. height: 30,
  131. marginRight: 5
  132. }
  133. });