-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_example.js
70 lines (60 loc) · 2.04 KB
/
http_example.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
59
60
61
62
63
64
65
66
67
68
69
70
import React, { Component } from 'react'
import { View, Text, TouchableHighlight } from 'react-native'
import Moment from 'moment';
import { Feather } from '@expo/vector-icons';
import AnimateNumber from 'react-native-animate-number'
class HttpExample extends Component {
state = {
data: ''
}
componentDidMount = () => {
setInterval(() => {
fetch('http://api.thingspeak.com/channels/1183380/feeds/last.json', {
method: 'GET'
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
this.setState({
data: responseJson
})
})
.catch((error) => {
console.error(error);
});
}, 5000)
}
handleClick() {
console.log('Click happened');
fetch('http://api.thingspeak.com/channels/1183380/feeds/last.json', {
method: 'GET'
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
this.setState({
data: responseJson
})
})
.catch((error) => {
console.error(error);
});
}
render() {
return (
<View style={{alignContent:"center", alignItems:"center"}}>
<TouchableHighlight
onPress={() => this.handleClick()}>
<Feather name="refresh-ccw" size={24} color="black" style={{ padding: 10 }} />
</TouchableHighlight>
<AnimateNumber style={{ color: "#2C589D", fontSize: 90,fontFamily: 'Montserrat_500Medium'}} value={this.state.data.field1} countBy={1}
timing={(interval, progress) => {
// slow start, slow end
return interval * (1 - Math.sin(Math.PI*progress) )*10
}}/>
<Text style={{ color: "#000", fontSize: 15,fontFamily: 'Montserrat_500Medium' }}>LAST UPDATE: {Moment(this.state.data.created_at).format('DD MMM HH:mm')} </Text>
</View>
)
}
}
export default HttpExample