Skip to content

Commit e46322c

Browse files
authored
[Woo POS] Modularization: Bring existing changes to trunk (#16132)
2 parents 1e411df + 9da0a71 commit e46322c

File tree

198 files changed

+1631
-1123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+1631
-1123
lines changed
Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import SwiftUI
22

33
public struct IndefiniteCircularProgressViewStyle: ProgressViewStyle {
4-
var size: CGFloat
5-
var lineWidth: CGFloat = Constants.lineWidth
6-
var lineCap: CGLineCap = .round
7-
var circleColor: Color = Color(.primaryButtonBackground).opacity(Constants.backgroundOpacity)
8-
var fillColor: Color = Color(.primaryButtonBackground)
4+
public var size: CGFloat
5+
public var lineWidth: CGFloat = Constants.lineWidth
6+
public var lineCap: CGLineCap = .round
7+
public var circleColor: Color = Color(.primaryButtonBackground).opacity(Constants.backgroundOpacity)
8+
public var fillColor: Color = Color(.primaryButtonBackground)
99

10-
private let arcStart: Double = Constants.initialArcStart
1110
private let animationDuration: Double = 1.6
1211

1312
@State private var arcEnd: Double = Constants.initialArcEnd
1413
@State private var rotation: Angle = Constants.threeQuarterRotation
1514
@State private var viewRotation: Angle = .radians(0)
1615
@State private var arcTimer: Timer?
1716

17+
public init(size: CGFloat, lineWidth: CGFloat = Constants.lineWidth, lineCap: CGLineCap = .round, circleColor: Color? = nil, fillColor: Color? = nil) {
18+
self.size = size
19+
self.lineWidth = lineWidth
20+
self.lineCap = lineCap
21+
self.circleColor = circleColor ?? Color(.primaryButtonBackground).opacity(Constants.backgroundOpacity)
22+
self.fillColor = fillColor ?? Color(.primaryButtonBackground)
23+
}
24+
1825
public func makeBody(configuration: ProgressViewStyleConfiguration) -> some View {
1926
VStack {
2027
ZStack {
@@ -78,21 +85,21 @@ public struct IndefiniteCircularProgressViewStyle: ProgressViewStyle {
7885
}
7986
}
8087

81-
private extension IndefiniteCircularProgressViewStyle {
88+
public extension IndefiniteCircularProgressViewStyle {
8289
enum Constants {
83-
static let lineWidth: CGFloat = 10.0
84-
static let backgroundOpacity: CGFloat = 0.2
90+
public static let lineWidth: CGFloat = 10.0
91+
public static let backgroundOpacity: CGFloat = 0.2
8592

86-
static let initialArcStart: Double = 0
87-
static let initialArcEnd: Double = 0.05
88-
static let fullCircle: Double = 1
93+
public static let initialArcStart: Double = 0
94+
public static let initialArcEnd: Double = 0.05
95+
public static let fullCircle: Double = 1
8996

90-
static let threeQuarterRotation: Angle = .radians((9 * Double.pi)/6)
91-
static let fullRotation: Angle = .radians(Double.pi * 2)
97+
public static let threeQuarterRotation: Angle = .radians((9 * Double.pi)/6)
98+
public static let fullRotation: Angle = .radians(Double.pi * 2)
9299
}
93100

94101
enum Localization {
95-
static let inProgressAccessibilityLabel = NSLocalizedString(
102+
public static let inProgressAccessibilityLabel = NSLocalizedString(
96103
"In progress",
97104
comment: "Accessibility label for an indeterminate loading indicator")
98105
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ import SwiftUI
22
import Combine
33

44
@Observable
5-
final class KeyboardObserver {
6-
private(set) var isKeyboardVisible: Bool = false
7-
private(set) var keyboardHeight: CGFloat = 0
5+
public final class KeyboardObserver {
6+
public private(set) var isKeyboardVisible: Bool = false
7+
public private(set) var keyboardHeight: CGFloat = 0
88

99
/// When an external keyboard is in use, iPadOS shows a quicktype bar at the bottom of the screen.
1010
/// This is reported as a keyboard with height, so `isKeyboardVisible` will be true and
1111
/// keyboard height will be > 0.
1212
/// However, it's much less of an impingement on the view, so there may be no modification to the view required.
1313
/// `isFullSizeKeyboardVisible` is true when the full software keyboard is shown.
14-
var isFullSizeKeyboardVisible: Bool {
14+
public var isFullSizeKeyboardVisible: Bool {
1515
return keyboardHeight > Constants.hardwareKeyboardHelperBarHeightThreshold
1616
}
1717

1818
private var cancellables = Set<AnyCancellable>()
1919

20-
init() {
20+
public init() {
2121
NotificationCenter.Publisher(center: .default, name: UIResponder.keyboardWillShowNotification)
2222
.merge(with: NotificationCenter.Publisher(center: .default, name: UIResponder.keyboardDidShowNotification))
2323
.receive(on: DispatchQueue.main)
@@ -47,9 +47,9 @@ final class KeyboardObserver {
4747
}
4848
}
4949

50-
private extension KeyboardObserver {
50+
public extension KeyboardObserver {
5151
enum Constants {
52-
static let hardwareKeyboardHelperBarHeightThreshold: CGFloat = 90
52+
public static let hardwareKeyboardHelperBarHeightThreshold: CGFloat = 90
5353
}
5454
}
5555

@@ -60,22 +60,22 @@ private struct KeyboardObserverKey: EnvironmentKey {
6060
}
6161
}
6262

63-
extension EnvironmentValues {
63+
public extension EnvironmentValues {
6464
var keyboardObserver: KeyboardObserver {
6565
get { self[KeyboardObserverKey.self] }
6666
set { self[KeyboardObserverKey.self] = newValue }
6767
}
6868
}
6969

70-
struct KeyboardObserverProvider: ViewModifier {
70+
public struct KeyboardObserverProvider: ViewModifier {
7171
@State private var observer = KeyboardObserver()
7272

73-
func body(content: Content) -> some View {
73+
public func body(content: Content) -> some View {
7474
content.environment(\.keyboardObserver, observer)
7575
}
7676
}
7777

78-
extension View {
78+
public extension View {
7979
func injectKeyboardObserver() -> some View {
8080
modifier(KeyboardObserverProvider())
8181
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import SwiftUI
22

33
/// Wraps a VStack inside a ScrollView, ensuring the content expands to fill the available space
44
///
5-
struct ScrollableVStack<Content: View>: View {
5+
public struct ScrollableVStack<Content: View>: View {
66
let alignment: HorizontalAlignment
77
let padding: CGFloat
88
let spacing: CGFloat?
99
let content: Content
1010

11-
init(
11+
public init(
1212
alignment: HorizontalAlignment = .center,
1313
padding: CGFloat = 24,
1414
spacing: CGFloat? = nil,
@@ -20,7 +20,7 @@ struct ScrollableVStack<Content: View>: View {
2020
self.content = content()
2121
}
2222

23-
var body: some View {
23+
public var body: some View {
2424
GeometryReader { geometry in
2525
ScrollView {
2626
VStack(alignment: alignment, spacing: spacing) {
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import SwiftUI
22

33
/// Text field has a rounded border that has a thicker border and brighter border color when the field is focused.
4-
struct WooRoundedBorderTextFieldStyle: TextFieldStyle {
4+
public struct WooRoundedBorderTextFieldStyle: TextFieldStyle {
55
private let focused: Bool
66
private let focusedBorderColor: Color
77
private let unfocusedBorderColor: Color
@@ -19,7 +19,7 @@ struct WooRoundedBorderTextFieldStyle: TextFieldStyle {
1919
/// - insets: The insets between the background border and the text input.
2020
/// - height: An optional fixed height for the field.
2121
/// - content: Optional closure to wrap the text field content.
22-
init(focused: Bool,
22+
public init(focused: Bool,
2323
focusedBorderColor: Color = Defaults.focusedBorderColor,
2424
unfocusedBorderColor: Color = Defaults.unfocusedBorderColor,
2525
backgroundColor: Color = .clear,
@@ -37,7 +37,7 @@ struct WooRoundedBorderTextFieldStyle: TextFieldStyle {
3737
self.content = content
3838
}
3939

40-
func _body(configuration: TextField<Self._Label>) -> some View {
40+
public func _body(configuration: TextField<Self._Label>) -> some View {
4141
let styledContent = content?(configuration) ?? AnyView(configuration)
4242

4343
styledContent
@@ -53,11 +53,11 @@ struct WooRoundedBorderTextFieldStyle: TextFieldStyle {
5353
}
5454
}
5555

56-
extension WooRoundedBorderTextFieldStyle {
56+
public extension WooRoundedBorderTextFieldStyle {
5757
enum Defaults {
58-
static let focusedBorderColor: Color = .init(uiColor: .brand)
59-
static let unfocusedBorderColor: Color = .gray
60-
static let insets = EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)
58+
public static let focusedBorderColor: Color = .init(uiColor: .brand)
59+
public static let unfocusedBorderColor: Color = .gray
60+
public static let insets = EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)
6161
}
6262
}
6363

WooCommerce/Classes/Tools/Connectivity/ConnectivityObserver.swift renamed to Modules/Sources/WooFoundation/Utilities/Connectivity/ConnectivityObserver.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Combine
22

33
/// Interface for the observing connectivity
44
///
5-
protocol ConnectivityObserver {
5+
public protocol ConnectivityObserver {
66
/// Getter for current state of the connectivity.
77
var currentStatus: ConnectivityStatus { get }
88

@@ -21,7 +21,7 @@ protocol ConnectivityObserver {
2121
/// - unknown: It is unknown whether the network is reachable.
2222
/// - notReachable: The network is not reachable.
2323
/// - reachable: The network is reachable.
24-
enum ConnectivityStatus: Equatable {
24+
public enum ConnectivityStatus: Equatable {
2525
case unknown
2626
case notReachable
2727
case reachable(type: ConnectionType)
@@ -32,7 +32,7 @@ enum ConnectivityStatus: Equatable {
3232
/// - ethernetOrWiFi: The connection type is either over Ethernet or WiFi.
3333
/// - cellular: The connection type is a cellular connection.
3434
/// - other: The connection type is via a local loopback network, virtual network or other unknown types.
35-
enum ConnectionType: Equatable {
35+
public enum ConnectionType: Equatable {
3636
case ethernetOrWiFi
3737
case cellular
3838
case other

WooCommerce/Classes/Tools/Connectivity/DefaultConnectivityObserver.swift renamed to Modules/Sources/WooFoundation/Utilities/Connectivity/DefaultConnectivityObserver.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import Combine
22
import Network
33

4-
final class DefaultConnectivityObserver: ConnectivityObserver {
4+
public final class DefaultConnectivityObserver: ConnectivityObserver {
55

66
/// Network monitor to evaluate connection.
77
///
88
private let networkMonitor: NetworkMonitoring
99
private let observingQueue: DispatchQueue = .global(qos: .background)
1010

11-
@Published private(set) var currentStatus: ConnectivityStatus = .unknown
11+
@Published private(set) public var currentStatus: ConnectivityStatus = .unknown
1212

13-
var statusPublisher: AnyPublisher<ConnectivityStatus, Never> {
13+
public var statusPublisher: AnyPublisher<ConnectivityStatus, Never> {
1414
$currentStatus.eraseToAnyPublisher()
1515
}
1616

17+
public convenience init() {
18+
self.init(networkMonitor: NWPathMonitor())
19+
}
20+
1721
init(networkMonitor: NetworkMonitoring = NWPathMonitor()) {
1822
self.networkMonitor = networkMonitor
1923
startObserving()
@@ -25,11 +29,11 @@ final class DefaultConnectivityObserver: ConnectivityObserver {
2529
}
2630
}
2731

28-
func startObserving() {
32+
public func startObserving() {
2933
networkMonitor.start(queue: observingQueue)
3034
}
3135

32-
func stopObserving() {
36+
public func stopObserving() {
3337
networkMonitor.cancel()
3438
}
3539

WooCommerce/Classes/View Modifiers/View+AutofocusTextModifier.swift renamed to Modules/Sources/WooFoundation/ViewModifiers/View+AutofocusTextModifier.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import SwiftUI
22

33
/// Autofocus for `TextField` and `TextEditor` in iOS 15 and later
44
///
5-
struct AutofocusTextModifier: ViewModifier {
5+
public struct AutofocusTextModifier: ViewModifier {
66

77
@FocusState private var textFieldIsFocused: Bool
88

9-
func body(content: Content) -> some View {
9+
public init() {}
10+
11+
public func body(content: Content) -> some View {
1012
content
1113
.focused($textFieldIsFocused)
1214
.onAppear {
@@ -21,7 +23,7 @@ struct AutofocusTextModifier: ViewModifier {
2123

2224
// MARK: View extension
2325

24-
extension View {
26+
public extension View {
2527

2628
/// Autofocus in `TextField` and `TextEditor` is available only for iOS15+
2729
///

WooCommerce/Classes/View Modifiers/View+Conditionals.swift renamed to Modules/Sources/WooFoundation/ViewModifiers/View+Conditionals.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SwiftUI
22

3-
extension View {
3+
public extension View {
44
/// Renders a view if the provided `condition` is met.
55
/// If the `condition` is not met, an `nil` will be used in place of the receiver view.
66
///

WooCommerce/Classes/View Modifiers/View+Measurements.swift renamed to Modules/Sources/WooFoundation/ViewModifiers/View+Measurements.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SwiftUI
22

3-
extension View {
3+
public extension View {
44
/// Measures the height of a view and calls the provided callback with the height value.
55
/// The callback is called both when the view first appears and whenever its height changes.
66
/// If the view contains a list, consider wrapping it in a VStack to ensure the height updates are emitted as a group

WooCommerce/Classes/View Modifiers/View+RoundedBorder.swift renamed to Modules/Sources/WooFoundation/ViewModifiers/View+RoundedBorder.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import SwiftUI
22

33
/// Custom view modifier for applying a rounded border to a view.
4-
struct RoundedBorder: ViewModifier {
4+
public struct RoundedBorder: ViewModifier {
55
let cornerRadius: CGFloat
66
let lineColor: Color
77
let lineWidth: CGFloat
88
let dashed: Bool
99

10-
func body(content: Content) -> some View {
10+
public init(cornerRadius: CGFloat, lineColor: Color, lineWidth: CGFloat, dashed: Bool) {
11+
self.cornerRadius = cornerRadius
12+
self.lineColor = lineColor
13+
self.lineWidth = lineWidth
14+
self.dashed = dashed
15+
}
16+
17+
public func body(content: Content) -> some View {
1118
content
1219
.overlay {
1320
RoundedRectangle(cornerRadius: cornerRadius)
@@ -19,12 +26,11 @@ struct RoundedBorder: ViewModifier {
1926

2027
private extension RoundedBorder {
2128
enum Layout {
22-
static let height: CGFloat = 1
2329
static let dashLength: CGFloat = 5
2430
}
2531
}
2632

27-
extension View {
33+
public extension View {
2834
/// Applies a rounded border to a view.
2935
func roundedBorder(cornerRadius: CGFloat, lineColor: Color, lineWidth: CGFloat, dashed: Bool = false) -> some View {
3036
self.modifier(RoundedBorder(cornerRadius: cornerRadius, lineColor: lineColor, lineWidth: lineWidth, dashed: dashed))

0 commit comments

Comments
 (0)