Skip to content

Commit a0a74e9

Browse files
authored
Fix an issue with compliance popover not dismissing for self-hosted site (#23932)
2 parents fef54d1 + f9012c3 commit a0a74e9

File tree

6 files changed

+33
-115
lines changed

6 files changed

+33
-115
lines changed

Modules/Sources/DesignSystem/Foundation/CGFloat+DesignSystem.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ public extension CGFloat {
1212
public static let max: CGFloat = 48
1313
}
1414

15-
public enum Hitbox {
16-
public static let minTappableLength: CGFloat = 44
17-
}
18-
1915
public enum Radius {
2016
public static let small: CGFloat = 5
2117
public static let medium: CGFloat = 10

Modules/Sources/DesignSystem/Gallery/LengthGallery.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct LengthGallery: View {
3030
ZStack {
3131
RoundedRectangle(cornerRadius: .DS.Radius.small)
3232
.fill(.background)
33-
.frame(height: .DS.Hitbox.minTappableLength)
33+
.frame(height: 44)
3434
HStack {
3535
Text(name)
3636
.offset(x: .DS.Padding.double)

WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopover.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
import SwiftUI
22
import JetpackStatsWidgetsCore
3-
import DesignSystem
43

54
struct CompliancePopover: View {
65
@StateObject
76
var viewModel: CompliancePopoverViewModel
87

98
var body: some View {
10-
VStack(alignment: .leading, spacing: .DS.Padding.double) {
11-
titleText
12-
subtitleText
13-
analyticsToggle
14-
footnote
15-
buttonsHStack
9+
ScrollView(.vertical) {
10+
VStack(alignment: .leading, spacing: 8) {
11+
titleText.padding(.top, 16)
12+
subtitleText
13+
analyticsToggle.padding(.top, 8)
14+
footnote
15+
}
16+
.padding(20)
17+
}
18+
.safeAreaInset(edge: .bottom) {
19+
HStack(spacing: 8) {
20+
settingsButton
21+
saveButton
22+
}
23+
.padding(20)
24+
.background(Color(.systemBackground))
1625
}
17-
.padding(.DS.Padding.medium)
18-
.fixedSize(horizontal: false, vertical: true)
1926
}
2027

2128
private var titleText: some View {
@@ -33,7 +40,7 @@ struct CompliancePopover: View {
3340
Toggle(Strings.toggleTitle, isOn: $viewModel.isAnalyticsEnabled)
3441
.foregroundStyle(Color(.label))
3542
.toggleStyle(UIAppColor.switchStyle)
36-
.padding(.vertical, .DS.Padding.single)
43+
.padding(.vertical, 8)
3744
}
3845

3946
private var footnote: some View {
@@ -42,26 +49,19 @@ struct CompliancePopover: View {
4249
.foregroundColor(.secondary)
4350
}
4451

45-
private var buttonsHStack: some View {
46-
HStack(spacing: .DS.Padding.single) {
47-
settingsButton
48-
saveButton
49-
}.padding(.top, .DS.Padding.medium)
50-
}
51-
5252
private var settingsButton: some View {
5353
Button(action: {
5454
self.viewModel.didTapSettings()
5555
}) {
5656
ZStack {
57-
RoundedRectangle(cornerRadius: .DS.Padding.single)
58-
.stroke(.gray, lineWidth: .DS.Border.thin)
57+
RoundedRectangle(cornerRadius: 8)
58+
.stroke(.gray, lineWidth: 0.5)
5959
Text(Strings.settingsButtonTitle)
6060
.font(.body)
6161
}
6262
}
6363
.foregroundColor(AppColor.brand)
64-
.frame(height: .DS.Hitbox.minTappableLength)
64+
.frame(height: 44)
6565
}
6666

6767
private var saveButton: some View {
@@ -76,7 +76,7 @@ struct CompliancePopover: View {
7676
}
7777
}
7878
.foregroundColor(.white)
79-
.frame(height: .DS.Hitbox.minTappableLength)
79+
.frame(height: 44)
8080
}
8181
}
8282

WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverCoordinator.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ final class CompliancePopoverCoordinator: CompliancePopoverCoordinatorProtocol {
101101
contextManager: ContextManager.shared
102102
)
103103
complianceViewModel.coordinator = self
104-
let complianceViewController = CompliancePopoverViewController(viewModel: complianceViewModel)
105-
let bottomSheetViewController = BottomSheetViewController(childViewController: complianceViewController, customHeaderSpacing: 0)
106-
107-
bottomSheetViewController.show(from: presentingViewController)
104+
let complianceVC = CompliancePopoverViewController(viewModel: complianceViewModel)
105+
complianceVC.sheetPresentationController?.detents = [.medium(), .large()]
106+
complianceVC.isModalInPresentation = true
107+
presentingViewController.present(complianceVC, animated: true)
108108
}
109109
}
110110

WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverViewController.swift

Lines changed: 3 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,12 @@ import UIKit
22
import SwiftUI
33
import WordPressUI
44

5-
final class CompliancePopoverViewController: UIViewController {
6-
7-
// MARK: - Dependencies
8-
5+
final class CompliancePopoverViewController: UIHostingController<CompliancePopover> {
96
private let viewModel: CompliancePopoverViewModel
107

11-
// MARK: - Views
12-
13-
private let scrollView: UIScrollView = {
14-
let view = UIScrollView()
15-
view.showsVerticalScrollIndicator = false
16-
view.translatesAutoresizingMaskIntoConstraints = false
17-
return view
18-
}()
19-
20-
private let hostingController: UIHostingController<CompliancePopover>
21-
22-
private var contentView: UIView {
23-
return hostingController.view
24-
}
25-
26-
// MARK: - Init
27-
288
init(viewModel: CompliancePopoverViewModel) {
299
self.viewModel = viewModel
30-
let content = CompliancePopover(viewModel: viewModel)
31-
self.hostingController = UIHostingController(rootView: content)
32-
super.init(nibName: nil, bundle: nil)
10+
super.init(rootView: CompliancePopover(viewModel: viewModel))
3311
}
3412

3513
required dynamic init?(coder aDecoder: NSCoder) {
@@ -40,60 +18,7 @@ final class CompliancePopoverViewController: UIViewController {
4018

4119
override func viewDidLoad() {
4220
super.viewDidLoad()
43-
self.addContentView()
44-
self.viewModel.didDisplayPopover()
45-
}
4621

47-
override func viewDidLayoutSubviews() {
48-
super.viewDidLayoutSubviews()
49-
// Calculate the size needed for the view to fit its content
50-
let targetSize = CGSize(width: view.bounds.width, height: 0)
51-
self.contentView.frame = CGRect(origin: .zero, size: targetSize)
52-
let contentViewSize = contentView.systemLayoutSizeFitting(targetSize)
53-
self.contentView.frame.size = contentViewSize
54-
55-
// Set the scrollView's content size to match the contentView's size
56-
//
57-
// Scroll is enabled / disabled automatically depending on whether the `contentSize` is bigger than the its size.
58-
self.scrollView.contentSize = contentViewSize
59-
60-
// Set the preferred content size for the view controller to match the contentView's size
61-
//
62-
// This property should be updated when `DrawerPresentable.collapsedHeight` is `intrinsicHeight`.
63-
// Because under the hood the `BottomSheetViewController` reads this property to layout its subviews.
64-
self.preferredContentSize = contentViewSize
65-
}
66-
67-
private func addContentView() {
68-
self.view.addSubview(scrollView)
69-
self.view.pinSubviewToAllEdges(scrollView)
70-
self.hostingController.willMove(toParent: self)
71-
self.addChild(hostingController)
72-
self.contentView.translatesAutoresizingMaskIntoConstraints = true
73-
self.scrollView.addSubview(contentView)
74-
self.hostingController.didMove(toParent: self)
75-
}
76-
}
77-
78-
// MARK: - DrawerPresentable
79-
80-
extension CompliancePopoverViewController: DrawerPresentable {
81-
var collapsedHeight: DrawerHeight {
82-
if traitCollection.verticalSizeClass == .compact {
83-
return .maxHeight
84-
}
85-
return .intrinsicHeight
86-
}
87-
88-
var allowsUserTransition: Bool {
89-
return false
90-
}
91-
92-
var allowsDragToDismiss: Bool {
93-
false
94-
}
95-
96-
var allowsTapToDismiss: Bool {
97-
return false
22+
self.viewModel.didDisplayPopover()
9823
}
9924
}

WordPress/Classes/ViewRelated/EEUUSCompliance/CompliancePopoverViewModel.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import UIKit
33
import WordPressUI
44

5-
class CompliancePopoverViewModel: ObservableObject {
5+
final class CompliancePopoverViewModel: ObservableObject {
66

77
@Published
88
var isAnalyticsEnabled: Bool = !WPAppAnalytics.userHasOptedOut()
@@ -45,13 +45,10 @@ class CompliancePopoverViewModel: ObservableObject {
4545
let account = try? WPAccount.lookupDefaultWordPressComAccount(in: context)
4646
return (account?.userID, account?.wordPressComRestApi)
4747
}
48-
49-
guard let accountID, let restAPI else {
50-
return
48+
if let accountID, let restAPI {
49+
let change = AccountSettingsChange.tracksOptOut(!isAnalyticsEnabled)
50+
AccountSettingsService(userID: accountID.intValue, api: restAPI).saveChange(change)
5151
}
52-
53-
let change = AccountSettingsChange.tracksOptOut(!isAnalyticsEnabled)
54-
AccountSettingsService(userID: accountID.intValue, api: restAPI).saveChange(change)
5552
coordinator?.dismiss()
5653
defaults.didShowCompliancePopup = true
5754
analyticsTracker.trackPrivacyChoicesBannerSaveButtonTapped(analyticsEnabled: isAnalyticsEnabled)

0 commit comments

Comments
 (0)