ScrollRow.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. * @param:
  3. * itemWidth: 每一个图片宽度
  4. * itemHeight: 每一个图片高度
  5. * data: 数据 Arrary
  6. * nav: 路由方法
  7. */
  8. import React, { Component } from "react";
  9. import {
  10. StyleSheet,
  11. Text,
  12. View,
  13. FlatList,
  14. TouchableOpacity,
  15. Image
  16. } from "react-native";
  17. import BasePage from '../BasePage'
  18. import Dimensions from '../utils/dimensions'
  19. import courseDetails from '../services/courseDetails'
  20. export default class ScrollRow extends Component {
  21. render() {
  22. return (
  23. <FlatList
  24. data={this.props.data}
  25. horizontal={true}
  26. renderItem={({ item, separators }) => this.renderItem(item, separators)}
  27. keyExtractor={(item, index) => index.toString()}
  28. showsHorizontalScrollIndicator = {false}
  29. />
  30. )
  31. }
  32. renderItem(item, separators) {
  33. const courseId = item.course ? item.course.id : item.operationContent;
  34. return (
  35. <TouchableOpacity
  36. style={{
  37. // flex: 1,
  38. height: this.props.itemHeight,
  39. width: this.props.itemWidth,
  40. flexDirection: 'row',
  41. alignItems: 'center',
  42. marginLeft: 9,
  43. }}
  44. onPress={() => this.playOrGoback(courseId, item.playUrl, item)}
  45. activeOpacity={1}
  46. >
  47. <View style={{
  48. height: this.props.itemHeight,
  49. width: this.props.itemWidth,
  50. flexDirection: 'column',
  51. alignItems: 'center',
  52. position: 'relative'
  53. // flex: 1,
  54. }}>
  55. <Image
  56. source={{
  57. uri: item.zoneCourse ? item.zoneCourse.iconImg : item.iconImg ? item.iconImg : item.boothContent
  58. // uri: item.icon
  59. }}
  60. style={{
  61. borderRadius: 10,
  62. width: this.props.itemWidth,
  63. height: this.props.itemHeight,
  64. marginBottom: 6,
  65. }}
  66. />
  67. {item.summary
  68. ?
  69. <Text style={styles.itemSummary}>
  70. {item.summary}
  71. </Text>
  72. :
  73. item.title
  74. ?
  75. <Text style={styles.itemSummary}>
  76. {item.title}
  77. </Text>
  78. :
  79. null
  80. }
  81. {
  82. item.price ?
  83. <Image
  84. // source={ require('../images/courseDetails/nobuy.png')}
  85. style={{
  86. position: 'absolute',
  87. width: 30,
  88. height: 30
  89. }}
  90. />
  91. :
  92. null
  93. }
  94. </View>
  95. </TouchableOpacity>
  96. )
  97. }
  98. playOrGoback(courseId, playUrl, item) {
  99. if (this.props.type) {
  100. this.props.changeUri(playUrl)
  101. courseDetails.playLog({
  102. "title": item.title,
  103. "url": item.playUrl,
  104. courseId,
  105. "courseWareId": item.id,
  106. "playStopTime": "",
  107. "type": "LIBRARY",
  108. "platFormType": "MOBILE"
  109. }).then( res => console.log('添加播放记录', res))
  110. .catch( error => console.log(error))
  111. } else {
  112. this.props.nav('CourseDetails', {courseId})
  113. }
  114. }
  115. }
  116. const styles = StyleSheet.create({
  117. wrapper: {
  118. },
  119. itemSummary: {
  120. // flex:1,
  121. width: '100%',
  122. height: 20,
  123. alignItems: 'center',
  124. justifyContent: "flex-start",
  125. color: '#151515',
  126. fontSize: 13,
  127. }
  128. })