Header.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * @param: uri String, username String,flowerNumber String, onPressCallback function
  3. *
  4. */
  5. import React, { Component } from "react";
  6. import {
  7. StyleSheet,
  8. Text,
  9. View,
  10. Image,
  11. TouchableOpacity,
  12. } from "react-native";
  13. import Dimensions from '../utils/dimensions'
  14. /** 因没有图,所以Image先用颜色代替,有图可替换 */
  15. type Props = {};
  16. const styles = StyleSheet.create({
  17. wrapper: {
  18. width: Dimensions.width,
  19. height: 72,
  20. flex: 1,
  21. alignItems: "center",
  22. // backgroundColor: 'red',
  23. justifyContent: "center",
  24. flexDirection: "row"
  25. },
  26. avatar: {
  27. width: 44,
  28. height: 44,
  29. borderRadius: 50,
  30. marginLeft: 11,
  31. marginRight: 11
  32. },
  33. leftBox:{
  34. flex: 1,
  35. flexDirection: "column"
  36. },
  37. userName:{
  38. fontSize: 18,
  39. fontWeight: "bold",
  40. textAlign: "left",
  41. textAlignVertical: "bottom",
  42. color: "#3f3f3f"
  43. },
  44. leftBottomRow: {
  45. flexDirection: "row",
  46. alignItems: "center"
  47. },
  48. flowerIcon:{
  49. marginLeft: 10,
  50. alignItems: "center",
  51. justifyContent: "center",
  52. width: 27,
  53. height: 14
  54. },
  55. flowerNumber:{
  56. textAlignVertical: "center",
  57. marginLeft: 3
  58. }
  59. })
  60. export default class Header extends Component<Props> {
  61. render() {
  62. return (
  63. <View
  64. style={styles.wrapper}
  65. >
  66. <TouchableOpacity activeOpacity={1} onPress={this.props.onPress}>
  67. <Image
  68. source={this.props.uri ? {
  69. uri: this.props.uri
  70. } : require('../images/userInfo/default_photo.png')}
  71. style={styles.avatar}
  72. />
  73. </TouchableOpacity>
  74. <View
  75. style={styles.leftBox}
  76. >
  77. <View style={styles.leftBottomRow}>
  78. <Text
  79. style={styles.userName}
  80. >
  81. {this.props.isVisitor ? '新用户登录送7天VIP' : this.props.username}
  82. </Text>
  83. {
  84. this.props.isVisitor ?
  85. null
  86. :
  87. <Image
  88. source={this.props.isVip ? require("../images/common/vip.png") : require("../images/common/novip.png")}
  89. style={styles.flowerIcon}
  90. />
  91. }
  92. </View>
  93. <TouchableOpacity activeOpacity={1} onPress={ () => this.click()}>
  94. <Text
  95. style={styles.flowerNumber}
  96. >
  97. {this.props.isVisitor ? '立即登录' : this.props.isVip ? '' : '开通VIP'}
  98. </Text>
  99. </TouchableOpacity>
  100. </View>
  101. </View>
  102. );
  103. }
  104. click() {
  105. // alert(this.props.isVisitor)
  106. // this.props.nav('Loading')
  107. if (this.props.isVisitor) {
  108. this.props.nav('Login')
  109. } else if (!this.props.isVip) {
  110. this.props.nav('Buy')
  111. }
  112. }
  113. }
  114. /**
  115. 使用方法
  116. <Header
  117. uri="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1295208965,3056573814&amp;fm=26&amp;gp=0.jpg"
  118. username="卡通笨笨熊"
  119. flowerNumber="123234"
  120. onPress={() => this.toNextPage("MainActivity")}
  121. />
  122. */