Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import { StyleSheet, View, Text, Image, TouchableWithoutFeedback } from 'react-native';
  3. import { Card, CardItem, Body } from 'native-base';
  4. import { FlatGrid } from 'react-native-super-grid';
  5. import NavigationService from '../components/NavigationService.js';
  6. import Loading from '../components/Loading.js';
  7. import { URL } from '../components/url';
  8. import axios from 'axios';
  9.  
  10. export default class CategoryGrid extends Component {
  11.  
  12.     constructor(props) {
  13.         super(props);
  14.         this.state = {
  15.             isLoading: false,
  16.             error: '',
  17.             slide: []
  18.         }
  19.     }
  20.  
  21.     componentDidMount() {
  22.         this.getCategorySlide();
  23.     }
  24.  
  25.     getCategorySlide = () => {
  26.         this.setState({ isLoading: true })
  27.         axios.get(URL + "app/apiv3/index.php/get_slayd_v/apikey/melhem3/dil/az")
  28.             .then(result => this.setState({
  29.                 isLoading: false,
  30.                 slide: result.data
  31.             }))
  32.             .catch(error => this.setState({
  33.                 isLoading: false,
  34.                 error: error
  35.             }));
  36.     }
  37.  
  38.     _renderItem = ({ item }) => {
  39.         return (
  40.             <TouchableWithoutFeedback onPress={() => NavigationService.navigate('CategoryHomeDetail', { id: item.slayd_url_metn.slice(10, 30), title: item.slayd_adi })}>
  41.                 <Card style={styles.cardStyle}>
  42.                     <CardItem cardBody>
  43.                         <Image resizeMode="contain" source={{ uri: URL + item.slayd_sekil_url }} style={styles.itemImage} />
  44.                     </CardItem>
  45.                     <CardItem>
  46.                         <Body style={styles.cardBodyStyle}>
  47.                             <Text>{item.slayd_adi}</Text>
  48.                         </Body>
  49.                     </CardItem>
  50.                 </Card>
  51.             </TouchableWithoutFeedback>
  52.         );
  53.     }
  54.  
  55.     render() {
  56.         const { isLoading, slide } = this.state;
  57.         if (isLoading) {
  58.             <Loading />
  59.         }
  60.         return (
  61.             <View style={styles.viewStyle} >
  62.                 <FlatGrid
  63.                     itemDimension={130}
  64.                     items={slide}
  65.                     renderItem={this._renderItem}
  66.                 />
  67.             </View>
  68.         );
  69.     }
  70.  
  71. }
  72. const styles = StyleSheet.create({
  73.     viewStyle: {
  74.         padding: 20
  75.     },
  76.     cardStyle: {
  77.         borderRadius: 15,
  78.         overflow: 'hidden'
  79.     },
  80.     itemImage: {
  81.         flex: 1,
  82.         width: null,
  83.         height: 130,
  84.     },
  85.     cardBodyStyle: {
  86.         justifyContent: 'center',
  87.         alignItems: 'center'
  88.     }
  89. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement