@@ -3,6 +3,11 @@ import SwiftUI
33/// View to summarize the Simple Payments order to be created
44///
55struct SimplePaymentsSummary : View {
6+
7+ /// Order note content
8+ ///
9+ let noteContent : String ?
10+
611 var body : some View {
712 VStack {
813 ScrollView {
@@ -20,7 +25,7 @@ struct SimplePaymentsSummary: View {
2025
2126 Spacer ( minLength: Layout . spacerHeight)
2227
23- NoteSection ( )
28+ NoteSection ( content : noteContent )
2429 }
2530 }
2631
@@ -110,34 +115,65 @@ private struct PaymentsSection: View {
110115/// Represents the Order note section
111116///
112117private struct NoteSection : View {
118+
119+ /// Order note content
120+ ///
121+ let content : String ?
122+
113123 var body : some View {
114124 Group {
115125 Divider ( )
116126
117127 VStack ( alignment: . leading, spacing: SimplePaymentsSummary . Layout. verticalNoteSpacing) {
118- Text ( SimplePaymentsSummary . Localization. orderNote)
119- . headlineStyle ( )
120128
121- Button ( action: {
122- print ( " Tapped add note " )
123- } , label: {
124- HStack ( ) {
125- Image ( uiImage: . plusImage)
129+ HStack {
130+ Text ( SimplePaymentsSummary . Localization. orderNote)
131+ . headlineStyle ( )
132+ . frame ( maxWidth: . infinity, alignment: . leading)
126133
127- Text ( SimplePaymentsSummary . Localization. addNote )
128- . frame ( maxWidth : . infinity , alignment : . leading )
134+ Button ( SimplePaymentsSummary . Localization. editNote ) {
135+ print ( " Tapped on Edit " )
129136 }
130137 . foregroundColor ( Color ( . accent) )
131138 . bodyStyle ( )
132- } )
133- . frame ( maxWidth: . infinity)
139+ . renderedIf ( content != nil )
140+ }
141+
142+ noteContent ( )
143+
134144 }
135145 . padding ( )
136146 . background ( Color ( . listForeground) )
137147
138148 Divider ( )
139149 }
140150 }
151+
152+ /// Builds a button to add a note if no note is present. If there is a note present only displays it
153+ ///
154+ @ViewBuilder private func noteContent( ) -> some View {
155+ if let content = content {
156+
157+ Text ( content)
158+ . bodyStyle ( )
159+
160+ } else {
161+
162+ Button ( action: {
163+ print ( " Tapped add note " )
164+ } , label: {
165+ HStack ( ) {
166+ Image ( uiImage: . plusImage)
167+
168+ Text ( SimplePaymentsSummary . Localization. addNote)
169+ . frame ( maxWidth: . infinity, alignment: . leading)
170+ }
171+ . foregroundColor ( Color ( . accent) )
172+ . bodyStyle ( )
173+ } )
174+ . frame ( maxWidth: . infinity)
175+ }
176+ }
141177}
142178
143179/// Represents the bottom take payment button
@@ -188,6 +224,8 @@ private extension SimplePaymentsSummary {
188224 comment: " Title text of the row that holds the order note when creating a simple payment " )
189225 static let addNote = NSLocalizedString ( " Add Note " ,
190226 comment: " Title text of the button that adds a note when creating a simple payment " )
227+ static let editNote = NSLocalizedString ( " Edit " ,
228+ comment: " Title text of the button that edits a note when creating a simple payment " )
191229
192230 static func takePayment( total: String ) -> String {
193231 NSLocalizedString ( " Take Payment ( \( total) ) " ,
@@ -199,15 +237,19 @@ private extension SimplePaymentsSummary {
199237// MARK: Previews
200238struct SimplePaymentsSummary_Preview : PreviewProvider {
201239 static var previews : some View {
202- SimplePaymentsSummary ( )
240+ SimplePaymentsSummary ( noteContent : nil )
203241 . environment ( \. colorScheme, . light)
204242 . previewDisplayName ( " Light " )
205243
206- SimplePaymentsSummary ( )
244+ SimplePaymentsSummary ( noteContent: " Dispatch by tomorrow morning at Fake Street 123, via the boulevard. " )
245+ . environment ( \. colorScheme, . light)
246+ . previewDisplayName ( " Light Content " )
247+
248+ SimplePaymentsSummary ( noteContent: nil )
207249 . environment ( \. colorScheme, . dark)
208250 . previewDisplayName ( " Dark " )
209251
210- SimplePaymentsSummary ( )
252+ SimplePaymentsSummary ( noteContent : nil )
211253 . environment ( \. sizeCategory, . accessibilityExtraExtraLarge)
212254 . previewDisplayName ( " Accessibility " )
213255 }
0 commit comments