mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-03-29 21:52:10 +02:00
Combine examples
This commit is contained in:
@@ -10,27 +10,51 @@ import SwiftUI
|
||||
|
||||
struct RepositoryListView : View {
|
||||
|
||||
@EnvironmentObject private var viewModel: RepositoryListViewModel
|
||||
@State private var text: String = ""
|
||||
@ObjectBinding
|
||||
private(set) var viewModel: RepositoryListViewModel
|
||||
|
||||
var body: some View {
|
||||
|
||||
NavigationView {
|
||||
|
||||
TextField($text,
|
||||
placeholder: Text("Search reposipories..."),
|
||||
onCommit: { self.viewModel.search(query: self.text) })
|
||||
VStack {
|
||||
HStack {
|
||||
|
||||
TextField($viewModel.text,
|
||||
placeholder: Text("Search reposipories..."),
|
||||
onCommit: { self.viewModel.search() })
|
||||
.frame(height: 40)
|
||||
.padding(EdgeInsets(top: 0, leading: 8, bottom: 0, trailing: 8))
|
||||
.border(Color.gray, cornerRadius: 8)
|
||||
.padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16))
|
||||
|
||||
Button(action: { self.viewModel.search() }) {
|
||||
Text("Search")
|
||||
}
|
||||
.frame(height: 40)
|
||||
.padding(EdgeInsets(top: 0, leading: 8, bottom: 0, trailing: 8))
|
||||
.border(Color.gray, cornerRadius: 8)
|
||||
.padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16))
|
||||
.border(Color.blue, cornerRadius: 8)
|
||||
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 16))
|
||||
}
|
||||
|
||||
List {
|
||||
|
||||
viewModel.errorMessage.map(Text.init)?
|
||||
.lineLimit(nil)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
ForEach(viewModel.repositories.identified(by: \.id)) { repository in
|
||||
RepositoryView(repository: repository)
|
||||
|
||||
NavigationLink(destination:
|
||||
WebView(url: repository.htmlUrl)
|
||||
.navigationBarTitle(Text(repository.fullName))
|
||||
) {
|
||||
|
||||
RepositoryView(repository: repository)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationBarTitle(Text("Search🔍"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user