CourseTitle.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. flex: 1,
  30. width: this.props.width,
  31. height: this.props.height,
  32. flexDirection: "column",
  33. // backgroundColor: this.props.backgroundColor ? this.props.backgroundColor : '#fff'
  34. }}
  35. >
  36. <View
  37. style={{
  38. flex: 1
  39. }}
  40. />
  41. <View
  42. style={{
  43. flex: 1,
  44. flexDirection: "row",
  45. alignItems: 'center'
  46. }}
  47. >
  48. <View
  49. style={{
  50. flex: 1,
  51. alignItems: "center",
  52. justifyContent: "center"
  53. }}
  54. >
  55. <TouchableOpacity activeOpacity={1} onPress={this.props.backPress}>
  56. {this.selectleftIcon()}
  57. </TouchableOpacity>
  58. </View>
  59. <View
  60. style={{
  61. flex: 5,
  62. alignItems: "center",
  63. justifyContent: "center"
  64. }}
  65. >
  66. <Text
  67. style={{
  68. width: "100%",
  69. fontSize: 16,
  70. fontWeight: "bold",
  71. color: this.props.textcolor,
  72. textAlign: "center"
  73. }}
  74. >
  75. {this.props.title}
  76. </Text>
  77. </View>
  78. <View
  79. style={{
  80. flex: 1,
  81. alignItems: "center",
  82. justifyContent: "center"
  83. }}
  84. >
  85. <TouchableOpacity activeOpacity={1} onPress={this.props.rightPress}>
  86. {this.props.righttype ? this.selectRightIcon() : null}
  87. </TouchableOpacity>
  88. </View>
  89. </View>
  90. <View
  91. style={{
  92. flex: 1
  93. }}
  94. />
  95. </View>
  96. );
  97. }
  98. selectleftIcon() {
  99. let type = this.props.lefttype;
  100. let back = "";
  101. switch (type) {
  102. case 1:
  103. //左侧返回图片1
  104. back = require("../images/schedulePage/back_black.png");
  105. break;
  106. case 2:
  107. //左侧返回图片2
  108. back = require("../images/userInfo/back_white.png");
  109. break;
  110. }
  111. return (
  112. <Image
  113. source={back}
  114. style={{
  115. width: 20,
  116. height: 20,
  117. resizeMode: "contain"
  118. }}
  119. />
  120. );
  121. }
  122. selectRightIcon() {
  123. let type = this.props.righttype;
  124. let right = "";
  125. switch (type) {
  126. case 1:
  127. //课程表标题,右侧是分享
  128. right = require("../images/common/share.png");
  129. break;
  130. case 2:
  131. //个人中心,右侧是设置
  132. right = require("../images/common/setting.png");
  133. break;
  134. default:
  135. return true;
  136. }
  137. return (
  138. <Image
  139. source={right}
  140. style={{
  141. width: 30,
  142. height: 30
  143. }}
  144. />
  145. );
  146. }
  147. }
  148. /**
  149. <CourseTitle
  150. width={this.getWindowWidth()}
  151. title="第12周 爱上幼儿园"
  152. //设置左侧按钮样式
  153. lefttype={2}
  154. //设置右侧按钮样式
  155. righttype={1}
  156. //设置文字颜色
  157. textcolor={"red"}
  158. // backPress={() => this.goBack()}
  159. //左侧按钮方法
  160. backPress={() => alert("点击返回")}
  161. //右侧按钮方法
  162. rightPress={() => alert("点击分享")}
  163. />
  164. </View>
  165. */