WantToWatchTab.js
3.96 KB
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
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
TouchableOpacity,
AsyncStorage,
ScrollView,
//불러오기 위한 것
Image,
} from 'react-native';
import { Icon } from "native-base";
import axios from "axios";
const API_KEY = "2bf00f660b1a6a3ffeb6e06ac270cce3";
const NAVER_CLIENT_ID = "KqPsntd1hcPJ8FUPBGqN";
const NAVER_CLIENT_SECRET = "0GRb3uya1U";
export default class App extends Component {
state = {
date: "", //날짜
imgurl0: [], //이미지
name0: [], //제목
};
//날짜 정하기
componentDidMount() {
var day = new Date().getDate() - 1; // 어제 날짜
if (day == 1) {
day = 30;
} else if (day < 10) {
day = "0" + day;
}
var month = new Date().getMonth() + 1; //Current Month
var year = new Date().getFullYear(); //Current Year
var date = year + "" + month + day;
this.getMovieList(date);
}
getMovieList = async date => {
axios
.get(
`http://www.kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json?key=${API_KEY}&targetDt=${date}`
)
.then(
response => {
this.setState({
//영화 제목
name0: response.data.boxOfficeResult.dailyBoxOfficeList[0].movieNm,
});
temp = response.data.boxOfficeResult.dailyBoxOfficeList[0].movieNm;
fetch(
`https://openapi.naver.com/v1/search/movie.json?query='${temp}'`,
{
headers: {
"X-Naver-Client-Id": NAVER_CLIENT_ID,
"X-Naver-Client-Secret": NAVER_CLIENT_SECRET
}
}
)
.then(response => response.json())
.then(json => {
this.setState({
imgurl0: json.items[0].image
});
});
}
)
.catch(error => {
console.log(error);
});
};
//네비게이션 바
static navigationOptions = {
tabBarIcon: ({ tintColor }) => (
<Icon name='ios-star' style={{ color: tintColor }} />
)
}
//저장 함수
// saveData() {
// AsyncStorage.setItem('test', this.state.name0);
// }
//출력 함수
displayData = async () => {
try {
let user = await AsyncStorage.getItem('MovieLists');
alert(user);
}
catch (error) {
alert(error)
}
}
render() {
return (
<View style={styles.container}>
<View style={styles.top}>
{/* bind해주면 위에 saveData 돌아간다 */}
{/* <TouchableOpacity onPress={this.saveData.bind(this)}>
<Image
style={styles.poster}
source={{ uri: `${this.state.imgurl0}` }}
/>
<Text>{this.state.name0}</Text>
<Text style={styles.textStyle}>영화 정보 저장</Text>
</TouchableOpacity> */}
</View>
<View style={styles.bottom}>
<TouchableOpacity onPress={this.displayData}>
<Text style={styles.textStyle}>영화 정보 출력</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center"
},
top: {
flex: 2,
justifyContent: 'center',
alignItems: 'center',
},
bottom: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
textStyle: {
fontSize: 25,
},
poster: {
flex: 5,
paddingHorizontal: 50
},
});