ScrollRow.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * @param:
  3. * itemWidth: 每一个图片宽度
  4. * itemHeight: 每一个图片高度
  5. * data: 数据 Arrary
  6. */
  7. import React, { Component } from "react";
  8. import {
  9. StyleSheet,
  10. Text,
  11. View,
  12. FlatList,
  13. TouchableOpacity,
  14. Image
  15. } from "react-native";
  16. import Dimensions from '../utils/dimensions'
  17. export default class ScrollRow extends Component {
  18. render() {
  19. return (
  20. <FlatList
  21. data={[{
  22. summary: 'Title Text', key: 'item1', icon:
  23. "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",
  24. }, {
  25. summary: 'Title Text', key: 'item2', icon:
  26. "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",
  27. }, {
  28. summary: 'Title Text', key: 'item3', icon:
  29. "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",
  30. }, {
  31. summary: 'Title Text', key: 'item4', icon:
  32. "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",
  33. }, {
  34. title: 'Title Text', key: 'item5', icon:
  35. "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",
  36. }, {
  37. summary: 'Title Text', key: 'item6', icon:
  38. "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",
  39. }]}
  40. horizontal={true}
  41. renderItem={({ item, separators }) => this.renderItem(item, separators)}
  42. />
  43. )
  44. }
  45. renderItem(item, separators) {
  46. return (
  47. <TouchableOpacity
  48. style={{
  49. // flex: 1,
  50. height: this.props.itemHeight,
  51. width: this.props.itemWidth,
  52. flexDirection: 'row',
  53. alignItems: 'center',
  54. marginLeft: 9,
  55. }}
  56. onPress={() => {
  57. alert(item.title);
  58. }}
  59. activeOpacity={1}
  60. >
  61. <View style={{
  62. height: this.props.itemHeight,
  63. width: this.props.itemWidth,
  64. flexDirection: 'column',
  65. alignItems: 'center',
  66. // flex: 1,
  67. }}>
  68. <Image
  69. source={{
  70. uri: item.icon
  71. }}
  72. style={{
  73. borderRadius: 10,
  74. width: this.props.itemWidth,
  75. height: this.props.itemHeight,
  76. marginBottom: 6,
  77. }}
  78. />
  79. {item.summary
  80. ?
  81. <Text style={styles.itemSummary}>
  82. {item.summary}
  83. </Text>
  84. :
  85. null
  86. }
  87. </View>
  88. </TouchableOpacity>
  89. )
  90. }
  91. }
  92. const styles = StyleSheet.create({
  93. wrapper: {
  94. },
  95. itemSummary: {
  96. // flex:1,
  97. width: '100%',
  98. height: 20,
  99. alignItems: 'center',
  100. justifyContent: "flex-start",
  101. color: '#151515',
  102. fontSize: 13,
  103. }
  104. })