Skip to content

Commit

Permalink
MAUI viewer ran against PerformanceAnalysisMode (#1456)
Browse files Browse the repository at this point in the history
  • Loading branch information
williambohrmann3 committed Jul 1, 2024
1 parent ceb06b7 commit 0b6780d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ private void CategoriesCollectionView_SelectionChanged(object sender, SelectionC
selectedCategory.IsSelected = true;
previousCategory.IsSelected = false;

_viewModel.CategorySelected(selectedCategory.CategoryName);
FlyoutMenuViewModel.CategorySelected(selectedCategory.CategoryName);

}
catch (Exception ex)
{
Debug.Write(ex.ToString());
}
}
}
}
6 changes: 3 additions & 3 deletions src/MAUI/Maui.Samples/ViewModels/CategoryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace ArcGIS.ViewModels
{
public partial class CategoryViewModel : ObservableObject
{
private static readonly string DefaultCategory = "Featured";
private const string DefaultCategory = "Featured";
private double _sampleImageWidth;
private double _sampleImageHeight;
public double SampleImageWidth => _sampleImageWidth;
Expand Down Expand Up @@ -71,7 +71,7 @@ private void UpdateCategory(string category)
SamplesItems = samplesCollection;
}

private List<SampleInfo> GetSamplesInCategory(string category)
private static List<SampleInfo> GetSamplesInCategory(string category)
{
var categoryNode = SampleManager.Current.FullTree.Items.OfType<SearchableTreeNode>().FirstOrDefault(c => c.Name == category);

Expand Down Expand Up @@ -100,7 +100,7 @@ void UpdateFavorite(string sampleFormalName)
}

[RelayCommand]
void SampleSelected(SampleViewModel sampleViewModel)
static void SampleSelected(SampleViewModel sampleViewModel)
{
if(SampleManager.Current.SelectedSample == null)
_ = SampleLoader.LoadSample(sampleViewModel.SampleObject);
Expand Down
2 changes: 1 addition & 1 deletion src/MAUI/Maui.Samples/ViewModels/FlyoutMenuViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void Initialize()
[ObservableProperty]
private ObservableCollection<FlyoutCategoryViewModel> _categories;

public void CategorySelected(string categoryName)
public static void CategorySelected(string categoryName)
{
WeakReferenceMessenger.Default.Send(categoryName);
}
Expand Down
13 changes: 5 additions & 8 deletions src/MAUI/Maui.Samples/ViewModels/SearchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void PerformSearch()
else
{
// Remove punctuation from the search text and any trailing white space at the end.
var searchKeywords = GetKeywords(SearchText);
var searchKeywords = SearchViewModel.GetKeywords(SearchText);

// Check if the keywords are the same as the previous search.
if (Enumerable.SequenceEqual(searchKeywords, _previousSearchKeywords))
Expand Down Expand Up @@ -84,7 +84,7 @@ void PerformSearch()

try
{
if (sampleResults.Any())
if (sampleResults.Count != 0)
{
sampleResults = sampleResults.OrderByDescending(sampleResults => sampleResults.Score).ThenBy(sampleResults => sampleResults.SampleName).ToList();
SearchItems = new ObservableCollection<SearchResultViewModel>(sampleResults);
Expand All @@ -101,7 +101,7 @@ void PerformSearch()
}
}

private int GetMatches(string[] contentKeywords, string[] searchKeywords)
private static int GetMatches(string[] contentKeywords, string[] searchKeywords)
{
int matches = 0;

Expand All @@ -123,7 +123,7 @@ private int GetMatches(string[] contentKeywords, string[] searchKeywords)
return matches;
}

private string[] GetKeywords(string text)
private static string[] GetKeywords(string text)
{
// Remove punctuation from the search text and any trailing white space at the end.
Regex regex = new Regex("[^a-zA-Z0-9 -]");
Expand All @@ -134,10 +134,7 @@ private string[] GetKeywords(string text)

foreach (var word in commonWords)
{
if (cleanedTextWords.Contains(word))
{
cleanedTextWords.Remove(word);
}
cleanedTextWords.Remove(word);
}

return cleanedTextWords.ToArray();
Expand Down
26 changes: 13 additions & 13 deletions src/MAUI/Maui.Samples/Views/SamplePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public partial class SamplePage : ContentPage
{
private ContentPage _sampleContent;
private Assembly _assembly;
private int _lastViewedFileIndex = 0;
private int _lastViewedFileIndex;

// single-instance webviews reused on each view, to avoid a memory leak in webview
private static WebView DescriptionView = new WebView();
Expand Down Expand Up @@ -179,21 +179,21 @@ private static IEnumerable<T> TreeWalker<T>(VisualElement root)
private async Task<string> GetDescriptionHtml(SampleInfo sampleInfo)
{
string category = sampleInfo.Category;
if (category.Contains(" "))
if (category.Contains(' '))
{
// Make categories with spaces into titlecase folder name.
category = $"{category.Split(" ")[0]}{category.Split(" ")[1][0].ToString().ToUpper()}{category.Split(" ")[1].Substring(1)}";
}

using Stream fileStream = await FileSystem.Current.OpenAppPackageFileAsync($"Samples/{category}/{sampleInfo.FormalName}/readme.md").ConfigureAwait(false);
StreamReader r = new StreamReader(fileStream);
var readmeContent = r.ReadToEnd();
var readmeContent = await r.ReadToEndAsync();
readmeContent = Markdig.Markdown.ToHtml(readmeContent);

// Set CSS for dark mode or light mode.
string markdownCssType = Application.Current.RequestedTheme == Microsoft.Maui.ApplicationModel.AppTheme.Dark ? "github-markdown-dark.css" : "github-markdown.css";
string cssResource = _assembly.GetManifestResourceNames().Single(n => n.EndsWith($"SyntaxHighlighting.{markdownCssType}"));
string cssContent = new StreamReader(_assembly.GetManifestResourceStream(cssResource)).ReadToEnd();
string cssContent = await new StreamReader(_assembly.GetManifestResourceStream(cssResource)).ReadToEndAsync();

#if WINDOWS
// Remove the readme header on Windows so it doesn't repeat the title.
Expand All @@ -205,7 +205,7 @@ private async Task<string> GetDescriptionHtml(SampleInfo sampleInfo)
if (sourceStream is not null)
{
using var memoryStream = new MemoryStream();
sourceStream.CopyTo(memoryStream);
await sourceStream.CopyToAsync(memoryStream);
byte[] image = memoryStream.ToArray();
memoryStream.Close();

Expand Down Expand Up @@ -502,7 +502,7 @@ private async void GitHubToolbarItem_Clicked(object sender, EventArgs e)
await OpenGitHub();
}

private async Task OpenGitHub()
private static async Task OpenGitHub()
{
try
{
Expand All @@ -529,7 +529,7 @@ private void ScreenshotButton_Clicked(object sender, EventArgs e)
// Code here is adapted from the following Stack Overflow answers:
// https://stackoverflow.com/q/24466482
// https://stackoverflow.com/a/15537372
private void SaveScreenshot(VisualElement source)
private static void SaveScreenshot(VisualElement source)
{
double scale = ScreenshotManager.ScreenshotSettings.ScaleFactor.HasValue ? ScreenshotManager.ScreenshotSettings.ScaleFactor.Value : double.NaN;

Expand Down Expand Up @@ -643,23 +643,23 @@ private async Task LoadContent()
{
var fileName = _path.Split('/').Last();
var xamlPath = assembly.GetManifestResourceNames().Single(n => n.EndsWith($"{fileName}"));
SourceCode = baseContent = new StreamReader(assembly.GetManifestResourceStream(xamlPath)).ReadToEnd();
SourceCode = baseContent = await new StreamReader(assembly.GetManifestResourceStream(xamlPath)).ReadToEndAsync();
}
else
{
using Stream fileStream = await FileSystem.Current.OpenAppPackageFileAsync(_path).ConfigureAwait(false);
SourceCode = baseContent = new StreamReader(fileStream).ReadToEnd();
SourceCode = baseContent = await new StreamReader(fileStream).ReadToEndAsync();
}
#else
using Stream fileStream = await FileSystem.Current.OpenAppPackageFileAsync(_path).ConfigureAwait(false);
SourceCode = baseContent = new StreamReader(fileStream).ReadToEnd();
SourceCode = baseContent = await new StreamReader(fileStream).ReadToEndAsync();
#endif
// For xaml files, search for dynamic resource styles, taking into account any whitespace.
if (_path.EndsWith(".xaml") && String.Concat(baseContent.Where(c => !Char.IsWhiteSpace(c)))
.Contains("Style=\"{DynamicResource"))
{
// Display a comment on the second line of the file.
baseContent = baseContent.Insert(baseContent.IndexOf(">")+1,
baseContent = baseContent.Insert(baseContent.IndexOf('>')+1,
"\n<!-- Styles used in this sample can be copied from Resources/Styles/Styles.xaml. -->");
}

Expand All @@ -672,15 +672,15 @@ private async Task LoadContent()
// Set CSS for dark mode or light mode.
string markdownCssType = Application.Current.RequestedTheme == Microsoft.Maui.ApplicationModel.AppTheme.Dark ? "highlight-dark.css" : "highlight.css";
string cssResource = assembly.GetManifestResourceNames().Single(n => n.EndsWith($"SyntaxHighlighting.{markdownCssType}"));
string cssContent = new StreamReader(assembly.GetManifestResourceStream(cssResource)).ReadToEnd();
string cssContent = await new StreamReader(assembly.GetManifestResourceStream(cssResource)).ReadToEndAsync();

// Set the background color. Color values are taken from corresponding css files.
string backgroundColor = Application.Current.RequestedTheme == Microsoft.Maui.ApplicationModel.AppTheme.Dark ? "#1e1e1e" : "#fff";
cssContent = $"{cssContent} body {{ background: {backgroundColor};}}";

// Read javascript content.
string jsResource = assembly.GetManifestResourceNames().Single(n => n.EndsWith($"SyntaxHighlighting.highlight.js"));
string jsContent = new StreamReader(assembly.GetManifestResourceStream(jsResource)).ReadToEnd();
string jsContent = await new StreamReader(assembly.GetManifestResourceStream(jsResource)).ReadToEndAsync();

// Build the html.
_fullContent =
Expand Down

0 comments on commit 0b6780d

Please sign in to comment.