ScrollRow.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. export default class ScrollRow extends Component {
  20. render() {
  21. return (
  22. <FlatList
  23. data={this.props.data}
  24. horizontal={true}
  25. renderItem={({ item, separators }) => this.renderItem(item, separators)}
  26. />
  27. )
  28. }
  29. renderItem(item, separators) {
  30. const courseId = item.course ? item.course.id : item.operationContent;
  31. return (
  32. <TouchableOpacity
  33. style={{
  34. // flex: 1,
  35. height: this.props.itemHeight,
  36. width: this.props.itemWidth,
  37. flexDirection: 'row',
  38. alignItems: 'center',
  39. marginLeft: 9,
  40. }}
  41. onPress={() => this.playOrGoback(courseId, item.playUrl)}
  42. activeOpacity={1}
  43. >
  44. <View style={{
  45. height: this.props.itemHeight,
  46. width: this.props.itemWidth,
  47. flexDirection: 'column',
  48. alignItems: 'center',
  49. // flex: 1,
  50. }}>
  51. <Image
  52. source={{
  53. uri: item.zoneCourse ? item.zoneCourse.iconImg : item.iconImg ? item.iconImg : item.boothContent
  54. // uri: item.icon
  55. }}
  56. style={{
  57. borderRadius: 10,
  58. width: this.props.itemWidth,
  59. height: this.props.itemHeight,
  60. marginBottom: 6,
  61. }}
  62. />
  63. {item.summary
  64. ?
  65. <Text style={styles.itemSummary}>
  66. {item.summary}
  67. </Text>
  68. :
  69. item.title
  70. ?
  71. <Text style={styles.itemSummary}>
  72. {item.title}
  73. </Text>
  74. :
  75. null
  76. }
  77. </View>
  78. </TouchableOpacity>
  79. )
  80. }
  81. playOrGoback(courseId, playUrl) {
  82. if (this.props.type) {
  83. this.props.changeUri(playUrl)
  84. } else {
  85. this.props.nav('CourseDetails', {courseId})
  86. }
  87. }
  88. }
  89. const styles = StyleSheet.create({
  90. wrapper: {
  91. },
  92. itemSummary: {
  93. // flex:1,
  94. width: '100%',
  95. height: 20,
  96. alignItems: 'center',
  97. justifyContent: "flex-start",
  98. color: '#151515',
  99. fontSize: 13,
  100. }
  101. })