@@ -18,11 +18,7 @@ public LogView()
1818
1919 private void OnLogAdded ( object ? sender , EventArgs e )
2020 {
21- MainThread . BeginInvokeOnMainThread ( ( ) =>
22- {
23- RebuildLogList ( ) ;
24- _ = ScrollToBottomAsync ( ) ;
25- } ) ;
21+ MainThread . BeginInvokeOnMainThread ( RebuildLogList ) ;
2622 }
2723
2824 private void RebuildLogList ( )
@@ -31,8 +27,9 @@ private void RebuildLogList()
3127 LogList . Children . Clear ( ) ;
3228 _logRows . Clear ( ) ;
3329
34- for ( int i = 0 ; i < logs . Count ; i ++ )
30+ for ( int i = logs . Count - 1 ; i >= 0 ; i -- )
3531 {
32+ var displayIndex = logs . Count - 1 - i ;
3633 var entry = logs [ i ] ;
3734 var row = new HorizontalStackLayout { Spacing = 4 , Padding = new Thickness ( 0 , 1 ) } ;
3835
@@ -43,7 +40,7 @@ private void RebuildLogList()
4340 FontSize = 11 ,
4441 FontFamily = "DroidSansMono" ,
4542 VerticalOptions = LayoutOptions . Center ,
46- AutomationId = $ "log_entry_{ i } _timestamp",
43+ AutomationId = $ "log_entry_{ displayIndex } _timestamp",
4744 } ;
4845 var level = new Label
4946 {
@@ -54,7 +51,7 @@ private void RebuildLogList()
5451 FontAttributes = FontAttributes . Bold ,
5552 VerticalOptions = LayoutOptions . Center ,
5653 Margin = new Thickness ( 4 , 0 ) ,
57- AutomationId = $ "log_entry_{ i } _level",
54+ AutomationId = $ "log_entry_{ displayIndex } _level",
5855 } ;
5956 var msg = new Label
6057 {
@@ -63,13 +60,13 @@ private void RebuildLogList()
6360 FontSize = 11 ,
6461 FontFamily = "DroidSansMono" ,
6562 VerticalOptions = LayoutOptions . Center ,
66- AutomationId = $ "log_entry_{ i } _message",
63+ AutomationId = $ "log_entry_{ displayIndex } _message",
6764 } ;
6865
6966 row . Children . Add ( ts ) ;
7067 row . Children . Add ( level ) ;
7168 row . Children . Add ( msg ) ;
72- row . AutomationId = $ "log_entry_{ i } ";
69+ row . AutomationId = $ "log_entry_{ displayIndex } ";
7370
7471 LogList . Children . Add ( row ) ;
7572 _logRows . Add ( row ) ;
@@ -83,12 +80,7 @@ private void UpdateCount()
8380 var count = LogManager . Instance . Logs . Count ;
8481 LogCountLabel . Text = $ "({ count } )";
8582 ClearIcon . IsVisible = count > 0 ;
86- }
87-
88- private async Task ScrollToBottomAsync ( )
89- {
90- await Task . Delay ( 50 ) ;
91- await LogScrollView . ScrollToAsync ( 0 , LogScrollView . ContentSize . Height , false ) ;
83+ EmptyLabel . IsVisible = count == 0 ;
9284 }
9385
9486 private void OnHeaderTapped ( object ? sender , TappedEventArgs e )
0 commit comments