Skip to content

Commit 46e859b

Browse files
Merge pull request #92 from componentskit/improvements
Bug fixes
2 parents e4cff7c + a27b1ee commit 46e859b

File tree

8 files changed

+37
-7
lines changed

8 files changed

+37
-7
lines changed

Examples/DemosApp/DemosApp.xcodeproj/project.pbxproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 50;
6+
objectVersion = 70;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -80,7 +80,6 @@
8080
740D221F2CD3BECA006731A5 /* Project object */ = {
8181
isa = PBXProject;
8282
attributes = {
83-
BuildIndependentTargetsInParallel = 1;
8483
LastSwiftUpdateCheck = 1610;
8584
LastUpgradeCheck = 1610;
8685
TargetAttributes = {

Sources/ComponentsKit/Components/Button/SUButton.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ private struct CustomButtonStyle: SwiftUI.ButtonStyle {
108108
configuration.label
109109
.font(self.model.preferredFont.font)
110110
.lineLimit(1)
111+
.contentShape(.rect)
111112
.padding(.horizontal, self.model.horizontalPadding)
112113
.frame(maxWidth: self.model.width)
113114
.frame(height: self.model.height)

Sources/ComponentsKit/Components/Button/UKButton.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import AutoLayout
22
import UIKit
33

44
/// A UIKit component that performs an action when it is tapped by a user.
5-
open class UKButton: UIView, UKComponent {
5+
open class UKButton: FullWidthComponent, UKComponent {
66
// MARK: Properties
77

88
/// A closure that is triggered when the button is tapped.

Sources/ComponentsKit/Components/InputField/UKInputField.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import AutoLayout
22
import UIKit
33

44
/// A UIKit component that displays a field to input a text.
5-
open class UKInputField: UIView, UKComponent {
5+
open class UKInputField: FullWidthComponent, UKComponent {
66
// MARK: Public Properties
77

88
/// A closure that is triggered when the text changes.
@@ -140,6 +140,8 @@ open class UKInputField: UIView, UKComponent {
140140
self.horizontalStackView.vertically()
141141
self.horizontalStackViewConstraints = self.horizontalStackView.horizontally(self.model.horizontalPadding)
142142

143+
self.captionLabel.horizontally()
144+
143145
self.textField.setContentHuggingPriority(.defaultLow, for: .horizontal)
144146
self.titleLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal)
145147
}

Sources/ComponentsKit/Components/ProgressBar/UKProgressBar.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import AutoLayout
22
import UIKit
33

44
/// A UIKit component that visually represents the progress of a task or process using a horizontal bar.
5-
open class UKProgressBar: UIView, UKComponent {
5+
open class UKProgressBar: FullWidthComponent, UKComponent {
66
// MARK: - Public Properties
77

88
/// A model that defines the appearance properties.

Sources/ComponentsKit/Components/SegmentedControl/UKSegmentedControl.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import AutoLayout
22
import UIKit
33

44
/// A UIKit component that allows users to choose between multiple segments or options.
5-
open class UKSegmentedControl<ID: Hashable>: UIView, UKComponent {
5+
open class UKSegmentedControl<ID: Hashable>: FullWidthComponent, UKComponent {
66
// MARK: Properties
77

88
/// A closure that is triggered when a selected segment changes.

Sources/ComponentsKit/Components/Slider/UKSlider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import AutoLayout
22
import UIKit
33

44
/// A UIKit component that lets users select a value from a range by dragging a thumb along a track.
5-
open class UKSlider: UIView, UKComponent {
5+
open class UKSlider: FullWidthComponent, UKComponent {
66
// MARK: - Properties
77

88
/// A closure that is triggered when the `currentValue` changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import UIKit
2+
3+
/// A base-class for views whose intrinsic content size depends on the
4+
/// width of their super-view (e.g. full width button, input field, etc.).
5+
///
6+
/// By inheriting from `FullWidthComponent` the component gets automatic
7+
/// `invalidateIntrinsicContentSize()` calls whenever the device rotates, the
8+
/// window is resized (iPad multitasking, Stage Manager) or the view moves
9+
/// into a different container with a new width.
10+
open class FullWidthComponent: UIView {
11+
private var lastKnownParentWidth: CGFloat = .nan
12+
13+
open override func layoutSubviews() {
14+
super.layoutSubviews()
15+
16+
guard let parentWidth = self.superview?.bounds.width else { return }
17+
18+
if parentWidth != self.lastKnownParentWidth {
19+
self.lastKnownParentWidth = parentWidth
20+
21+
// Defer to the next run-loop tick so the current layout pass
22+
// finishes with the new parent size first.
23+
DispatchQueue.main.async {
24+
self.invalidateIntrinsicContentSize()
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)