Skip to content
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

Fix drag animation #1210

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ jobs:
strategy:
matrix:
run-config:
- { xcode_version: '10.3', simulator: 'name=iPad (5th generation),OS=12.4' }
- { xcode_version: '10.3', simulator: 'name=iPhone 8,OS=12.4' }
- { xcode_version: '11.7', simulator: 'name=iPhone SE (2nd generation),OS=13.7' }
- { xcode_version: '12.2', simulator: 'name=iPhone SE (2nd generation),OS=14.2' }
- { xcode_version: '11.7', simulator: 'name=iPhone 8,OS=13.7' }
- { xcode_version: '12.2', simulator: 'name=iPad Pro (12.9-inch) (4th generation),OS=14.2' }

steps:
- name: Checkout Project
Expand Down
1 change: 1 addition & 0 deletions KIF Tests/LandscapeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ - (void)beforeAll
// only scroll if we are on iphone
if(UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
[tester scrollViewWithAccessibilityIdentifier:@"Test Suite TableView" byFractionOfSizeHorizontal:0 vertical:-0.2];
[tester waitForTimeInterval:0.5];
}
}

Expand Down
11 changes: 11 additions & 0 deletions KIF Tests/ScrollViewTests_ViewTestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import <KIF/KIF.h>
#import "KIFTestStepValidation.h"
#import "UIAccessibilityElement-KIFAdditions.h"
#import "UIView-KIFAdditions.h"

@interface ScrollViewTests_ViewTestActor : KIFTestCase
@end
Expand Down Expand Up @@ -37,4 +39,13 @@ - (void)testScrollingToTapOffscreenTextView
[[viewTester usingLabel:@"TextView"] tap];
}

- (void)testScrollingDownAndUp
{
[[viewTester usingLabel:@"Long Scroll View"] scrollByFractionOfSizeHorizontal:0 vertical:-1];
[[viewTester usingLabel:@"Bottom Label"] waitForView];

[[viewTester usingLabel:@"Long Scroll View"] scrollByFractionOfSizeHorizontal:0 vertical:1];
[[viewTester usingLabel:@"Top Label"] waitForView];
}

@end
21 changes: 21 additions & 0 deletions Sources/KIF/Classes/KIFUITestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,28 @@ - (void)scrollAccessibilityElement:(UIAccessibilityElement *)element inView:(UIV
scrollStart.x -= scrollDisplacement.x / 2;
scrollStart.y -= scrollDisplacement.y / 2;

// Scrolling does not work if we are at the end of the view
// So if our scroll start is equal to the heigh, inset 5
if (scrollStart.x == CGRectGetWidth(elementFrame)) {
if (scrollDisplacement.x < 0) {
scrollStart.x -= CGRectGetWidth(elementFrame) * 0.05;
} else {
scrollStart.x += CGRectGetWidth(elementFrame) * 0.05;
}

}

if (scrollStart.y == CGRectGetHeight(elementFrame)) {
if (scrollDisplacement.y < 0) {
scrollStart.y -= CGRectGetHeight(elementFrame) * 0.05;
} else {
scrollStart.y += CGRectGetHeight(elementFrame) * 0.05;
}
}

[viewToScroll dragFromPoint:scrollStart displacement:scrollDisplacement steps:kNumberOfPointsInScrollPath];

[self waitForAnimationsToFinish];
}

- (void)waitForFirstResponderWithAccessibilityLabel:(NSString *)label
Expand Down
7 changes: 6 additions & 1 deletion Test Host/Base.lproj/MainStoryboard.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1683,15 +1683,20 @@ Line Break
<rect key="frame" x="0.0" y="0.0" width="414" height="808"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="SLR-Kl-7v1">
<rect key="frame" x="20" y="382" width="374" height="216"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
</scrollView>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vCe-NZ-HE8">
<rect key="frame" x="106" y="304" width="200" height="200"/>
<rect key="frame" x="107" y="8" width="200" height="200"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
</scrollView>
</subviews>
<color key="backgroundColor" red="1" green="0.99997437000274658" blue="0.99999129772186279" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<navigationItem key="navigationItem" title="ScrollViews" id="SpZ-dM-ZUT"/>
<connections>
<outlet property="longScrollview" destination="SLR-Kl-7v1" id="All-XX-BDv"/>
<outlet property="scrollView" destination="vCe-NZ-HE8" id="dda-Sp-2kA"/>
</connections>
</viewController>
Expand Down
20 changes: 20 additions & 0 deletions Test Host/ScrollViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <UIKit/UIKit.h>

@interface ScrollViewController : UIViewController<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *longScrollview;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@end

Expand All @@ -23,6 +24,25 @@ - (void)viewDidLoad
self.scrollView.contentSize = CGSizeMake(2000, 2000);
self.scrollView.delegate = self;

self.longScrollview.accessibilityLabel = @"Long Scroll View";
CGFloat longScrollViewHeight = CGRectGetHeight(self.longScrollview.bounds) * 2;
self.longScrollview.contentSize = CGSizeMake(CGRectGetWidth(self.longScrollview.bounds), longScrollViewHeight);
self.longScrollview.backgroundColor = UIColor.redColor;

UILabel *topLabel = [[UILabel alloc] init];
topLabel.text = @"THIS IS THE TOP";
topLabel.accessibilityLabel = @"Top Label";
topLabel.textAlignment = UITextAlignmentCenter;
[self.longScrollview addSubview:topLabel];
topLabel.frame = CGRectMake(0, 0, CGRectGetWidth(self.longScrollview.bounds), 40);

UILabel *bottomLabel = [[UILabel alloc] init];
bottomLabel.text = @"THIS IS THE BOTTOM";
bottomLabel.accessibilityLabel = @"Bottom Label";
bottomLabel.textAlignment = UITextAlignmentCenter;
[self.longScrollview addSubview:bottomLabel];
bottomLabel.frame = CGRectMake(0, longScrollViewHeight - 40, CGRectGetWidth(self.longScrollview.bounds), 40);

UIButton *bottomButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[bottomButton setTitle:@"Down" forState:UIControlStateNormal];
bottomButton.backgroundColor = [UIColor greenColor];
Expand Down