Skip to content

Commit

Permalink
feat: Add SafeArea
Browse files Browse the repository at this point in the history
  • Loading branch information
kazo0 committed Sep 6, 2022
1 parent 92daa6a commit f12a7e9
Show file tree
Hide file tree
Showing 52 changed files with 3,150 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Uno.Toolkit.Samples.Droid
[Activity(
MainLauncher = true,
ConfigurationChanges = global::Uno.UI.ActivityHelper.AllConfigChanges,
WindowSoftInputMode = SoftInput.AdjustPan | SoftInput.StateHidden
WindowSoftInputMode = SoftInput.AdjustPan | SoftInput.StateHidden
)]
public class MainActivity : Windows.UI.Xaml.ApplicationActivity
{
Expand All @@ -38,7 +38,7 @@ public class MainActivity : Windows.UI.Xaml.ApplicationActivity
[Export("GetScreenshot")]
public string GetScreenshot(string displayId)
{
var rootView = Windows.UI.Xaml.Window.Current.Content as View;
var rootView = this.ContentView;

var bitmap = Android.Graphics.Bitmap.CreateBitmap(rootView.Width, rootView.Height, Android.Graphics.Bitmap.Config.Argb8888);
var locationOfViewInWindow = new int[2];
Expand All @@ -64,7 +64,7 @@ public string GetScreenshot(string displayId)

// PixelCopy.Request returns the actual rendering of the screen location
// for the app, incliing OpenGL content.
PixelCopy.Request(Window, scope, bitmap, listener, new Android.OS.Handler(_pixelCopyHandlerThread.Looper));
PixelCopy.Request(Window, srcRect: null, bitmap, listener, new Android.OS.Handler(_pixelCopyHandlerThread.Looper));

listener.WaitOne();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Uno.Toolkit.Samples" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="29" />
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="31" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="Uno.Toolkit.Samples"></application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<item name="android:windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>


<!-- This makes the status bar translucent and allows content to be drawn behind --><!--
<item name="android:windowTranslucentStatus">true</item>-->
</style>
</resources>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<AndroidUseAapt2>true</AndroidUseAapt2>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v11.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v12.0</TargetFrameworkVersion>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseIntermediateDesignerFile>True</AndroidUseIntermediateDesignerFile>
<ResourcesDirectory>..\Uno.Toolkit.Samples.Shared\Strings</ResourcesDirectory>
Expand Down Expand Up @@ -76,15 +76,24 @@
<PackageReference Include="Uno.UniversalImageLoader" Version="1.9.35" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Xamarin.Android.Support.CustomTabs">
<Version>28.0.0.3</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.AppCompat.AppCompatResources">
<Version>1.2.0.5</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Browser">
<Version>1.4.0.2</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData">
<Version>2.3.1.1</Version>
</PackageReference>
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="4.5.0-dev.453" />
<PackageReference Include="Uno.Core.Extensions.Compatibility" Version="4.0.1" />
<PackageReference Include="Uno.Core.Extensions.Logging.Singleton" Version="4.0.1" />
<PackageReference Include="Xamarin.Jetbrains.Annotations">
<Version>23.0.0.4</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private Shell BuildShell()
AddNavigationItems(nv);

// landing navigation
ShellNavigateTo<ChipSamplePage>(
ShellNavigateTo<SafeAreaSamplePage>(
#if WINDOWS_UWP
// note: on uwp, NavigationView.SelectedItem MUST be set on launch to avoid entering compact-mode
trySynchronizeCurrentItem: true
Expand Down Expand Up @@ -182,7 +182,7 @@ void NavViewItemVisualStateFix(MUXC.NavigationViewItem nvi)
if (!nvi.IsSelected)
{
// depending on the DisplayMode, a NVIP may or may not be used.
var nvip = VisualTreeHelperEx.GetFirstDescendant<MUXCP.NavigationViewItemPresenter>(nvi, x => x.Name == "NavigationViewItemPresenter");
var nvip = VisualTreeAncestryHelper.GetFirstDescendant<MUXCP.NavigationViewItemPresenter>(nvi, x => x.Name == "NavigationViewItemPresenter");
VisualStateManager.GoToState((Control)nvip ?? nvi, "Normal", true);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Windows.Foundation.Collections;
using MUXC = Microsoft.UI.Xaml.Controls;
using Uno.Toolkit.Samples.Entities;
using static Uno.UI.FeatureConfiguration;

#if __IOS__
using Foundation;
Expand Down Expand Up @@ -69,6 +68,9 @@ public App()

#if HAS_UNO
FeatureConfiguration.Style.SetUWPDefaultStylesOverride<Frame>(false);
#endif
#if __ANDROID__ && USE_UITESTS
FeatureConfiguration.NativeFramePresenter.AndroidUnloadInactivePages = true;
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public NavigationBarSamplePage()
private void ModalFlyout_Opened(object sender, object e)
{
var flyoutContent = (sender as Flyout)?.Content;
var modalFrame = VisualTreeHelperEx.GetFirstDescendant<Frame>(flyoutContent, x => x.Name == "ModalFrame");
var modalFrame = VisualTreeAncestryHelper.GetFirstDescendant<Frame>(flyoutContent, x => x.Name == "ModalFrame");
modalFrame?.Navigate(typeof(MaterialNavigationBarSample_ModalPage1));
}

private void M3ModalFlyout_Opened(object sender, object e)
{
var flyoutContent = (sender as Flyout)?.Content;
var modalFrameM3 = VisualTreeHelperEx.GetFirstDescendant<Frame>(flyoutContent, x => x.Name == "M3ModalFrame");
var modalFrameM3 = VisualTreeAncestryHelper.GetFirstDescendant<Frame>(flyoutContent, x => x.Name == "M3ModalFrame");
modalFrameM3?.Navigate(typeof(M3MaterialNavigationBarSample_ModalPage1));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Page x:Class="Uno.Toolkit.Samples.Content.Controls.SafeAreaSamplePage"
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:Uno.Toolkit.Samples.Content.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sample="using:Uno.Toolkit.Samples"
xmlns:utu="using:Uno.Toolkit.UI"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<sample:SamplePageLayout IsDesignAgnostic="True">
<sample:SamplePageLayout.DesignAgnosticTemplate>
<DataTemplate>
<StackPanel Margin="0,20" Spacing="20">
<Button HorizontalAlignment="Center"
VerticalAlignment="Center"
AutomationProperties.AutomationId="SafeArea_Launch_AP_Sample_Button"
Click="LaunchAPSample"
Content="Show Sample using Attached Properties" />

<Button HorizontalAlignment="Center"
VerticalAlignment="Center"
AutomationProperties.AutomationId="SafeArea_Launch_Control_Sample_Button"
Click="LaunchControlSample"
Content="Show Sample using SafeArea Control" />

<Button HorizontalAlignment="Center"
VerticalAlignment="Center"
AutomationProperties.AutomationId="SafeArea_Launch_SoftInput_Sample_Button"
Click="LaunchSoftInputSample"
Content="Show SoftInput Sample" />

</StackPanel>
</DataTemplate>
</sample:SamplePageLayout.DesignAgnosticTemplate>
</sample:SamplePageLayout>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.Toolkit.Samples.Entities;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Uno.Toolkit.Samples.Content.NestedSamples;
using Uno.Toolkit.UI;
using Uno.Toolkit.Samples.Helpers;
#if IS_WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
#else
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
#endif

namespace Uno.Toolkit.Samples.Content.Controls
{
[SamplePage(SampleCategory.Controls, nameof(SafeArea))]
public sealed partial class SafeAreaSamplePage : Page
{
public SafeAreaSamplePage()
{
this.InitializeComponent();
}

private void LaunchAPSample(object sender, RoutedEventArgs e)
{
Shell.GetForCurrentView().ShowNestedSample<SafeAreaSamplePage_NestedPage>(clearStack: true);
}

private void LaunchControlSample(object sender, RoutedEventArgs e)
{
Shell.GetForCurrentView().ShowNestedSample<SafeArea_Control_NestedPage>(clearStack: true);
}

private void LaunchSoftInputSample(object sender, RoutedEventArgs e)
{
Shell.GetForCurrentView().ShowNestedSample<SafeArea_SoftInput_NestedPage>(clearStack: true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@
</utu:NavigationBar.SecondaryCommands>
</utu:NavigationBar>
<StackPanel Spacing="8"
BorderThickness="20"
BorderBrush="Red"
Background="Yellow"
Grid.Row="1"
VerticalAlignment="Center"
Padding="16,0">
VerticalAlignment="Stretch">
<Button Content="Exit sample"
Click="NavigateBack" />
<Button Click="NavigateToNextPage"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<Page x:Class="Uno.Toolkit.Samples.Content.NestedSamples.SafeAreaSamplePage_NestedPage"
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:Uno.Toolkit.Samples.Content.NestedSamples"
xmlns:um="using:Uno.Material"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:toolkit="using:Uno.UI.Toolkit"
xmlns:utu="using:Uno.Toolkit.UI"
Background="Green"
mc:Ignorable="d">
<Grid AutomationProperties.AutomationId="WrappingGrid">
<Border x:Name="MyBorder"
AutomationProperties.AutomationId="MyBorder"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="Red"
BorderBrush="Yellow"
BorderThickness="{Binding RelativeSource={RelativeSource Self}, Path=Padding}">
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center"
Spacing="10">
<Button AutomationProperties.AutomationId="ExitSampleButton"
Content="Exit Sample"
HorizontalAlignment="Center"
Click="ExitSample">
<um:ControlExtensions.Icon>
<SymbolIcon Symbol="Cancel"/>
</um:ControlExtensions.Icon>
</Button>
<muxc:RadioButtons HorizontalAlignment="Center"
Header="Inset Mode:">
<RadioButton x:Name="PaddingMode"
Checked="PaddingChecked"
Content="Padding"
IsChecked="True" />
<RadioButton x:Name="MarginMode"
Checked="MarginChecked"
Content="Margin" />
</muxc:RadioButtons>
<TextBlock HorizontalAlignment="Center"
Text="Inset Mask:" />
<StackPanel HorizontalAlignment="Center"
Orientation="Horizontal">
<CheckBox x:Name="LeftMask"
Checked="LeftChecked"
Content="Left"
Unchecked="LeftUnchecked" />
<CheckBox x:Name="TopMask"
Checked="TopChecked"
Content="Top"
Unchecked="TopUnchecked" />
<CheckBox x:Name="RightMask"
Checked="RightChecked"
Content="Right"
Unchecked="RightUnchecked" />
<CheckBox x:Name="BottomMask"
Checked="BottomChecked"
Content="Bottom"
Unchecked="BottomUnchecked" />
</StackPanel>
<Button AutomationProperties.AutomationId="ClearMasks"
HorizontalAlignment="Center"
Click="ClearAllMasks"
Content="Clear Masks" />
<Button AutomationProperties.AutomationId="SetAllTwenty"
HorizontalAlignment="Center"
Click="AllTwenty"
Content="All 20" />
<TextBlock HorizontalAlignment="Center"
Text="SafeArea Override:" />
<Border utu:SafeArea.Insets="SoftInput">
<StackPanel HorizontalAlignment="Center"
Orientation="Horizontal"
Spacing="10">
<TextBox x:Name="OverrideInsetLeft"
AutomationProperties.AutomationId="OverrideInsetLeft"
Header="Left"
TextChanged="UpdateInsets" />
<TextBox x:Name="OverrideInsetTop"
AutomationProperties.AutomationId="OverrideInsetTop"
Header="Top"
TextChanged="UpdateInsets" />
<TextBox x:Name="OverrideInsetRight"
AutomationProperties.AutomationId="OverrideInsetRight"
Header="Right"
TextChanged="UpdateInsets" />
<TextBox x:Name="OverrideInsetBottom"
AutomationProperties.AutomationId="OverrideInsetBottom"
Header="Bottom"
TextChanged="UpdateInsets" />
</StackPanel>
</Border>
</StackPanel>
</Border>
<!--<Border Background="Blue"
Grid.Row="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderThickness="30"
BorderBrush="Purple"/>-->
</Grid>
</Page>
Loading

0 comments on commit f12a7e9

Please sign in to comment.