Header.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import React, { Component } from "react";
  2. import {
  3. Platform,
  4. StyleSheet,
  5. Text,
  6. View,
  7. Image,
  8. TouchableOpacity,
  9. ImageBackground,
  10. Button,
  11. Dimensions,
  12. DeviceEventEmitter
  13. } from "react-native";
  14. const instructions = Platform.select({
  15. ios: "Press Cmd+R to reload,\n" + "Cmd+D or shake for dev menu",
  16. android:
  17. "Double tap R on your keyboard to reload,\n" +
  18. "Shake or press menu button for dev menu"
  19. });
  20. type Props = {};
  21. var width = Dimensions.get("window").width;
  22. var height = Dimensions.get("window").height;
  23. export default class Header extends Component<Props> {
  24. render() {
  25. return (
  26. <TouchableOpacity onPress={this.props.onPress}>
  27. <View
  28. style={{
  29. width: this.props.width,
  30. height: this.props.height,
  31. flexDirection: "column"
  32. }}
  33. >
  34. <View style={{ flex: 1 }} />
  35. <View
  36. style={{
  37. flex: 1,
  38. alignItems: "center",
  39. justifyContent: "center",
  40. flexDirection: "row"
  41. }}
  42. >
  43. <Image
  44. source={{
  45. uri: this.props.uri
  46. }}
  47. style={{
  48. width: 60,
  49. height: 60,
  50. borderRadius: 50
  51. }}
  52. />
  53. <View
  54. style={{
  55. flex: 0.1
  56. }}
  57. />
  58. <View
  59. style={{
  60. flex: 10,
  61. width: "100%",
  62. height: "100%",
  63. flexDirection: "column"
  64. }}
  65. >
  66. <Text
  67. style={{
  68. width: "100%",
  69. height: "50%",
  70. fontSize: 18,
  71. fontWeight: "bold",
  72. textAlign: "left",
  73. textAlignVertical: "bottom"
  74. }}
  75. >
  76. {this.props.username}
  77. </Text>
  78. <View
  79. style={{
  80. flex: 2,
  81. flexDirection: "row"
  82. }}
  83. >
  84. <Image
  85. source={{
  86. uri: this.props.uri
  87. }}
  88. style={{
  89. alignItems: "center",
  90. justifyContent: "center",
  91. width: 20,
  92. height: 20
  93. }}
  94. />
  95. <Text
  96. style={{
  97. flex: 1,
  98. textAlignVertical: "center",
  99. marginLeft: 2
  100. }}
  101. >
  102. {this.props.flowerNumber}
  103. </Text>
  104. </View>
  105. </View>
  106. </View>
  107. <View style={{ flex: 1 }} />
  108. </View>
  109. </TouchableOpacity>
  110. );
  111. }
  112. }
  113. /**
  114. 使用方法
  115. <Header
  116. uri="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1295208965,3056573814&amp;fm=26&amp;gp=0.jpg"
  117. width={400}
  118. height={150}
  119. username="卡通笨笨熊"
  120. flowerNumber="123234"
  121. onPress={() => this.toNextPage("MainActivity")}
  122. />
  123. */