diff --git a/Vector/Categories/UIViewController+VectorSearch.h b/Vector/Categories/UIViewController+VectorSearch.h index fe5a1af69..cdce0a66a 100644 --- a/Vector/Categories/UIViewController+VectorSearch.h +++ b/Vector/Categories/UIViewController+VectorSearch.h @@ -39,6 +39,8 @@ */ @property (nonatomic, readonly) UIImageView *backgroundImageView; +@property (nonatomic, readonly) NSLayoutConstraint *backgroundImageViewBottomConstraint; + /** Show/Hide the search bar. diff --git a/Vector/Categories/UIViewController+VectorSearch.m b/Vector/Categories/UIViewController+VectorSearch.m index 5ae8d7daf..430d6cf46 100644 --- a/Vector/Categories/UIViewController+VectorSearch.m +++ b/Vector/Categories/UIViewController+VectorSearch.m @@ -71,6 +71,11 @@ return self.searchInternals.backgroundImageView; } +- (NSLayoutConstraint *)backgroundImageViewBottomConstraint +{ + return self.searchInternals.backgroundImageViewBottomConstraint; +} + - (void)showSearch:(BOOL)animated { // Backup screen header before displaying the search bar in it diff --git a/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.m b/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.m index c4e7d1f43..5edfbb920 100644 --- a/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.m +++ b/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.m @@ -45,7 +45,7 @@ double const kPublicRoomsDirectoryDataExpiration = 10; NSString *searchPatternsListString = [_searchPatternsList componentsJoinedByString:@""]; NSString *newSearchPatternsListString = [newSearchPatternsList componentsJoinedByString:@""]; - if (![newSearchPatternsListString isEqualToString:searchPatternsListString]) + if ((searchPatternsListString || newSearchPatternsListString) && ![newSearchPatternsListString isEqualToString:searchPatternsListString]) { _searchPatternsList = newSearchPatternsList; [self refreshPublicRooms]; diff --git a/Vector/ViewController/HomeViewController.m b/Vector/ViewController/HomeViewController.m index 1c9041fe3..f0526c434 100644 --- a/Vector/ViewController/HomeViewController.m +++ b/Vector/ViewController/HomeViewController.m @@ -420,6 +420,8 @@ [self setKeyboardHeightForBackgroundImage:keyboardHeight]; [super setKeyboardHeight:keyboardHeight]; + + [self checkAndShowBackgroundImage]; } - (void)startActivityIndicator @@ -451,19 +453,32 @@ } } -// Check if there is enough room for displaying the background -// before displaying it +// Check conditions before displaying the background - (void)checkAndShowBackgroundImage { - // In landscape with the iPhone 5 & 6 screen size, the backgroundImageView overlaps the tabs header, - // So, hide backgroundImageView - if (self.backgroundImageView.superview.frame.size.height > 375 && (self.searchBar.text.length == 0)) + // Note: This background is hidden when keyboard is dismissed. + // The other conditions depend on the current selected view controller. + if (self.selectedViewController == recentsViewController) { - self.backgroundImageView.hidden = NO; + self.backgroundImageView.hidden = (!recentsDataSource.hideRecents || !recentsDataSource.hidepublicRoomsDirectory || (self.keyboardHeight == 0)); + } + else if (self.selectedViewController == searchViewController) + { + self.backgroundImageView.hidden = (((searchDataSource.serverCount != 0) && !searchViewController.noResultsLabel.isHidden) || (self.keyboardHeight == 0)); } else { - self.backgroundImageView.hidden = YES; + self.backgroundImageView.hidden = (self.keyboardHeight == 0); + } + + if (!self.backgroundImageView.hidden) + { + // Check whether there is enough space to display this background + // For example, in landscape with the iPhone 5 & 6 screen size, the backgroundImageView must be hidden. + if ((self.selectedViewController.view.frame.size.height - self.backgroundImageViewBottomConstraint.constant) < self.backgroundImageView.frame.size.height) + { + self.backgroundImageView.hidden = YES; + } } } @@ -678,14 +693,15 @@ recentsDataSource.hideRecents = YES; recentsDataSource.hidepublicRoomsDirectory = NO; - // Reset message search if any + // Reset search result (if any) + [recentsDataSource searchWithPatterns:nil]; if (searchDataSource.searchText.length) { [searchDataSource searchMessageText:nil]; } - - [self checkAndShowBackgroundImage]; } + + [self checkAndShowBackgroundImage]; } #pragma mark - UISearchBarDelegate