-
Notifications
You must be signed in to change notification settings - Fork 121
[Woo POS] Modularization: Extract FormattableAmountTextField, Coupon Creation, ProductImageThumbnail #16134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
staskus
merged 7 commits into
trunk
from
woomob-935-woo-pos-hack-week-pos-modularization-shared-ui-components
Sep 18, 2025
Merged
[Woo POS] Modularization: Extract FormattableAmountTextField, Coupon Creation, ProductImageThumbnail #16134
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
88974ef
POS Modularization: Use FormattableAmountTextField through type-erase…
staskus 7dff630
POS Modularization: Move Coupon and Discount creation views to the ad…
staskus 68b32d6
Move ProductImageThumbnail to WooFoundation
staskus ec92a8f
Merge branch 'trunk' into woomob-935-woo-pos-hack-week-pos-modulariza…
staskus faf4483
Make variables private
staskus e07e99c
Remove dynamicTypeSize
staskus cbe632f
Merge branch 'trunk' into woomob-935-woo-pos-hack-week-pos-modulariza…
staskus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
WooCommerce/Classes/Extensions/ProductImageThumbnail+Extensions.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import SwiftUI | ||
| import struct WooFoundation.ProductImageThumbnail | ||
|
|
||
| // Convenience initializer that maintains the default behavior. | ||
| extension ProductImageThumbnail where Placeholder == Image { | ||
| init(productImageURL: URL?, | ||
| productImageSize: CGFloat, | ||
| scale: CGFloat, | ||
| productImageCornerRadius: CGFloat = 0, | ||
| foregroundColor: Color, | ||
| cachesOriginalImage: Bool = false) { | ||
| self.init(productImageURL: productImageURL, | ||
| productImageSize: productImageSize, | ||
| scale: scale, | ||
| productImageCornerRadius: productImageCornerRadius, | ||
| foregroundColor: foregroundColor, | ||
| cachesOriginalImage: cachesOriginalImage) { | ||
| Image(uiImage: .productPlaceholderImage) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
WooCommerce/Classes/POS/Adaptors/View Adaptors/POSCouponCreationSheetAdaptor.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import SwiftUI | ||
| import struct Yosemite.Coupon | ||
|
|
||
| /// Provide access to AddEditCouponView and ViewModel for POS without making it as an explicit type dependency | ||
| /// AddEditCouponView cannot be easily moved and reused in a shared module due to multiple dependencies | ||
| /// This is used as a workaround to enable POS modularization without requiring a larger refactoring effort | ||
| /// | ||
|
|
||
| struct POSCouponCreationViewAdaptor: View { | ||
| @StateObject private var viewModel: AddEditCouponViewModel | ||
| @Binding var showTypeSelection: Bool | ||
| let dismissHandler: () -> Void | ||
| let onDisappear: () -> Void | ||
|
|
||
| init(discountType: Coupon.DiscountType, | ||
| showTypeSelection: Binding<Bool>, | ||
| onSuccess: @escaping (Coupon) -> Void, | ||
| dismissHandler: @escaping () -> Void, | ||
| onDisappear: @escaping () -> Void) { | ||
| _showTypeSelection = showTypeSelection | ||
| self.dismissHandler = dismissHandler | ||
| self.onDisappear = onDisappear | ||
| _viewModel = StateObject(wrappedValue: AddEditCouponViewModel( | ||
| discountType: discountType, | ||
| onSuccess: onSuccess | ||
| )) | ||
| } | ||
|
|
||
| var body: some View { | ||
| var view = AddEditCoupon(viewModel) | ||
| view.dismissHandler = dismissHandler | ||
| view.onDisappear = onDisappear | ||
| view.discountTypeHandler = { _ in | ||
| showTypeSelection = true | ||
| } | ||
|
|
||
| return view | ||
| .interactiveDismissDisabled() | ||
| } | ||
| } | ||
|
|
||
| struct POSDiscountTypeSelectionSheetAdaptor: View { | ||
| @Binding var isPresented: Bool | ||
| let title: String | ||
| let cancelButtonTitle: String | ||
| let onSelection: (Coupon.DiscountType) -> Void | ||
|
|
||
| var body: some View { | ||
| let command = DiscountTypeBottomSheetListSelectorCommand(selected: nil) { type in | ||
| onSelection(type) | ||
| } | ||
|
|
||
| NavigationView { | ||
| BottomSheetListSelector( | ||
| viewProperties: BottomSheetListSelectorViewProperties(), | ||
| command: command, | ||
| onDismiss: { _ in | ||
| isPresented = false | ||
| } | ||
| ) | ||
| .navigationBarTitleDisplayMode(.large) | ||
| .navigationTitle(title) | ||
| .toolbar { | ||
| ToolbarItem(placement: .cancellationAction) { | ||
| Button(cancelButtonTitle) { | ||
| isPresented = false | ||
| } | ||
| } | ||
| } | ||
| } | ||
| .navigationViewStyle(.stack) | ||
| .interactiveDismissDisabled() | ||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
WooCommerce/Classes/POS/Adaptors/View Adaptors/POSFormattableAmountTextFieldAdaptor.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import SwiftUI | ||
|
|
||
| /// Provide access to FormattableAmountTextField and ViewModel for POS without making it as an explicit type dependency | ||
| /// FormattableAmountTextField cannot be easily moved and reused in a shared module due to multiple dependencies | ||
| /// This is used as a workaround to enable POS modularization without requiring a larger refactoring effort | ||
| /// | ||
| struct POSFormattableAmountTextFieldAdaptor: View { | ||
| @StateObject private var textFieldViewModel: FormattableAmountTextFieldViewModel | ||
| let preset: Decimal? | ||
| let onSubmit: () -> Void | ||
| let onChange: (String) -> Void | ||
|
|
||
| init(preset: Decimal?, onSubmit: @escaping () -> Void, onChange: @escaping (String) -> Void) { | ||
| self._textFieldViewModel = StateObject(wrappedValue: FormattableAmountTextFieldViewModel( | ||
| size: .extraLarge, | ||
| locale: Locale.autoupdatingCurrent, | ||
| storeCurrencySettings: ServiceLocator.currencySettings, | ||
| allowNegativeNumber: false) | ||
| ) | ||
| self.preset = preset | ||
| self.onSubmit = onSubmit | ||
| self.onChange = onChange | ||
| } | ||
|
|
||
| var body: some View { | ||
| FormattableAmountTextField(viewModel: textFieldViewModel, style: .pos) | ||
| .dynamicTypeSize(...DynamicTypeSize.accessibility1) | ||
| .onSubmit { | ||
| onSubmit() | ||
| } | ||
| .onChange(of: textFieldViewModel.amount) { _, newValue in | ||
| onChange(newValue) | ||
| } | ||
| .onAppear { | ||
| if let preset { | ||
| textFieldViewModel.presetAmount(preset) | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.