Skip to content

Commit f9beff8

Browse files
authored
Merge pull request #26 from malcommac/patch/autosizing-swiftui
Compatibility with SwiftUI hosted View
2 parents a4dfd2a + a4f6a58 commit f9beff8

File tree

7 files changed

+56
-43
lines changed

7 files changed

+56
-43
lines changed

README.md

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
<p align="center" >
2-
<img src="banner.png" width=300px alt="ScrollStackController" title="ScrollStackController">
1+
<p align="center">
2+
<picture>
3+
<source media="(prefers-color-scheme: dark)" srcset="./Resources/scrollstack-dark.png" width="350">
4+
<img alt="logo-library" src="./Resources/scrollstack-light.png" width="350">
5+
</picture>
36
</p>
47

5-
<p align="center"><strong>Easy scrollable layouts in UIKit</strong></p>
8+
[![Swift](https://img.shields.io/badge/Swift-5.3_5.4_5.5_5.6-orange?style=flat-square)](https://img.shields.io/badge/Swift-5.3_5.4_5.5_5.6-Orange?style=flat-square)
9+
[![Platform](https://img.shields.io/badge/Platforms-iOS-4E4E4E.svg?colorA=28a745)](#installation)
10+
[![Swift Package Manager](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange?style=flat-square)](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange?style=flat-square)
11+
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/ScrollStackController.svg?style=flat-square)](https://img.shields.io/cocoapods/v/ScrollStackController.svg)
12+
613

714
Create complex scrollable layout using UIViewControllers or plain UIViews and simplify your code!
815

@@ -32,41 +39,43 @@ You can think of it as `UITableView` but with several differences:
3239
*Hi fellow developer!*
3340
You know, maintaing and developing tools consumes resources and time. While I enjoy making them **your support is foundamental to allow me continue its development**.
3441

35-
If you are using SwiftLocation or any other of my creations please consider the following options:
42+
If you are using `ScrollStackController` or any other of my creations please consider the following options:
3643

3744
- [**Make a donation with PayPal**](https://www.paypal.com/paypalme/danielemargutti/20)
3845
- [**Become a Sponsor**](https://github.com/sponsors/malcommac)
39-
4046
- [Follow Me](https://github.com/malcommac)
4147

4248
<a name="index"/>
4349

4450
## Table of Contents
4551

46-
- [When to use `ScrollStackController` and when not](#whentousescrollstackcontrollerandwhennot)
47-
- [How to use it](#howtouseit)
48-
- [Adding Rows](#addingrows)
49-
- [Removing / Replacing Rows](#removingreplacingrows)
50-
- [Move Rows](#moverows)
51-
- [Hide / Show Rows](#hideshowrows)
52-
- [Hide / Show Rows with custom animations](#customanimations)
53-
- [Reload Rows](#reloadrows)
54-
- [Sizing Rows](#sizingrows)
55-
- [Fixed Row Size](#fixedrowsize)
56-
- [Fitting Layout Row Size](#fittinglayoutrowsize)
57-
- [Collapsible Rows](#collapsiblerows)
58-
- [Working with dynamic UICollectionView/UITableView/UITextView](#workingwithdynamicuicollectionviewuitableviewuitextview)
59-
- [Using plain UIViews instead of view controllers](#lightweightplainuiview)
60-
- [Rows Separator](#rowsseparator)
61-
- [Tap On Rows](#taponrows)
62-
- [Get the row/controller](#utilsmethods)
63-
- [Set Row Insets](#setrowinsets)
64-
- [Change ScrollStack scrolling axis](#changescrollaxis)
65-
- [Subscribe to Events](#rowevents)
66-
- [Example App](#exampleapp)
67-
- [Installation](#installation)
68-
- [System Requirements](#systemrequirements)
69-
- [Author & License](#authorlicense)
52+
- [❤️ Your Support](#️-your-support)
53+
- [Table of Contents](#table-of-contents)
54+
- [When to use `ScrollStackController` and when not](#when-to-use-scrollstackcontroller-and-when-not)
55+
- [How to use it](#how-to-use-it)
56+
- [Adding Rows](#adding-rows)
57+
- [Removing / Replacing Rows](#removing--replacing-rows)
58+
- [Move Rows](#move-rows)
59+
- [Hide / Show Rows](#hide--show-rows)
60+
- [Hide / Show Rows with custom animations](#hide--show-rows-with-custom-animations)
61+
- [Reload Rows](#reload-rows)
62+
- [Sizing Rows](#sizing-rows)
63+
- [Fixed Row Size](#fixed-row-size)
64+
- [Fitting Layout Row Size](#fitting-layout-row-size)
65+
- [Collapsible Rows](#collapsible-rows)
66+
- [Working with dynamic UICollectionView/UITableView/UITextView](#working-with-dynamic-uicollectionviewuitableviewuitextview)
67+
- [Rows Separator](#rows-separator)
68+
- [Using plain UIViews instead of view controllers](#using-plain-uiviews-instead-of-view-controllers)
69+
- [Tap On Rows](#tap-on-rows)
70+
- [Get the row/controller](#get-the-rowcontroller)
71+
- [Set Row Insets](#set-row-insets)
72+
- [Change ScrollStack scrolling axis](#change-scrollstack-scrolling-axis)
73+
- [Subscribe to Row Events](#subscribe-to-row-events)
74+
- [System Requirements](#system-requirements)
75+
- [Example App](#example-app)
76+
- [Installation](#installation)
77+
- [Contributing](#contributing)
78+
- [Copyright \& Acknowledgements](#copyright--acknowledgements)
7079

7180
<a name="whentousescrollstackcontrollerandwhennot"/>
7281

Resources/scrollstack-dark.png

29.6 KB
Loading

Resources/scrollstack-light.png

32.5 KB
Loading

ScrollStackController.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "ScrollStackController"
3-
s.version = "1.5.1"
3+
s.version = "1.6.0"
44
s.summary = "Create complex scrollable layout using UIViewController and simplify your code"
55
s.homepage = "https://github.com/malcommac/ScrollStackController"
66
s.license = { :type => "MIT", :file => "LICENSE" }
@@ -10,5 +10,5 @@ Pod::Spec.new do |s|
1010
s.source = { :git => "https://github.com/malcommac/ScrollStackController.git", :tag => s.version.to_s }
1111
s.frameworks = "Foundation", "UIKit"
1212
s.source_files = 'Sources/**/*.swift'
13-
s.swift_versions = ['5.0', '5.1', '5.3', '5.4', '5.5', '5.7', '5.8']
13+
s.swift_versions = ['5.0', '5.1', '5.3', '5.4', '5.5', '5.7', '5.8', '5.9']
1414
end

Sources/ScrollStackController/ScrollStackRow.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,6 @@ open class ScrollStackRow: UIView, UIGestureRecognizerDelegate {
130130
didSet {
131131
separatorView.isHidden = isSeparatorHidden
132132
}
133-
// get {
134-
// return separatorView.isHidden
135-
// }
136-
// set {
137-
// separatorView.isHidden = newValue
138-
// }
139133
}
140134

141135
// MARK: Private Properties
@@ -245,9 +239,10 @@ open class ScrollStackRow: UIView, UIGestureRecognizerDelegate {
245239
setNeedsUpdateConstraints()
246240
}
247241

248-
open override func updateConstraints() {
242+
open override func layoutSubviews() {
243+
super.layoutSubviews()
244+
// called the event to update the height of the row.
249245
askForCutomizedSizeOfContentView(animated: false)
250-
super.updateConstraints()
251246
}
252247

253248
private func applyParentStackAttributes() {
@@ -366,16 +361,25 @@ open class ScrollStackRow: UIView, UIGestureRecognizerDelegate {
366361

367362
var bestSize: CGSize!
368363
if stackView.axis == .vertical {
369-
let maxAllowedSize = CGSize(width: stackView.bounds.size.width, height: CGFloat.greatestFiniteMagnitude)
370-
bestSize = contentView.systemLayoutSizeFitting(maxAllowedSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .defaultLow)
364+
let maxAllowedSize = CGSize(width: contentView.bounds.width, height: 0)
365+
bestSize = contentView.systemLayoutSizeFitting(
366+
maxAllowedSize,
367+
withHorizontalFittingPriority: .required,
368+
verticalFittingPriority: .fittingSizeLevel
369+
)
371370
} else {
372-
let maxAllowedSize = CGSize(width: CGFloat.greatestFiniteMagnitude, height: stackView.bounds.size.height)
373-
bestSize = contentView.systemLayoutSizeFitting(maxAllowedSize, withHorizontalFittingPriority: .defaultLow, verticalFittingPriority: .required)
371+
let maxAllowedSize = CGSize(width: 0, height: contentView.bounds.height)
372+
bestSize = contentView.systemLayoutSizeFitting(
373+
maxAllowedSize,
374+
withHorizontalFittingPriority: .fittingSizeLevel,
375+
verticalFittingPriority: .required
376+
)
374377
}
375378

376379
setupRowToFixedValue(bestSize.height)
377380
}
378381

382+
379383
// MARK: - Handle Touch
380384

381385
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {

banner.png

-68 KB
Binary file not shown.

0 commit comments

Comments
 (0)