|
| 1 | +import React, { Component } from 'react'; |
| 2 | +import { ScrollView, StyleSheet, Text, View, Image,TextInput } from 'react-native'; |
| 3 | +import {ImageBackground, rgb } from 'react-native' |
| 4 | +import { AppRegistry, SectionList , FlatList, Linking, TouchableOpacity,AsyncStorage} from 'react-native'; |
| 5 | +import * as Animatable from 'react-native-animatable'; |
| 6 | +import { Button, Icon,SearchBar} from 'react-native-elements' |
| 7 | +import Ionicons from 'react-native-vector-icons/Ionicons'; |
| 8 | +AnimatImg = Animatable.createAnimatableComponent(Image); |
| 9 | +AnimatText = Animatable.createAnimatableComponent(TextInput); |
| 10 | +AnimateButton= Animatable.createAnimatableComponent(Button); |
| 11 | +import Search from './search'; |
| 12 | + |
| 13 | + |
| 14 | +const axios = require('axios'); |
| 15 | + |
| 16 | + |
| 17 | +// Create reusable components for the text |
| 18 | +class TextView extends Component { |
| 19 | + render() { |
| 20 | + return ( |
| 21 | + <Text style={{fontSize: 20}}>{this.props.text}</Text> |
| 22 | + ); |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +// Default class that represent the main components in the |
| 27 | +// Follower page |
| 28 | +export default class Repositories extends React.Component { |
| 29 | + static navigationOptions = { |
| 30 | + title: 'Following', |
| 31 | + headerStyle: { |
| 32 | + backgroundColor: 'rgb(245,245,240)', |
| 33 | + }, |
| 34 | + }; |
| 35 | + |
| 36 | + // constructor that has a default urlAvatar because it must have one |
| 37 | + constructor(props){ |
| 38 | + super(props); |
| 39 | + this.state = { |
| 40 | + urlAvatar: 'https://facebook.github.io/react-native/docs/assets/favicon.png',// Place holder |
| 41 | + data: [], |
| 42 | + target: "" , |
| 43 | + value: "", |
| 44 | + fulldata:[], |
| 45 | + search : '', |
| 46 | + |
| 47 | + } |
| 48 | + } |
| 49 | + handleSearch = text => { |
| 50 | + this.setState({ search:text }); |
| 51 | + }; |
| 52 | + |
| 53 | + // Render function that display the necessary data |
| 54 | + render() { |
| 55 | + const { search } = this.state; |
| 56 | + |
| 57 | + let table = [] |
| 58 | + // For loop that consequtively generate all the views that come from API |
| 59 | + for (let i = 0; i < this.state.data.length; i+=4) { |
| 60 | + let row = [] |
| 61 | + let content = [] |
| 62 | + for(let j = i; j < i+4 && j < this.state.data.length; j++){ |
| 63 | + let index = i+j |
| 64 | + content.push(<TouchableOpacity onPress={()=>{Linking.openURL(this.state.data[j]['html_url'])}}> |
| 65 | + <Image |
| 66 | + style = {styles.userIconStyle} |
| 67 | + source = {{uri: this.state.data[j]['avatar_url']}} |
| 68 | + /> |
| 69 | + </TouchableOpacity>) |
| 70 | + } |
| 71 | + row.push(<View style = {styles.accoutInfoStyle}>{content}</View>) |
| 72 | + table.push(<View style = {styles.accountStyle}>{row}</View>) |
| 73 | + } |
| 74 | + return ( |
| 75 | + |
| 76 | + <ScrollView style={styles.container}> |
| 77 | + |
| 78 | + <AnimatView animation ="bounceInDown" style ={styles.viewCon} > |
| 79 | + <Animatable.Text style = {styles.RepoStyle}>{this.state.data.length}</Animatable.Text> |
| 80 | + <SearchBar |
| 81 | + platform = 'ios' |
| 82 | + placeholder="Enter the Username!!!" |
| 83 | + onChangeText= {this.handleSearch} |
| 84 | + value={this.state.search} |
| 85 | + /> |
| 86 | + <Button |
| 87 | + onPress = { () =>{ |
| 88 | + AsyncStorage.setItem('@MySuperStore:type','repositories'); |
| 89 | + AsyncStorage.setItem('@MySuperStore:search',this.state.search); |
| 90 | + AsyncStorage.setItem('@MySuperStore:para','score'); |
| 91 | + this.props.navigation.navigate('search'); |
| 92 | + } |
| 93 | + } |
| 94 | + title="GO" |
| 95 | + color="white" |
| 96 | + accessibilityLabel="Learn more about this purple button" |
| 97 | + /> |
| 98 | + </AnimatView> |
| 99 | + |
| 100 | + {table} |
| 101 | + </ScrollView> |
| 102 | + ); |
| 103 | + } |
| 104 | + // Fetch data from API in github |
| 105 | + async getData(){ |
| 106 | + axios.get('https://api.github.com/users/'+ 'javaThonc' +'/following') |
| 107 | + .then((res) => { |
| 108 | + const dataAPI = res.data; |
| 109 | + // Split text into individual words and count length |
| 110 | + this.setState({ |
| 111 | + data:dataAPI, |
| 112 | + }) |
| 113 | + AsyncStorage.setItem('@MySuperStore:followingList', JSON.stringify(this.state.data)); |
| 114 | + }) |
| 115 | + } |
| 116 | + // Fetch data after creating the data |
| 117 | + componentDidMount(){ |
| 118 | + this.getData(); |
| 119 | + } |
| 120 | + |
| 121 | +} |
| 122 | +// Different styles for different views in the profile Page |
| 123 | +const styles = StyleSheet.create({ |
| 124 | + Button:{ |
| 125 | + height: 50, |
| 126 | + paddingTop:100, |
| 127 | + backgroundColor:'#1E6738', |
| 128 | + }, |
| 129 | + viewCon:{ |
| 130 | + backgroundColor:'rgb(22, 104, 204)', |
| 131 | + }, |
| 132 | + container: { |
| 133 | + flex: 1, |
| 134 | + backgroundColor: '#fff', |
| 135 | + }, |
| 136 | + userIconStyle:{ |
| 137 | + width: 80, |
| 138 | + height: 80, |
| 139 | + backgroundColor: 'transparent', |
| 140 | + borderColor: 'rgb(245,245, 240)', |
| 141 | + borderWidth: 2, |
| 142 | + borderRadius:40, |
| 143 | + }, |
| 144 | + userInfoStyle:{ |
| 145 | + flex: 1, |
| 146 | + paddingBottom:5 |
| 147 | + }, |
| 148 | + RepoStyle:{ |
| 149 | + flex: 1, |
| 150 | + justifyContent: 'center', |
| 151 | + flexDirection: 'row', |
| 152 | + textAlign:'center', |
| 153 | + fontSize:110, |
| 154 | + fontWeight: 'bold', |
| 155 | + color:'white', |
| 156 | + fontFamily: 'AvenirNextCondensed-Heavy' |
| 157 | + }, |
| 158 | + accoutInfoStyle:{ |
| 159 | + flex: 1, |
| 160 | + justifyContent: 'space-between', |
| 161 | + paddingTop: 5, |
| 162 | + paddingBottom: 5, |
| 163 | + flexDirection: 'row', |
| 164 | + paddingLeft:15, |
| 165 | + paddingRight:15 |
| 166 | + }, |
| 167 | + accountStyle:{ |
| 168 | + paddingTop: 50, |
| 169 | + }, |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | +}); |
0 commit comments