Skip to content

Commit d1700ca

Browse files
Diogo Simao Marquesfkuehne
authored andcommitted
VLCFavoriteListViewController: Fix the search bar when the view is scrolled
The search bar is now properly handled when the view is scrolled: - The search is hidden when the text field is empty - The search bar remains on the screen if the user is currently searching
1 parent 5c9c894 commit d1700ca

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Sources/Network/Favorite/iOS/VLCFavoriteListViewController.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,24 @@ extension VLCFavoriteListViewController: UISearchBarDelegate {
307307

308308
extension VLCFavoriteListViewController: UIScrollViewDelegate {
309309
func scrollViewDidScroll(_ scrollView: UIScrollView) {
310+
// This ensures that the search bar is always visible like a sticky while searching
311+
if isSearching {
312+
searchBar.endEditing(true)
313+
if let searchBarText = searchBar.text,
314+
searchBarText.isEmpty {
315+
searchBarCancelButtonClicked(searchBar)
316+
}
317+
return
318+
}
319+
310320
searchBarConstraint?.constant = -min(scrollView.contentOffset.y, searchBarSize) - searchBarSize
311-
view.layoutIfNeeded()
312321
if scrollView.contentOffset.y < -searchBarSize && scrollView.contentInset.top != searchBarSize {
313322
tableView.contentInset.top = searchBarSize
314323
}
324+
325+
if scrollView.contentOffset.y >= 0 && scrollView.contentInset.top != 0 {
326+
tableView.contentInset.top = 0
327+
}
315328
}
316329
}
317330

0 commit comments

Comments
 (0)