SchedulePage.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. let colorTemp = '';
  200. let colorIndexTemp = 0;
  201. const colorList = this.state.colorList;
  202. ScheduleUrl.getSchedule('KINDERGARTEN').success(res => {
  203. res.data.wareList.forEach((item, index) => {
  204. if (index === 0) {
  205. colorTemp = item.subTitle;
  206. }
  207. if (item.subTitle === colorTemp) {
  208. item.subColor = colorList[colorIndexTemp];
  209. } else {
  210. colorIndexTemp++;
  211. if (colorIndexTemp > colorList.length - 1) {
  212. colorIndexTemp = 0
  213. }
  214. colorTemp = item.subTitle;
  215. item.subColor = colorList[colorIndexTemp];
  216. }
  217. })
  218. this.setState({
  219. scheduleTitle: res.data.category.title,
  220. wareList: res.data.wareList
  221. })
  222. })
  223. }
  224. showSharedDialog() {
  225. this.video.pause();
  226. this.shareddialog.setModalVisible(true);
  227. }
  228. onBackAndroid = () => {
  229. if (this.state.isFull) {
  230. return true;
  231. } else {
  232. }
  233. };
  234. onError() {
  235. alert("播放器异常");
  236. this.setState({
  237. video_show: false
  238. });
  239. }
  240. onEnd() {
  241. alert("播放结束");
  242. this.setState({
  243. video_show: false
  244. });
  245. this.video.refreshVideo();
  246. }
  247. fullScreenPlayer() {
  248. if (!this.state.isFull) {
  249. Orientation.lockToLandscape();
  250. this.setState({
  251. video_frame_height: "100%",
  252. statusbar_hidden: true,
  253. isFull: true,
  254. x: 0,
  255. y: 0,
  256. video_width: "100%",
  257. video_height: "100%"
  258. });
  259. } else {
  260. Orientation.lockToPortrait();
  261. this.setState({
  262. video_frame_height: "32%",
  263. x: this.state.videoImage_x,
  264. y: this.state.videoImage_y,
  265. video_width: this.state.videoImage_width,
  266. video_height: this.state.videoImage_height,
  267. statusbar_hidden: false,
  268. isFull: false
  269. });
  270. }
  271. }
  272. changeUrl(data) {
  273. //切换视频并且播放
  274. // alert(url);
  275. // if (this.state.playing_key == data.key) {
  276. // return;
  277. // }
  278. const handle = findNodeHandle(this.video_image);
  279. setTimeout(() => {
  280. UIManager.measure(handle, (x, y, width, height, pageX, pageY) => {
  281. this.setState({
  282. x: pageX,
  283. y: pageY,
  284. video_width: width,
  285. video_height: height,
  286. videoImage_width: width,
  287. videoImage_height: height,
  288. videoImage_x: pageX,
  289. videoImage_y: pageY,
  290. video_show: true,
  291. video_uri: data.playUrl,
  292. playing_key: data.key
  293. });
  294. });
  295. }, 0);
  296. this.video.start();
  297. }
  298. }