Skip to content

Commit

Permalink
Merge pull request #16 from UnicordDev/feature/windowed-sheets
Browse files Browse the repository at this point in the history
Windowed sheets!
  • Loading branch information
WamWooWam authored Dec 6, 2024
2 parents 4dc96ed + ee3d3bc commit 1bf2bf8
Showing 41 changed files with 1,048 additions and 205 deletions.
11 changes: 7 additions & 4 deletions UniSky/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -53,18 +53,21 @@ private void ConfigureServices()
collection.AddLogging(c => c.AddDebug()
.SetMinimumLevel(LogLevel.Trace));

collection.AddSingleton<IProtocolService, ProtocolService>();
collection.AddSingleton<ISettingsService, SettingsService>();
collection.AddSingleton<IThemeService, ThemeService>();
collection.AddSingleton<INavigationServiceLocator, NavigationServiceLocator>();
collection.AddSingleton<IProtocolService, ProtocolService>();
collection.AddSingleton<ISafeAreaService, SafeAreaService>();
collection.AddSingleton<ISheetService, SheetService>();
collection.AddScoped<ISafeAreaService, CoreWindowSafeAreaService>();
collection.AddScoped<ISheetService, SheetService>();

collection.AddTransient<LoginService>();
collection.AddTransient<SessionService>();

Ioc.Default.ConfigureServices(collection.BuildServiceProvider());
ServiceContainer.Default.ConfigureServices(collection.BuildServiceProvider());

Configurator.Formatters.Register("en", (locale) => new ShortTimespanFormatter("en"));
Configurator.Formatters.Register("en-GB", (locale) => new ShortTimespanFormatter("en"));
Configurator.Formatters.Register("en-US", (locale) => new ShortTimespanFormatter("en"));
}

protected override void OnActivated(IActivatedEventArgs args)
26 changes: 8 additions & 18 deletions UniSky/Controls/Compose/ComposeSheet.xaml
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:compose="using:UniSky.ViewModels.Compose"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="320"
mc:Ignorable="d" d:DesignHeight="350" d:DesignWidth="480"
Style="{StaticResource DefaultSheetControlStyle}"
DataContext="{x:Bind ViewModel, Mode=OneWay}"
PrimaryButtonCommand="{x:Bind ViewModel.PostCommand}"
@@ -96,7 +96,7 @@
Height="48"
Margin="0,0,8,0"
VerticalAlignment="Top"
ProfilePicture="{x:Bind ViewModel.ReplyTo.Author.AvatarUrl, Mode=OneWay}"/>
ProfilePicture="{Binding ReplyTo.Author.AvatarUrl, Mode=OneWay}"/>
<StackPanel Grid.Column="1"
Margin="0,0,0,8">
<TextBlock Foreground="{ThemeResource SystemControlForegroundBaseMediumLowBrush}"
@@ -123,21 +123,11 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Ellipse Width="48"
Height="48"
Margin="0,0,8,0"
VerticalAlignment="Top">
<Ellipse.Fill>
<ImageBrush>
<ImageBrush.ImageSource>
<BitmapImage UriSource="{Binding AvatarUrl}"
DecodePixelWidth="48"
DecodePixelHeight="48"
DecodePixelType="Logical"/>
</ImageBrush.ImageSource>
</ImageBrush>
</Ellipse.Fill>
</Ellipse>
<muxc:PersonPicture Width="48"
Height="48"
Margin="0,0,8,0"
VerticalAlignment="Top"
ProfilePicture="{Binding AvatarUrl, Mode=OneWay}"/>

<TextBox x:Name="PrimaryTextBox"
x:Uid="ComposePrimaryTextBox"
@@ -261,7 +251,7 @@
<controls:RadialProgressBar Grid.Column="1"
Margin="8,6"
Minimum="0"
Maximum="{x:Bind ViewModel.MaxCharacters}"
Maximum="{x:Bind ViewModel.MaxCharacters, FallbackValue=300}"
Value="{x:Bind ViewModel.Characters, Mode=OneWay}"
Width="32"
Height="32"/>
25 changes: 20 additions & 5 deletions UniSky/Controls/Compose/ComposeSheet.xaml.cs
Original file line number Diff line number Diff line change
@@ -4,14 +4,17 @@
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using CommunityToolkit.Mvvm.DependencyInjection;
using Ipfs;
using Microsoft.Extensions.DependencyInjection;
using UniSky.Controls.Sheet;
using UniSky.Services;
using UniSky.ViewModels.Compose;
using UniSky.ViewModels.Posts;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.Resources;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Foundation.Metadata;
using Windows.UI.Popups;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
@@ -50,6 +53,11 @@ public ComposeSheet()
this.strings = ResourceLoader.GetForCurrentView();
}

protected override void OnBottomInsetsChanged(double leftInset, double rightInset)
{
FooterContainer.Padding = new Thickness(leftInset, 0, rightInset, 2);
}

public bool Not(bool b, bool a)
=> !a && !b;

@@ -70,11 +78,11 @@ private void OnShowing(SheetControl sender, SheetShowingEventArgs e)

if (e.Parameter is PostViewModel replyTo)
{
this.ViewModel = ActivatorUtilities.CreateInstance<ComposeViewModel>(Ioc.Default, replyTo);
this.ViewModel = ActivatorUtilities.CreateInstance<ComposeViewModel>(ServiceContainer.Scoped, replyTo, Controller);
}
else
{
this.ViewModel = ActivatorUtilities.CreateInstance<ComposeViewModel>(Ioc.Default);
this.ViewModel = ActivatorUtilities.CreateInstance<ComposeViewModel>(ServiceContainer.Scoped, Controller);
}
}

@@ -104,10 +112,17 @@ private async void OnHiding(SheetControl sender, SheetHidingEventArgs e)
var deferral = e.GetDeferral();
try
{
if (ViewModel.IsDirty && await new ComposeDiscardDraftDialog().ShowAsync() != ContentDialogResult.Primary)
if (ViewModel.IsDirty)
{
e.Cancel = true;
return;
var discardDraftDialog = new ComposeDiscardDraftDialog();
if (Controller != null && ApiInformation.IsApiContractPresent(typeof(UniversalApiContract).FullName, 8))
discardDraftDialog.XamlRoot = Controller.Root.XamlRoot;

if (await discardDraftDialog.ShowAsync() != ContentDialogResult.Primary)
{
e.Cancel = true;
return;
}
}
}
finally
20 changes: 2 additions & 18 deletions UniSky/Controls/PreviewPaneAuroraControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.Toolkit.Uwp.UI.Helpers;
using Microsoft.Toolkit.Uwp.UI.Media.Geometry;
using Windows.UI;
using Windows.UI.Xaml;
@@ -16,23 +17,6 @@ namespace System.Windows.Shell.Aurora
/// </summary>
public partial class PreviewPaneAuroraControl : UserControl
{
//private record ColorSet(Color Aurora, Color Background);

//private ColorSet[] _colorSets = new[]
//{
// new ColorSet(Color.FromArgb(255, 0x85, 0x99, 0xB4), Color.FromArgb(255, 0x5A, 0x6B, 0x7D)), // Default
// new ColorSet(Color.FromArgb(255, 0x51, 0x90, 0xDA), Color.FromArgb(255, 0x24, 0x43, 0x8E)), // Documents
// new ColorSet(Color.FromArgb(255, 0xF2, 0xA4, 0x7B), Color.FromArgb(255, 0xD2, 0x64, 0x2A)), // Contacts
// new ColorSet(Color.FromArgb(255, 0xDA, 0x51, 0x51), Color.FromArgb(255, 0x74, 0x14, 0x14)), // Music
// new ColorSet(Color.FromArgb(255, 0x9E, 0xCA, 0x4E), Color.FromArgb(255, 0x6E, 0x97, 0x24)), // Games
// new ColorSet(Color.FromArgb(255, 0x6F, 0x49, 0x70), Color.FromArgb(255, 0x26, 0x08, 0x27)), // Photos
//};

//private static Random _random = new Random();
//private int _i = _random.Next(6);
//private Color _color = Color.FromArgb(255, 0x85, 0x99, 0xB4);
//private TimeSpan _duration = TimeSpan.FromSeconds(0.5);

public Color Color
{
get { return (Color)GetValue(ColorProperty); }
@@ -59,7 +43,7 @@ private static void OnColorChanged(DependencyObject d, DependencyPropertyChanged
var control = (PreviewPaneAuroraControl)d;

var hslColor = newValue.ToHsl();
if (control.ActualTheme == ElementTheme.Dark)
if (Application.Current.RequestedTheme == ApplicationTheme.Dark)
{
var hslBackground = hslColor with { L = hslColor.L * 0.7 };
var colorBackground = ColorHelper.FromHsl(hslBackground.H, hslBackground.S, hslBackground.L);
3 changes: 2 additions & 1 deletion UniSky/Controls/RichTextBlock/RichTextBlock.cs
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using UniSky.Pages;
using UniSky.Services;
@@ -139,7 +140,7 @@ private void Hyperlink_Click(Hyperlink sender, HyperlinkClickEventArgs args)
if (sender.GetValue(HyperlinkUrlProperty) is not Uri { Scheme: "unisky" } uri)
return;

var service = Ioc.Default.GetRequiredService<INavigationServiceLocator>()
var service = ServiceContainer.Scoped.GetRequiredService<INavigationServiceLocator>()
.GetNavigationService("Home");

var path = uri.PathAndQuery.Split('/', StringSplitOptions.RemoveEmptyEntries);
91 changes: 91 additions & 0 deletions UniSky/Controls/Sheet/SheetControl.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using System.Windows.Input;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Toolkit.Uwp.Deferred;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using UniSky.Services;
using Windows.ApplicationModel;
using Windows.Foundation;
using Windows.UI.ViewManagement;
using Windows.UI.WindowManagement;
using Windows.UI.WindowManagement.Preview;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
@@ -188,16 +193,63 @@ public bool IsSecondaryButtonEnabled
public static readonly DependencyProperty IsSecondaryButtonEnabledProperty =
DependencyProperty.Register("IsSecondaryButtonEnabled", typeof(bool), typeof(SheetControl), new PropertyMetadata(true));

public Size PreferredWindowSize
{
get { return (Size)GetValue(PreferredWindowSizeProperty); }
set { SetValue(PreferredWindowSizeProperty, value); }
}

// Using a DependencyProperty as the backing store for PreferredWindowSize. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PreferredWindowSizeProperty =
DependencyProperty.Register("PreferredWindowSize", typeof(Size), typeof(SheetControl), new PropertyMetadata(new Size(320, 400)));


public event TypedEventHandler<SheetControl, SheetShowingEventArgs> Showing;
public event TypedEventHandler<SheetControl, RoutedEventArgs> Shown;
public event TypedEventHandler<SheetControl, SheetHidingEventArgs> Hiding;
public event TypedEventHandler<SheetControl, RoutedEventArgs> Hidden;

public ISheetController Controller { get; private set; }

public SheetControl()
{
this.DefaultStyleKey = typeof(SheetControl);
}

internal void SetSheetController(ISheetController controller)
{
Controller = controller;
}

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

if (Controller != null && Controller.IsFullWindow)
{
VisualStateManager.GoToState(this, "FullWindow", false);
var titleBarDragArea = this.FindDescendantByName("TitleBarDragArea");
Controller.SafeAreaService.SafeAreaUpdated += OnSafeAreaUpdated;
Controller.SafeAreaService.SetTitleBar(titleBarDragArea);

var inputPane = InputPane.GetForCurrentView();
inputPane.Showing += OnInputPaneShowing;
inputPane.Hiding += OnInputPaneHiding;

this.SizeChanged += OnSizeChanged;
}
else
{
VisualStateManager.GoToState(this, "Standard", false);
}
}

private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
var rightButton = this.FindDescendantByName("PrimaryTitleBarButton");
this.OnBottomInsetsChanged(0, rightButton.ActualWidth + 16);
}

internal void InvokeShowing(object parameter)
{
Showing?.Invoke(this, new SheetShowingEventArgs(parameter));
@@ -220,7 +272,46 @@ internal void InvokeShown()

internal void InvokeHidden()
{
if (Controller.IsFullWindow)
{
Controller.SafeAreaService.SafeAreaUpdated += OnSafeAreaUpdated;
}

Hidden?.Invoke(this, new RoutedEventArgs());
}

private void OnInputPaneShowing(InputPane sender, InputPaneVisibilityEventArgs args)
{
var ButtonsGrid = (Grid)this.FindDescendantByName("ButtonsGrid");
ButtonsGrid.Margin = new Thickness(0, 0, 0, args.OccludedRect.Height);
args.EnsuredFocusedElementInView = true;
}

private void OnInputPaneHiding(InputPane sender, InputPaneVisibilityEventArgs args)
{
var ButtonsGrid = (Grid)this.FindDescendantByName("ButtonsGrid");
ButtonsGrid.Margin = new Thickness(0, 0, 0, args.OccludedRect.Height);
args.EnsuredFocusedElementInView = true;
}

private void OnSafeAreaUpdated(object sender, SafeAreaUpdatedEventArgs e)
{
var titleBarGrid = (Grid)this.FindDescendantByName("TitleBarGrid");

if (e.SafeArea.HasTitleBar)
{
titleBarGrid.Height = e.SafeArea.Bounds.Top;
titleBarGrid.Padding = new Thickness();
}
else
{
titleBarGrid.Height = 42;
titleBarGrid.Padding = new Thickness(0, e.SafeArea.Bounds.Top, 0, 4);
}

Margin = new Thickness(e.SafeArea.Bounds.Left, 0, e.SafeArea.Bounds.Right, e.SafeArea.Bounds.Bottom);
}

protected virtual void OnBottomInsetsChanged(double leftInset, double rightInset) { }
}
}
Loading

0 comments on commit 1bf2bf8

Please sign in to comment.