-
Notifications
You must be signed in to change notification settings - Fork 121
[Woo POS][Barcodes] Disable scanning when the support view is open #15972
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-945-wooposbarcodes-disable-scanning-when-the-support-view-is
Aug 5, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f4271b0
Create POSSheet for detecting sheet presentation
staskus 2433949
Apply posRootSheet to POSentryPointVIew for detecting sheet presentation
staskus e8dbc68
Use posSheet instead of sheet within POS
staskus a2cd558
Set posSheetManager environmentObject in PointOfSaleEntryPointView
staskus bbf0e7b
Update POSSheet documentation
staskus a3158db
Chance support form button from done to cancel on POS
staskus 04949bb
Merge branch 'trunk' into woomob-945-wooposbarcodes-disable-scanning-…
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
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
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
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
130 changes: 130 additions & 0 deletions
130
WooCommerce/Classes/POS/Presentation/Reusable Views/POSSheet.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,130 @@ | ||
| import SwiftUI | ||
|
|
||
| // | ||
| // POSSheet - Wraps default SwiftUI .sheet() modifiers to support sheet presentation detection within POS. | ||
| // | ||
| // Usage: Replace .sheet() with .posSheet() and inject POSSheetManager at the POS root. | ||
| // Sheet presentation can be detected via POSSheetManager.isPresented. | ||
| // | ||
|
|
||
| // MARK: - Sheet Detection Infrastructure | ||
|
|
||
| final class POSSheetManager: ObservableObject { | ||
| @Published private(set) var isPresented: Bool = false | ||
| private var presentedSheets: Set<String> = [] | ||
|
|
||
| func registerSheetPresented(id: String) { | ||
| presentedSheets.insert(id) | ||
| updateState() | ||
| } | ||
|
|
||
| func registerSheetDismissed(id: String) { | ||
| presentedSheets.remove(id) | ||
| updateState() | ||
| } | ||
|
|
||
| private func updateState() { | ||
| isPresented = !presentedSheets.isEmpty | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Individual Sheet Modifiers | ||
|
|
||
| struct POSSheetViewModifier<SheetContent: View>: ViewModifier { | ||
| @EnvironmentObject var sheetManager: POSSheetManager | ||
| @Binding var isPresented: Bool | ||
| let onDismiss: (() -> Void)? | ||
| let sheetContent: () -> SheetContent | ||
|
|
||
| @State private var sheetId = UUID().uuidString | ||
|
|
||
| func body(content: Content) -> some View { | ||
| content | ||
| .sheet(isPresented: $isPresented, onDismiss: onDismiss, content: sheetContent) | ||
| .onChange(of: isPresented) { newValue in | ||
| if newValue { | ||
| sheetManager.registerSheetPresented(id: sheetId) | ||
| } else { | ||
| sheetManager.registerSheetDismissed(id: sheetId) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| struct POSSheetViewModifierForItem<Item: Identifiable & Equatable, SheetContent: View>: ViewModifier { | ||
| @EnvironmentObject var sheetManager: POSSheetManager | ||
| @Binding var item: Item? | ||
| let onDismiss: (() -> Void)? | ||
| let sheetContent: (Item) -> SheetContent | ||
|
|
||
| @State private var sheetId = UUID().uuidString | ||
|
|
||
| func body(content: Content) -> some View { | ||
| content | ||
| .sheet(item: $item, onDismiss: onDismiss, content: sheetContent) | ||
| .onChange(of: item) { newItem in | ||
| let newValue = newItem != nil | ||
| if newValue { | ||
| sheetManager.registerSheetPresented(id: sheetId) | ||
| } else { | ||
| sheetManager.registerSheetDismissed(id: sheetId) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // MARK: - View Modifiers | ||
|
|
||
| extension View { | ||
| /// Shows a sheet with automatic detection of presentation. | ||
| /// | ||
| /// This works exactly like the native .sheet() modifier but automatically tracks | ||
| /// presentation state. | ||
| /// | ||
| /// This will only work in a view hierarchy containing a `POSSheetManager` environment object. | ||
| /// | ||
| /// - Parameters: | ||
| /// - isPresented: Binding to control when the sheet is shown. | ||
| /// - onDismiss: Optional closure executed when the sheet is dismissed. | ||
| /// - content: Content to show in the sheet | ||
| /// - Returns: a modified view which can show the sheet content specified, when applicable. | ||
| func posSheet<SheetContent: View>( | ||
| isPresented: Binding<Bool>, | ||
| onDismiss: (() -> Void)? = nil, | ||
| @ViewBuilder content: @escaping () -> SheetContent | ||
| ) -> some View { | ||
| self.modifier( | ||
| POSSheetViewModifier( | ||
| isPresented: isPresented, | ||
| onDismiss: onDismiss, | ||
| sheetContent: content | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| /// Shows a sheet with automatic detection of presentation. | ||
| /// | ||
| /// This works exactly like the native .sheet(item:) modifier but automatically tracks | ||
| /// presentation state. | ||
| /// | ||
| /// This will only work in a view hierarchy containing a `POSSheetManager` environment object. | ||
| /// | ||
| /// - Parameters: | ||
| /// - item: Binding to control when the sheet is shown. When non-nil, the item is used to build the content. | ||
| /// - onDismiss: Optional closure executed when the sheet is dismissed. | ||
| /// - content: Content to show in the sheet | ||
| /// - Returns: a modified view which can show the sheet content specified, when applicable. | ||
| func posSheet<Item: Identifiable & Equatable, SheetContent: View>( | ||
| item: Binding<Item?>, | ||
| onDismiss: (() -> Void)? = nil, | ||
| @ViewBuilder content: @escaping (Item) -> SheetContent | ||
| ) -> some View { | ||
| self.modifier( | ||
| POSSheetViewModifierForItem( | ||
| item: item, | ||
| onDismiss: onDismiss, | ||
| sheetContent: content | ||
| ) | ||
| ) | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated to this PR, as it happens in trunk as well: I noticed that after confirming the email alert on top of the support form, there was no obvious way to exit the form. The "Done" CTA in the navigation bar is actually the CTA to dismiss the form after checking the code, but I thought it's to submit the form as a user. Since interactive dismissal is disabled, maybe we can rename this "Done" to some dismissing action like "Cancel" and place it in the leading edge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great observation. It's an easy change, I will do it and merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simulator.Screen.Recording.-.iPad.Pro.11-inch.M4.-.2025-08-05.at.12.11.07.mov