Skip to content

Commit 77a4675

Browse files
committed
Add reusable DisclosureIndicator
1 parent 6593288 commit 77a4675

File tree

6 files changed

+40
-43
lines changed

6 files changed

+40
-43
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Creation/ProductsSection/AddProductToOrder.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ struct AddProductToOrder: View {
1111
///
1212
@ObservedObject var viewModel: AddProductToOrderViewModel
1313

14-
/// Keeps track of the current screen scale
15-
///
16-
@ScaledMetric private var scale = 1
17-
1814
var body: some View {
1915
NavigationView {
2016
VStack {
@@ -73,12 +69,7 @@ struct AddProductToOrder: View {
7369
ProductRow(viewModel: rowViewModel)
7470
.frame(maxWidth: .infinity, alignment: .leading)
7571

76-
Image(uiImage: .chevronImage)
77-
.resizable()
78-
.flipsForRightToLeftLayoutDirection(true)
79-
.frame(width: Constants.chevronSize(scale: scale), height: Constants.chevronSize(scale: scale))
80-
.foregroundColor(Color(.systemGray))
81-
.accessibility(hidden: true)
72+
DisclosureIndicator()
8273
}
8374
}
8475
} else {
@@ -95,9 +86,6 @@ private extension AddProductToOrder {
9586
enum Constants {
9687
static let dividerHeight: CGFloat = 1
9788
static let defaultPadding: CGFloat = 16
98-
static func chevronSize(scale: CGFloat) -> CGFloat {
99-
22 * scale
100-
}
10189
}
10290

10391
enum Localization {

WooCommerce/Classes/ViewRelated/Orders/Simple Payments/Method/SimplePaymentsMethod.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,7 @@ private struct MethodRow: View {
150150
}
151151
.frame(maxWidth: .infinity, alignment: .leading)
152152

153-
Image(uiImage: .chevronImage)
154-
.resizable()
155-
.flipsForRightToLeftLayoutDirection(true)
156-
.frame(width: SimplePaymentsMethod.Layout.chevronWidthHeight(scale: scale),
157-
height: SimplePaymentsMethod.Layout.chevronWidthHeight(scale: scale))
158-
.foregroundColor(Color(.systemGray))
159-
.accessibility(hidden: true)
153+
DisclosureIndicator()
160154
}
161155
.padding(.vertical, SimplePaymentsMethod.Layout.verticalPadding)
162156
.padding(.horizontal, insets: safeAreaInsets)
@@ -206,10 +200,6 @@ private extension SimplePaymentsMethod {
206200
static func iconWidthHeight(scale: CGFloat) -> CGFloat {
207201
24 * scale
208202
}
209-
210-
static func chevronWidthHeight(scale: CGFloat) -> CGFloat {
211-
22 * scale
212-
}
213203
}
214204
}
215205

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import SwiftUI
2+
3+
struct DisclosureIndicator: View {
4+
/// Keeps track of the current screen scale
5+
///
6+
@ScaledMetric private var scale = 1
7+
8+
var body: some View {
9+
Image(uiImage: .chevronImage)
10+
.resizable()
11+
.flipsForRightToLeftLayoutDirection(true)
12+
.frame(width: Constants.chevronSize(scale: scale), height: Constants.chevronSize(scale: scale))
13+
.foregroundColor(Color(.systemGray))
14+
.accessibility(hidden: true)
15+
}
16+
}
17+
18+
// MARK: Constants
19+
private extension DisclosureIndicator {
20+
enum Constants {
21+
static func chevronSize(scale: CGFloat) -> CGFloat {
22+
22 * scale
23+
}
24+
}
25+
}
26+
27+
struct DisclosureIndicator_Previews: PreviewProvider {
28+
static var previews: some View {
29+
DisclosureIndicator()
30+
.previewLayout(.sizeThatFits)
31+
}
32+
}

WooCommerce/Classes/ViewRelated/ReusableViews/SwiftUI Components/NavigationRow.swift

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ struct NavigationRow<Content: View>: View {
1616
///
1717
let action: () -> Void
1818

19-
/// Keeps track of the current screen scale
20-
///
21-
@ScaledMetric private var scale = 1
22-
2319
/// Environment safe areas
2420
///
2521
@Environment(\.safeAreaInsets) var safeAreaInsets: EdgeInsets
@@ -37,13 +33,7 @@ struct NavigationRow<Content: View>: View {
3733
HStack {
3834
content
3935
Spacer()
40-
Image(uiImage: .chevronImage)
41-
.resizable()
42-
.flipsForRightToLeftLayoutDirection(true)
43-
.frame(width: Layout.chevronWidthHeight(scale: scale),
44-
height: Layout.chevronWidthHeight(scale: scale))
45-
.foregroundColor(Color(.systemGray))
46-
.accessibility(hidden: true)
36+
DisclosureIndicator()
4737
.renderedIf(selectable)
4838
}
4939
.padding()
@@ -56,9 +46,6 @@ struct NavigationRow<Content: View>: View {
5646

5747
private enum Layout {
5848
static let minHeight: CGFloat = 44
59-
static func chevronWidthHeight(scale: CGFloat) -> CGFloat {
60-
22 * scale
61-
}
6249
}
6350

6451
struct NavigationRow_Previews: PreviewProvider {

WooCommerce/Classes/ViewRelated/ReusableViews/SwiftUI Components/TitleAndValueRow.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ struct TitleAndValueRow: View {
3333
.padding(.vertical, Constants.verticalPadding)
3434
}
3535

36-
Image(uiImage: .chevronImage)
37-
.flipsForRightToLeftLayoutDirection(true)
36+
DisclosureIndicator()
3837
.renderedIf(selectionStyle == .disclosure)
39-
.frame(width: Constants.imageSize, height: Constants.imageSize)
40-
.foregroundColor(Color(UIColor.gray(.shade30)))
4138
}
4239
.contentShape(Rectangle())
4340
})
@@ -99,7 +96,6 @@ private extension Text {
9996

10097
private extension TitleAndValueRow {
10198
enum Constants {
102-
static let imageSize: CGFloat = 22
10399
static let minHeight: CGFloat = 44
104100
static let maxHeight: CGFloat = 136
105101
static let horizontalPadding: CGFloat = 16

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,7 @@
11891189
CC593A6B26EA640800EF0E04 /* PackageCreationError+UI.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC593A6A26EA640800EF0E04 /* PackageCreationError+UI.swift */; };
11901190
CC69236226010946002FB669 /* LoginProloguePages.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC69236126010946002FB669 /* LoginProloguePages.swift */; };
11911191
CC6923AC26010D8D002FB669 /* LoginProloguePageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC6923AB26010D8D002FB669 /* LoginProloguePageViewController.swift */; };
1192+
CC72BB6427BD842500837876 /* DisclosureIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC72BB6327BD842500837876 /* DisclosureIndicator.swift */; };
11921193
CC770C8A27B1497700CE6ABC /* SearchHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC770C8927B1497700CE6ABC /* SearchHeader.swift */; };
11931194
CC77488E2719A07D0043CDD7 /* ShippingLabelAddressTopBannerFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC77488D2719A07D0043CDD7 /* ShippingLabelAddressTopBannerFactoryTests.swift */; };
11941195
CC8413E423F5C48E00EFC277 /* stop.sh in Resources */ = {isa = PBXBuildFile; fileRef = CCFC011123E9E40B00157A78 /* stop.sh */; };
@@ -2820,6 +2821,7 @@
28202821
CC593A6A26EA640800EF0E04 /* PackageCreationError+UI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PackageCreationError+UI.swift"; sourceTree = "<group>"; };
28212822
CC69236126010946002FB669 /* LoginProloguePages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginProloguePages.swift; sourceTree = "<group>"; };
28222823
CC6923AB26010D8D002FB669 /* LoginProloguePageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginProloguePageViewController.swift; sourceTree = "<group>"; };
2824+
CC72BB6327BD842500837876 /* DisclosureIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisclosureIndicator.swift; sourceTree = "<group>"; };
28232825
CC770C8927B1497700CE6ABC /* SearchHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchHeader.swift; sourceTree = "<group>"; };
28242826
CC77488D2719A07D0043CDD7 /* ShippingLabelAddressTopBannerFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelAddressTopBannerFactoryTests.swift; sourceTree = "<group>"; };
28252827
CCB366AE274518EC007D437A /* NewOrderViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewOrderViewModelTests.swift; sourceTree = "<group>"; };
@@ -5084,6 +5086,7 @@
50845086
AEACCB6C2785FF4A000D01F0 /* NavigationRow.swift */,
50855087
CCF87BBD279047BC00461C43 /* InfiniteScrollList.swift */,
50865088
CC770C8927B1497700CE6ABC /* SearchHeader.swift */,
5089+
CC72BB6327BD842500837876 /* DisclosureIndicator.swift */,
50875090
);
50885091
path = "SwiftUI Components";
50895092
sourceTree = "<group>";
@@ -8967,6 +8970,7 @@
89678970
0298430C259351F100979CAE /* ShippingLabelsTopBannerFactory.swift in Sources */,
89688971
020BE74D23B1F5EB007FE54C /* TitleAndTextFieldTableViewCell.swift in Sources */,
89698972
023D692E2588BF0900F7DA72 /* ShippingLabelPaperSizeListSelectorCommand.swift in Sources */,
8973+
CC72BB6427BD842500837876 /* DisclosureIndicator.swift in Sources */,
89708974
77E53EC52510C193003D385F /* ProductDownloadListViewController+Droppable.swift in Sources */,
89718975
0259D5F92581F0E6003B1CD6 /* ShippingLabelPaperSizeOptionView.swift in Sources */,
89728976
D81F2D37225F0D160084BF9C /* EmptyListMessageWithActionView.swift in Sources */,

0 commit comments

Comments
 (0)