Skip to content

Commit

Permalink
Add accessibility support to the pull-to-refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
lilthree committed Oct 19, 2023
1 parent 8c48064 commit 615e7fe
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 112 deletions.
7 changes: 4 additions & 3 deletions Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def shared
platform :ios, '9.0'
platform :ios, '11.0'
pod 'Seafile', :path => "./"
pod 'AFNetworking', '~> 4.0.0'
pod 'OpenSSL-Universal', '1.0.2.17'
Expand Down Expand Up @@ -41,8 +41,9 @@ post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'YES'
if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 8.0
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '8.0'
config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = "arm64"
if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 11.0
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
end
end
if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle"
Expand Down
3 changes: 3 additions & 0 deletions common/Classes/UISearchBar+SeafExtend.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ + (void)load {

- (void)seaf_layoutSubviews {
[self seaf_layoutSubviews];
if (@available(iOS 16.0, *)) {
return;
}
if (@available(iOS 13.0, *)) {
//fix searchbar's frame
UIView *backgroundView = [self performSelector:NSSelectorFromString(@"_backgroundView")];
Expand Down
62 changes: 31 additions & 31 deletions seafile/SeafActivityViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
typedef void (^ModificationHandler)(NSString *repoId, NSString *path);

@interface SeafActivityViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *loadingView;
@property (strong) NSArray *events;
@property BOOL eventsMore;
@property int eventsOffset;
Expand All @@ -46,12 +45,6 @@ @implementation SeafActivityViewController
@synthesize connection = _connection;


- (void)refresh:(id)sender
{
[self showLoadingView];
[self moreEvents:0];
}

- (void)viewDidLoad
{
[super viewDidLoad];
Expand All @@ -60,8 +53,6 @@ - (void)viewDidLoad

// Do any additional setup after loading the view from its nib.
self.title = NSLocalizedString(@"Activities", @"Seafile");
self.navigationItem.rightBarButtonItem = [self getBarItemAutoSize:@"refresh2" action:@selector(refresh:)];
// self.navigationController.navigationBar.tintColor = BAR_COLOR;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 60.0;
self.tableView.tableFooterView = [UIView new];
Expand Down Expand Up @@ -101,15 +92,43 @@ - (void)viewDidLoad
__strong typeof (weakSelf) strongSelf = weakSelf;
[strongSelf moreEvents:strongSelf.eventsOffset];
}];

self.tableView.refreshControl = [[UIRefreshControl alloc] init];
[self.tableView.refreshControl addTarget:self action:@selector(refreshControlChanged) forControlEvents:UIControlEventValueChanged];
}

#pragma mark - pull to Refresh
- (void)refreshControlChanged {
if (!self.tableView.isDragging) {
[self refresh:nil];
}
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (self.tableView.refreshControl.isRefreshing) {
[self refresh:nil];
}
}

- (void)refresh:(id)sender {
self.tableView.accessibilityElementsHidden = YES;
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, self.tableView.refreshControl);
[self moreEvents:0];
}

- (void)endRefreshing {
self.tableView.accessibilityElementsHidden = NO;
[self.tableView.refreshControl endRefreshing];
}

- (void)reloadData
{
[self.tableView.infiniteScrollingView stopAnimating];
self.tableView.showsInfiniteScrolling = _eventsMore;
[self dismissLoadingView];
[self endRefreshing];
[self.tableView reloadData];
}

