Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. StyleSheet,
  4. View,
  5. TouchableWithoutFeedback,
  6. TextInput,
  7. Dimensions,
  8. FlatList,
  9. ScrollView
  10. } from 'react-native';
  11. import {
  12. Container,
  13. Header,
  14. Content,
  15. List,
  16. ListItem,
  17. Left,
  18. Body,
  19. Right,
  20. Thumbnail,
  21. Text,
  22. Button,
  23. Icon
  24. } from 'native-base';
  25. import { StackNavigator } from 'react-navigation';
  26. import {connect} from 'react-redux'
  27. import {_getAllStores} from './../../api/api';
  28. import {loadStores} from '../../actions/stores';
  29.  
  30. const {width, height} = Dimensions.get('window')
  31.  
  32. class StoreList extends Component {
  33. componentWillMount(){
  34. this.props.dispatch(loadStores());
  35. }
  36. constructor(props) {
  37. super(props);
  38. this.state = {
  39. text: '',
  40. data: ''
  41. };
  42. };
  43. static navigationOptions = {
  44. header: null
  45. };
  46. filter(text) {
  47. const {stores} = this.props.stores.stores;
  48. const newData = stores.filter(function(item) {
  49. const itemData = item.name.toUpperCase();
  50. const textData = text.toUpperCase();
  51.  
  52. return itemData.indexOf(textData) > -1;
  53. });
  54. this.setState({
  55. data: newData,
  56. text: text
  57. });
  58. };
  59. deleteData() {
  60. this.setState({text: '', data: ''});
  61. };
  62. _renderItem(item) {
  63. return (
  64. <ListItem>
  65. <Left>
  66. <Thumbnail source={{uri: item.logo}}/>
  67. </Left>
  68. <Body>
  69. <Text style={{color: 'black'}}>{item.name}</Text>
  70. </Body>
  71. <Right />
  72. </ListItem>
  73. );
  74. };
  75. renderList(stores) {
  76. console.log("CTM");
  77. //this.chargeData(stores);
  78. return(
  79. <Container>
  80. <Header>
  81. <Left>
  82. <TouchableWithoutFeedback onPress={() => this.props.navigation.navigate('HomeScreen')}>
  83. <Text style={styles.backButtonText}>Back</Text>
  84. </TouchableWithoutFeedback>
  85. </Left>
  86. <Body>
  87. <TextInput
  88. value={this.state.text}
  89. onChangeText={(text) => this.filter(text)}
  90. style={styles.input}
  91. placeholder="Search"
  92. placeholderTextColor="grey"
  93. />
  94. </Body>
  95. <Right>
  96. <Button>
  97. <Icon name='options' onPress={() => this.props.navigation.navigate('CategoryList')} />
  98.  
  99. </Button>
  100. </Right>
  101. </Header>
  102. <List
  103. dataArray={stores.stores}
  104. renderRow={(item) => this._renderItem(item)}>
  105. </List>
  106. </Container>
  107. )
  108.  
  109. }
  110. render() {
  111. const {stores} = this.props.stores;
  112. return (
  113. <Container>
  114. {stores.stores ? this.renderList(stores) : null}
  115. </Container>
  116. );
  117. };
  118. };
  119.  
  120. const styles = StyleSheet.create({
  121. input: {
  122. height: 35,
  123. backgroundColor: '#e5e7f2',
  124. width: width / 2,
  125. marginHorizontal: 10,
  126. paddingLeft: 10,
  127. borderRadius: 3
  128. },
  129. backButtonText: {
  130. color: 'white',
  131. fontSize: 15
  132. }
  133. });
  134.  
  135. const mapStateToProps = state => {
  136. return {stores: state.storesReducer}
  137. }
  138.  
  139. export default connect(mapStateToProps)(StoreList);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement