-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
157 lines (147 loc) · 4.06 KB
/
App.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import React, { Component } from 'react';
import { StyleSheet, View, Text, TouchableOpacity } from 'react-native';
import GridView from 'react-native-super-grid';
import { Navigator } from 'react-native-deprecated-custom-components'; // 0.1.1
import PopupDialog, {
DialogTitle,
DialogButton,
ScaleAnimation,
} from 'react-native-popup-dialog';
import API from './API/googleFinance.js';
import StockView from './StockView';
const scaleAnimation = new ScaleAnimation();
const items = [
{ name: 'Apple', code: 'NASDAQ:AAPL' },
{ name: 'Google', code: 'NASDAQ:GOOG' },
{ name: 'Facebook', code: 'NASDAQ:FB' },
{ name: 'Microsoft', code: 'NASDAQ:MSFT' },
{ name: 'Alibaba', code: 'NYSE:BABA' },
{ name: 'SET', code: 'INDEXBKK:SET' },
{ name: 'S&P', code: 'INDEXSP:.INX' },
{ name: 'NASDAQ', code: 'INDEXNASDAQ:.IXIC' },
{ name: 'Dow Jones', code: 'INDEXDJX:.DJI' },
{ name: 'Shanghai', code: 'SHA:000001' },
{ name: 'Nikkei', code: 'INDEXNIKKEI:NI225' },
{ name: 'Hang Sang', code: 'INDEXHANGSENG:HSI' },
{ name: 'TSEC', code: 'TPE:TAIEX' },
{ name: 'IPC MEXICO', code: 'INDEXBMV:ME' },
];
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
dialogShow: false,
name: 'SET',
code: 'INDEXBKK:SET',
index: '0.00',
changeRaw: '+0.00',
changePercent: '+0.00',
};
//this.showScaleAnimationDialog = this.showScaleAnimationDialog.bind(this);
}
configureScene() {
return Navigator.SceneConfigs.FloatFromRight;
}
showScaleAnimationDialog(_name, _code) {
API(_code).then(data => {
console.log(data);
this.setState({
name: _name,
code: _code,
index: data.stockIndex,
changeRaw: data.stockChangeRaw,
changePercent: data.stockChangePercent,
});
});
this.scaleAnimationDialog.show();
}
renderScene = () => (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text
style={{
paddingTop: 75,
paddingBottom: 25,
fontSize: 28,
fontWeight: '600',
}}>
USA Tech Stock Markets
</Text>
<GridView
itemWidth={130}
items={items}
style={styles.gridView}
renderItem={item => (
<TouchableOpacity
style={styles.itemContainer}
onPress={() => this.showScaleAnimationDialog(item.name, item.code)}>
<Text style={styles.itemName}>{item.name}</Text>
</TouchableOpacity>
)}
/>
</View>
);
render() {
return (
<View style={{ flex: 1 }}>
<Navigator
initialRoute={{
name: 'index',
title: 'Popup Dialog',
}}
ref={navigator => {
this.navigator = navigator;
}}
renderScene={this.renderScene}
configureScene={this.configureScene}
style={styles.navigator}
/>
<PopupDialog
ref={popupDialog => {
this.scaleAnimationDialog = popupDialog;
}}
dialogAnimation={scaleAnimation}
dialogTitle={<DialogTitle title="STOCK" />}
actions={[
<DialogButton
text="DISMISS"
onPress={() => {
this.scaleAnimationDialog.dismiss();
}}
key="button-1"
/>,
]}
height={0.5}
width={0.9}>
<StockView
name={this.state.name}
code={this.state.code}
index={this.state.index}
changeRaw={this.state.changeRaw}
changePercent={this.state.changePercent}
/>
</PopupDialog>
</View>
);
}
}
const styles = StyleSheet.create({
gridView: {
paddingTop: 25,
flex: 1,
},
itemContainer: {
justifyContent: 'center',
alignItems: 'center',
borderRadius: 10,
borderWidth: 2,
borderColor: '#000',
padding: 10,
height: 100,
backgroundColor: '#fff',
},
itemName: {
fontSize: 22,
color: '#000',
fontWeight: '600',
},
});