korkeep

AsyncStore로 두 페이지에서 DB연동 구현

...@@ -7,7 +7,7 @@ import { ...@@ -7,7 +7,7 @@ import {
7 SafeAreaView, 7 SafeAreaView,
8 ScrollView, 8 ScrollView,
9 Alert, 9 Alert,
10 - TouchableOpacity 10 + TouchableOpacity,
11 } from "react-native"; 11 } from "react-native";
12 import { Icon } from "native-base"; 12 import { Icon } from "native-base";
13 import { AsyncStorage } from "react-native"; 13 import { AsyncStorage } from "react-native";
...@@ -207,9 +207,13 @@ export default class MovieRankingTab extends Component { ...@@ -207,9 +207,13 @@ export default class MovieRankingTab extends Component {
207 var date = year + "" + month + day; 207 var date = year + "" + month + day;
208 this.getMovieList(date); 208 this.getMovieList(date);
209 } 209 }
210 +
210 _onPressButton(temp) { 211 _onPressButton(temp) {
211 - Alert.alert(temp); 212 + Alert.alert(temp);//메시지 띄우고
213 + console.log(temp);//콘솔에 log 띄운다
214 + AsyncStorage.setItem('MovieLists', temp); //DB에 저장한다
212 } 215 }
216 +
213 render() { 217 render() {
214 return ( 218 return (
215 <SafeAreaView style={style.container}> 219 <SafeAreaView style={style.container}>
......
...@@ -80,14 +80,14 @@ export default class App extends Component { ...@@ -80,14 +80,14 @@ export default class App extends Component {
80 } 80 }
81 81
82 //저장 함수 82 //저장 함수
83 - saveData() { 83 + // saveData() {
84 - AsyncStorage.setItem('test', this.state.name0); 84 + // AsyncStorage.setItem('test', this.state.name0);
85 - } 85 + // }
86 86
87 //출력 함수 87 //출력 함수
88 displayData = async () => { 88 displayData = async () => {
89 try { 89 try {
90 - let user = await AsyncStorage.getItem('test'); 90 + let user = await AsyncStorage.getItem('MovieLists');
91 alert(user); 91 alert(user);
92 } 92 }
93 catch (error) { 93 catch (error) {
...@@ -100,14 +100,15 @@ export default class App extends Component { ...@@ -100,14 +100,15 @@ export default class App extends Component {
100 return ( 100 return (
101 <View style={styles.container}> 101 <View style={styles.container}>
102 <View style={styles.top}> 102 <View style={styles.top}>
103 - <TouchableOpacity onPress={this.saveData.bind(this)}> 103 + {/* bind해주면 위에 saveData 돌아간다 */}
104 + {/* <TouchableOpacity onPress={this.saveData.bind(this)}>
104 <Image 105 <Image
105 style={styles.poster} 106 style={styles.poster}
106 source={{ uri: `${this.state.imgurl0}` }} 107 source={{ uri: `${this.state.imgurl0}` }}
107 /> 108 />
108 <Text>{this.state.name0}</Text> 109 <Text>{this.state.name0}</Text>
109 <Text style={styles.textStyle}>영화 정보 저장</Text> 110 <Text style={styles.textStyle}>영화 정보 저장</Text>
110 - </TouchableOpacity> 111 + </TouchableOpacity> */}
111 </View> 112 </View>
112 113
113 <View style={styles.bottom}> 114 <View style={styles.bottom}>
......