Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Article page HTML rendering #184

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions App/Models/Article.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using SQLite;
using SQLiteNetExtensions.Attributes;
using SQLiteNetExtensions.Extensions;
using System.Reflection;

namespace GamHubApp.Models;

Expand Down Expand Up @@ -141,4 +142,22 @@ public Command ShareArticle
}); ;
}
}

[Ignore]
public string HTMLContent
{
get
{

var assembly = Assembly.GetExecutingAssembly();
string style;
// Read the embedded resource
using (Stream stream = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.Resources.Styles.ArticleStyle.css"))
using (StreamReader reader = new (stream))
{
style = $"<style type=\"text/css\">{reader.ReadToEnd()}</style>";
}
return style+Content;
}
}
}
21 changes: 21 additions & 0 deletions App/Resources/Styles/ArticleStyle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@font-face {
font-family: TextFont;
src: url("file:///android_asset/Ubuntu-Medium.ttf")
}
img, [class^="image-"] {
width: 250px;
height: auto;
}

label {
font-family: TextFont;
font-size: medium;
text-align: justify;
}

a {
color: #4AC776;
}
* {
color: #ecebeb;
}
28 changes: 21 additions & 7 deletions App/Views/ArticlePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,27 @@
</Grid>
</Grid>
<!-- content -->
<Label Text="{Binding SelectedArticle.Content, Mode=OneWay}"
FontFamily="P-Regular"
TextColor="{StaticResource FontColor}"
Margin="10"
TextType="Html"
Grid.Row="3"
/>
<!-- NOTE: a bug prevent use from using WebView on iOS. see: https://github.com/dotnet/maui/issues/21604-->

<Label Text="{Binding SelectedArticle.Content, Mode=OneWay}"
FontFamily="P-Regular"
IsVisible="{OnPlatform Android='false',
iOS='true'}"
TextColor="{StaticResource FontColor}"
Margin="10"
TextType="Html"
Grid.Row="3"
/>
<WebView Grid.Row="3"
IsVisible="{OnPlatform Android='true',
iOS='false'}"
x:Name="contentView"
BackgroundColor="Transparent"
>
<WebView.Source>
<HtmlWebViewSource Html="{Binding SelectedArticle.HTMLContent, Mode=OneWay}"/>
</WebView.Source>
</WebView>

<!-- Button to open to the default Browser -->
<Button Text="Read more"
Expand Down
Loading