-
Notifications
You must be signed in to change notification settings - Fork 39
Scroll indicators update - positioning correction, support for both indicators at the same time #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Scroll indicators update - positioning correction, support for both indicators at the same time #229
Changes from 93 commits
a699f9c
61cf77b
7c048e8
c1330a0
8324590
9f1538c
d4d833e
bb7abba
6ce8af6
15a32c5
ebb41cd
19611b4
5f3149e
e11665c
696b5ec
4a0d458
9df9578
4b165b7
54afeee
4b2ed66
a09c179
f26136c
9042ce9
f3acd87
59bfdfd
e5d8f8f
9a0f804
68edcf5
e03b6d0
59b1d9d
810f0ef
a8efa15
7f4d5a7
0137095
eaf1e88
2c77d5c
c43e4d9
b13e05d
3158be6
ff215e1
7086a9d
df2624b
3a24ba3
b9b6df4
5ec8cf7
975f308
e2e62d0
fd3218f
63c89f4
497b07c
d94bead
399d18e
faa63de
646b7d2
be7e9cf
8060600
7b9e543
6af7c80
19c16fd
08ff58e
f24db7e
66938cf
91ec3cd
d1a2e74
d19f0af
75553c8
147831f
df0b435
6cc4e28
bc35223
b5dcd2a
c39799b
ead7c57
1649892
2c1a237
ab05997
b22318a
7ac4e70
60d850f
65c5f0c
0e44547
fd14007
2039d6d
b2e2c46
6379d21
fa4b095
abc824c
b3e59f0
17e0f0a
658a4a2
7298827
7d39faa
8c57422
cc0452b
8a81fe4
ac1f2ec
36e63e4
6a899ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,65 @@ class UIScrollViewTests: XCTestCase { | |
| XCTAssertEqual(scrollView.contentInset, arbitraryContentInset) | ||
| } | ||
|
|
||
| func testScrollIndicatorsViewHierarchyPositions() { | ||
| // subviews[0] is the back-most view, higher indexes are higher in layer hierarchy | ||
| // we want scroll indicators to always remain on top of 'normal' subviews | ||
| // and we want newer 'normal' subviews to be above older ones | ||
|
|
||
| // TODO: iOS does not allow explicit access to scroll indicators via subviews | ||
| // we should remove that, too - but for now it's the easy way to go and helpful in testing | ||
|
|
||
| let view1 = UIView() | ||
| let view2 = UIView() | ||
| let view3 = UIView() | ||
|
|
||
| scrollView.addSubview(view1) | ||
| scrollView.addSubview(view2) | ||
| scrollView.addSubview(view3) | ||
|
|
||
| let horizontalIndicatorIndex = scrollView.subviews.index(of: scrollView.horizontalScrollIndicator)! | ||
| let verticalIndicatorIndex = scrollView.subviews.index(of: scrollView.verticalScrollIndicator)! | ||
| let label1Index = scrollView.subviews.index(of: view1)! | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it makes sense to put this into a variable, because (as mentioned below) it will be invalid as soon as we insert another view. |
||
| let label2Index = scrollView.subviews.index(of: view2)! | ||
| let label3Index = scrollView.subviews.index(of: view3)! | ||
|
|
||
| XCTAssert(horizontalIndicatorIndex > label1Index) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is this different to the case at the bottom? |
||
| XCTAssert(verticalIndicatorIndex > label1Index) | ||
|
|
||
| XCTAssert(label2Index > label1Index) | ||
|
|
||
| XCTAssertEqual(label1Index, 0) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the point in adding three subviews? we already have other tests that test the behaviour of how is this different to the case at the bottom? |
||
| XCTAssertEqual(label2Index, 1) | ||
| XCTAssertEqual(label3Index, 2) | ||
| XCTAssertEqual(horizontalIndicatorIndex, 3) | ||
| XCTAssertEqual(verticalIndicatorIndex, 4) | ||
| XCTAssertEqual(scrollView.subviews.count, 5) | ||
|
|
||
| let viewToBeInserted1 = UIView() | ||
| scrollView.insertSubview(viewToBeInserted1, at: 1) | ||
| let indexOfInsertedView1 = scrollView.subviews.index(of: viewToBeInserted1)! | ||
|
|
||
| // This might seem weird, but that's what happens in iOS: | ||
| // the inserted view and the one that was in its place before will have the same index | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible this is only weird because of how the test is written? It doesn't seem that weird to me that the indexes will overlap once we insert a new subview if we're not getting the new indexes after inserting the subview? What am I missing here? It seems like we should get the new indexes here which would be less confusing?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're not missing anything, I can't believe I missed this! 🤦♂ thanks! |
||
| XCTAssertEqual(label1Index, 0) | ||
| XCTAssertEqual(indexOfInsertedView1, 1) | ||
| XCTAssertEqual(label2Index, 1) | ||
| XCTAssertEqual(label3Index, 2) | ||
| XCTAssertEqual(horizontalIndicatorIndex, 3) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is misleading at best: all of these indexes will be incorrect now, so what's the point in asserting what their old value was? I'm really not happy with this, as written |
||
| XCTAssertEqual(verticalIndicatorIndex, 4) | ||
| XCTAssertEqual(scrollView.subviews.count, 6) | ||
|
|
||
|
|
||
| let viewToBeInserted2 = UIView() | ||
| scrollView.insertSubview(viewToBeInserted2, at: 5) // position currently occupied by scroll indicator | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test is too long. this could be two or three separate tests which would be much clearer if one of them fails
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for this and all the other very valid concerns. I rewrote the test(s) in a way that hopefully takes into account all of them. |
||
| let indexOfInsertedView2 = scrollView.subviews.index(of: viewToBeInserted1)! | ||
|
|
||
| // If we try to insert at a position occupied by or above indicators, | ||
| // the inserted view should 'slide down' and assume the highest position below indicators | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice, these comments are helpful thanks!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but this should just be its own standalone test. it tests one single behaviour that obviously must be true. if we insert a subview it should always be behind the indicators. end of test. if that breaks we know what to fix. does that make sense? |
||
| XCTAssert(indexOfInsertedView2 < horizontalIndicatorIndex) | ||
| XCTAssert(indexOfInsertedView2 < verticalIndicatorIndex) | ||
| } | ||
|
|
||
| func testScrollIndicatorsVisibility() { | ||
| //TODO: update to match iOS behaviour: | ||
| //1. frame is always there, alpha changes from 0 to 1 | ||
|
|
@@ -98,10 +157,6 @@ class UIScrollViewTests: XCTestCase { | |
|
|
||
| // TODO: test final position. [blocked by setting contentOffset programatically - test behaviour in iOS] | ||
|
|
||
| func testIfScrollIndicatorsAreAccurate() { | ||
| // TODO: how? | ||
| } | ||
|
|
||
| func testIfScrollViewBouncesBackAferPullIfNeeded() { | ||
| // TODO: test setting inset and bouncing after it's implented in ScrollView | ||
| } | ||
|
|
@@ -158,11 +213,11 @@ class UIScrollViewTests: XCTestCase { | |
| wait(for: [beginDraggingExpectation, didScrollExpectation, didEndDraggingExpectation], timeout: 1.0) | ||
| } | ||
|
|
||
| func mockTouch(toPoint: CGPoint, inScrollView scrollView: UIScrollView) { | ||
| func mockTouch(toPoint point: CGPoint, inScrollView scrollView: UIScrollView) { | ||
| let mockTouch = UITouch(touchId: 0, at: CGPoint(x: 0, y: 0), timestamp: 0) | ||
|
|
||
| scrollView.panGestureRecognizer.touchesBegan([mockTouch], with: UIEvent()) | ||
| mockTouch.updateAbsoluteLocation(CGPoint(x: 100, y: 100)) | ||
| mockTouch.updateAbsoluteLocation(point) | ||
| scrollView.panGestureRecognizer.touchesMoved([mockTouch], with: UIEvent()) | ||
| scrollView.panGestureRecognizer.touchesEnded([mockTouch], with: UIEvent()) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.