Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. import React from "react";
  2. import { View, Image, Text, TouchableOpacity, StyleSheet } from "react-native";
  3.  
  4. import images from "../../../assets/images";
  5. import { responsiveWidth } from "react-native-responsive-dimensions";
  6. import {connect} from 'react-redux';
  7.  
  8. /**
  9. * Created by MaRoCa on 02/18/2020.
  10. */
  11. class BrandListItem extends React.Component {
  12. constructor(props) {
  13. super(props);
  14.  
  15. const img = this.props.item.img_url;
  16. this.state = {
  17. searchField: "",
  18. items: [],
  19. allitems : [],
  20. img: img
  21. ? {
  22. uri: this.props.item.img_url
  23. }
  24. : images.imgBrandPlaceholder
  25. };
  26. }
  27. componentWillReceiveProps(nextProps){
  28. this.setState({searchField:nextProps.searchText})
  29. }
  30. formatToTitleCase = str => {
  31. let updatedStr = str.toLowerCase().split(" ");
  32.  
  33. for (var i = 0; i < updatedStr.length; i++) {
  34. updatedStr[i] = updatedStr[i][0].toUpperCase() + updatedStr[i].slice(1);
  35. }
  36. updatedStr = updatedStr.join(" ");
  37.  
  38. return updatedStr;
  39. };
  40.  
  41. onErrorLoadingImg = img => {
  42. this.setState({ img: img });
  43. };
  44. brandItem = () =>{
  45. // const allItem= []
  46. const item = this.props.item
  47. // allItem.push(item)
  48. // this.setState({items:[...this.state.items,...allItem]})
  49. // const filteredItems = this.state.items.filter(value=>{
  50. // return value.brand.toLowerCase().includes(this.state.searchField.toLowerCase())
  51. // })
  52. return item
  53. }
  54.  
  55. render() {
  56. const item = this.brandItem()
  57. console.log("state",this.state.items)
  58. return (
  59. <View style={{ flex: 1 }}>
  60. <TouchableOpacity
  61. onPress={() => this.props.onPress(item.brand)}
  62. activeOpacity={0.7}
  63. >
  64. <View style={styles.listItemParent}>
  65. <Image
  66. style={styles.brandImg}
  67. source={this.state.img}
  68. defaultSource={images.imgBrandPlaceholder}
  69. onError={() => this.onErrorLoadingImg(images.imgBrandPlaceholder)}
  70. />
  71. <Text style={styles.brandName}>
  72. {item.brand ? this.formatToTitleCase(item.brand) : item.brand}
  73. </Text>
  74. </View>
  75. </TouchableOpacity>
  76. </View>
  77. );
  78. }
  79. }
  80.  
  81. const styles = StyleSheet.create({
  82. listItemParent: {
  83. flexDirection: "row",
  84. borderBottomWidth: 1,
  85. borderBottomColor: "#127ebd",
  86. paddingTop: 10,
  87. paddingBottom: 20
  88. },
  89. brandImg: {
  90. width: responsiveWidth(10),
  91. height: responsiveWidth(10),
  92. marginHorizontal: 10
  93. },
  94. brandName: {
  95. textAlign: "left",
  96. textAlignVertical: "center",
  97. marginLeft: 20,
  98. fontSize: 18,
  99. color: "#127ebd"
  100. }
  101. });
  102.  
  103. const mapStateToProps = state => {
  104. const searchText = state.searchme.searchField;
  105. return{
  106. searchText: searchText
  107. }
  108. }
  109. export default connect(mapStateToProps,null)(BrandListItem);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement