1+ using System ;
12using System . Collections . Generic ;
23using System . Linq ;
34using fluXis . Database . Maps ;
@@ -27,6 +28,7 @@ public partial class MapList : FluXisScrollContainer, ISelectionManager
2728 private List < IListItem > items { get ; } = new ( ) ;
2829
2930 private bool bulkInserting ;
31+ private bool entering = true ;
3032
3133 public MapList ( Bindable < MapUtils . SortingMode > sorting )
3234 {
@@ -141,6 +143,12 @@ protected override void Update()
141143 }
142144
143145 Content . Height = pos ;
146+
147+ if ( pos > 0 && entering )
148+ {
149+ entering = false ;
150+ Schedule ( ( ) => ScheduleAfterChildren ( scrollEnter ) ) ;
151+ }
144152 }
145153
146154 public void Sort ( )
@@ -163,17 +171,36 @@ public void ScrollToSelected(bool smooth = true)
163171 ScrollToItem ( selected , smooth ) ;
164172 }
165173
174+ private void scrollEnter ( )
175+ {
176+ var selected = items . FirstOrDefault ( c => c . State . Value == SelectedState . Selected ) ;
177+
178+ if ( selected != null )
179+ {
180+ var position = getScrollPosition ( selected ) ;
181+ var start = Math . Max ( position - 800 , 0 ) ;
182+ ScrollTo ( start , false ) ;
183+ ScrollTo ( position ) ;
184+ }
185+ }
186+
166187 public void ScrollToItem ( IListItem item , bool smooth = true )
188+ {
189+ var pos = getScrollPosition ( item ) ;
190+ ScrollTo ( pos , smooth ) ;
191+ }
192+
193+ private double getScrollPosition ( IListItem item )
167194 {
168195 var top = item . ScrollPosition ;
169196 var center = top + item . ScrollSize / 2 ;
170197
171198 if ( center < DisplayableContent / 2 )
172- ScrollTo ( 0 , smooth ) ;
173- else if ( center > ScrollableExtent + DisplayableContent / 2 )
174- ScrollToEnd ( smooth ) ;
175- else
176- ScrollTo ( center - DisplayableContent / 2 , smooth ) ;
199+ return 0 ;
200+ if ( center > ScrollableExtent + DisplayableContent / 2 )
201+ return ScrollableExtent ;
202+
203+ return center - DisplayableContent / 2 ;
177204 }
178205
179206 public RealmMap CurrentMap => MapBindable . Value ;
0 commit comments