Skip to content

Commit

Permalink
Add isScrollEnabled property to list Behavior (#543)
Browse files Browse the repository at this point in the history
- Adds a new `isScrollEnabled` property to List's `Behavior` to disable
scroll view scrolling if needed
  • Loading branch information
mseijas authored Aug 28, 2024
1 parent 03a27c2 commit fcfe026
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions ListableUI/Sources/Behavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -59,6 +63,7 @@ public struct Behavior : Equatable
decelerationRate : DecelerationRate = .normal,
verticalLayoutGravity : VerticalLayoutGravity = .top
) {
self.isScrollEnabled = isScrollEnabled
self.keyboardDismissMode = keyboardDismissMode
self.keyboardAdjustmentMode = keyboardAdjustmentMode

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fcfe026

Please sign in to comment.