BugFix: Tap on clock status bar should scroll you up

https://github.com/vector-im/vector-ios/issues/289
https://github.com/vector-im/vector-ios/issues/125
This commit is contained in:
giomfo 2016-05-19 17:22:29 +02:00
parent 8f31f0a14f
commit c9eee9ff4e
8 changed files with 134 additions and 23 deletions

View file

@ -19,6 +19,12 @@
#import "HomeViewController.h"
#pragma mark - Notifications
/**
Posted when the user taps the clock status bar.
*/
extern NSString *const kAppDelegateDidTapStatusBarNotification;
@interface AppDelegate : UIResponder <UIApplicationDelegate, MXKCallViewControllerDelegate, MXKContactDetailsViewControllerDelegate, MXKRoomMemberDetailsViewControllerDelegate, UISplitViewControllerDelegate, UINavigationControllerDelegate>
{
BOOL isAPNSRegistered;

View file

@ -50,6 +50,8 @@
#define MAKE_STRING(x) #x
#define MAKE_NS_STRING(x) @MAKE_STRING(x)
NSString *const kAppDelegateDidTapStatusBarNotification = @"kAppDelegateDidTapStatusBarNotification";
@interface AppDelegate ()
{
/**
@ -1766,4 +1768,21 @@
return NO;
}
#pragma mark - Status Bar Tap handling
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.window];
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
if (CGRectContainsPoint(statusBarFrame, point))
{
[[NSNotificationCenter defaultCenter] postNotificationName:kAppDelegateDidTapStatusBarNotification object:nil];
}
}
@end

View file

@ -32,6 +32,8 @@
#import "InviteRecentTableViewCell.h"
#import "DirectoryRecentTableViewCell.h"
#import "AppDelegate.h"
@interface RecentsViewController ()
{
// The "parent" segmented view controller
@ -52,6 +54,9 @@
// Observe UIApplicationDidEnterBackgroundNotification to cancel editing mode when app leaves the foreground state.
id UIApplicationDidEnterBackgroundNotificationObserver;
// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
id kAppDelegateDidTapStatusBarNotificationObserver;
}
@end
@ -135,6 +140,13 @@
{
[self.recentsTableView deselectRowAtIndexPath:indexPath animated:NO];
}
// Observe kAppDelegateDidTapStatusBarNotificationObserver.
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
[self scrollToTop:YES];
}];
}
- (void)viewWillDisappear:(BOOL)animated
@ -143,6 +155,12 @@
// Leave potential editing mode
[self setEditing:NO];
if (kAppDelegateDidTapStatusBarNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:kAppDelegateDidTapStatusBarNotificationObserver];
kAppDelegateDidTapStatusBarNotificationObserver = nil;
}
}
- (void)viewDidAppear:(BOOL)animated
@ -202,7 +220,7 @@
if (_shouldScrollToTopOnRefresh)
{
[self scrollToTop];
[self scrollToTop:NO];
_shouldScrollToTopOnRefresh = NO;
}
@ -215,14 +233,9 @@
}
}
- (void)scrollToTop
- (void)scrollToTop:(BOOL)animated
{
// Stop any scrolling effect before scrolling to the tableview top
[UIView setAnimationsEnabled:NO];
self.recentsTableView.contentOffset = CGPointMake(-self.recentsTableView.contentInset.left, -self.recentsTableView.contentInset.top);
[UIView setAnimationsEnabled:YES];
[self.recentsTableView setContentOffset:CGPointMake(-self.recentsTableView.contentInset.left, -self.recentsTableView.contentInset.top) animated:animated];
}
- (void)refreshCurrentSelectedCell:(BOOL)forceVisible

View file

@ -54,6 +54,9 @@
id leaveRoomNotificationObserver;
RoomMemberDetailsViewController *detailsViewController;
// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
id kAppDelegateDidTapStatusBarNotificationObserver;
}
@end
@ -159,6 +162,13 @@
// Refresh display
[self.tableView reloadData];
// Observe kAppDelegateDidTapStatusBarNotificationObserver.
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
[self.tableView setContentOffset:CGPointMake(-self.tableView.contentInset.left, -self.tableView.contentInset.top) animated:YES];
}];
}
- (void)viewWillDisappear:(BOOL)animated
@ -173,6 +183,12 @@
// cancel any pending search
[self searchBarCancelButtonClicked:_searchBarView];
if (kAppDelegateDidTapStatusBarNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:kAppDelegateDidTapStatusBarNotificationObserver];
kAppDelegateDidTapStatusBarNotificationObserver = nil;
}
}
#pragma mark -

View file

@ -30,10 +30,15 @@
#import "RageShakeManager.h"
#import "AppDelegate.h"
@interface RoomSearchViewController ()
{
// The event selected in the search results
MXEvent *selectedEvent;
// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
id kAppDelegateDidTapStatusBarNotificationObserver;
}
@end
@ -69,6 +74,24 @@
{
[self showSearch:animated];
}
// Observe kAppDelegateDidTapStatusBarNotificationObserver.
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
[self.searchTableView setContentOffset:CGPointMake(-self.searchTableView.contentInset.left, -self.searchTableView.contentInset.top) animated:YES];
}];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
if (kAppDelegateDidTapStatusBarNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:kAppDelegateDidTapStatusBarNotificationObserver];
kAppDelegateDidTapStatusBarNotificationObserver = nil;
}
}
#pragma mark - Override MXKViewController

View file

@ -34,6 +34,8 @@
#import "MXRoom+Vector.h"
#import "AppDelegate.h"
#define ROOM_SECTION 0
#define ROOM_SECTION_PHOTO 0
@ -70,6 +72,9 @@
// switches
UISwitch *roomNotifSwitch;
// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
id kAppDelegateDidTapStatusBarNotificationObserver;
}
@end
@ -119,6 +124,13 @@
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didMXSessionStateChange:) name:kMXSessionStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didUpdateRules:) name:kMXNotificationCenterDidUpdateRules object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didAccountUserInfoDidChange:) name:kMXKAccountUserInfoDidChangeNotification object:nil];
// Observe kAppDelegateDidTapStatusBarNotificationObserver.
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
[self.tableView setContentOffset:CGPointMake(-self.tableView.contentInset.left, -self.tableView.contentInset.top) animated:YES];
}];
}
- (void)viewWillDisappear:(BOOL)animated
@ -129,6 +141,12 @@
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXSessionStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXNotificationCenterDidUpdateRules object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXKAccountUserInfoDidChangeNotification object:nil];
if (kAppDelegateDidTapStatusBarNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:kAppDelegateDidTapStatusBarNotificationObserver];
kAppDelegateDidTapStatusBarNotificationObserver = nil;
}
}
// this method is called when the viewcontroller is displayed inside another one.

View file

@ -96,6 +96,9 @@
// The position of the first touch down event stored in case of scrolling when the expanded header is visible.
CGPoint startScrollingPoint;
// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
id kAppDelegateDidTapStatusBarNotificationObserver;
}
@end
@ -268,6 +271,13 @@
{
[self showExpandedHeader:YES];
}
// Observe kAppDelegateDidTapStatusBarNotificationObserver.
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
[self.bubblesTableView setContentOffset:CGPointMake(-self.bubblesTableView.contentInset.left, -self.bubblesTableView.contentInset.top) animated:YES];
}];
}
- (void)viewWillDisappear:(BOOL)animated
@ -295,25 +305,16 @@
// Hide expanded/preview header to restore navigation bar settings
[self showExpandedHeader:NO];
[self showPreviewHeader:NO];
if (kAppDelegateDidTapStatusBarNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:kAppDelegateDidTapStatusBarNotificationObserver];
kAppDelegateDidTapStatusBarNotificationObserver = nil;
}
}
- (void)viewDidAppear:(BOOL)animated
{
if (self.childViewControllers)
{
// Dispose data source defined for room member list view controller (if any)
for (id childViewController in self.childViewControllers)
{
if ([childViewController isKindOfClass:[MXKRoomMemberListViewController class]])
{
MXKRoomMemberListViewController *viewController = (MXKRoomMemberListViewController*)childViewController;
MXKDataSource *dataSource = [viewController dataSource];
[viewController destroy];
[dataSource destroy];
}
}
}
[super viewDidAppear:animated];
if (self.roomDataSource)

View file

@ -96,6 +96,9 @@
NSInteger userSettingsPhoneNumberIndex;
NSInteger userSettingsNightModeSepIndex;
NSInteger userSettingsNightModeIndex;
// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
id kAppDelegateDidTapStatusBarNotificationObserver;
}
/**
@ -244,6 +247,13 @@
// Refresh linked emails in parallel
[self loadLinkedEmails];
// Observe kAppDelegateDidTapStatusBarNotificationObserver.
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
[self.tableView setContentOffset:CGPointMake(-self.tableView.contentInset.left, -self.tableView.contentInset.top) animated:YES];
}];
}
- (void)viewWillDisappear:(BOOL)animated
@ -274,6 +284,11 @@
notificationCenterDidFailObserver = nil;
}
if (kAppDelegateDidTapStatusBarNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:kAppDelegateDidTapStatusBarNotificationObserver];
kAppDelegateDidTapStatusBarNotificationObserver = nil;
}
}
#pragma mark - Internal methods