- (void)moreEvents:(int)offset
{
if (_connection.isNewActivitiesApiSupported) {
Expand All @@ -131,7 +150,7 @@ - (void)moreEvents:(int)offset
Debug("%lu events, more:%d, offset:%d", (unsigned long)_events.count, _eventsMore, _eventsOffset);
[self reloadData];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON, NSError *error) {
[self dismissLoadingView];
[self endRefreshing];
[self.tableView.infiniteScrollingView stopAnimating];
if (self.isVisible)
[SVProgressHUD showErrorWithStatus:NSLocalizedString(@"Failed to load activities", @"Seafile")];
Expand Down Expand Up @@ -163,7 +182,7 @@ - (void)newApiRequest:(int)page {
Debug("%lu events, more:%d, offset:%d", (unsigned long)_events.count, _eventsMore, _eventsOffset);
[self reloadData];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON, NSError *error) {
[self dismissLoadingView];
[self endRefreshing];
[self.tableView.infiniteScrollingView stopAnimating];
if (self.isVisible)
[SVProgressHUD showErrorWithStatus:NSLocalizedString(@"Failed to load activities", @"Seafile")];
Expand Down Expand Up @@ -267,29 +286,10 @@ - (NSString *)getCommitDesc:(NSDictionary *)event
}
}

- (void)showLoadingView
{
if (!self.loadingView) {
self.loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.loadingView.color = [UIColor darkTextColor];
self.loadingView.hidesWhenStopped = YES;
[self.view addSubview:self.loadingView];
}
self.loadingView.center = self.view.center;
self.loadingView.frame = CGRectMake(self.loadingView.frame.origin.x, (self.view.frame.size.height-self.loadingView.frame.size.height)/2, self.loadingView.frame.size.width, self.loadingView.frame.size.height);
[self.loadingView startAnimating];
}

- (void)dismissLoadingView
{
[self.loadingView stopAnimating];
}

- (void)viewWillAppear:(BOOL)animated
{
if (!_events) {
[self moreEvents:0];
[self showLoadingView];
}
[super viewWillAppear:animated];
}
Expand Down
37 changes: 27 additions & 10 deletions seafile/SeafDirViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,32 @@ - (void)viewDidLoad
NSArray *items = [NSArray arrayWithObjects:flexibleFpaceItem, self.chooseItem, flexibleFpaceItem, nil];
[self setToolbarItems:items];

__weak typeof(self) weakSelf = self;
[self.tableView addPullToRefresh:[SVArrowPullToRefreshView class] withActionHandler:^{
if (![weakSelf checkNetworkStatus]) {
[weakSelf performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:0.1];
return;
}
self.tableView.refreshControl = [[UIRefreshControl alloc] init];
[self.tableView.refreshControl addTarget:self action:@selector(refreshControlChanged) forControlEvents:UIControlEventValueChanged];
}

weakSelf.directory.delegate = weakSelf;
[weakSelf.directory loadContent:YES];
}];
- (void)refreshControlChanged {
if (!self.tableView.isDragging) {
[self pullToRefresh];
}
}

- (void)pullToRefresh {
if (![self checkNetworkStatus]) {
[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:0.1];
return;
}

self.tableView.accessibilityElementsHidden = YES;
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, self.tableView.refreshControl);
self.directory.delegate = self;
[self.directory loadContent:YES];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (self.tableView.refreshControl.isRefreshing) {
[self pullToRefresh];
}
}

- (void)setOperationState:(OperationState)operationState {
Expand Down Expand Up @@ -262,6 +278,7 @@ - (void)viewDidUnload

- (void)doneLoadingTableViewData
{
[self.tableView.pullToRefreshView stopAnimating];
self.tableView.accessibilityElementsHidden = NO;
[self.tableView.refreshControl endRefreshing];
}
@end
67 changes: 42 additions & 25 deletions seafile/SeafFileViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Copyright (c) 2012 Seafile Ltd. All rights reserved.
//
#import "MWPhotoBrowser.h"
#import "UIScrollView+SVPullToRefresh.h"

#import "SeafAppDelegate.h"
#import "SeafFileViewController.h"
Expand Down Expand Up @@ -56,7 +55,7 @@
};


@interface SeafFileViewController ()<QBImagePickerControllerDelegate, SeafUploadDelegate, SeafDirDelegate, SeafShareDelegate, MFMailComposeViewControllerDelegate, SWTableViewCellDelegate, MWPhotoBrowserDelegate>
@interface SeafFileViewController ()<QBImagePickerControllerDelegate, SeafUploadDelegate, SeafDirDelegate, SeafShareDelegate, MFMailComposeViewControllerDelegate, SWTableViewCellDelegate, MWPhotoBrowserDelegate, UIScrollViewAccessibilityDelegate>
- (UITableViewCell *)getSeafFileCell:(SeafFile *)sfile forTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath;
- (UITableViewCell *)getSeafDirCell:(SeafDir *)sdir forTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath;
- (UITableViewCell *)getSeafRepoCell:(SeafRepo *)srepo forTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath;
Expand Down Expand Up @@ -213,21 +212,11 @@ - (void)viewDidLoad
self.navigationController.navigationBar.tintColor = BAR_COLOR;
[self.navigationController setToolbarHidden:YES animated:NO];

__weak typeof(self) weakSelf = self;
[self.tableView addPullToRefresh:[SVArrowPullToRefreshView class] withActionHandler:^{
[weakSelf.tableView reloadData];
if (weakSelf.searchDisplayController.active)
return;
if (![weakSelf checkNetworkStatus]) {
[weakSelf performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:0.1];
return;
}

weakSelf.state = STATE_LOADING;
weakSelf.directory.delegate = weakSelf;
[weakSelf.directory loadContent:YES];
}];

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
self.tableView.refreshControl = refreshControl;
[self.tableView.refreshControl addTarget:self action:@selector(refreshControlChanged) forControlEvents:UIControlEventValueChanged];

