diff Simoleon/Tests/ChildListResets.swift @ 156:84137052813d

Refactor code
author Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
date Sat, 28 Aug 2021 11:15:25 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Simoleon/Tests/ChildListResets.swift	Sat Aug 28 11:15:25 2021 +0100
@@ -0,0 +1,44 @@
+//
+//  ModalSheetSelection.swift
+//  Simoleon
+//
+//  Created by Dennis Concepción Martín on 26/8/21.
+//
+
+import SwiftUI
+
+struct ParentView: View {
+    @State var selection: Int = 1
+    @State private var showingList = false
+    
+    var body: some View {
+        VStack {
+            Button("Show list", action: {showingList = true})
+                .sheet(isPresented: $showingList) {
+                    ModalSheetSelection(selection: $selection)
+                }
+            
+            Text("My first var is: \(selection)")
+        }
+    }
+}
+
+struct ModalSheetSelection: View {
+    @Binding var selection: Int
+    
+    var body: some View {
+        NavigationView {
+            List {
+                SearchBar(placeholder: "", text: .constant(""))
+                ForEach((1..<100), id: \.self) { number in
+                    Button(action: {selection = number}) {
+                        Text("\(number)")
+                    }
+                }
+            }
+            .id(UUID())
+            .navigationTitle("Currencies")
+            .navigationBarTitleDisplayMode(.inline)
+        }
+    }
+}