SchedulePage.js 9.0 KB

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