Created
June 21, 2019 12:08
-
-
Save bestiosdeveloper/0219e8d126bdaf650b5b8b00216e2bd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct MainHomeV : View { | |
@State private var searchQuery: String = "cricket" | |
@EnvironmentObject var viewModel: MainHomeVM | |
var todayStr: String { | |
Date().toString(dateFormat: "EEE, dd MMM yyyy") | |
} | |
var body: some View { | |
NavigationView { | |
List { | |
SearchBarV(text: $searchQuery, placeholder: Text("Search"), onCommit: search) | |
ForEach(viewModel.articals.identified(by: \.self)) { artcl in | |
NavigationButton( | |
destination: NewsDetailV(artical: artcl)) { | |
NewsRowV(artical: artcl) | |
} | |
} | |
}.navigationBarTitle(Text(todayStr)) | |
}.onAppear(perform: search) | |
} | |
private func search() { | |
viewModel.search(forQuery: searchQuery) | |
} | |
} | |
#if DEBUG | |
struct MainHomeV_Previews : PreviewProvider { | |
static var previews: some View { | |
MainHomeV() | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment