Header.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. width: 320,
  39. fontSize: 18,
  40. fontWeight: "bold",
  41. textAlign: "left",
  42. textAlignVertical: "bottom",
  43. color: "#3f3f3f"
  44. },
  45. leftBottomRow: {
  46. flexDirection: "row",
  47. alignItems: "center"
  48. },
  49. flowerIcon:{
  50. alignItems: "center",
  51. justifyContent: "center",
  52. width: 12,
  53. height: 12,
  54. backgroundColor: "blue"
  55. },
  56. flowerNumber:{
  57. textAlignVertical: "center",
  58. marginLeft: 3
  59. }
  60. })
  61. export default class Header extends Component<Props> {
  62. render() {
  63. return (
  64. <TouchableOpacity activeOpacity={1} onPress={this.props.onPress}>
  65. <View
  66. style={styles.wrapper}
  67. >
  68. <Image
  69. source={{
  70. uri: this.props.uri
  71. }}
  72. style={styles.avatar}
  73. />
  74. <View
  75. style={styles.leftBox}
  76. >
  77. <Text
  78. style={styles.userName}
  79. >
  80. {this.props.username}
  81. </Text>
  82. <View
  83. style={styles.leftBottomRow}
  84. >
  85. <Image
  86. // source={{
  87. // uri: this.props.uri
  88. // }}
  89. style={styles.flowerIcon}
  90. />
  91. <Text
  92. style={styles.flowerNumber}
  93. >
  94. {this.props.flowerNumber}
  95. </Text>
  96. </View>
  97. </View>
  98. </View>
  99. </TouchableOpacity>
  100. );
  101. }
  102. }
  103. /**
  104. 使用方法
  105. <Header
  106. uri="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1295208965,3056573814&amp;fm=26&amp;gp=0.jpg"
  107. username="卡通笨笨熊"
  108. flowerNumber="123234"
  109. onPress={() => this.toNextPage("MainActivity")}
  110. />
  111. */