Skip to content

Commit

Permalink
Merge pull request #6 from Toine-db/sample_pages
Browse files Browse the repository at this point in the history
basic sample pages
  • Loading branch information
Toine-db authored Jan 21, 2025
2 parents 0a76bb8 + edb9b6d commit 9bd4103
Show file tree
Hide file tree
Showing 19 changed files with 294 additions and 7,955 deletions.
58 changes: 52 additions & 6 deletions samples/Plugin.Maui.MarkdownView.Sample/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,59 @@
x:Class="Plugin.Maui.MarkdownView.Sample.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Plugin.Maui.MarkdownView.Sample"
Shell.FlyoutBehavior="Disabled"
xmlns:pages="clr-namespace:Plugin.Maui.MarkdownView.Sample.Pages"
Shell.FlyoutBehavior="Flyout"
Shell.FlyoutBackgroundColor="{AppThemeBinding Light={StaticResource Gray100}, Dark={StaticResource Gray600}}"
Title="Plugin.Maui.MarkdownView.Sample">

<ShellContent
Title="MarkdownView Plugin"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />
<Shell.Resources>

<Color x:Key="FlyoutHeaderColor">#FFFFFF</Color>
<Style TargetType="FontImageSource" >
<Setter Property="Color" Value="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"/>
</Style>

</Shell.Resources>

<Shell.FlyoutHeader>
<Grid HeightRequest="100"
BackgroundColor="{StaticResource Primary}">
<Label Text="Markdown Viewer"
VerticalOptions="Center"
Style="{DynamicResource Headline}"
TextColor="{DynamicResource FlyoutHeaderColor}" />
</Grid>
</Shell.FlyoutHeader>

<FlyoutItem Title="In XAML">
<FlyoutItem.FlyoutIcon>
<FontImageSource
FontFamily="FontAwesomeRegular"
Glyph="&#xf1c9;" />
</FlyoutItem.FlyoutIcon>
<Tab>
<ShellContent ContentTemplate="{DataTemplate pages:MarkdownInXamlPage}" />
</Tab>
</FlyoutItem>
<FlyoutItem Title="From File">
<FlyoutItem.FlyoutIcon>
<FontImageSource
FontFamily="FontAwesomeRegular"
Glyph="&#xf15b;" />
</FlyoutItem.FlyoutIcon>
<Tab>
<ShellContent ContentTemplate="{DataTemplate pages:MarkdownFromFilePage}" />
</Tab>
</FlyoutItem>
<FlyoutItem Title="From Remote">
<FlyoutItem.FlyoutIcon>
<FontImageSource
FontFamily="FontAwesomeSolid"
Glyph="&#xf0ed;" />
</FlyoutItem.FlyoutIcon>
<Tab>
<ShellContent ContentTemplate="{DataTemplate pages:MarkdownFromRemotePage}" />
</Tab>
</FlyoutItem>

</Shell>
23 changes: 23 additions & 0 deletions samples/Plugin.Maui.MarkdownView.Sample/AppShell.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,31 @@

public partial class AppShell : Shell
{
private bool _hasShownFlyoutMenu;

public AppShell()
{
InitializeComponent();
}

protected override void OnAppearing()
{
base.OnAppearing();

// prevent HotReload from showing flyout menu again and again and again...
if (!_hasShownFlyoutMenu)
{
ShowFlyoutMenu();
}
}

private void ShowFlyoutMenu()
{
_hasShownFlyoutMenu = true;
Dispatcher.Dispatch(async () =>
{
await Task.Delay(1000);
FlyoutIsPresented = true;
});
}
}
21 changes: 0 additions & 21 deletions samples/Plugin.Maui.MarkdownView.Sample/MainPage.xaml.cs

This file was deleted.

3 changes: 3 additions & 0 deletions samples/Plugin.Maui.MarkdownView.Sample/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public static MauiApp CreateMauiApp()
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
fonts.AddFont("FontAwesomeRegular.otf", "FontAwesomeRegular");
fonts.AddFont("FontAwesomeBrands.otf", "FontAwesomeBrands");
fonts.AddFont("FontAwesomeSolid.otf", "FontAwesomeSolid");
});

#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:markdownView="clr-namespace:Plugin.Maui.MarkdownView;assembly=Plugin.Maui.MarkdownView"
x:Class="Plugin.Maui.MarkdownView.Sample.Pages.MarkdownFromFilePage"
Title="MarkdownFromFilePage">

<ScrollView>
<markdownView:MarkdownView x:Name="MarkdownView" />
</ScrollView>

</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Plugin.Maui.MarkdownView.Sample.Pages;

public partial class MarkdownFromFilePage : ContentPage
{
public MarkdownFromFilePage()
{
InitializeComponent();
}

protected override async void OnAppearing()
{
base.OnAppearing();

await using var stream = await FileSystem.OpenAppPackageFileAsync("LorumMarkdown.md");
using var reader = new StreamReader(stream);
var markdown = await reader.ReadToEndAsync();

MarkdownView.MarkdownText = markdown;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:markdownView="clr-namespace:Plugin.Maui.MarkdownView;assembly=Plugin.Maui.MarkdownView"
x:Class="Plugin.Maui.MarkdownView.Sample.Pages.MarkdownFromRemotePage"
Title="MarkdownFromRemotePage">

<RefreshView x:Name="RefreshView" Refreshing="OnRefreshing" >
<ScrollView>
<markdownView:MarkdownView x:Name="MarkdownView" />
</ScrollView>
</RefreshView>

</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
namespace Plugin.Maui.MarkdownView.Sample.Pages;

public partial class MarkdownFromRemotePage : ContentPage
{
private const string RemoteFile = "https://enbyin.com/resources/MarkdownExample.md";

public MarkdownFromRemotePage()
{
InitializeComponent();

SetRemoteBasePathForResources();
}

private void SetRemoteBasePathForResources()
{
// To work with online images and other resources
// 1. determine images/resources base path
// 2. create and set new IViewSupplier that works with the base path
// 3. set some (prefix) paths that the system can ignore when converting relative paths

var remoteFile = new Uri(RemoteFile);
var basePathRemoteFile = string.Format("{0}{1}"
, remoteFile.GetLeftPart(UriPartial.Authority)
, string.Join(string.Empty,
remoteFile.Segments.Take(remoteFile.Segments.Length - 1)));

MarkdownView.ViewSupplier = new MauiViewSupplier
{
BasePathForRelativeUrlConversion = basePathRemoteFile,
PrefixesToIgnoreForRelativeUrlConversion = Array.Empty<string>()
};
}

protected override void OnAppearing()
{
base.OnAppearing();
RefreshView.IsRefreshing = true;
}

private async void OnRefreshing(object? sender, EventArgs e)
{
await LoadMarkdownFromRemote();
RefreshView.IsRefreshing = false;
}

private async Task LoadMarkdownFromRemote()
{
try
{
using var http = new HttpClient();
var markdown = await http.GetStringAsync(RemoteFile);

MarkdownView.MarkdownText = markdown;
}
catch (Exception e)

Check warning on line 55 in samples/Plugin.Maui.MarkdownView.Sample/Pages/MarkdownFromRemotePage.xaml.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

The variable 'e' is declared but never used

Check warning on line 55 in samples/Plugin.Maui.MarkdownView.Sample/Pages/MarkdownFromRemotePage.xaml.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

The variable 'e' is declared but never used

Check warning on line 55 in samples/Plugin.Maui.MarkdownView.Sample/Pages/MarkdownFromRemotePage.xaml.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

The variable 'e' is declared but never used

Check warning on line 55 in samples/Plugin.Maui.MarkdownView.Sample/Pages/MarkdownFromRemotePage.xaml.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

The variable 'e' is declared but never used

Check warning on line 55 in samples/Plugin.Maui.MarkdownView.Sample/Pages/MarkdownFromRemotePage.xaml.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

The variable 'e' is declared but never used

Check warning on line 55 in samples/Plugin.Maui.MarkdownView.Sample/Pages/MarkdownFromRemotePage.xaml.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

The variable 'e' is declared but never used

Check warning on line 55 in samples/Plugin.Maui.MarkdownView.Sample/Pages/MarkdownFromRemotePage.xaml.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

The variable 'e' is declared but never used

Check warning on line 55 in samples/Plugin.Maui.MarkdownView.Sample/Pages/MarkdownFromRemotePage.xaml.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

The variable 'e' is declared but never used

Check warning on line 55 in samples/Plugin.Maui.MarkdownView.Sample/Pages/MarkdownFromRemotePage.xaml.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

The variable 'e' is declared but never used

Check warning on line 55 in samples/Plugin.Maui.MarkdownView.Sample/Pages/MarkdownFromRemotePage.xaml.cs

View workflow job for this annotation

GitHub Actions / build-sample-ci

The variable 'e' is declared but never used
{
MarkdownView.MarkdownText = $"__error: wasn't able to retrieve '{RemoteFile}'__";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:markdownView="clr-namespace:Plugin.Maui.MarkdownView;assembly=Plugin.Maui.MarkdownView"
x:Class="Plugin.Maui.MarkdownView.Sample.MainPage">
x:Class="Plugin.Maui.MarkdownView.Sample.Pages.MarkdownInXamlPage"
Title="MarkdownInXamlPage">

<ScrollView>
<!-- xml:space > workaround to keep line-breaks and spacing during HotReload -->
<markdownView:MarkdownView x:Name="MarkdownView" xml:space="preserve">
An h1 header
============

Markdown in XAML!

Paragraphs are separated by a blank line.

2nd paragraph. *Italic*, **bold**, and `monospace`. Itemized lists
Expand Down Expand Up @@ -143,4 +146,4 @@ which you wish to be displayed literally, ex.: \`foo\`, \*bar\*, etc.
</markdownView:MarkdownView>
</ScrollView>

</ContentPage>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Plugin.Maui.MarkdownView.Sample.Pages;

public partial class MarkdownInXamlPage : ContentPage
{
public MarkdownInXamlPage()
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,16 @@
<ProjectReference Include="..\..\src\Plugin.Maui.MarkdownView\Plugin.Maui.MarkdownView.csproj" />
</ItemGroup>

<ItemGroup>
<MauiXaml Update="Pages\MarkdownFromFilePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\MarkdownFromRemotePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\MarkdownInXamlPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

</Project>
Loading

0 comments on commit 9bd4103

Please sign in to comment.