SchedulePage.js 7.2 KB

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