-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ra1028/keepsContentOffset
Add new updater option keepsContentOffset
- Loading branch information
Showing
11 changed files
with
218 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import UIKit | ||
|
||
internal extension UIScrollView { | ||
var _isContetRectContainsBounds: Bool { | ||
return CGRect(origin: .zero, size: contentSize) | ||
.inset(by: availableContentInset.inverted) | ||
.contains(bounds) | ||
} | ||
|
||
var _maxContentOffsetX: CGFloat { | ||
return contentSize.width + availableContentInset.right - bounds.width | ||
} | ||
|
||
var _maxContentOffsetY: CGFloat { | ||
return contentSize.height + availableContentInset.bottom - bounds.height | ||
} | ||
|
||
var _isScrolling: Bool { | ||
return isTracking || isDragging || isDecelerating | ||
} | ||
} | ||
|
||
private extension UIScrollView { | ||
var availableContentInset: UIEdgeInsets { | ||
if #available(iOS 11.0, tvOS 11.0, *) { | ||
return adjustedContentInset | ||
} | ||
else { | ||
return contentInset | ||
} | ||
} | ||
} | ||
|
||
private extension UIEdgeInsets { | ||
var inverted: UIEdgeInsets { | ||
return UIEdgeInsets(top: -top, left: -left, bottom: -bottom, right: -right) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import XCTest | ||
@testable import Carbon | ||
|
||
@available(iOS 11.0, *) | ||
final class MockScrollViewExtensionsTests: XCTestCase { | ||
func testIsContetRectContainsBounds() { | ||
let scrollView1 = MockScrollView() | ||
scrollView1.contentInset = UIEdgeInsets(top: 1, left: 2, bottom: 3, right: 4) | ||
scrollView1.contentSize = CGSize(width: 100, height: 200) | ||
scrollView1.bounds.size = CGSize(width: 30, height: 40) | ||
scrollView1.contentOffset = CGPoint(x: 10, y: 20) | ||
|
||
let scrollView2 = MockScrollView() | ||
scrollView2.contentInset = UIEdgeInsets(top: 1, left: 2, bottom: 3, right: 4) | ||
scrollView2.contentSize = CGSize(width: 100, height: 20) | ||
scrollView2.bounds.size = CGSize(width: 30, height: 40) | ||
scrollView2.contentOffset = CGPoint(x: 10, y: 20) | ||
|
||
let scrollView3 = MockScrollView() | ||
scrollView3.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 21, right: 11) | ||
scrollView3.contentSize = CGSize(width: 100, height: 200) | ||
scrollView3.bounds.size = CGSize(width: 100, height: 200) | ||
scrollView3.contentOffset = CGPoint(x: 10, y: 20) | ||
|
||
XCTAssertTrue(scrollView1._isContetRectContainsBounds) | ||
XCTAssertFalse(scrollView2._isContetRectContainsBounds) | ||
XCTAssertTrue(scrollView3._isContetRectContainsBounds) | ||
} | ||
|
||
func testIsScrolling() { | ||
let scrollView1 = MockScrollView() | ||
scrollView1._isTracking = true | ||
|
||
let scrollView2 = MockScrollView() | ||
scrollView2._isDragging = true | ||
|
||
let scrollView3 = MockScrollView() | ||
scrollView3._isDecelerating = true | ||
|
||
XCTAssertTrue(scrollView1._isScrolling) | ||
XCTAssertTrue(scrollView2._isScrolling) | ||
XCTAssertTrue(scrollView3._isScrolling) | ||
} | ||
|
||
func textMaxContentOffsetX() { | ||
let scrollView = MockScrollView() | ||
scrollView.contentInset = UIEdgeInsets(top: 1, left: 2, bottom: 3, right: 4) | ||
scrollView.contentSize = CGSize(width: 100, height: 200) | ||
scrollView.bounds.size = CGSize(width: 30, height: 40) | ||
scrollView.contentOffset = CGPoint(x: 10, y: 20) | ||
|
||
XCTAssertEqual(scrollView._maxContentOffsetX, 74) | ||
} | ||
|
||
func textMaxContentOffsetY() { | ||
let scrollView = MockScrollView() | ||
scrollView.contentInset = UIEdgeInsets(top: 1, left: 2, bottom: 3, right: 4) | ||
scrollView.contentSize = CGSize(width: 100, height: 200) | ||
scrollView.bounds.size = CGSize(width: 30, height: 40) | ||
scrollView.contentOffset = CGPoint(x: 10, y: 20) | ||
|
||
XCTAssertEqual(scrollView._maxContentOffsetY, 163) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.