Skip to content

Instantly share code, notes, and snippets.

View azamsharp's full-sized avatar

Mohammad Azam azamsharp

View GitHub Profile
struct ContentView: View {
let customers = ["Alex", "Mary", "John"]
@State var selectedCustomer: String?
var body: some View {
NavigationView {
VStack {
// get the selected customer
@azamsharp
azamsharp / .swift
Last active January 23, 2021 18:42
struct CustomerListView: View {
let customers: [String]
let onSelected: ((String) -> Void)?
init(customers: [String], onSelected: ((String) -> Void)? = nil) {
self.customers = customers
self.onSelected = onSelected
}
var body: some View {
NavigationView {
VStack {
CustomerListView(customers: customers)
}
.navigationTitle("Customers")
import SwiftUI
struct CustomerListView: View {
let customers: [String]
var body: some View {
List(customers, id: \.self) { customer in
NavigationView {
VStack {
List(customers, id: \.self) { customer in
NavigationLink(
destination: DetailView(customer: customer),
label: {
HStack {
Text(customer)
Spacer()
import SwiftUI
struct DetailView: View {
let customer: String
var body: some View {
Text(customer)
.font(.largeTitle)
//
// ContentView.swift
// RoutingDemo
//
// Created by Mohammad Azam on 1/13/21.
//
import SwiftUI
extension View {
NavigationView {
VStack {
Button(action: {}, label: {
Navigator.navigate(.detail("USA"), content: {
Text("GO")
})
})
.navigationTitle("Countries")
NavigationView {
VStack {
List(countries, id: \.self) { country in
Navigator.navigate(.detail(country), content: {
Text(country)
})
}.listStyle(PlainListStyle())
.navigationTitle("Countries")
class Navigator {
static func navigate<T: View>(_ route: Route, content: () -> T) -> AnyView {
switch route {
case .detail(let country):
return
NavigationLink(
destination: DetailView(country: country)) {
content()