CourseTitle.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. /** 因没有图,所以Image先用颜色代替,有图可替换 */
  15. const instructions = Platform.select({
  16. ios: "Press Cmd+R to reload,\n" + "Cmd+D or shake for dev menu",
  17. android:
  18. "Double tap R on your keyboard to reload,\n" +
  19. "Shake or press menu button for dev menu"
  20. });
  21. type Props = {};
  22. var width = Dimensions.get("window").width;
  23. var height = Dimensions.get("window").height;
  24. export default class CourseTitle extends Component<Props> {
  25. render() {
  26. return (
  27. <View
  28. style={{
  29. backgroundColor: "withe",
  30. width: this.props.width,
  31. height: this.props.height,
  32. flexDirection: "column"
  33. }}
  34. >
  35. <View
  36. style={{
  37. flex: 1
  38. }}
  39. />
  40. <View
  41. style={{
  42. flex: 1,
  43. flexDirection: "row"
  44. }}
  45. >
  46. <View
  47. style={{
  48. flex: 1,
  49. alignItems: "center",
  50. justifyContent: "center"
  51. }}
  52. >
  53. <TouchableOpacity
  54. //返回
  55. activeOpacity={1}
  56. onPress={this.props.backPress}
  57. >
  58. <Image
  59. style={{ width: 20, height: 20, backgroundColor: "blue" }}
  60. />
  61. </TouchableOpacity>
  62. </View>
  63. <View style={{ flex: 5 }}>
  64. <Text
  65. style={{
  66. width: "100%",
  67. fontSize: 18,
  68. fontWeight: "bold",
  69. textAlign: "center"
  70. }}
  71. >
  72. {this.props.title}
  73. </Text>
  74. </View>
  75. <View style={{ flex: 1 }}>
  76. <TouchableOpacity
  77. //分享
  78. activeOpacity={1}
  79. onPress={this.props.sharedpress}
  80. >
  81. <Image
  82. style={{ width: 20, height: 20, backgroundColor: "blue" }}
  83. />
  84. </TouchableOpacity>
  85. </View>
  86. </View>
  87. <View
  88. style={{
  89. flex: 1
  90. }}
  91. />
  92. </View>
  93. );
  94. }
  95. }
  96. /**
  97. 使用方法
  98. <CourseTitle
  99. width={150}
  100. height={50}
  101. title="学前"
  102. backPress={() => this.goBack()}
  103. sharedpress={() => alert("点击分享")}
  104. />
  105. */