Skip to content

Commit

Permalink
Improve the styling
Browse files Browse the repository at this point in the history
  • Loading branch information
theospears committed Oct 1, 2023
1 parent 748078c commit df6b475
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 22 deletions.
6 changes: 5 additions & 1 deletion BeeSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 53;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -80,6 +80,7 @@
E42CB452291727B200A35AB9 /* HealthKitError.swift in Sources */ = {isa = PBXBuildFile; fileRef = E42CB451291727B200A35AB9 /* HealthKitError.swift */; };
E42CB453291727B200A35AB9 /* HealthKitError.swift in Sources */ = {isa = PBXBuildFile; fileRef = E42CB451291727B200A35AB9 /* HealthKitError.swift */; };
E42CB454291727B200A35AB9 /* HealthKitError.swift in Sources */ = {isa = PBXBuildFile; fileRef = E42CB451291727B200A35AB9 /* HealthKitError.swift */; };
E43833942AC1473E0098A38F /* InlineDatePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = E43833932AC1473E0098A38F /* InlineDatePicker.swift */; };
E43BEA842A036A9C00FC3A38 /* LogReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = E43BEA832A036A9C00FC3A38 /* LogReader.swift */; };
E43BEA862A036D4300FC3A38 /* LogReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E43BEA852A036D4300FC3A38 /* LogReaderTests.swift */; };
E43D9AFB2929C37D00FC1578 /* DatapointValueAccessory.swift in Sources */ = {isa = PBXBuildFile; fileRef = E43D9AFA2929C37D00FC1578 /* DatapointValueAccessory.swift */; };
Expand Down Expand Up @@ -348,6 +349,7 @@
E4040D732A7B5F0E008E7D0E /* WorkoutMinutesHealthKitMetric.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkoutMinutesHealthKitMetric.swift; sourceTree = "<group>"; };
E417572C2A6446FE0029CDDA /* CurrentUserManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentUserManagerTests.swift; sourceTree = "<group>"; };
E42CB451291727B200A35AB9 /* HealthKitError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HealthKitError.swift; sourceTree = "<group>"; };
E43833932AC1473E0098A38F /* InlineDatePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InlineDatePicker.swift; sourceTree = "<group>"; };
E43BEA832A036A9C00FC3A38 /* LogReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogReader.swift; sourceTree = "<group>"; };
E43BEA852A036D4300FC3A38 /* LogReaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogReaderTests.swift; sourceTree = "<group>"; };
E43D9AFA2929C37D00FC1578 /* DatapointValueAccessory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatapointValueAccessory.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -517,6 +519,7 @@
A1C170DF1BEEB3110018D32B /* UIFontExtension.swift */,
E43D9AFA2929C37D00FC1578 /* DatapointValueAccessory.swift */,
E46DC80E2AA58DF20059FDFE /* PullToRefreshHint.swift */,
E43833932AC1473E0098A38F /* InlineDatePicker.swift */,
);
name = UI;
sourceTree = "<group>";
Expand Down Expand Up @@ -1143,6 +1146,7 @@
A1BE73AA1E8B45BF00DEC4DB /* ChooseHKMetricViewController.swift in Sources */,
A149147B1BE79FD50060600A /* EditNotificationsViewController.swift in Sources */,
A1BE73AC1E8B47E700DEC4DB /* HealthKitMetricTableViewCell.swift in Sources */,
E43833942AC1473E0098A38F /* InlineDatePicker.swift in Sources */,
A1C11B481B06F5D100D22871 /* Constants.swift in Sources */,
E4B0833D293810EB00A71564 /* DataPoint.swift in Sources */,
E44CE7732993317B00394E87 /* ServiceLocator.swift in Sources */,
Expand Down
24 changes: 4 additions & 20 deletions BeeSwift/EditDatapointViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EditDatapointViewController: UIViewController, UITextFieldDelegate {

var datapoint : ExistingDataPoint
var goalSlug : String
fileprivate var datePicker = UIDatePicker()
fileprivate var datePicker = InlineDatePicker()
fileprivate var valueField = UITextField()
fileprivate var commentField = UITextField()

Expand Down Expand Up @@ -59,16 +59,11 @@ class EditDatapointViewController: UIViewController, UITextFieldDelegate {

formView.addSubview(self.datePicker)
self.datePicker.snp.makeConstraints { (make) in
make.left.right.equalTo(formView)
make.top.equalTo(dateLabel.snp.bottom)
make.left.right.equalTo(formView).inset(10)
make.top.equalTo(dateLabel.snp.bottom).offset(3)
}
self.datePicker.datePickerMode = .date
self.datePicker.preferredDatePickerStyle = .compact
self.datePicker.contentHorizontalAlignment = .left
self.datePicker.backgroundColor = nil
if let bgView = self.datePicker.subviews.first?.subviews.first?.subviews.first {
bgView.backgroundColor = nil
}

let daystamp = self.datapoint.daystamp
let dateFormatter = DateFormatter()
Expand All @@ -80,7 +75,7 @@ class EditDatapointViewController: UIViewController, UITextFieldDelegate {
formView.addSubview(divider1)
divider1.snp.makeConstraints { (make) in
make.left.right.equalTo(formView).inset(10)
make.top.equalTo(self.datePicker.snp.bottom)
make.top.equalTo(self.datePicker.snp.bottom).offset(10)
make.height.equalTo(1)
}
divider1.backgroundColor = UIColor(white: 0.5, alpha: 0.5)
Expand Down Expand Up @@ -259,15 +254,4 @@ class EditDatapointViewController: UIViewController, UITextFieldDelegate {

self.present(alert, animated: true, completion: nil)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
if let bgView = self.datePicker.subviews.first?.subviews.first?.subviews.first {
bgView.backgroundColor = nil
}
}

}
2 changes: 1 addition & 1 deletion BeeSwift/GoalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class GoalViewController: UIViewController, UIScrollViewDelegate, DatapointTabl

let editDatapointViewController = EditDatapointViewController(goalSlug: goal.slug, datapoint: existingDatapoint)
let navigationController = UINavigationController(rootViewController: editDatapointViewController)
navigationController.modalPresentationStyle = .popover
navigationController.modalPresentationStyle = .formSheet
self.present(navigationController, animated: true, completion: nil)
}

Expand Down
62 changes: 62 additions & 0 deletions BeeSwift/InlineDatePicker.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// InlineDatePicker.swift
// BeeSwift
//
// A date picker component designed to be shown fully inline. Unlike
// the default inline date picked mode it does not add margin or background.
//
// This component modifies private subviews within the UIDatePicker hierarchy, so any
// changes should be tested against all supported iOS versions

import Foundation

class InlineDatePicker : UIDatePicker {
init() {
super.init(frame: .zero)
self.preferredDatePickerStyle = .compact

resetStyle()
}

required init?(coder: NSCoder) {
super.init(coder: coder)
}

override func didMoveToSuperview() {
super.didMoveToSuperview()
resetStyle()
}

override func layoutSubviews() {
super.layoutSubviews()
resetStyle()
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
resetStyle()
}

private func resetStyle() {
if let iosCompactView = self.subviews.first,
let compactDateLabel = iosCompactView.subviews.first {

// Switch to a transparent background
if let bgView = compactDateLabel.subviews.first {
bgView.backgroundColor = nil
}

// Remove the padding around the date label
if compactDateLabel.subviews.count >= 2 {
let linkedLabel = compactDateLabel.subviews[1]

for constraint in compactDateLabel.constraints {
if constraint.firstItem === linkedLabel || constraint.secondItem === linkedLabel {
constraint.constant = 0
}
}
}
}
}

}

0 comments on commit df6b475

Please sign in to comment.