Skip to content

Commit

Permalink
Stop changing UIScrollView.bounces when locking or unlocking a scroll…
Browse files Browse the repository at this point in the history
… view

Resolved #524
  • Loading branch information
scenee committed Apr 6, 2023
1 parent 6ecc792 commit 375227b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
8 changes: 2 additions & 6 deletions Sources/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ class Core: NSObject, UIGestureRecognizerDelegate {
if let cur = scrollView {
if oldValue == nil {
initialScrollOffset = cur.contentOffset
scrollBounce = cur.bounces
scrollIndictorVisible = cur.showsVerticalScrollIndicator
}
} else {
if let pre = oldValue {
pre.isDirectionalLockEnabled = false
pre.bounces = scrollBounce
pre.showsVerticalScrollIndicator = scrollIndictorVisible
}
}
Expand Down Expand Up @@ -64,7 +62,6 @@ class Core: NSObject, UIGestureRecognizerDelegate {
// Scroll handling
private var initialScrollOffset: CGPoint = .zero
private var stopScrollDeceleration: Bool = false
private var scrollBounce = false
private var scrollIndictorVisible = false

// MARK: - Interface
Expand Down Expand Up @@ -1033,11 +1030,11 @@ class Core: NSObject, UIGestureRecognizerDelegate {
}
log.debug("lock scroll view")

scrollBounce = scrollView.bounces
scrollIndictorVisible = scrollView.showsVerticalScrollIndicator

// Must not modify the UIScrollView.bounces property here. If you reset it to unlock the tracking scroll view,
// UIScrollView may unexpectedly alter the scroll offset when dealing with small scrollable content.
scrollView.isDirectionalLockEnabled = true
scrollView.bounces = false
scrollView.showsVerticalScrollIndicator = false
}

Expand All @@ -1046,7 +1043,6 @@ class Core: NSObject, UIGestureRecognizerDelegate {
log.debug("unlock scroll view")

scrollView.isDirectionalLockEnabled = false
scrollView.bounces = scrollBounce
scrollView.showsVerticalScrollIndicator = scrollIndictorVisible
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ extension UIGestureRecognizer.State: CustomDebugStringConvertible {

extension UIScrollView {
var isLocked: Bool {
return !showsVerticalScrollIndicator && !bounces && isDirectionalLockEnabled
return !showsVerticalScrollIndicator && isDirectionalLockEnabled
}
var fp_contentInset: UIEdgeInsets {
if #available(iOS 11.0, *) {
Expand Down
8 changes: 0 additions & 8 deletions Tests/CoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,41 @@ class CoreTests: XCTestCase {

let contentVC1 = UITableViewController(nibName: nil, bundle: nil)
XCTAssertEqual(contentVC1.tableView.showsVerticalScrollIndicator, true)
XCTAssertEqual(contentVC1.tableView.bounces, true)
fpc.set(contentViewController: contentVC1)
fpc.track(scrollView: contentVC1.tableView)
fpc.showForTest()

XCTAssertEqual(fpc.state, .half)
XCTAssertEqual(contentVC1.tableView.showsVerticalScrollIndicator, false)
XCTAssertEqual(contentVC1.tableView.bounces, false)

fpc.move(to: .full, animated: false)
XCTAssertEqual(contentVC1.tableView.showsVerticalScrollIndicator, true)
XCTAssertEqual(contentVC1.tableView.bounces, true)

fpc.move(to: .tip, animated: false)
XCTAssertEqual(contentVC1.tableView.showsVerticalScrollIndicator, false)
XCTAssertEqual(contentVC1.tableView.bounces, false)

let exp1 = expectation(description: "move to full with animation")
fpc.move(to: .full, animated: true) {
XCTAssertEqual(contentVC1.tableView.showsVerticalScrollIndicator, true)
XCTAssertEqual(contentVC1.tableView.bounces, true)
exp1.fulfill()
}
wait(for: [exp1], timeout: 1.0)

let exp2 = expectation(description: "move to tip with animation")
fpc.move(to: .tip, animated: false) {
XCTAssertEqual(contentVC1.tableView.showsVerticalScrollIndicator, false)
XCTAssertEqual(contentVC1.tableView.bounces, false)
exp2.fulfill()
}
wait(for: [exp2], timeout: 1.0)

// Reset the content vc
let contentVC2 = UITableViewController(nibName: nil, bundle: nil)
XCTAssertEqual(contentVC2.tableView.showsVerticalScrollIndicator, true)
XCTAssertEqual(contentVC2.tableView.bounces, true)
fpc.set(contentViewController: contentVC2)
fpc.track(scrollView: contentVC2.tableView)
fpc.show(animated: false, completion: nil)
XCTAssertEqual(fpc.state, .half)
XCTAssertEqual(contentVC2.tableView.showsVerticalScrollIndicator, false)
XCTAssertEqual(contentVC2.tableView.bounces, false)
}

func test_getBackdropAlpha_1positions() {
Expand Down

0 comments on commit 375227b

Please sign in to comment.