Advertisement
Guest User

Untitled

a guest
Jul 11th, 2019
112
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 } from 'react-native';
  3. import { H3, Text } 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 { heightPercentageToDP as hp } from 'react-native-responsive-screen';
  8. import { ScrollView } from 'react-native-gesture-handler';
  9. import PartnersInfo from './PartnersInfo';
  10.  
  11. export default class InfoDetailInfo extends Component {
  12.  
  13.     constructor(props) {
  14.         super(props);
  15.         this.state = {
  16.             isLoading: false,
  17.             error: '',
  18.             items: []
  19.         }
  20.         this.reRenderSomething = this.props.nav.addListener('willFocus', () => {
  21.             this.componentDidMount();
  22.         });
  23.     }
  24.  
  25.     async componentDidMount() {
  26.         this.getItems(this.props.url);
  27.     }
  28.  
  29.     getItems = (url_path) => {
  30.         this.setState({ isLoading: true });
  31.         axios.create({ headers: { 'from-app': '1' } }).get(url_path)
  32.             .then(result =>
  33.                 this.setState({
  34.                     items: result.data.page.blocks,
  35.                     isLoading: false
  36.                 })
  37.             )
  38.             .catch(error => this.setState({
  39.                 error,
  40.                 isLoading: false
  41.             }));
  42.     }
  43.  
  44.     render() {
  45.         const { isLoading, items } = this.state;
  46.         if (isLoading || items.length === 0) {
  47.             return (<Loading />);
  48.         }
  49.         return (
  50.             <View style={styles.viewStyle}>
  51.                 <ScrollView>
  52.                     {items.filter(i => "#" + i.anchor === this.props.anchor).map(i =>
  53.                         <View>
  54.                             <H3 style={styles.titleStyle}>{i.title}</H3>
  55.                             {i.blocks.map(i1 =>
  56.                                 <View>
  57.                                     {(i1.type === 'rectangle_blocks') ?
  58.                                         (<View style={styles.textStyle}>
  59.                                             {i1.block.map(i2 =>
  60.                                                 <View>
  61.                                                     <Text style={styles.titleStyle}>{i2.title}</Text>
  62.                                                     <Text style={styles.textStyle}>{i2.desc}</Text>
  63.                                                 </View>
  64.                                             )}
  65.                                         </View>) : (<View></View>)}
  66.                                     <View style={styles.textStyle}>
  67.                                         {(i1.type === 'text_image_right') ?
  68.                                             ((typeof i1.body !== "undefined") ?
  69.                                                 (<View>
  70.                                                     {(i1.title !== '') ? (<Text style={styles.titleStyle}>{i1.title}</Text>) : (<View></View>)}
  71.                                                     <HTML html={i1.body} />
  72.                                                 </View>) :
  73.                                                 (<View></View>)) : (<View></View>)}
  74.                                     </View>
  75.                                     {(i1.type === 'rectangle_blocks_with_image' || i1.type === 'auto_slide_banners') ?
  76.                                         (<View>
  77.                                             {(typeof i1.block !== "undefined") ? (<PartnersInfo items={i1.block} />) : (<View></View>)}
  78.                                         </View>) : (<View></View>)
  79.                                     }
  80.                                 </View>
  81.                             )}
  82.                         </View>
  83.                     )}
  84.                 </ScrollView>
  85.             </View>
  86.         );
  87.     }
  88.  
  89. }
  90. const styles = StyleSheet.create({
  91.     viewStyle: {
  92.         flex: 1,
  93.         padding: 25,
  94.         marginTop: 10,
  95.         backgroundColor: '#fff',
  96.         justifyContent: 'flex-end'
  97.     },
  98.     titleStyle: {
  99.         fontWeight: 'bold',
  100.         paddingLeft: 5
  101.     },
  102.     textStyle: {
  103.         padding: 5
  104.     },
  105.     itemImage: {
  106.         borderRadius: 15,
  107.         marginTop: 10,
  108.         marginBottom: 15,
  109.         width: null,
  110.         height: hp('10%'),
  111.     }
  112. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement