From fcfe0260c374d9bb9181c73fbd85f686d120e3e8 Mon Sep 17 00:00:00 2001 From: Matias Seijas Date: Tue, 27 Aug 2024 20:40:38 -0400 Subject: [PATCH] Add isScrollEnabled property to list Behavior (#543) - Adds a new `isScrollEnabled` property to List's `Behavior` to disable scroll view scrolling if needed --- CHANGELOG.md | 2 ++ ListableUI/Sources/Behavior.swift | 5 +++++ .../Layout/ListLayout/ListLayoutScrollViewProperties.swift | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46130559d..3d1ddd4e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Added +- Added new `isScrollEnabled` property to `Behavior` to disable scrolling on a list if needed. + ### Removed - Revert: Fixed an issue where animations would occur when dequeuing / reusing cells. A layout is now forced without animation before presentation. diff --git a/ListableUI/Sources/Behavior.swift b/ListableUI/Sources/Behavior.swift index 180e60c20..1e52886c4 100644 --- a/ListableUI/Sources/Behavior.swift +++ b/ListableUI/Sources/Behavior.swift @@ -13,6 +13,9 @@ import UIKit /// when the list content underflows the available space in the list view. public struct Behavior : Equatable { + /// Whether the list scroll view should be enabled. + public var isScrollEnabled: Bool + /// How the keyboard should be dismissed (if at all) based on scrolling of the list view. public var keyboardDismissMode : UIScrollView.KeyboardDismissMode @@ -48,6 +51,7 @@ public struct Behavior : Equatable /// Creates a new `Behavior` based on the provided parameters. public init( + isScrollEnabled: Bool = true, keyboardDismissMode : UIScrollView.KeyboardDismissMode = .interactive, keyboardAdjustmentMode : KeyboardAdjustmentMode = .adjustsWhenVisible, scrollsToTop : ScrollsToTop = .enabled, @@ -59,6 +63,7 @@ public struct Behavior : Equatable decelerationRate : DecelerationRate = .normal, verticalLayoutGravity : VerticalLayoutGravity = .top ) { + self.isScrollEnabled = isScrollEnabled self.keyboardDismissMode = keyboardDismissMode self.keyboardAdjustmentMode = keyboardAdjustmentMode diff --git a/ListableUI/Sources/Layout/ListLayout/ListLayoutScrollViewProperties.swift b/ListableUI/Sources/Layout/ListLayout/ListLayoutScrollViewProperties.swift index 3d633ca89..b7b0aea1e 100644 --- a/ListableUI/Sources/Layout/ListLayout/ListLayoutScrollViewProperties.swift +++ b/ListableUI/Sources/Layout/ListLayout/ListLayoutScrollViewProperties.swift @@ -48,6 +48,10 @@ public struct ListLayoutScrollViewProperties : Equatable /// because some UIScrollView properties, even when set to the same value, can affect or stop scrolling if it /// is in progress. Hard to tell which across iOS versions, so just always be defensive. + if view.isScrollEnabled != behavior.isScrollEnabled { + view.isScrollEnabled = behavior.isScrollEnabled + } + let isPagingEnabled = self.isPagingEnabled || behavior.isPagingEnabled if view.isPagingEnabled != isPagingEnabled {