SchedulePage.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow
  7. */
  8. import React, { Component } from "react";
  9. import {
  10. Platform,
  11. StyleSheet,
  12. Text,
  13. View,
  14. Image,
  15. TouchableOpacity,
  16. ImageBackground,
  17. FlatList,
  18. findNodeHandle,
  19. UIManager,
  20. StatusBar,
  21. BackHandler,
  22. Button,
  23. DeviceEventEmitter
  24. } from "react-native";
  25. import Orientation from "react-native-orientation";
  26. import AndroidUtil from "../../util/AndroidUtil";
  27. import BasePage from "../BasePage";
  28. import CourseTitle from "./CourseTitle";
  29. import SharedDialog from "./SharedDialog";
  30. import ScheduleFlatItem from "./ScheduleFlatItem";
  31. import CusVideo from "./CusVideo";
  32. import ScheduleUrl from '../services/schedule'
  33. export default class SchedulePage extends BasePage {
  34. constructor(props) {
  35. super(props);
  36. this.state = {
  37. statusbar_hidden: false,
  38. video_show: false,
  39. x: 0.0,
  40. y: 0.0,
  41. videoImg_flex: 1,
  42. videoImage_width: 0,
  43. videoImage_height: 0,
  44. videoImage_x: 0.0,
  45. videoImage_y: 0.0,
  46. video_uri:
  47. "https://www.apple.com/105/media/cn/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-cn-20170912_1280x720h.mp4",
  48. title_height: "9%",
  49. video_frame_height: "32%",
  50. seat_height: "2%",
  51. flatlist_height: "60%",
  52. isFull: false,
  53. playing_key: 0,
  54. scheduleTitle: '',
  55. wareList: [],
  56. colorList: [
  57. '#FFBC3D',
  58. '#FB5B76',
  59. '#EC48E1',
  60. '#39D6B9',
  61. '#3397F0'
  62. ]
  63. };
  64. }
  65. render() {
  66. return (
  67. <View
  68. style={{
  69. flex: 1
  70. }}
  71. >
  72. <StatusBar
  73. // backgroundColor={"transparent"}
  74. barStyle={"dark-content"}
  75. backgroundColor={"white"}
  76. translucent={false}
  77. hidden={this.state.statusbar_hidden}
  78. />
  79. <View
  80. style={{
  81. flex: 1,
  82. backgroundColor: "#F3F3F3",
  83. justifyContent: "center",
  84. alignItems: "center"
  85. }}
  86. >
  87. <View
  88. style={{
  89. height: this.state.title_height,
  90. backgroundColor: "white"
  91. }}
  92. >
  93. <CourseTitle
  94. width={this.getWindowWidth()}
  95. title={this.state.scheduleTitle}
  96. lefttype={1}
  97. righttype={1}
  98. textcolor={"#231F20"}
  99. backPress={() => this.goBack()}
  100. // backPress={() => alert("左侧按钮")}
  101. rightPress={this.showSharedDialog.bind(this)}
  102. />
  103. </View>
  104. <View
  105. style={{
  106. height: this.state.video_frame_height,
  107. width: "100%"
  108. }}
  109. >
  110. <Image
  111. source={{
  112. uri:
  113. "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556277324856&di=dc1548a0c5ba10481af922e174912937&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F05%2F12%2F82c4568a90055adcf8fbb896f0841c69.jpg"
  114. }}
  115. style={{
  116. width: "100%",
  117. height: "100%"
  118. }}
  119. ref={c => {
  120. this.video_image = c;
  121. }}
  122. />
  123. </View>
  124. <View
  125. style={{
  126. height: this.state.seat_height
  127. }}
  128. />
  129. <View
  130. style={{
  131. height: this.state.flatlist_height,
  132. justifyContent: "center",
  133. alignItems: "center",
  134. width: "100%"
  135. }}
  136. >
  137. <FlatList
  138. ItemSeparatorComponent={() => (
  139. <View
  140. style={{
  141. height: 10
  142. }}
  143. />
  144. )}
  145. ListFooterComponent={() => (
  146. <View
  147. style={{
  148. height: 30
  149. }}
  150. />
  151. )}
  152. renderItem={({ item }) => {
  153. return this.loadFlatItem(item);
  154. }}
  155. keyExtractor={(item, index) => item.id.toString()}
  156. horizontal={false}
  157. data={this.state.wareList}
  158. />
  159. </View>
  160. </View>
  161. <CusVideo
  162. show={this.state.video_show}
  163. uri={this.state.video_uri}
  164. ref={view => (this.video = view)}
  165. needback={false}
  166. videofullScreenPlayer={this.fullScreenPlayer.bind(this)}
  167. onError={this.onError.bind(this)}
  168. onEnd={this.onEnd.bind(this)}
  169. style={{
  170. left: this.state.x,
  171. top: this.state.y,
  172. width: this.state.video_width,
  173. height: this.state.video_height,
  174. overflow: "hidden",
  175. position: "absolute"
  176. }}
  177. />
  178. <SharedDialog ref={view => (this.shareddialog = view)} />
  179. </View>
  180. );
  181. }
  182. loadFlatItem(data) {
  183. return (
  184. <ScheduleFlatItem
  185. width={this.getWindowWidth() * 0.9}
  186. height={50}
  187. data={data}
  188. onPress={() => this.changeUrl(data)}
  189. />
  190. );
  191. }
  192. componentWillMount() {
  193. BackHandler.addEventListener("hardwareBackPress", this.onBackAndroid);
  194. }
  195. componentWillUnmount() {
  196. BackHandler.removeEventListener("hardwareBackPress", this.onBackAndroid);
  197. }
  198. componentDidMount() {
  199. const { id } = this.props.navigation.state.params;
  200. alert(id)
  201. let colorTemp = '';
  202. let colorIndexTemp = 0;
  203. const colorList = this.state.colorList;
  204. ScheduleUrl.getSchedule('KINDERGARTEN').success(res => {
  205. res.data.wareList.forEach((item, index) => {
  206. if (index === 0) {
  207. colorTemp = item.subTitle;
  208. }
  209. if (item.subTitle === colorTemp) {
  210. item.subColor = colorList[colorIndexTemp];
  211. } else {
  212. colorIndexTemp++;
  213. if (colorIndexTemp > colorList.length - 1) {
  214. colorIndexTemp = 0
  215. }
  216. colorTemp = item.subTitle;
  217. item.subColor = colorList[colorIndexTemp];
  218. }
  219. })
  220. this.setState({
  221. scheduleTitle: res.data.category.title,
  222. wareList: res.data.wareList
  223. })
  224. })
  225. }
  226. showSharedDialog() {
  227. this.video.pause();
  228. this.shareddialog.setModalVisible(true);
  229. }
  230. onBackAndroid = () => {
  231. if (this.state.isFull) {
  232. return true;
  233. } else {
  234. }
  235. };
  236. onError() {
  237. alert("播放器异常");
  238. this.setState({
  239. video_show: false
  240. });
  241. }
  242. onEnd() {
  243. alert("播放结束");
  244. this.setState({
  245. video_show: false
  246. });
  247. this.video.refreshVideo();
  248. }
  249. fullScreenPlayer() {
  250. if (!this.state.isFull) {
  251. Orientation.lockToLandscape();
  252. this.setState({
  253. video_frame_height: "100%",
  254. statusbar_hidden: true,
  255. isFull: true,
  256. x: 0,
  257. y: 0,
  258. video_width: "100%",
  259. video_height: "100%"
  260. });
  261. } else {
  262. Orientation.lockToPortrait();
  263. this.setState({
  264. video_frame_height: "32%",
  265. x: this.state.videoImage_x,
  266. y: this.state.videoImage_y,
  267. video_width: this.state.videoImage_width,
  268. video_height: this.state.videoImage_height,
  269. statusbar_hidden: false,
  270. isFull: false
  271. });
  272. }
  273. }
  274. changeUrl(data) {
  275. //切换视频并且播放
  276. // alert(url);
  277. // if (this.state.playing_key == data.key) {
  278. // return;
  279. // }
  280. const handle = findNodeHandle(this.video_image);
  281. setTimeout(() => {
  282. UIManager.measure(handle, (x, y, width, height, pageX, pageY) => {
  283. this.setState({
  284. x: pageX,
  285. y: pageY,
  286. video_width: width,
  287. video_height: height,
  288. videoImage_width: width,
  289. videoImage_height: height,
  290. videoImage_x: pageX,
  291. videoImage_y: pageY,
  292. video_show: true,
  293. video_uri: data.playUrl,
  294. playing_key: data.key
  295. });
  296. });
  297. }, 0);
  298. this.video.start();
  299. }
  300. }