self.view.accessibilityElements = @[refreshControl, self.tableView];
Debug(@"%@", self.view);
[self refreshView];
}
Expand Down Expand Up @@ -1136,9 +1125,38 @@ - (void)download:(SeafBase *)entry failed:(NSError *)error
}
}

- (void)doneLoadingTableViewData
{
[self.tableView.pullToRefreshView stopAnimating];
#pragma mark - pull to Refresh
- (void)refreshControlChanged {
if (!self.tableView.isDragging) {
[self pullToRefresh];
}
}

- (void)pullToRefresh {
[self.tableView reloadData];
if (self.searchDisplayController.active)
return;
if (![self checkNetworkStatus]) {
[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:0.1];
return;
}

self.tableView.accessibilityElementsHidden = YES;
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, self.tableView.refreshControl);
self.state = STATE_LOADING;
self.directory.delegate = self;
[self.directory loadContent:YES];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (self.tableView.refreshControl.isRefreshing) {
[self pullToRefresh];
}
}

- (void)doneLoadingTableViewData {
[self.tableView.refreshControl endRefreshing];
self.tableView.accessibilityElementsHidden = NO;
}

#pragma mark - edit files
Expand Down Expand Up @@ -1899,13 +1917,12 @@ - (UISearchController *)searchController {
if (!_searchController) {
_searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchReslutController];
_searchController.searchResultsUpdater = self.searchReslutController;
_searchController.searchBar.barTintColor = [UIColor colorWithRed:240/255.0 green:239/255.0 blue:246/255.0 alpha:1.0];
_searchController.searchBar.barTintColor = [UIColor whiteColor];
[_searchController.searchBar sizeToFit];

UIImageView *barImageView = [[[_searchController.searchBar.subviews firstObject] subviews] firstObject];
barImageView.layer.borderColor = [UIColor colorWithRed:240/255.0 green:239/255.0 blue:246/255.0 alpha:1.0].CGColor;
barImageView.layer.borderWidth = 1;
self.definesPresentationContext = YES;
// barImageView.backgroundColor = [UIColor clearColor];
// barImageView.layer.borderWidth = 1;
// self.definesPresentationContext = YES;
}
return _searchController;
}
Expand Down
41 changes: 32 additions & 9 deletions seafile/SeafStarredFilesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ - (void)refresh:(id)sender
@synchronized(self) {
Debug("Succeeded to get starred files ...\n");
[self handleData:JSON];
[self.tableView.pullToRefreshView stopAnimating];
[self endPullRefresh];
[self.tableView reloadData];
}
}
Expand Down Expand Up @@ -92,14 +92,8 @@ - (void)viewDidLoad
self.tableView.sectionHeaderTopPadding = 0;
}

__weak typeof(self) weakSelf = self;
[self.tableView addPullToRefresh:[SVArrowPullToRefreshView class] withActionHandler:^{
if (![weakSelf checkNetworkStatus]) {
[weakSelf.tableView.pullToRefreshView stopAnimating];
} else {
[weakSelf refresh:nil];
}
}];
self.tableView.refreshControl = [[UIRefreshControl alloc] init];
[self.tableView.refreshControl addTarget:self action:@selector(refreshControlChanged) forControlEvents:UIControlEventValueChanged];
}

- (void)viewWillAppear:(BOOL)animated
Expand Down Expand Up @@ -165,6 +159,35 @@ - (void)setConnection:(SeafConnection *)conn
[self.tableView reloadData];
}


#pragma mark - pull to Refresh
- (void)refreshControlChanged {
if (!self.tableView.isDragging) {
[self pullToRefresh];
}
}

- (void)pullToRefresh {
if (![self checkNetworkStatus]) {
[self.tableView.refreshControl endRefreshing];
} else {
self.tableView.accessibilityElementsHidden = YES;
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, self.tableView.refreshControl);
[self refresh:nil];
}
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (self.tableView.refreshControl.isRefreshing) {
[self pullToRefresh];
}
}

- (void)endPullRefresh {
[self.tableView.refreshControl endRefreshing];
self.tableView.accessibilityElementsHidden = NO;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
Expand Down
4 changes: 3 additions & 1 deletion seafile/Supporting Files/seafile-appstore-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@
<key>UIRequiresFullScreen</key>
<true/>
<key>UIStatusBarHidden</key>
<true/>
<false/>
<key>UIStatusBarHidden~ipad</key>
<true/>
<key>UIStatusBarStyle</key>
<string></string>
<key>UIStatusBarTintParameters</key>
<dict>
<key>UINavigationBar</key>
Expand Down
Loading

0 comments on commit 615e7fe

Please sign in to comment.