Skip to content

Commit

Permalink
feat: create MessageControl (#408)
Browse files Browse the repository at this point in the history
References: #382
  • Loading branch information
al-kau authored Nov 4, 2024
1 parent cf7b4dd commit 05890bf
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 12 deletions.
17 changes: 5 additions & 12 deletions source/Eppie.App/Eppie.App.Shared/Views/MessagePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="using:Tuvi.App.Shared.Behaviors"
xmlns:controls="using:Tuvi.App.Shared.Controls"
xmlns:eppie_controls="using:Eppie.App.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:extensions="using:Tuvi.App.Shared.Extensions"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:local="using:Tuvi.App.Shared.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:not_win="http://uno.ui/not_win"
xmlns:viewmodels="using:Tuvi.App.ViewModels"
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d not_win">
mc:Ignorable="d">

<local:MessagePageBase.DataContext>
<viewmodels:MessagePageViewModel />
Expand Down Expand Up @@ -226,16 +226,9 @@
BorderBrush="#FFE0E0E0"
BorderThickness="1">

<!-- ToDo: WinAppSDK doesn't have WebView -->
<not_win:WebView extensions:WebViewExtension.StringSourceWithDisabledJavaScript="{x:Bind ViewModel.MessageInfo.MessageHtmlBody, Mode=OneWay}" Visibility="{x:Bind ViewModel.MessageInfo.HasHtmlBody, Mode=OneWay}" />

<ScrollViewer Padding="4" Visibility="{x:Bind ViewModel.MessageInfo.HasHtmlBody, Converter={StaticResource InverseBoolToVisibilityConverter}, Mode=OneWay}">

<TextBlock IsTextSelectionEnabled="True"
Style="{StaticResource MessageTextStyle}"
Text="{x:Bind ViewModel.MessageInfo.MessageTextBody, Mode=OneWay}" />

</ScrollViewer>
<eppie_controls:MessageControl HasHtmlBody="{x:Bind ViewModel.MessageInfo.HasHtmlBody, Mode=OneWay}"
HtmlBody="{x:Bind ViewModel.MessageInfo.MessageHtmlBody, Mode=OneWay}"
TextBody="{x:Bind ViewModel.MessageInfo.MessageTextBody, Mode=OneWay}"/>
</Grid>

<!-- Wrapped to Grid because Android doesn't have Visibility=Collapsed for ProgressRing -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#if WINDOWS_UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
#else
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
#endif

namespace Eppie.App.UI.Controls
{
public sealed partial class MessageControl : UserControl
{
public bool HasHtmlBody
{
get { return (bool)GetValue(HasHtmlBodyProperty); }
set { SetValue(HasHtmlBodyProperty, value); }
}

public static readonly DependencyProperty HasHtmlBodyProperty =
DependencyProperty.Register(nameof(HasHtmlBody), typeof(bool), typeof(MessageControl), new PropertyMetadata(false));

public string TextBody
{
get { return (string)GetValue(TextBodyProperty); }
set { SetValue(TextBodyProperty, value); }
}

public static readonly DependencyProperty TextBodyProperty =
DependencyProperty.Register(nameof(TextBody), typeof(string), typeof(MessageControl), new PropertyMetadata(null));

public string HtmlBody
{
get { return (string)GetValue(HtmlBodyProperty); }
set { SetValue(HtmlBodyProperty, value); }
}

public static readonly DependencyProperty HtmlBodyProperty =
DependencyProperty.Register(nameof(HtmlBody), typeof(string), typeof(MessageControl), new PropertyMetadata(null));

public MessageControl()
{
this.InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\MailBoxesListControl.xaml.cs">
<DependentUpon>MailBoxesListControl.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Controls\MessageControl.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\MessageListControl.xaml.cs">
<DependentUpon>MessageListControl.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<UserControl x:Class="Eppie.App.UI.Controls.MessageControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:extensions="using:Tuvi.App.Shared.Extensions"
xmlns:local="using:Eppie.App.UI.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">

<Grid>
<WebView extensions:WebViewExtension.StringSourceWithDisabledJavaScript="{x:Bind HtmlBody, Mode=OneWay}" Visibility="{x:Bind HasHtmlBody, Mode=OneWay}" />

<ScrollViewer Padding="4" Visibility="{x:Bind HasHtmlBody, Converter={StaticResource InverseBoolToVisibilityConverter}, Mode=OneWay}">

<TextBlock IsTextSelectionEnabled="True"
Style="{StaticResource MessageTextStyle}"
Text="{x:Bind TextBody, Mode=OneWay}" />

</ScrollViewer>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@
<Name>Eppie.App.ViewModels</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Page Include="Controls\MessageControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<Import Project="..\Eppie.App.UI.Shared\Eppie.App.UI.Shared.projitems" Label="Shared" />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<UserControl x:Class="Eppie.App.UI.Controls.MessageControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Eppie.App.UI.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">

<Grid>
<ScrollViewer Padding="4">

<TextBlock IsTextSelectionEnabled="True"
Style="{StaticResource MessageTextStyle}"
Text="{x:Bind TextBody, Mode=OneWay}" />

</ScrollViewer>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@
<ItemGroup Condition="'$(TargetFramework)' != 'net8.0-windows10.0.19041'">
<PackageReference Include="Uno.Microsoft.Xaml.Behaviors.WinUI.Managed" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controls\" />
</ItemGroup>

</Project>

0 comments on commit 05890bf

Please sign in to comment.