Skip to content

Commit

Permalink
Merge pull request #26 from malcommac/patch/autosizing-swiftui
Browse files Browse the repository at this point in the history
Compatibility with SwiftUI hosted View
  • Loading branch information
malcommac authored Nov 30, 2023
2 parents a4dfd2a + a4f6a58 commit f9beff8
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 43 deletions.
67 changes: 38 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<p align="center" >
<img src="banner.png" width=300px alt="ScrollStackController" title="ScrollStackController">
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="./Resources/scrollstack-dark.png" width="350">
<img alt="logo-library" src="./Resources/scrollstack-light.png" width="350">
</picture>
</p>

<p align="center"><strong>Easy scrollable layouts in UIKit</strong></p>
[![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)
[![Platform](https://img.shields.io/badge/Platforms-iOS-4E4E4E.svg?colorA=28a745)](#installation)
[![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)
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/ScrollStackController.svg?style=flat-square)](https://img.shields.io/cocoapods/v/ScrollStackController.svg)


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

Expand Down Expand Up @@ -32,41 +39,43 @@ You can think of it as `UITableView` but with several differences:
*Hi fellow developer!*
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**.

If you are using SwiftLocation or any other of my creations please consider the following options:
If you are using `ScrollStackController` or any other of my creations please consider the following options:

- [**Make a donation with PayPal**](https://www.paypal.com/paypalme/danielemargutti/20)
- [**Become a Sponsor**](https://github.com/sponsors/malcommac)

- [Follow Me](https://github.com/malcommac)

<a name="index"/>

## Table of Contents

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

<a name="whentousescrollstackcontrollerandwhennot"/>

Expand Down
Binary file added Resources/scrollstack-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/scrollstack-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ScrollStackController.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ScrollStackController"
s.version = "1.5.1"
s.version = "1.6.0"
s.summary = "Create complex scrollable layout using UIViewController and simplify your code"
s.homepage = "https://github.com/malcommac/ScrollStackController"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand All @@ -10,5 +10,5 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/malcommac/ScrollStackController.git", :tag => s.version.to_s }
s.frameworks = "Foundation", "UIKit"
s.source_files = 'Sources/**/*.swift'
s.swift_versions = ['5.0', '5.1', '5.3', '5.4', '5.5', '5.7', '5.8']
s.swift_versions = ['5.0', '5.1', '5.3', '5.4', '5.5', '5.7', '5.8', '5.9']
end
Binary file not shown.
28 changes: 16 additions & 12 deletions Sources/ScrollStackController/ScrollStackRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@ open class ScrollStackRow: UIView, UIGestureRecognizerDelegate {
didSet {
separatorView.isHidden = isSeparatorHidden
}
// get {
// return separatorView.isHidden
// }
// set {
// separatorView.isHidden = newValue
// }
}

// MARK: Private Properties
Expand Down Expand Up @@ -245,9 +239,10 @@ open class ScrollStackRow: UIView, UIGestureRecognizerDelegate {
setNeedsUpdateConstraints()
}

open override func updateConstraints() {
open override func layoutSubviews() {
super.layoutSubviews()
// called the event to update the height of the row.
askForCutomizedSizeOfContentView(animated: false)
super.updateConstraints()
}

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

var bestSize: CGSize!
if stackView.axis == .vertical {
let maxAllowedSize = CGSize(width: stackView.bounds.size.width, height: CGFloat.greatestFiniteMagnitude)
bestSize = contentView.systemLayoutSizeFitting(maxAllowedSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .defaultLow)
let maxAllowedSize = CGSize(width: contentView.bounds.width, height: 0)
bestSize = contentView.systemLayoutSizeFitting(
maxAllowedSize,
withHorizontalFittingPriority: .required,
verticalFittingPriority: .fittingSizeLevel
)
} else {
let maxAllowedSize = CGSize(width: CGFloat.greatestFiniteMagnitude, height: stackView.bounds.size.height)
bestSize = contentView.systemLayoutSizeFitting(maxAllowedSize, withHorizontalFittingPriority: .defaultLow, verticalFittingPriority: .required)
let maxAllowedSize = CGSize(width: 0, height: contentView.bounds.height)
bestSize = contentView.systemLayoutSizeFitting(
maxAllowedSize,
withHorizontalFittingPriority: .fittingSizeLevel,
verticalFittingPriority: .required
)
}

setupRowToFixedValue(bestSize.height)
}


// MARK: - Handle Touch

public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
Expand Down
Binary file removed banner.png
Binary file not shown.

0 comments on commit f9beff8

Please sign in to comment.