Skip to content

Commit

Permalink
fix: Article page HTML rendering (#184)
Browse files Browse the repository at this point in the history
* Article detail - UI | Introduce a CSS file to set up the layout

* Article page | disable webview for content as it's way too buggy

* cleaup - article view | remove redandent stuff

* Style - article | add brighter colours for links
  • Loading branch information
bricefriha authored Jan 29, 2025
1 parent f3a1216 commit b9cd347
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
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

0 comments on commit b9cd347

Please sign in to comment.