Showing
2 changed files
with
136 additions
and
40 deletions
This diff is collapsed. Click to expand it.
1 | -import React, {Component} from 'react'; | 1 | +import React, { Component } from 'react'; |
2 | -import {Platform, StyleSheet, Text, | 2 | +import { |
3 | - View,TouchableOpacity, AsyncStorage, | 3 | + StyleSheet, |
4 | -} from 'react-native'; | 4 | + Text, |
5 | + View, | ||
6 | + TouchableOpacity, | ||
7 | + AsyncStorage, | ||
8 | + ScrollView, | ||
9 | + //불러오기 위한 것 | ||
10 | + Image, | ||
11 | +} from 'react-native'; | ||
5 | import { Icon } from "native-base"; | 12 | import { Icon } from "native-base"; |
13 | +import axios from "axios"; | ||
14 | +const API_KEY = "2bf00f660b1a6a3ffeb6e06ac270cce3"; | ||
15 | +const NAVER_CLIENT_ID = "KqPsntd1hcPJ8FUPBGqN"; | ||
16 | +const NAVER_CLIENT_SECRET = "0GRb3uya1U"; | ||
6 | 17 | ||
7 | - | 18 | + |
8 | -export default class App extends Component { | 19 | +export default class App extends Component { |
20 | + state = { | ||
21 | + date: "", //날짜 | ||
22 | + imgurl0: [], //이미지 | ||
23 | + name0: [], //제목 | ||
24 | + }; | ||
25 | + | ||
26 | + //날짜 정하기 | ||
27 | + componentDidMount() { | ||
28 | + var day = new Date().getDate() - 1; // 어제 날짜 | ||
29 | + if (day == 1) { | ||
30 | + day = 30; | ||
31 | + } else if (day < 10) { | ||
32 | + day = "0" + day; | ||
33 | + } | ||
34 | + var month = new Date().getMonth() + 1; //Current Month | ||
35 | + var year = new Date().getFullYear(); //Current Year | ||
36 | + var date = year + "" + month + day; | ||
37 | + this.getMovieList(date); | ||
38 | + } | ||
39 | + | ||
40 | + getMovieList = async date => { | ||
41 | + axios | ||
42 | + .get( | ||
43 | + `http://www.kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json?key=${API_KEY}&targetDt=${date}` | ||
44 | + ) | ||
45 | + .then( | ||
46 | + response => { | ||
47 | + this.setState({ | ||
48 | + //영화 제목 | ||
49 | + name0: response.data.boxOfficeResult.dailyBoxOfficeList[0].movieNm, | ||
50 | + }); | ||
51 | + | ||
52 | + temp = response.data.boxOfficeResult.dailyBoxOfficeList[0].movieNm; | ||
53 | + fetch( | ||
54 | + `https://openapi.naver.com/v1/search/movie.json?query='${temp}'`, | ||
55 | + { | ||
56 | + headers: { | ||
57 | + "X-Naver-Client-Id": NAVER_CLIENT_ID, | ||
58 | + "X-Naver-Client-Secret": NAVER_CLIENT_SECRET | ||
59 | + } | ||
60 | + } | ||
61 | + ) | ||
62 | + .then(response => response.json()) | ||
63 | + .then(json => { | ||
64 | + this.setState({ | ||
65 | + imgurl0: json.items[0].image | ||
66 | + }); | ||
67 | + }); | ||
68 | + } | ||
69 | + ) | ||
70 | + .catch(error => { | ||
71 | + console.log(error); | ||
72 | + }); | ||
73 | + }; | ||
74 | + | ||
9 | //네비게이션 바 | 75 | //네비게이션 바 |
10 | static navigationOptions = { | 76 | static navigationOptions = { |
11 | tabBarIcon: ({ tintColor }) => ( | 77 | tabBarIcon: ({ tintColor }) => ( |
12 | <Icon name='ios-star' style={{ color: tintColor }} /> | 78 | <Icon name='ios-star' style={{ color: tintColor }} /> |
13 | ) | 79 | ) |
14 | } | 80 | } |
15 | - saveData(){ | 81 | + |
16 | - let name = "앙기모띠"; | 82 | + //저장 함수 |
17 | - AsyncStorage.setItem('user',name); | 83 | + saveData() { |
18 | - } | 84 | + AsyncStorage.setItem('test', this.state.name0); |
19 | - displayData = async ()=>{ | 85 | + } |
20 | - try{ | 86 | + |
21 | - let user = await AsyncStorage.getItem('user'); | 87 | + //출력 함수 |
22 | - alert(user); | 88 | + displayData = async () => { |
23 | - } | 89 | + try { |
24 | - catch(error){ | 90 | + let user = await AsyncStorage.getItem('test'); |
25 | - alert(error) | 91 | + alert(user); |
26 | - } | 92 | + } |
27 | - } | 93 | + catch (error) { |
28 | - render() { | 94 | + alert(error) |
29 | - return ( | 95 | + } |
30 | - <View style={styles.container}> | 96 | + } |
31 | - <TouchableOpacity onPress ={this.saveData}> | 97 | + |
32 | - <Text>User정보 저장</Text> | 98 | + |
33 | - </TouchableOpacity> | 99 | + render() { |
34 | - <TouchableOpacity onPress ={this.displayData}> | 100 | + return ( |
35 | - <Text>User정보 출력</Text> | 101 | + <View style={styles.container}> |
36 | - </TouchableOpacity> | 102 | + <View style={styles.top}> |
37 | - </View> | 103 | + <TouchableOpacity onPress={this.saveData.bind(this)}> |
38 | - ); | 104 | + <Image |
39 | - } | 105 | + style={styles.poster} |
40 | -} | 106 | + source={{ uri: `${this.state.imgurl0}` }} |
41 | - | 107 | + /> |
42 | -const styles = StyleSheet.create({ | 108 | + <Text>{this.state.name0}</Text> |
43 | - container: { | 109 | + <Text style={styles.textStyle}>영화 정보 저장</Text> |
44 | - flex: 1, | 110 | + </TouchableOpacity> |
45 | - justifyContent: 'center', | 111 | + </View> |
46 | - alignItems: 'center', | 112 | + |
47 | - backgroundColor: '#F5FCFF', | 113 | + <View style={styles.bottom}> |
48 | - }, | 114 | + <TouchableOpacity onPress={this.displayData}> |
115 | + <Text style={styles.textStyle}>영화 정보 출력</Text> | ||
116 | + </TouchableOpacity> | ||
117 | + </View> | ||
118 | + </View> | ||
119 | + ); | ||
120 | + } | ||
121 | +} | ||
122 | + | ||
123 | +const styles = StyleSheet.create({ | ||
124 | + container: { | ||
125 | + flex: 1, | ||
126 | + alignItems: "center" | ||
127 | + }, | ||
128 | + top: { | ||
129 | + flex: 2, | ||
130 | + justifyContent: 'center', | ||
131 | + alignItems: 'center', | ||
132 | + }, | ||
133 | + bottom: { | ||
134 | + flex: 1, | ||
135 | + justifyContent: 'center', | ||
136 | + alignItems: 'center', | ||
137 | + }, | ||
138 | + textStyle: { | ||
139 | + fontSize: 25, | ||
140 | + }, | ||
141 | + poster: { | ||
142 | + flex: 5, | ||
143 | + paddingHorizontal: 50 | ||
144 | + }, | ||
49 | }); | 145 | }); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment