Advertisement
Guest User

BrandsComponent

a guest
Apr 24th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import { View, Text, TouchableOpacity, Image, StyleSheet } from 'react-native';
  3. import axios from 'axios';
  4. import strings from '../assests/res/strings'
  5. import { Actions } from 'react-native-router-flux';
  6.  
  7. export default class BrandsComponent extends Component {
  8.     constructor(props) {
  9.         super(props);
  10.  
  11.         this.state = {
  12.           questions: null,
  13.         };
  14.       }
  15.    
  16.       redirectBrandInfo(){
  17.         Actions.brandInfo();
  18.       }
  19.  
  20.       async componentDidMount() {
  21.         const brands = (await axios.get('MY BACKEND URL')).data;
  22.         this.setState({
  23.           brands,
  24.         });
  25.       }
  26.       render()
  27.       {  
  28.         const info = strings.brandContainer.info;
  29.         return (
  30.           <View style={{
  31.             flex: 1,
  32.             flexDirection: 'column',
  33.             justifyContent: 'center',
  34.             alignItems: 'center',
  35.             backgroundColor: '#FFF'
  36.           }}>
  37.           <Text style = { styles.title}>Brand list</Text>
  38.           <Text style = { styles.normal}>{info}</Text>      
  39.           {
  40.             this.state.brands && this.state.brands.map(brand =>
  41.             <TouchableOpacity
  42.              key={brand._id}
  43.              onPress ={() => this.redirectBrandInfo()} >
  44.               <View style={styles.button}>
  45.               <Image
  46.                 style = { styles.imageStyle }
  47.                 source={{uri: brand.logo_small}}/>
  48.               </View>
  49.             </TouchableOpacity>
  50.           )}
  51.           </View>
  52.         );  
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement