Showing
2 changed files
with
111 additions
and
15 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 | + Text, | ||
5 | + View, | ||
6 | + TouchableOpacity, | ||
7 | + AsyncStorage, | ||
8 | + ScrollView, | ||
9 | + //불러오기 위한 것 | ||
10 | + Image, | ||
4 | } from 'react-native'; | 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() { |
84 | + AsyncStorage.setItem('test', this.state.name0); | ||
18 | } | 85 | } |
19 | - displayData = async ()=>{ | 86 | + |
20 | - try{ | 87 | + //출력 함수 |
21 | - let user = await AsyncStorage.getItem('user'); | 88 | + displayData = async () => { |
89 | + try { | ||
90 | + let user = await AsyncStorage.getItem('test'); | ||
22 | alert(user); | 91 | alert(user); |
23 | } | 92 | } |
24 | - catch(error){ | 93 | + catch (error) { |
25 | alert(error) | 94 | alert(error) |
26 | } | 95 | } |
27 | } | 96 | } |
97 | + | ||
98 | + | ||
28 | render() { | 99 | render() { |
29 | return ( | 100 | return ( |
30 | <View style={styles.container}> | 101 | <View style={styles.container}> |
31 | - <TouchableOpacity onPress ={this.saveData}> | 102 | + <View style={styles.top}> |
32 | - <Text>User정보 저장</Text> | 103 | + <TouchableOpacity onPress={this.saveData.bind(this)}> |
104 | + <Image | ||
105 | + style={styles.poster} | ||
106 | + source={{ uri: `${this.state.imgurl0}` }} | ||
107 | + /> | ||
108 | + <Text>{this.state.name0}</Text> | ||
109 | + <Text style={styles.textStyle}>영화 정보 저장</Text> | ||
33 | </TouchableOpacity> | 110 | </TouchableOpacity> |
34 | - <TouchableOpacity onPress ={this.displayData}> | 111 | + </View> |
35 | - <Text>User정보 출력</Text> | 112 | + |
113 | + <View style={styles.bottom}> | ||
114 | + <TouchableOpacity onPress={this.displayData}> | ||
115 | + <Text style={styles.textStyle}>영화 정보 출력</Text> | ||
36 | </TouchableOpacity> | 116 | </TouchableOpacity> |
37 | </View> | 117 | </View> |
118 | + </View> | ||
38 | ); | 119 | ); |
39 | } | 120 | } |
40 | } | 121 | } |
... | @@ -42,8 +123,23 @@ export default class App extends Component { | ... | @@ -42,8 +123,23 @@ export default class App extends Component { |
42 | const styles = StyleSheet.create({ | 123 | const styles = StyleSheet.create({ |
43 | container: { | 124 | container: { |
44 | flex: 1, | 125 | flex: 1, |
126 | + alignItems: "center" | ||
127 | + }, | ||
128 | + top: { | ||
129 | + flex: 2, | ||
45 | justifyContent: 'center', | 130 | justifyContent: 'center', |
46 | alignItems: 'center', | 131 | alignItems: 'center', |
47 | - backgroundColor: '#F5FCFF', | 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 | ||
48 | }, | 144 | }, |
49 | }); | 145 | }); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment