Skip to content

Bug fixes #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Examples/DemosApp/DemosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 70;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -80,7 +80,6 @@
740D221F2CD3BECA006731A5 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1610;
LastUpgradeCheck = 1610;
TargetAttributes = {
Expand Down
1 change: 1 addition & 0 deletions Sources/ComponentsKit/Components/Button/SUButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private struct CustomButtonStyle: SwiftUI.ButtonStyle {
configuration.label
.font(self.model.preferredFont.font)
.lineLimit(1)
.contentShape(.rect)
.padding(.horizontal, self.model.horizontalPadding)
.frame(maxWidth: self.model.width)
.frame(height: self.model.height)
Expand Down
2 changes: 1 addition & 1 deletion Sources/ComponentsKit/Components/Button/UKButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import AutoLayout
import UIKit

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

/// A closure that is triggered when the button is tapped.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import AutoLayout
import UIKit

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

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

self.captionLabel.horizontally()

self.textField.setContentHuggingPriority(.defaultLow, for: .horizontal)
self.titleLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import AutoLayout
import UIKit

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

/// A model that defines the appearance properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import AutoLayout
import UIKit

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

/// A closure that is triggered when a selected segment changes.
Expand Down
2 changes: 1 addition & 1 deletion Sources/ComponentsKit/Components/Slider/UKSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import AutoLayout
import UIKit

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

/// A closure that is triggered when the `currentValue` changes.
Expand Down
28 changes: 28 additions & 0 deletions Sources/ComponentsKit/Helpers/UIKit/FullWidthComponent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import UIKit

/// A base-class for views whose intrinsic content size depends on the
/// width of their super-view (e.g. full width button, input field, etc.).
///
/// By inheriting from `FullWidthComponent` the component gets automatic
/// `invalidateIntrinsicContentSize()` calls whenever the device rotates, the
/// window is resized (iPad multitasking, Stage Manager) or the view moves
/// into a different container with a new width.
open class FullWidthComponent: UIView {
private var lastKnownParentWidth: CGFloat = .nan

open override func layoutSubviews() {
super.layoutSubviews()

guard let parentWidth = self.superview?.bounds.width else { return }

if parentWidth != self.lastKnownParentWidth {
self.lastKnownParentWidth = parentWidth

// Defer to the next run-loop tick so the current layout pass
// finishes with the new parent size first.
DispatchQueue.main.async {
self.invalidateIntrinsicContentSize()
}
}
}
}