// // SearchView.swift // SodaLive // // Created by klaus on 3/27/25. // import SwiftUI import Kingfisher struct SearchViewTabItem { let title: String let tab: SearchViewModel.CurrentTab } struct SearchView: View { @StateObject var viewModel = SearchViewModel() @State private var isFocused: Bool = false let tabItemList = [ SearchViewTabItem(title: I18n.Search.tabUnified, tab: .UNIFIED), SearchViewTabItem(title: I18n.Search.tabCreator, tab: .CREATOR), SearchViewTabItem(title: I18n.Search.tabContent, tab: .CONTENT), SearchViewTabItem(title: I18n.Search.tabSeries, tab: .SERIES) ] var body: some View { NavigationView { BaseView(isLoading: $viewModel.isLoading) { VStack(spacing: 0) { HStack(spacing: 0) { Button { AppState.shared.back() } label: { Image("ic_back") .resizable() .frame(width: 20, height: 20) } .padding(13.3) HStack(spacing: 0) { Image("ic_title_search_black") FocusedTextField( text: $viewModel.keyword, isFirstResponder: isFocused ) .padding(.horizontal, 13.3) .onAppear { DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { isFocused = true } } } .frame(height: 50) .padding(.horizontal, 21.3) .frame(maxWidth: .infinity) .background(Color.gray22) .clipShape(RoundedRectangle(cornerRadius: 6.7)) .overlay( RoundedRectangle(cornerRadius: 6.7) .strokeBorder(lineWidth: 1) .foregroundColor(Color.graybb) ) } .padding(.trailing, 13.3) if !viewModel.searchUnifiedCreatorList.isEmpty || !viewModel.searchUnifiedContentList.isEmpty || !viewModel.searchUnifiedSeriesList.isEmpty { ScrollView(.horizontal, showsIndicators: false) { HStack(spacing: 8) { ForEach(0.. 2 { Text(I18n.Search.noResults) .appFont(size: 18.3, weight: .medium) .foregroundColor(.white) .padding(.top, 20) } Spacer() } .popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) { GeometryReader { geo in HStack { Spacer() Text(viewModel.errorMessage) .padding(.vertical, 13.3) .frame(width: geo.size.width - 66.7, alignment: .center) .appFont(size: 12, weight: .medium) .background(Color.button) .foregroundColor(Color.white) .multilineTextAlignment(.center) .cornerRadius(20) .padding(.top, 66.7) Spacer() } } } .onAppear { if viewModel.keyword.isEmpty { viewModel.keyword = UserDefaults.string(forKey: .searchChannel) } } .onTapGesture { hideKeyboard() } } } } } #Preview { SearchView() }