Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions SampleAppSwiftUI/Scenes/Home/Coin/CoinNews/CoinNewsListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,33 @@ struct CoinNewsListView: View {

var body: some View {
VStack {
ScrollView {
NavigationView {
if let newsModel = viewModel.coinNewsDataModel {
List {
ForEach(newsModel) { model in
NavigationLink(destination: WebView(url: URL(string: model.url))) {
HStack {
AsyncImage(url: URL(string: model.imageurl)) { phase in
if let image = phase.image {
image.resizable()
} else {
Image(.worldNews)
.resizable()
}
}
.scaledToFit()
.clipShape(Circle())
.frame(width: Dimensions.imageWidth, height: Dimensions.imageHeight)
Text(model.title)
if let newsModel = viewModel.coinNewsDataModel {
List {
ForEach(newsModel) { model in
NavigationLink(destination: WebView(url: URL(string: model.url))) {
HStack {
AsyncImage(url: URL(string: model.imageurl)) { phase in
if let image = phase.image {
image.resizable()
} else {
Image(.worldNews)
.resizable()
}
}
.scaledToFit()
.clipShape(Circle())
.frame(width: Dimensions.imageWidth, height: Dimensions.imageHeight)
Text(model.title)
}
}
.listStyle(.inset)
}
}.frame(height: UIScreen.main.bounds.height)
.navigationTitle("News")
.navigationBarTitleDisplayMode(.inline)
.navigationViewStyle(.automatic)
}
.listStyle(.inset)
}
}
.task(viewModel.onAppear)
.navigationTitle("News")
.navigationBarTitleDisplayMode(.inline)
}
}

Expand Down
44 changes: 21 additions & 23 deletions SampleAppSwiftUI/Scenes/Home/Coin/Detail/CoinDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,35 +97,33 @@ struct CoinDetailView: View {
}

var news: some View {
NavigationView {
VStack {
if let newsModel = viewModel.coinNewsDataModel {
List {
Section("News") {
ForEach(newsModel.prefix(5)) { model in
NavigationLink(destination: WebView(url: URL(string: model.url))) {
HStack {
AsyncImage(url: URL(string: model.imageurl)) { phase in
if let image = phase.image {
image.resizable()
} else {
Image(.worldNews)
.resizable()
}
VStack {
if let newsModel = viewModel.coinNewsDataModel {
List {
Section("News") {
ForEach(newsModel.prefix(5)) { model in
NavigationLink(destination: WebView(url: URL(string: model.url))) {
HStack {
AsyncImage(url: URL(string: model.imageurl)) { phase in
if let image = phase.image {
image.resizable()
} else {
Image(.worldNews)
.resizable()
}
.scaledToFit()
.clipShape(Circle())
.frame(width: Dimensions.imageWidth, height: Dimensions.imageHeight)
Text(model.title)
.limitedCharacterCount(Numbers.newsCharCount, model.title, "...")
}
.scaledToFit()
.clipShape(Circle())
.frame(width: Dimensions.imageWidth, height: Dimensions.imageHeight)
Text(model.title)
.limitedCharacterCount(Numbers.newsCharCount, model.title, "...")
}
}
}
}
.scrollDisabled(true)
.listStyle(.inset)
}
.scrollDisabled(true)
.listStyle(.inset)
}
}
}
Expand All @@ -135,11 +133,11 @@ struct CoinDetailView: View {
ScrollView {
coinDetailImage
news
.frame(height: Dimensions.imageHeight * 10)
Button {
} label: {
NavigationLink(destination: CoinNewsListView(coinData: viewModel.coinData)) {
Text("View More")
.frame(width: UIScreen.main.bounds.size.width - CoinDetailView.coinListFrameSize)
.font(.system(size: 18))
.padding()
.foregroundColor(Color(.searchIcon))
Expand Down
62 changes: 42 additions & 20 deletions SampleAppSwiftUI/Scenes/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,23 @@ struct HomeView: View {
@StateObject private var viewModel = HomeViewModel()
@State private var searchTerm = ""
@EnvironmentObject var router: Router
@State private var columnVisibility = NavigationSplitViewVisibility.doubleColumn

var body: some View {
NavigationStack(path: $router.homeNavigationPath) {
VStack(spacing: Spacings.home) {
SearchBarView(searchText: $searchTerm, topPadding: Paddings.SearchBar.shortTop)
FilterView(viewModel: viewModel)
.padding(.bottom, Paddings.filterBottom)
Divider()
CoinListView(viewModel: viewModel, filteredCoins: $viewModel.filteredCoins) {
Task {
await viewModel.fillModels()
}
}
}.padding(.horizontal, Paddings.side)
.navigationTitle("Home")
.navigationBarTitleDisplayMode(.inline)
.navigationDestination(for: Screen.self) { screen in
if screen.type == .detail, let data = screen.data as? CoinData {
CoinDetailView(coinData: data)
var stack: some View {
VStack(spacing: Spacings.home) {
SearchBarView(searchText: $searchTerm, topPadding: Paddings.SearchBar.shortTop)
FilterView(viewModel: viewModel)
.padding(.bottom, Paddings.filterBottom)
Divider()
CoinListView(viewModel: viewModel, filteredCoins: $viewModel.filteredCoins) {
Task {
await viewModel.fillModels()
}
}
}
.background(Color(.lightestGray))
.ignoresSafeArea(.all, edges: [.top, .trailing, .leading])
.padding(.horizontal, Paddings.side)
.navigationTitle("Home")
.navigationBarTitleDisplayMode(.inline)
.onAppear {
Task {
await viewModel.fillModels()
Expand All @@ -50,6 +43,35 @@ struct HomeView: View {
viewModel.sortOptions(sort: newValue)
})
}

var body: some View {
if UIDevice.current.userInterfaceIdiom != .pad {
NavigationStack(path: $router.homeNavigationPath) {
stack
.navigationDestination(for: Screen.self) { screen in
if screen.type == .detail, let data = screen.data as? CoinData {
CoinDetailView(coinData: data)
}
}
}
} else {
NavigationSplitView(columnVisibility: $columnVisibility) {
stack
} detail: {
if let screen = router.homeNavigationPath.last(where: { screen in
screen.type == .detail
}) {
if let data = screen.data as? CoinData {
NavigationStack {
CoinDetailView(coinData: data)
.id(UUID())
}
}
}
}
.navigationSplitViewStyle(.balanced)
}
}
}

#Preview {
Expand Down