Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import { View, StyleSheet, Image, Dimensions } from 'react-native';
  3. import { Card, CardItem, Body, Text, Toast, H3 } from 'native-base';
  4. import axios from 'axios';
  5. import Loading from '../components/Loading.js';
  6. import HTML from 'react-native-render-html';
  7. import I18n from '../locales';
  8.  
  9. export default class TransportInfo extends Component {
  10.  
  11.     constructor(props) {
  12.         super(props);
  13.         this.state = {
  14.             isLoading: false,
  15.             error: '',
  16.             items: []
  17.         }
  18.     }
  19.  
  20.     async componentDidMount() {
  21.         this.getItems(this.props.url);
  22.     }
  23.  
  24.     showErrorToast = () => {
  25.         this.setState({ isLoading: false });
  26.         Toast.show({
  27.             text: I18n.t('internetErrorText'),
  28.             type: "danger",
  29.             duration: 3000,
  30.             position: "top"
  31.         });
  32.     }
  33.  
  34.     getItems = (url_path) => {
  35.         this.setState({ isLoading: true });
  36.         axios.create({ headers: { 'from-app': '1' } }).get(url_path)
  37.             .then(result =>
  38.                 this.setState({
  39.                     items: result.data,
  40.                     isLoading: false
  41.                 })
  42.             )
  43.             .catch(error => this.showErrorToast());
  44.     }
  45.  
  46.     render() {
  47.         const { isLoading, items } = this.state;
  48.         if (isLoading || items.length === 0) {
  49.             return (<Loading />);
  50.         }
  51.  
  52.         return (
  53.             <View style={styles.viewStyle}>
  54.                 <Image style={styles.itemImage1} source={{ uri: items.page.banner_image }} />
  55.                 {items.page.blocks.map(i =>
  56.                     i.blocks.map(i1 =>
  57.                         <View style={styles.infoViewStyle}>
  58.                             {(i1.type === 'text_with_brown_text_block_and_image') ?
  59.                                 (<View>
  60.                                     {(i1.title !== '') ? (<Text style={styles.titleStyle}>{i1.title}</Text>) : (<View></View>)}
  61.                                     <H3 style={styles.titleStyle}>{i.title}</H3>
  62.                                     <HTML html={i.desc} />
  63.                                 </View>) : (<View></View>)}
  64.                         </View>
  65.                     )
  66.                 )}
  67.                 {items.page.blocks.map(i =>
  68.                     <View style={styles.infoViewStyle1}>
  69.                         {
  70.                             i.blocks.map(i1 =>
  71.                                 <View>
  72.                                     {(i1.type === 'text_image_right') ?
  73.                                         ((typeof i1.body !== "undefined") ?
  74.                                             (<View>
  75.                                                 {(i1.title !== '') ? (<Text style={styles.titleStyle}>{i1.title}</Text>) : (<View></View>)}
  76.                                                 <HTML html={i1.body} />
  77.                                             </View>) :
  78.                                             (<View></View>)) : (<View></View>)}
  79.                                     {(i1.type === 'rectangle_blocks_with_image' || i1.type === 'auto_slide_banners') ?
  80.                                         (<View>
  81.                                             {(typeof i1.block !== "undefined") ? (
  82.                                                 i1.block.map(i =>
  83.                                                     <Card style={styles.cardStyle}>
  84.                                                         <CardItem cardBody>
  85.                                                             <Image resizeMode="contain" source={{ uri: i.image }} style={styles.itemImage} />
  86.                                                         </CardItem>
  87.                                                         <CardItem>
  88.                                                             <Body>
  89.                                                                 <Text>{i.title}</Text>
  90.                                                                 <HTML html={i.desc_html} />
  91.                                                             </Body>
  92.                                                         </CardItem>
  93.                                                     </Card>
  94.                                                 )
  95.                                             ) : (<View></View>)}
  96.                                         </View>) : (<View></View>)
  97.                                     }
  98.                                 </View>
  99.                             )
  100.                         }
  101.                     </View>
  102.                 )}
  103.             </View>
  104.         );
  105.  
  106.     }
  107.  
  108. }
  109. const styles = StyleSheet.create({
  110.     viewStyle: {
  111.         flex: 1
  112.     },
  113.     infoViewStyle: {
  114.         flex: 1,
  115.         paddingLeft: 30,
  116.         paddingRight: 30,
  117.         paddingTop: 10
  118.     },
  119.     infoViewStyle1: {
  120.         flex: 1,
  121.         paddingLeft: 30,
  122.         paddingRight: 30,
  123.         paddingBottom: 30
  124.     },
  125.     cardStyle: {
  126.         overflow: 'hidden',
  127.         marginBottom: 20
  128.     },
  129.     itemImage: {
  130.         flex: 1,
  131.         width: null,
  132.         height: 200,
  133.     },
  134.     itemImage1: {
  135.         flex: 1,
  136.         width: Dimensions.get('window').width,
  137.         height: 200,
  138.     },
  139.     titleStyle: {
  140.         marginTop: 10,
  141.         marginBottom: 10
  142.     },
  143.     cardBodyStyle: {
  144.         justifyContent: 'flex-start',
  145.         alignItems: 'flex-start'
  146.     },
  147.     priceStyle: {
  148.         fontWeight: 'bold'
  149.     }
  150. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement