Skip to content

Commit d84840b

Browse files
committed
chore(demo): add empty state to log view
1 parent fbaa888 commit d84840b

3 files changed

Lines changed: 25 additions & 15 deletions

File tree

examples/demo/Controls/LogView.xaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,19 @@
8686
BackgroundColor="{StaticResource OsLogBackground}"
8787
AutomationId="log_view_list"
8888
>
89-
<VerticalStackLayout x:Name="LogList" Spacing="0" Padding="12,0" />
89+
<Grid>
90+
<Label
91+
x:Name="EmptyLabel"
92+
Text="No logs yet"
93+
TextColor="{StaticResource OsGrey500}"
94+
FontSize="11"
95+
FontFamily="DroidSansMono"
96+
HorizontalOptions="Center"
97+
VerticalOptions="Center"
98+
AutomationId="log_view_empty"
99+
/>
100+
<VerticalStackLayout x:Name="LogList" Spacing="0" Padding="12,0" />
101+
</Grid>
90102
</ScrollView>
91103
</Grid>
92104
</ContentView>

examples/demo/Controls/LogView.xaml.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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()
@@ -83,12 +79,7 @@ private void UpdateCount()
8379
var count = LogManager.Instance.Logs.Count;
8480
LogCountLabel.Text = $"({count})";
8581
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);
82+
EmptyLabel.IsVisible = count == 0;
9283
}
9384

9485
private void OnHeaderTapped(object? sender, TappedEventArgs e)

examples/demo/Services/LogManager.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.ObjectModel;
22
using System.ComponentModel;
3-
using System.Diagnostics;
43

54
namespace OneSignalDemo.Services;
65

@@ -47,14 +46,22 @@ private LogManager() { }
4746

4847
public void E(string tag, string message) => AddLog("E", tag, message);
4948

49+
private const int MaxEntries = 100;
50+
5051
private void AddLog(string level, string tag, string message)
5152
{
5253
var entry = new LogEntry(level, $"[{tag}] {message}");
53-
Debug.WriteLine($"{level} {entry.Timestamp} [{tag}] {message}");
54+
var line = $"[{level}][{tag}] {message}";
55+
if (level is "W" or "E")
56+
Console.Error.WriteLine(line);
57+
else
58+
Console.WriteLine(line);
5459

5560
MainThread.BeginInvokeOnMainThread(() =>
5661
{
57-
Logs.Add(entry);
62+
Logs.Insert(0, entry);
63+
if (Logs.Count > MaxEntries)
64+
Logs.RemoveAt(Logs.Count - 1);
5865
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Logs)));
5966
LogAdded?.Invoke(this, EventArgs.Empty);
6067
});

0 commit comments

Comments
 (0)