Skip to content

Commit

Permalink
streamline & improve InputPane handling in sheets
Browse files Browse the repository at this point in the history
  • Loading branch information
WamWooWam committed Jan 6, 2025
1 parent 11c46cc commit 6a85903
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
24 changes: 0 additions & 24 deletions UniSky/Controls/Compose/ComposeSheet.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ public bool Not(bool b, bool a)

private void OnShowing(IOverlayControl sender, OverlayShowingEventArgs e)
{
var inputPane = InputPane.GetForCurrentView();
inputPane.Showing += OnInputPaneShowing;
inputPane.Hiding += OnInputPaneHiding;

if (Window.Current.Content is FrameworkElement element)
{
element.AllowDrop = true;
Expand All @@ -76,10 +72,6 @@ private void OnShowing(IOverlayControl sender, OverlayShowingEventArgs e)

private void OnHidden(IOverlayControl sender, RoutedEventArgs args)
{
var inputPane = InputPane.GetForCurrentView();
inputPane.Showing -= OnInputPaneShowing;
inputPane.Hiding -= OnInputPaneHiding;

if (Window.Current.Content is FrameworkElement element)
{
element.AllowDrop = false;
Expand Down Expand Up @@ -119,22 +111,6 @@ private async void OnHiding(IOverlayControl sender, OverlayHidingEventArgs e)
}
}

private void OnInputPaneShowing(InputPane sender, InputPaneVisibilityEventArgs args)
{
if (ActualWidth > 620) return;

ContentGrid.Padding = new Thickness(0, 0, 0, args.OccludedRect.Height);
args.EnsuredFocusedElementInView = true;
}

private void OnInputPaneHiding(InputPane sender, InputPaneVisibilityEventArgs args)
{
if (ActualWidth > 620) return;

ContentGrid.Padding = new Thickness(0, 0, 0, args.OccludedRect.Height);
args.EnsuredFocusedElementInView = true;
}

private void HandleDrag(object sender, DragEventArgs e)
{
if (e.DataView.Contains(StandardDataFormats.Bitmap) ||
Expand Down
26 changes: 17 additions & 9 deletions UniSky/Controls/Sheet/SheetControl.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Windows.Input;
using System;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using UniSky.Controls.Overlay;
using UniSky.Services;
using Windows.Foundation;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand Down Expand Up @@ -131,16 +133,16 @@ protected override void OnApplyTemplate()
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);
}

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

private void OnSizeChanged(object sender, SizeChangedEventArgs e)
Expand All @@ -151,15 +153,21 @@ private void OnSizeChanged(object sender, SizeChangedEventArgs e)

private void OnInputPaneShowing(InputPane sender, InputPaneVisibilityEventArgs args)
{
var ButtonsGrid = (Grid)this.FindDescendantByName("ButtonsGrid");
ButtonsGrid.Margin = new Thickness(0, 0, 0, args.OccludedRect.Height);
var transform2 = this.TransformToVisual(Window.Current.Content);
var transformed2 = transform2.TransformBounds(new Rect(new Point(0, 0), this.RenderSize));
if (args.OccludedRect.Height == 0)
return;

var height = Math.Max(0, transformed2.Bottom - args.OccludedRect.Top);
this.Margin = new Thickness(0, 0, 0, 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);
this.Margin = new Thickness(0, 0, 0, 0);

args.EnsuredFocusedElementInView = true;
}

Expand Down

0 comments on commit 6a85903

Please sign in to comment.