11import SwiftUI
22import Combine
33
4- /// Hosting controller that wraps an `NewOrder ` view.
4+ /// Hosting controller that wraps an `OrderForm ` view.
55///
6- final class NewOrderHostingController : UIHostingController < NewOrder > {
6+ final class OrderFormHostingController : UIHostingController < OrderForm > {
77
88 /// References to keep the Combine subscriptions alive within the lifecycle of the object.
99 ///
@@ -12,7 +12,7 @@ final class NewOrderHostingController: UIHostingController<NewOrder> {
1212
1313 init ( viewModel: EditableOrderViewModel ) {
1414 self . viewModel = viewModel
15- super. init ( rootView: NewOrder ( viewModel: viewModel) )
15+ super. init ( rootView: OrderForm ( viewModel: viewModel) )
1616
1717 // Needed because a `SwiftUI` cannot be dismissed when being presented by a UIHostingController
1818 rootView. dismissHandler = { [ weak self] in
@@ -42,7 +42,7 @@ final class NewOrderHostingController: UIHostingController<NewOrder> {
4242
4343/// Intercepts back navigation (selecting back button or swiping back).
4444///
45- extension NewOrderHostingController {
45+ extension OrderFormHostingController {
4646 override func shouldPopOnBackButton( ) -> Bool {
4747 guard viewModel. canBeDismissed else {
4848 presentDiscardChangesActionSheet ( onDiscard: { [ weak self] in
@@ -60,7 +60,7 @@ extension NewOrderHostingController {
6060
6161/// Intercepts to the dismiss drag gesture.
6262///
63- extension NewOrderHostingController : UIAdaptivePresentationControllerDelegate {
63+ extension OrderFormHostingController : UIAdaptivePresentationControllerDelegate {
6464 func presentationControllerShouldDismiss( _ presentationController: UIPresentationController ) -> Bool {
6565 return viewModel. canBeDismissed
6666 }
@@ -74,7 +74,7 @@ extension NewOrderHostingController: UIAdaptivePresentationControllerDelegate {
7474
7575/// Private methods
7676///
77- private extension NewOrderHostingController {
77+ private extension OrderFormHostingController {
7878 func presentDiscardChangesActionSheet( onDiscard: @escaping ( ) -> Void ) {
7979 UIAlertController . presentDiscardChangesActionSheet ( viewController: self , onDiscard: onDiscard)
8080 }
@@ -90,9 +90,9 @@ private extension NewOrderHostingController {
9090 }
9191}
9292
93- /// View to create a new manual order
93+ /// View to create or edit an order
9494///
95- struct NewOrder : View {
95+ struct OrderForm : View {
9696 /// Set this closure with UIKit dismiss code. Needed because we need access to the UIHostingController `dismiss` method.
9797 ///
9898 var dismissHandler : ( ( ) -> Void ) = { }
@@ -192,13 +192,13 @@ private struct ProductsSection: View {
192192 Group {
193193 Divider ( )
194194
195- VStack ( alignment: . leading, spacing: NewOrder . Layout. verticalSpacing) {
196- Text ( NewOrder . Localization. products)
195+ VStack ( alignment: . leading, spacing: OrderForm . Layout. verticalSpacing) {
196+ Text ( OrderForm . Localization. products)
197197 . accessibilityAddTraits ( . isHeader)
198198 . headlineStyle ( )
199199
200200 ForEach ( viewModel. productRows) { productRow in
201- ProductRow ( viewModel: productRow, accessibilityHint: NewOrder . Localization. productRowAccessibilityHint)
201+ ProductRow ( viewModel: productRow, accessibilityHint: OrderForm . Localization. productRowAccessibilityHint)
202202 . onTapGesture {
203203 viewModel. selectOrderItem ( productRow. id)
204204 }
@@ -209,11 +209,11 @@ private struct ProductsSection: View {
209209 Divider ( )
210210 }
211211
212- Button ( NewOrder . Localization. addProduct) {
212+ Button ( OrderForm . Localization. addProduct) {
213213 showAddProduct. toggle ( )
214214 }
215215 . id ( addProductButton)
216- . accessibilityIdentifier ( NewOrder . Accessibility. addProductButtonIdentifier)
216+ . accessibilityIdentifier ( OrderForm . Accessibility. addProductButtonIdentifier)
217217 . buttonStyle ( PlusButtonStyle ( ) )
218218 . sheet ( isPresented: $showAddProduct, onDismiss: {
219219 scroll. scrollTo ( addProductButton)
@@ -237,21 +237,21 @@ private struct ProductsSection: View {
237237}
238238
239239// MARK: Constants
240- private extension NewOrder {
240+ private extension OrderForm {
241241 enum Layout {
242242 static let sectionSpacing : CGFloat = 16.0
243243 static let verticalSpacing : CGFloat = 22.0
244244 static let noSpacing : CGFloat = 0.0
245245 }
246246
247247 enum Localization {
248- static let createButton = NSLocalizedString ( " Create " , comment: " Button to create an order on the New Order screen " )
248+ static let createButton = NSLocalizedString ( " Create " , comment: " Button to create an order on the Order screen " )
249249 static let doneButton = NSLocalizedString ( " Done " , comment: " Button to dismiss the Order Editing screen " )
250250 static let cancelButton = NSLocalizedString ( " Cancel " , comment: " Button to cancel the creation of an order on the New Order screen " )
251- static let products = NSLocalizedString ( " Products " , comment: " Title text of the section that shows the Products when creating a new order " )
252- static let addProduct = NSLocalizedString ( " Add Product " , comment: " Title text of the button that adds a product when creating a new order " )
251+ static let products = NSLocalizedString ( " Products " , comment: " Title text of the section that shows the Products when creating or editing an order " )
252+ static let addProduct = NSLocalizedString ( " Add Product " , comment: " Title text of the button that adds a product when creating or editing an order " )
253253 static let productRowAccessibilityHint = NSLocalizedString ( " Opens product detail. " ,
254- comment: " Accessibility hint for selecting a product in a new order " )
254+ comment: " Accessibility hint for selecting a product in an order form " )
255255 }
256256
257257 enum Accessibility {
@@ -261,28 +261,28 @@ private extension NewOrder {
261261 }
262262}
263263
264- struct NewOrder_Previews : PreviewProvider {
264+ struct OrderForm_Previews : PreviewProvider {
265265 static var previews : some View {
266266 let viewModel = EditableOrderViewModel ( siteID: 123 )
267267
268268 NavigationView {
269- NewOrder ( viewModel: viewModel)
269+ OrderForm ( viewModel: viewModel)
270270 }
271271
272272 NavigationView {
273- NewOrder ( viewModel: viewModel)
273+ OrderForm ( viewModel: viewModel)
274274 }
275275 . environment ( \. sizeCategory, . accessibilityExtraExtraLarge)
276276 . previewDisplayName ( " Accessibility " )
277277
278278 NavigationView {
279- NewOrder ( viewModel: viewModel)
279+ OrderForm ( viewModel: viewModel)
280280 }
281281 . environment ( \. colorScheme, . dark)
282282 . previewDisplayName ( " Dark " )
283283
284284 NavigationView {
285- NewOrder ( viewModel: viewModel)
285+ OrderForm ( viewModel: viewModel)
286286 }
287287 . environment ( \. layoutDirection, . rightToLeft)
288288 . previewDisplayName ( " Right to left " )
0 commit comments