-
Notifications
You must be signed in to change notification settings - Fork 0
/
TreandingTest.js
58 lines (56 loc) · 1.28 KB
/
TreandingTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, {Component} from 'react'
import {
View,
StyleSheet,
Text,
TextInput
} from 'react-native'
import NavigationBar from './js/common/NavigationBar'
import GitHubTrending from 'GitHubTrending'
const URL = 'https://github.com/trending/'
export default class TreandingTest extends Component {
constructor (props) {
super(props)
this.trending = new GitHubTrending()
this.state = {
result: ''
}
}
onLoad () {
let url = URL + this.text
console.log(url)
this.trending.fetchTrending(url)
.then(result => {
this.setState({
result: JSON.stringify(result)
})
})
.catch(error => {
this.setState({
result: JSON.stringify(error)
})
})
}
render () {
return <View>
<NavigationBar
title={'TreandingTest'}
/>
<TextInput
style={{borderWidth: 1,
height: 40,
margin: 6
}}
onChangeText={text => this.text = text}
/>
<View style={{flexDirection: 'row'}}>
<Text style={{fontSize: 20, margin: 5}}
onPress={() => this.onLoad()}
>加载数据</Text>
<Text style={{flex: 1}}>
{this.state.result}
</Text>
</View>
</View>
}
}