File tree Expand file tree Collapse file tree 2 files changed +21
-13
lines changed
src/MobileUI/Features/Leaderboard Expand file tree Collapse file tree 2 files changed +21
-13
lines changed Original file line number Diff line number Diff line change 1- ο»Ώusing Microsoft . Maui . Controls . Internals ;
2-
3- namespace SSW . Rewards . Mobile . Pages ;
1+ ο»Ώnamespace SSW . Rewards . Mobile . Pages ;
42
53public partial class LeaderboardPage
64{
@@ -23,14 +21,21 @@ protected override async void OnAppearing()
2321 base . OnAppearing ( ) ;
2422 _firebaseAnalyticsService . Log ( "LeaderboardPage" ) ;
2523
24+ _viewModel . ScrollTo += ScrollTo ;
25+
2626 // Page might be ready a bit earlier due to cached leaderboard
2727 // while data is refreshed in the background.
2828 _viewModel . ReadyEarly += Animate ;
2929 await _viewModel . Initialise ( ) ;
3030
3131 await Animate ( ) ;
32+ }
3233
33- _viewModel . ScrollTo += ScrollTo ;
34+ protected override void OnDisappearing ( )
35+ {
36+ base . OnDisappearing ( ) ;
37+ _viewModel . ScrollTo -= ScrollTo ;
38+ _viewModel . ReadyEarly -= Animate ;
3439 }
3540
3641 private void ScrollTo ( int i )
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ public partial class LeaderboardViewModel : BaseViewModel
1515 private bool _loaded ;
1616
1717 private const int PageSize = 50 ;
18+ private const int ScrollDelayMilliseconds = 50 ;
1819 private int _page ;
1920 private bool _limitReached ;
2021
@@ -153,25 +154,27 @@ await _fileCacheService.FetchAndRefresh(
153154 LeaderViewModel myCard = Leaders . FirstOrDefault ( l => l . IsMe ) ;
154155 while ( myCard == null )
155156 {
156- myCard = Leaders . FirstOrDefault ( l => l . IsMe ) ;
157-
158- if ( myCard != null )
157+ if ( _limitReached )
159158 {
160- continue ;
159+ break ;
161160 }
162161
163162 ++ _page ;
164163
165164 var result = await FetchLeaderboard ( CurrentPeriod , _page , PageSize ) ;
166165 ProcessLeaders ( result ) ;
167166
168- if ( _limitReached )
169- {
170- break ;
171- }
167+ myCard = Leaders . FirstOrDefault ( l => l . IsMe ) ;
172168 }
173169
174- ScrollToCard ( myCard ) ;
170+ if ( myCard != null )
171+ {
172+ await MainThread . InvokeOnMainThreadAsync ( async ( ) =>
173+ {
174+ await Task . Delay ( ScrollDelayMilliseconds ) ;
175+ ScrollToCard ( myCard ) ;
176+ } ) ;
177+ }
175178 }
176179 else
177180 {
You canβt perform that action at this time.
0 commit comments