Advertisement
Guest User

Untitled

a guest
Nov 7th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import {
  3.   View,
  4.   Linking,Text,Alert, Image
  5. } from 'react-native';
  6.  
  7. import Results from '../components/Results';
  8. import Header from '../components/Header';
  9. import styles from '../constants/styles';
  10. import { StackNavigator } from 'react-navigation';
  11.  
  12. const algoliasearch = require('algoliasearch/reactnative')('*******', '**************************************');
  13. import AlgoliaSearchHelper from 'algoliasearch-helper';
  14.  
  15. export default class LinksScreen extends React.Component {
  16.   constructor(props) {
  17.     super(props);
  18.     this.state = { lastSearchResults: null };
  19.   }
  20.  
  21.   static navigationOptions = {
  22.     title: 'Preferiti',
  23.     header: null
  24.   };
  25.   componentWillMount(){
  26.     const helper = this.helper = AlgoliaSearchHelper(algoliasearch, '****************');
  27.  
  28.     helper.on('result', (res) => {
  29.       this.setState({lastSearchResults: res});
  30.     });
  31.  
  32.  
  33.   }
  34.   myfunc = () =>{
  35.     const {navigate} = this.props.navigation;
  36.     navigate('Prod_info', {prod_data: data});
  37.   };
  38.  
  39.  
  40.   render() {
  41.     const {navigate} = this.props.navigation;
  42.     const content = this.state.lastSearchResults &&
  43.       <Results hits={this.state.lastSearchResults.hits} openLink={this.openLink}  nav={navigate}/>;
  44.     if(this.state.lastSearchResults==null){
  45.       return(
  46.         <View style={{flex: 1,
  47.  
  48.           alignItems: 'stretch',
  49.           backgroundColor:'white'}}>
  50.         <Header helper={this.helper} />
  51.           {content}
  52.           <View style={{
  53.             flex: 1,
  54.             flexDirection: 'column',
  55.             justifyContent: 'center',
  56.             alignItems: 'center',
  57.           }}>
  58.             <Image
  59.               source={require('../assets/images/logo.png')}
  60.               style={{height: 100, width: 100}}
  61.             />
  62.             <Text style={{color: '#46DB85', fontWeight: 'bold'}}>EFFETTUA UNA RICERCA!</Text>
  63.           </View>
  64.         </View>
  65.       );
  66.     }else{
  67.     return (
  68.  
  69.       <View style={styles.container}>
  70.         <Header helper={this.helper} />
  71.         {content}
  72.       </View>
  73.  
  74.     );}
  75.   }
  76.  
  77.   openLink(url) {
  78.     Linking.openURL(url);
  79.   }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement