1
1
import { ItemEventData , SearchEventData , ItemsSource } from '.' ;
2
- import { ListViewBase , separatorColorProperty , itemTemplatesProperty , iosEstimatedRowHeightProperty , stickyHeaderProperty , stickyHeaderTemplateProperty , stickyHeaderHeightProperty , sectionedProperty , showSearchProperty } from './list-view-common' ;
2
+ import { ListViewBase , separatorColorProperty , itemTemplatesProperty , iosEstimatedRowHeightProperty , stickyHeaderProperty , stickyHeaderTemplateProperty , stickyHeaderHeightProperty , sectionedProperty , showSearchProperty , searchAutoHideProperty } from './list-view-common' ;
3
3
import { CoreTypes } from '../../core-types' ;
4
4
import { View , KeyedTemplate , Template } from '../core/view' ;
5
5
import { Length } from '../styling/length-shared' ;
@@ -499,36 +499,62 @@ export class ListView extends ListViewBase {
499
499
// 2. Tell it who will update results
500
500
this . _searchController . searchResultsUpdater = this . _searchDelegate ;
501
501
502
- // 3. Don't dim or obscure your table by default
502
+ // 3. Critical: Don't dim or obscure the table, and prevent extra content
503
503
this . _searchController . obscuresBackgroundDuringPresentation = false ;
504
+ this . _searchController . dimsBackgroundDuringPresentation = false ;
505
+ this . _searchController . hidesNavigationBarDuringPresentation = false ;
504
506
505
- // 4. Placeholder text
507
+ // 4. Placeholder text and styling
506
508
this . _searchController . searchBar . placeholder = 'Search' ;
507
509
this . _searchController . searchBar . searchBarStyle = UISearchBarStyle . Minimal ;
508
510
509
- // 5. CRITICAL: Make sure the search bar doesn't remain on screen if the user navigates
511
+ // 5. CRITICAL: Proper presentation context setup
510
512
const viewController = this . _getViewController ( ) ;
511
513
if ( viewController ) {
512
514
viewController . definesPresentationContext = true ;
515
+ viewController . providesPresentationContextTransitionStyle = true ;
513
516
514
- // 6a. If we're in a UINavigationController...
517
+ // 6a. If we're in a UINavigationController (iOS 11+) ...
515
518
if ( SDK_VERSION >= 11.0 && viewController . navigationItem ) {
516
519
viewController . navigationItem . searchController = this . _searchController ;
517
- viewController . navigationItem . hidesSearchBarWhenScrolling = false ;
520
+
521
+ // Set auto-hide behavior based on searchAutoHide property
522
+ viewController . navigationItem . hidesSearchBarWhenScrolling = this . searchAutoHide ;
523
+
524
+ // Optional: Enable large titles for better auto-hide effect when searchAutoHide is true
525
+ // if (this.searchAutoHide && viewController.navigationController && viewController.navigationController.navigationBar) {
526
+ // // Only set large titles if not already configured
527
+ // if (!viewController.navigationController.navigationBar.prefersLargeTitles) {
528
+ // viewController.navigationController.navigationBar.prefersLargeTitles = true;
529
+ // }
530
+ // // Set large title display mode for this specific view controller
531
+ // if (viewController.navigationItem.largeTitleDisplayMode === UINavigationItemLargeTitleDisplayMode.Automatic) {
532
+ // viewController.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayMode.Always;
533
+ // }
534
+ // }
518
535
} else {
519
- // 6b. Or just put it at the top of our table
536
+ // 6b. Fallback: put it at the top of our table
520
537
this . nativeViewProtected . tableHeaderView = this . _searchController . searchBar ;
521
538
}
522
539
} else {
523
540
// Fallback: no view controller found, use table header
524
541
this . nativeViewProtected . tableHeaderView = this . _searchController . searchBar ;
525
542
}
526
543
527
- // Ensure search bar is properly sized
544
+ // 7. Ensure search bar is properly sized and prevent content inset issues
528
545
this . _searchController . searchBar . sizeToFit ( ) ;
529
546
547
+ // 8. Disable automatic content inset adjustment that can cause spacing issues
548
+ if ( this . nativeViewProtected . respondsToSelector ( 'setContentInsetAdjustmentBehavior:' ) ) {
549
+ // iOS 11+ - prevent automatic content inset adjustments
550
+ this . nativeViewProtected . contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior . Never ;
551
+ } else {
552
+ // iOS 10 and below - disable automatic content inset
553
+ this . nativeViewProtected . automaticallyAdjustsScrollIndicatorInsets = false ;
554
+ }
555
+
530
556
if ( Trace . isEnabled ( ) ) {
531
- Trace . write ( `ListView: UISearchController setup complete` , Trace . categories . Debug ) ;
557
+ Trace . write ( `ListView: UISearchController setup complete with searchAutoHide: ${ this . searchAutoHide } ` , Trace . categories . Debug ) ;
532
558
}
533
559
}
534
560
@@ -545,6 +571,15 @@ export class ListView extends ListViewBase {
545
571
this . nativeViewProtected . tableHeaderView = null ;
546
572
}
547
573
574
+ // Reset content inset adjustment behavior
575
+ if ( this . nativeViewProtected . respondsToSelector ( 'setContentInsetAdjustmentBehavior:' ) ) {
576
+ // iOS 11+ - restore automatic content inset adjustments
577
+ this . nativeViewProtected . contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior . Automatic ;
578
+ } else {
579
+ // iOS 10 and below - restore automatic content inset
580
+ this . nativeViewProtected . automaticallyAdjustsScrollIndicatorInsets = true ;
581
+ }
582
+
548
583
// Cleanup references
549
584
this . _searchController . searchResultsUpdater = null ;
550
585
this . _searchController = null ;
@@ -1087,4 +1122,32 @@ export class ListView extends ListViewBase {
1087
1122
this . _cleanupSearchController ( ) ;
1088
1123
}
1089
1124
}
1125
+
1126
+ [ searchAutoHideProperty . getDefault ] ( ) : boolean {
1127
+ return false ;
1128
+ }
1129
+ [ searchAutoHideProperty . setNative ] ( value : boolean ) {
1130
+ if ( Trace . isEnabled ( ) ) {
1131
+ Trace . write ( `ListView: searchAutoHide set to ${ value } ` , Trace . categories . Debug ) ;
1132
+ }
1133
+
1134
+ // If search is already enabled, update the existing search controller
1135
+ if ( this . showSearch && this . _searchController ) {
1136
+ const viewController = this . _getViewController ( ) ;
1137
+ if ( viewController && viewController . navigationItem && SDK_VERSION >= 11.0 ) {
1138
+ viewController . navigationItem . hidesSearchBarWhenScrolling = value ;
1139
+
1140
+ // Enable large titles for better auto-hide effect when searchAutoHide is true
1141
+ // if (value && viewController.navigationController && viewController.navigationController.navigationBar) {
1142
+ // if (!viewController.navigationController.navigationBar.prefersLargeTitles) {
1143
+ // viewController.navigationController.navigationBar.prefersLargeTitles = true;
1144
+ // }
1145
+ // if (viewController.navigationItem.largeTitleDisplayMode === UINavigationItemLargeTitleDisplayMode.Automatic) {
1146
+ // viewController.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayMode.Always;
1147
+ // }
1148
+ // }
1149
+ }
1150
+ }
1151
+ // If search is not enabled yet, the property will be used when _setupSearchController is called
1152
+ }
1090
1153
}
0 commit comments