| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import React, { useState } from 'react';
- import {
- View,
- Text,
- TextInput,
- TouchableOpacity,
- FlatList,
- StyleSheet,
- } from 'react-native';
- import AsyncStorage from '@react-native-async-storage/async-storage';
- import { useRouter } from 'expo-router';
- interface Song {
- id: string;
- title: string;
- artist: string;
- }
- const MOCK_SONGS: Song[] = [
- { id: '1234', title: '좋은 날', artist: '아이유' },
- { id: '5678', title: '취중진담', artist: '김동률' },
- { id: '9101', title: 'LOVE DIVE', artist: 'IVE' },
- { id: '1121', title: 'Permission to Dance', artist: 'BTS' },
- ];
- export default function MainScreen() {
- const [keyword, setKeyword] = useState('');
- const [results, setResults] = useState<Song[]>([]);
- const router = useRouter();
- const handleSearch = () => {
- const filtered = MOCK_SONGS.filter(
- song =>
- song.title.includes(keyword) ||
- song.artist.includes(keyword)
- );
- setResults(filtered);
- };
- const handleAddToFavorites = async (song: Song) => {
- const stored = await AsyncStorage.getItem('favorites');
- const parsed = stored ? JSON.parse(stored) : [];
- await AsyncStorage.setItem('favorites', JSON.stringify([...parsed, song]));
- };
- return (
- <View style={styles.container}>
- <View style={styles.navbar}>
- <TouchableOpacity onPress={() => {}}>
- <Text style={styles.icon}>👤</Text>
- </TouchableOpacity>
- <TouchableOpacity onPress={() => {}}>
- <Text style={styles.icon}>⭐️</Text>
- </TouchableOpacity>
- <TouchableOpacity onPress={() => {}}>
- <Text style={styles.icon}>⚙️</Text>
- </TouchableOpacity>
- </View>
- {/* 타이틀 */}
- <Text style={styles.title}>Sing Song</Text>
- {/* 검색 영역 */}
- <TextInput
- placeholder="제목 또는 가수를 입력하세요"
- value={keyword}
- onChangeText={setKeyword}
- style={styles.input}
- />
- <TouchableOpacity onPress={handleSearch} style={styles.searchButton}>
- <Text style={styles.searchText}>검색</Text>
- </TouchableOpacity>
- {/* 검색 결과 리스트 */}
- <FlatList
- data={results}
- keyExtractor={(item) => item.id}
- renderItem={({ item }) => (
- <TouchableOpacity onPress={() => handleAddToFavorites(item)}>
- <View style={styles.item}>
- <Text>{item.id} - {item.title} ({item.artist})</Text>
- </View>
- </TouchableOpacity>
- )}
- ListEmptyComponent={<Text>검색 결과가 없습니다.</Text>}
- />
- </View>
- );
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- padding: 20,
- backgroundColor: '#fff',
- },
- navbar: {
- flexDirection: 'row',
- justifyContent: 'flex-end',
- gap: 16,
- marginBottom: 8,
- },
- icon: {
- fontSize: 20,
- },
- title: {
- fontSize: 24,
- fontWeight: 'bold',
- marginBottom: 16,
- },
- settings: {
- fontSize: 20,
- },
- input: {
- borderWidth: 1,
- borderColor: '#ccc',
- borderRadius: 8,
- padding: 8,
- marginBottom: 10,
- },
- searchButton: {
- backgroundColor: '#007AFF',
- padding: 10,
- borderRadius: 8,
- alignItems: 'center',
- marginBottom: 16,
- },
- searchText: {
- color: '#fff',
- fontWeight: 'bold',
- },
- item: {
- padding: 12,
- borderBottomWidth: 1,
- borderBottomColor: '#eee',
- },
- });
|