SchedulePage.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. const instructions = Platform.select({
  33. ios: "Press Cmd+R to reload,\n" + "Cmd+D or shake for dev menu",
  34. android:
  35. "Double tap R on your keyboard to reload,\n" +
  36. "Shake or press menu button for dev menu"
  37. });
  38. type Props = {};
  39. export default class SchedulePage extends BasePage {
  40. constructor(props) {
  41. super(props);
  42. this.state = {
  43. statusbar_hidden: false,
  44. video_show: false,
  45. x: 0.0,
  46. y: 0.0,
  47. videoImg_flex: 1,
  48. videoImage_width: 0,
  49. videoImage_height: 0,
  50. videoImage_x: 0.0,
  51. videoImage_y: 0.0,
  52. video_uri:
  53. "https://www.apple.com/105/media/cn/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-cn-20170912_1280x720h.mp4",
  54. title_height: "9%",
  55. video_frame_height: "32%",
  56. seat_height: "2%",
  57. flatlist_height: "60%",
  58. isFull: false,
  59. playing_key: 0
  60. };
  61. }
  62. render() {
  63. return (
  64. <View
  65. style={{
  66. flex: 1
  67. }}
  68. >
  69. <StatusBar
  70. // backgroundColor={"transparent"}
  71. barStyle={"dark-content"}
  72. backgroundColor={"white"}
  73. translucent={false}
  74. hidden={this.state.statusbar_hidden}
  75. />
  76. <View
  77. style={{
  78. flex: 1,
  79. backgroundColor: "#F3F3F3",
  80. justifyContent: "center",
  81. alignItems: "center"
  82. }}
  83. >
  84. <View
  85. style={{
  86. height: this.state.title_height,
  87. backgroundColor: "white"
  88. }}
  89. >
  90. <CourseTitle
  91. width={this.getWindowWidth()}
  92. title="第12周 爱上幼儿园"
  93. lefttype={1}
  94. righttype={1}
  95. textcolor={"#231F20"}
  96. backPress={() => this.goBack()}
  97. // backPress={() => alert("左侧按钮")}
  98. rightPress={this.showSharedDialog.bind(this)}
  99. />
  100. </View>
  101. <View
  102. style={{
  103. height: this.state.video_frame_height,
  104. width: "100%"
  105. }}
  106. >
  107. <Image
  108. source={{
  109. uri:
  110. "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"
  111. }}
  112. style={{
  113. width: "100%",
  114. height: "100%"
  115. }}
  116. ref={c => {
  117. this.video_image = c;
  118. }}
  119. />
  120. </View>
  121. <View
  122. style={{
  123. height: this.state.seat_height
  124. }}
  125. />
  126. <View
  127. style={{
  128. height: this.state.flatlist_height,
  129. justifyContent: "center",
  130. alignItems: "center",
  131. width: "100%"
  132. }}
  133. >
  134. <FlatList
  135. ItemSeparatorComponent={() => (
  136. <View
  137. style={{
  138. height: 10
  139. }}
  140. />
  141. )}
  142. ListFooterComponent={() => (
  143. <View
  144. style={{
  145. height: 30
  146. }}
  147. />
  148. )}
  149. renderItem={({ item }) => {
  150. return this.loadFlatItem(item);
  151. }}
  152. keyExtractor={(item, index) => item.key.toString()}
  153. horizontal={false}
  154. data={[
  155. {
  156. key: 1,
  157. typecolor: "#74E0FF",
  158. typename: "习惯养成",
  159. videoname: "碗里不剩一粒米",
  160. videourl: "碗里不剩一粒米xxxx"
  161. },
  162. {
  163. key: 2,
  164. typecolor: "#FB5B76",
  165. typename: "品格礼仪",
  166. videoname: "我有很多朋友",
  167. videourl: "我有很多朋友xxxx"
  168. },
  169. {
  170. key: 3,
  171. typecolor: "#EC48E1",
  172. typename: "自我保护",
  173. videoname: "小猫喵喵叫",
  174. videourl: "小猫喵喵叫xxxx"
  175. },
  176. {
  177. key: 4,
  178. typecolor: "#39D6B9",
  179. typename: "亲子游戏",
  180. videoname: "安静的睡前游戏-全家人都睡了",
  181. videourl: "安静的睡前游戏xxxx"
  182. },
  183. {
  184. key: 5,
  185. typecolor: "#3397F0",
  186. typename: "欢乐音乐",
  187. videoname: "小鸡捉虫子",
  188. videourl: "小鸡捉虫子xxxx"
  189. },
  190. {
  191. key: 11,
  192. typecolor: "#74E0FF",
  193. typename: "习惯养成",
  194. videoname: "碗里不剩一粒米",
  195. videourl: "碗里不剩一粒米xxxx"
  196. },
  197. {
  198. key: 12,
  199. typecolor: "#FB5B76",
  200. typename: "品格礼仪",
  201. videoname: "我有很多朋友",
  202. videourl: "我有很多朋友xxxx"
  203. },
  204. {
  205. key: 13,
  206. typecolor: "#EC48E1",
  207. typename: "自我保护",
  208. videoname: "小猫喵喵叫",
  209. videourl: "小猫喵喵叫xxxx"
  210. },
  211. {
  212. key: 14,
  213. typecolor: "#39D6B9",
  214. typename: "亲子游戏",
  215. videoname: "安静的睡前游戏-全家人都睡了",
  216. videourl:
  217. "https://www.apple.com/105/media/cn/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-cn-20170912_1280x720h.mp4"
  218. },
  219. {
  220. key: 15,
  221. typecolor: "#3397F0",
  222. typename: "欢乐音乐",
  223. videoname: "小鸡捉虫子",
  224. videourl: "http://chimee.org/vod/1.mp4"
  225. }
  226. ]}
  227. />
  228. </View>
  229. </View>
  230. <CusVideo
  231. show={this.state.video_show}
  232. uri={this.state.video_uri}
  233. ref={view => (this.video = view)}
  234. needback={false}
  235. videofullScreenPlayer={this.fullScreenPlayer.bind(this)}
  236. onError={this.onError.bind(this)}
  237. onEnd={this.onEnd.bind(this)}
  238. style={{
  239. left: this.state.x,
  240. top: this.state.y,
  241. width: this.state.video_width,
  242. height: this.state.video_height,
  243. overflow: "hidden",
  244. position: "absolute"
  245. }}
  246. />
  247. <SharedDialog ref={view => (this.shareddialog = view)} />
  248. </View>
  249. );
  250. }
  251. loadFlatItem(data) {
  252. return (
  253. <ScheduleFlatItem
  254. width={this.getWindowWidth() * 0.9}
  255. height={50}
  256. data={data}
  257. onPress={() => this.changeUrl(data)}
  258. />
  259. );
  260. }
  261. componentWillMount() {
  262. BackHandler.addEventListener("hardwareBackPress", this.onBackAndroid);
  263. }
  264. componentWillUnmount() {
  265. BackHandler.removeEventListener("hardwareBackPress", this.onBackAndroid);
  266. }
  267. showSharedDialog() {
  268. this.video.pause();
  269. this.shareddialog.setModalVisible(true);
  270. }
  271. onBackAndroid = () => {
  272. if (this.state.isFull) {
  273. return true;
  274. } else {
  275. }
  276. };
  277. onError() {
  278. alert("播放器异常");
  279. this.setState({
  280. video_show: false
  281. });
  282. }
  283. onEnd() {
  284. alert("播放结束");
  285. this.setState({
  286. video_show: false
  287. });
  288. this.video.refreshVideo();
  289. }
  290. fullScreenPlayer() {
  291. if (!this.state.isFull) {
  292. Orientation.lockToLandscape();
  293. this.setState({
  294. video_frame_height: "100%",
  295. statusbar_hidden: true,
  296. isFull: true,
  297. x: 0,
  298. y: 0,
  299. video_width: "100%",
  300. video_height: "100%"
  301. });
  302. } else {
  303. Orientation.lockToPortrait();
  304. this.setState({
  305. video_frame_height: "32%",
  306. x: this.state.videoImage_x,
  307. y: this.state.videoImage_y,
  308. video_width: this.state.videoImage_width,
  309. video_height: this.state.videoImage_height,
  310. statusbar_hidden: false,
  311. isFull: false
  312. });
  313. }
  314. }
  315. changeUrl(data) {
  316. //切换视频并且播放
  317. // alert(url);
  318. if (this.state.playing_key == data.key) {
  319. return;
  320. }
  321. const handle = findNodeHandle(this.video_image);
  322. setTimeout(() => {
  323. UIManager.measure(handle, (x, y, width, height, pageX, pageY) => {
  324. this.setState({
  325. x: pageX,
  326. y: pageY,
  327. video_width: width,
  328. video_height: height,
  329. videoImage_width: width,
  330. videoImage_height: height,
  331. videoImage_x: pageX,
  332. videoImage_y: pageY,
  333. video_show: true,
  334. video_uri: data.videourl,
  335. playing_key: data.key
  336. });
  337. });
  338. }, 0);
  339. this.video.start();
  340. }
  341. }