This commit is contained in:
Jason Smith 2018-03-05 13:47:35 -08:00
Родитель 84d75a721c 247a475498
Коммит 19e19e24d9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 6206609FF9813241
20 изменённых файлов: 715 добавлений и 5245 удалений

Просмотреть файл

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#ef4444" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="6dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#ef4444"
android:endColor="#992f2f"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="6dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>

Просмотреть файл

@ -27,6 +27,9 @@
<item name="windowActionModeOverlay">true</item> <item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item> <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
<!--Uncomment to test exceptionally red button-->
<!--<item name="android:buttonStyle">@style/red_button_style</item>-->
</style> </style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog"> <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
@ -35,4 +38,19 @@
<style name="TestStyle" parent="@android:style/Theme.Holo.Light.DarkActionBar"> <style name="TestStyle" parent="@android:style/Theme.Holo.Light.DarkActionBar">
</style> </style>
<style name="red_button_style" >
<item name="android:layout_width" >fill_parent</item>
<item name="android:layout_height" >wrap_content</item>
<item name="android:textColor" >#ffffff</item>
<item name="android:gravity" >center</item>
<item name="android:layout_margin" >3dp</item>
<item name="android:textSize" >30dp</item>
<item name="android:textStyle" >bold</item>
<item name="android:shadowColor" >#ffffff</item>
<item name="android:shadowDx" >1</item>
<item name="android:shadowDy" >4</item>
<item name="android:shadowRadius" >2</item>
<item name="android:background" >@drawable/red_button</item>
</style>
</resources> </resources>

Просмотреть файл

@ -200,6 +200,7 @@
<Compile Include="ColorPicker.cs" /> <Compile Include="ColorPicker.cs" />
<Compile Include="StringProvider.cs" /> <Compile Include="StringProvider.cs" />
<Compile Include="TestCloudService.cs" /> <Compile Include="TestCloudService.cs" />
<Compile Include="_1909CustomRenderer.cs" />
<Compile Include="_38989CustomRenderer.cs" /> <Compile Include="_38989CustomRenderer.cs" />
<Compile Include="BrokenImageSourceHandler.cs" /> <Compile Include="BrokenImageSourceHandler.cs" />
<Compile Include="_50787CustomRenderer.cs" /> <Compile Include="_50787CustomRenderer.cs" />
@ -335,6 +336,9 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
</AndroidResource> </AndroidResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\red_button.xml" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Import Project="..\packages\Xamarin.Insights.1.11.4\build\MonoAndroid10\Xamarin.Insights.targets" Condition="Exists('..\packages\Xamarin.Insights.1.11.4\build\MonoAndroid10\Xamarin.Insights.targets')" /> <Import Project="..\packages\Xamarin.Insights.1.11.4\build\MonoAndroid10\Xamarin.Insights.targets" Condition="Exists('..\packages\Xamarin.Insights.1.11.4\build\MonoAndroid10\Xamarin.Insights.targets')" />

Просмотреть файл

@ -0,0 +1,31 @@
using Android.Content;
using System;
using System.Linq;
using Xamarin.Forms;
using Xamarin.Forms.ControlGallery.Android;
using Xamarin.Forms.Platform.Android.AppCompat;
using Xamarin.Forms.Controls.Issues;
[assembly: ExportRenderer(typeof(Issue1909.FlatButton), typeof(FlatButtonRenderer))]
namespace Xamarin.Forms.ControlGallery.Android
{
public class FlatButtonRenderer : ButtonRenderer
{
public FlatButtonRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(Platform.Android.ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
if (this.Control != null && this.Element != null)
{
var nativeButton = (global::Android.Widget.Button)Control;
nativeButton.SetShadowLayer(0, 0, 0, global::Android.Graphics.Color.Transparent);
nativeButton.Elevation = 0;
}
}
}
}

Просмотреть файл

@ -0,0 +1,64 @@
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.Navigation)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 1355, "Setting Main Page in quick succession causes crash on Android",
PlatformAffected.Android)]
public class Issue1355 : TestContentPage
{
int _runCount = 0;
int _maxRunCount = 2;
const string Success = "Success";
protected override void Init()
{
Appearing += OnAppearing;
}
private void OnAppearing(object o, EventArgs eventArgs)
{
Application.Current.MainPage = CreatePage();
}
ContentPage CreatePage()
{
var page = new ContentPage
{
Content = new Label { Text = Success },
Title = $"CreatePage Iteration: {_runCount}"
};
page.Appearing += (sender, args) =>
{
_runCount += 1;
if (_runCount <= _maxRunCount)
{
Application.Current.MainPage = new NavigationPage(CreatePage());
}
};
return page;
}
#if UITEST
[Test]
public void SwitchMainPageOnAppearing()
{
// Without the fix, this would crash. If we're here at all, the test passed.
RunningApp.WaitForElement(Success);
}
#endif
}
}

Просмотреть файл

@ -0,0 +1,64 @@
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.Navigation)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 1355, "Setting Main Page in quick succession causes crash on Android",
PlatformAffected.Android)]
public class Issue1355 : TestContentPage
{
int _runCount = 0;
int _maxRunCount = 2;
const string Success = "Success";
protected override void Init()
{
Appearing += OnAppearing;
}
private void OnAppearing(object o, EventArgs eventArgs)
{
Application.Current.MainPage = CreatePage();
}
ContentPage CreatePage()
{
var page = new ContentPage
{
Content = new Label { Text = Success },
Title = $"CreatePage Iteration: {_runCount}"
};
page.Appearing += (sender, args) =>
{
_runCount += 1;
if (_runCount <= _maxRunCount)
{
Application.Current.MainPage = new NavigationPage(CreatePage());
}
};
return page;
}
#if UITEST
[Test]
public void SwitchMainPageOnAppearing()
{
// Without the fix, this would crash. If we're here at all, the test passed.
RunningApp.WaitForElement(Success);
}
#endif
}
}

Просмотреть файл

@ -1,6 +1,8 @@
using Xamarin.Forms.CustomAttributes; using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals; using Xamarin.Forms.Internals;
using System.Reflection; using System.Reflection;
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
#if UITEST #if UITEST
using Xamarin.Forms.Core.UITests; using Xamarin.Forms.Core.UITests;
@ -84,6 +86,14 @@ namespace Xamarin.Forms.Controls.Issues
}, },
}; };
foreach (var element in stackLayout.Descendants())
{
//TODO: if (element is Button button)
var button = element as Button;
if (button != null)
button.On<Android>().SetUseDefaultPadding(true).SetUseDefaultShadow(true);
}
Content = stackLayout; Content = stackLayout;
} }

Просмотреть файл

@ -0,0 +1,67 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 1909, "Xamarin.forms 2.5.0.280555 and android circle button issue", PlatformAffected.Android)]
public class Issue1909 : TestContentPage
{
public class FlatButton : Button { }
protected override void Init()
{
Button button = new Button
{
BackgroundColor = Color.Red,
CornerRadius = 32,
BorderWidth = 0,
FontSize = 36,
HeightRequest = 64,
HorizontalOptions = LayoutOptions.Center,
TextColor = Color.White,
VerticalOptions = LayoutOptions.Center,
WidthRequest = 64
};
button.On<Android>().SetUseDefaultPadding(true).SetUseDefaultShadow(true);
FlatButton flatButton = new FlatButton
{
BackgroundColor = Color.Red,
CornerRadius = 32,
BorderWidth = 0,
FontSize = 36,
HeightRequest = 64,
HorizontalOptions = LayoutOptions.Center,
TextColor = Color.White,
VerticalOptions = LayoutOptions.Center,
WidthRequest = 64
};
Content = new StackLayout
{
Children = {
new Label{ Text = "The following buttons should be perfectly round. The bottom button should be larger and should not have a shadow." },
button,
flatButton
}
};
}
#if UITEST
[Test]
[Category(UITestCategories.ManualReview)]
public void Issue1909Test()
{
RunningApp.Screenshot("I am at Issue 1909");
}
#endif
}
}

Просмотреть файл

@ -241,6 +241,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue1683.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1683.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1717.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1717.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla60001.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla60001.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1355.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla60056.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla60056.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla60122.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla60122.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla59863_0.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla59863_0.cs" />
@ -408,6 +409,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla59925.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla59925.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1326.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1326.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1436.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1436.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1909.cs" />
<Compile Include="$(MSBuildThisFileDirectory)_Template.cs" /> <Compile Include="$(MSBuildThisFileDirectory)_Template.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42620.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla42620.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" />

Просмотреть файл

@ -0,0 +1,7 @@
namespace Xamarin.Forms
{
public static class DesignMode
{
public static bool IsDesignModeEnabled { get; internal set; }
}
}

Просмотреть файл

@ -5,8 +5,17 @@ namespace Xamarin.Forms.Internals
{ {
public static class ResourceLoader public static class ResourceLoader
{ {
static Func<AssemblyName, string, string> resourceProvider;
//takes a resource path, returns string content //takes a resource path, returns string content
public static Func<AssemblyName, string, string> ResourceProvider { get; internal set; } public static Func<AssemblyName, string, string> ResourceProvider {
get => resourceProvider;
internal set {
DesignMode.IsDesignModeEnabled = true;
resourceProvider = value;
}
}
internal static Action<Exception> ExceptionHandler { get; set; } internal static Action<Exception> ExceptionHandler { get; set; }
} }
} }

Просмотреть файл

@ -0,0 +1,57 @@
namespace Xamarin.Forms.PlatformConfiguration.AndroidSpecific
{
using FormsElement = Forms.Button;
public static class Button
{
#region UseDefaultPadding
public static readonly BindableProperty UseDefaultPaddingProperty = BindableProperty.Create("UseDefaultPadding", typeof(bool), typeof(Button), false);
public static bool GetUseDefaultPadding(BindableObject element)
{
return (bool)element.GetValue(UseDefaultPaddingProperty);
}
public static void SetUseDefaultPadding(BindableObject element, bool value)
{
element.SetValue(UseDefaultPaddingProperty, value);
}
public static bool UseDefaultPadding(this IPlatformElementConfiguration<Android, FormsElement> config)
{
return GetUseDefaultPadding(config.Element);
}
public static IPlatformElementConfiguration<Android, FormsElement> SetUseDefaultPadding(this IPlatformElementConfiguration<Android, FormsElement> config, bool value)
{
SetUseDefaultPadding(config.Element, value);
return config;
}
#endregion
#region UseDefaultShadow
public static readonly BindableProperty UseDefaultShadowProperty = BindableProperty.Create("UseDefaultShadow", typeof(bool), typeof(Button), false);
public static bool GetUseDefaultShadow(BindableObject element)
{
return (bool)element.GetValue(UseDefaultShadowProperty);
}
public static void SetUseDefaultShadow(BindableObject element, bool value)
{
element.SetValue(UseDefaultShadowProperty, value);
}
public static bool UseDefaultShadow(this IPlatformElementConfiguration<Android, FormsElement> config)
{
return GetUseDefaultShadow(config.Element);
}
public static IPlatformElementConfiguration<Android, FormsElement> SetUseDefaultShadow(this IPlatformElementConfiguration<Android, FormsElement> config, bool value)
{
SetUseDefaultShadow(config.Element, value);
return config;
}
#endregion
}
}

Просмотреть файл

@ -45,6 +45,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
DrawerLayout _drawerLayout; DrawerLayout _drawerLayout;
MasterDetailPage _masterDetailPage; MasterDetailPage _masterDetailPage;
bool _toolbarVisible; bool _toolbarVisible;
bool _isAttachedToWindow;
// The following is based on https://android.googlesource.com/platform/frameworks/support.git/+/4a7e12af4ec095c3a53bb8481d8d92f63157c3b7/v4/java/android/support/v4/app/FragmentManager.java#677 // The following is based on https://android.googlesource.com/platform/frameworks/support.git/+/4a7e12af4ec095c3a53bb8481d8d92f63157c3b7/v4/java/android/support/v4/app/FragmentManager.java#677
// Must be overriden in a custom renderer to match durations in XML animation resource files // Must be overriden in a custom renderer to match durations in XML animation resource files
@ -218,15 +219,31 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
protected override void OnAttachedToWindow() protected override void OnAttachedToWindow()
{ {
base.OnAttachedToWindow(); base.OnAttachedToWindow();
PageController.SendAppearing(); PageController.SendAppearing();
// If the Appearing handler changed the application's main page for some reason,
// this page may no longer be part of the hierarchy; if so, we need to skip
// updating the toolbar and pushing the pages to avoid crashing the app
if (!IsAttachedToRoot())
{
return;
}
RegisterToolbar(); RegisterToolbar();
// If there is already stuff on the stack we need to push it
PushCurrentPages();
UpdateToolbar(); UpdateToolbar();
_isAttachedToWindow = true;
} }
protected override void OnDetachedFromWindow() protected override void OnDetachedFromWindow()
{ {
base.OnDetachedFromWindow(); base.OnDetachedFromWindow();
PageController.SendDisappearing(); PageController.SendDisappearing();
_isAttachedToWindow = false;
} }
protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e) protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
@ -277,10 +294,9 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
navController.InsertPageBeforeRequested += OnInsertPageBeforeRequested; navController.InsertPageBeforeRequested += OnInsertPageBeforeRequested;
navController.RemovePageRequested += OnRemovePageRequested; navController.RemovePageRequested += OnRemovePageRequested;
// If there is already stuff on the stack we need to push it if (_isAttachedToWindow && IsAttachedToRoot())
foreach (Page page in navController.Pages)
{ {
PushViewAsync(page, false); PushCurrentPages();
} }
} }
} }
@ -742,8 +758,6 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
Context.HideKeyboard(this); Context.HideKeyboard(this);
((Platform)Element.Platform).NavAnimationInProgress = false; ((Platform)Element.Platform).NavAnimationInProgress = false;
// TransitionDuration is how long the built-in animations are, and they are "reversible" in the sense that starting another one slightly before it's done is fine
return tcs.Task; return tcs.Task;
} }
@ -905,6 +919,28 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
}); });
} }
void PushCurrentPages()
{
var navController = (INavigationPageController)Element;
foreach (Page page in navController.Pages)
{
PushViewAsync(page, false);
}
}
bool IsAttachedToRoot()
{
var root = (Page)Element;
while (!Application.IsApplicationOrNull(root.RealParent))
{
root = (Page)root.RealParent;
}
return root.RealParent != null;
}
class ClickListener : Object, IOnClickListener class ClickListener : Object, IOnClickListener
{ {
readonly NavigationPage _element; readonly NavigationPage _element;

Просмотреть файл

@ -3,7 +3,10 @@ using System.ComponentModel;
using Android.Content.Res; using Android.Content.Res;
using Android.Graphics.Drawables; using Android.Graphics.Drawables;
using Android.OS; using Android.OS;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
using Specifics = Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
using AButton = Android.Widget.Button; using AButton = Android.Widget.Button;
using AColor = Android.Graphics.Color;
namespace Xamarin.Forms.Platform.Android namespace Xamarin.Forms.Platform.Android
{ {
@ -66,7 +69,21 @@ namespace Xamarin.Forms.Platform.Android
_backgroundDrawable = new ButtonDrawable(_nativeButton.Context.ToPixels, Forms.GetColorButtonNormal(_nativeButton.Context)); _backgroundDrawable = new ButtonDrawable(_nativeButton.Context.ToPixels, Forms.GetColorButtonNormal(_nativeButton.Context));
_backgroundDrawable.Button = _button; _backgroundDrawable.Button = _button;
_backgroundDrawable.SetPaddingTop(_nativeButton.PaddingTop);
var useDefaultPadding = _button.OnThisPlatform().UseDefaultPadding();
int paddingTop = useDefaultPadding ? _nativeButton.PaddingTop : 0;
int paddingLeft = useDefaultPadding ? _nativeButton.PaddingLeft : 0;
var useDefaultShadow = _button.OnThisPlatform().UseDefaultShadow();
float shadowRadius = useDefaultShadow ? 2 : _nativeButton.ShadowRadius;
float shadowDx = useDefaultShadow ? 0 : _nativeButton.ShadowDx;
float shadowDy = useDefaultShadow ? 4 : _nativeButton.ShadowDy;
AColor shadowColor = useDefaultShadow ? _backgroundDrawable.PressedBackgroundColor.ToAndroid() : _nativeButton.ShadowColor;
_backgroundDrawable.SetPadding(paddingTop, paddingLeft)
.SetShadow(shadowDy, shadowDx, shadowColor, shadowRadius);
if (_drawableEnabled) if (_drawableEnabled)
return; return;
@ -141,7 +158,9 @@ namespace Xamarin.Forms.Platform.Android
if (e.PropertyName.Equals(Button.BorderColorProperty.PropertyName) || if (e.PropertyName.Equals(Button.BorderColorProperty.PropertyName) ||
e.PropertyName.Equals(Button.BorderWidthProperty.PropertyName) || e.PropertyName.Equals(Button.BorderWidthProperty.PropertyName) ||
e.PropertyName.Equals(Button.CornerRadiusProperty.PropertyName) || e.PropertyName.Equals(Button.CornerRadiusProperty.PropertyName) ||
e.PropertyName.Equals(VisualElement.BackgroundColorProperty.PropertyName)) e.PropertyName.Equals(VisualElement.BackgroundColorProperty.PropertyName) ||
e.PropertyName.Equals(Specifics.Button.UseDefaultPaddingProperty.PropertyName) ||
e.PropertyName.Equals(Specifics.Button.UseDefaultShadowProperty.PropertyName))
{ {
Reset(); Reset();
UpdateDrawable(); UpdateDrawable();

Просмотреть файл

@ -2,28 +2,39 @@ using System;
using System.Linq; using System.Linq;
using Android.Graphics; using Android.Graphics;
using Android.Graphics.Drawables; using Android.Graphics.Drawables;
using AColor = Android.Graphics.Color;
namespace Xamarin.Forms.Platform.Android namespace Xamarin.Forms.Platform.Android
{ {
internal class ButtonDrawable : Drawable internal class ButtonDrawable : Drawable
{ {
public const int DefaultCornerRadius = 2; // Default value for Android material button. public const int DefaultCornerRadius = 2; // Default value for Android material button.
const int ShadowDy = 4;
readonly Func<double, float> _convertToPixels; readonly Func<double, float> _convertToPixels;
bool _isDisposed; bool _isDisposed;
Bitmap _normalBitmap; Bitmap _normalBitmap;
bool _pressed; bool _pressed;
Bitmap _pressedBitmap; Bitmap _pressedBitmap;
float _paddingLeft;
float _paddingTop; float _paddingTop;
Color _defaultColor; Color _defaultColor;
float PaddingLeft => _convertToPixels(8) / 2f; //<dimen name="button_padding_horizontal_material">8dp</dimen> AColor _shadowColor;
float PaddingTop //can change based on font, so this is not a constant float _shadowDx;
float _shadowDy;
float _shadowRadius;
float PaddingLeft
{ {
get { return (_paddingTop / 2f) + ShadowDy; } get { return (_paddingLeft / 2f); }
set { _paddingLeft = value; }
}
float PaddingTop
{
get { return (_paddingTop / 2f) + _shadowDy; }
set { _paddingTop = value; } set { _paddingTop = value; }
} }
public ButtonDrawable(Func<double, float> convertToPixels, Color defaultColor) public ButtonDrawable(Func<double, float> convertToPixels, Color defaultColor)
{ {
@ -64,9 +75,20 @@ namespace Xamarin.Forms.Platform.Android
canvas.DrawBitmap(bitmap, 0, 0, new Paint()); canvas.DrawBitmap(bitmap, 0, 0, new Paint());
} }
public void SetPaddingTop(float value) public ButtonDrawable SetShadow(float dy, float dx, AColor color, float radius)
{ {
_paddingTop = value; _shadowDx = dx;
_shadowDy = dy;
_shadowColor = color;
_shadowRadius = radius;
return this;
}
public ButtonDrawable SetPadding(float top, float left)
{
_paddingTop = top;
_paddingLeft = left;
return this;
} }
public void Reset() public void Reset()
@ -136,15 +158,12 @@ namespace Xamarin.Forms.Platform.Android
void DrawBackground(Canvas canvas, int width, int height, bool pressed) void DrawBackground(Canvas canvas, int width, int height, bool pressed)
{ {
const int shadowDx = 0;
const int shadowRadius = 2;
var paint = new Paint { AntiAlias = true }; var paint = new Paint { AntiAlias = true };
var path = new Path(); var path = new Path();
float borderRadius = ConvertCornerRadiusToPixels(); float borderRadius = ConvertCornerRadiusToPixels();
RectF rect = new RectF(0, 0, width, height - 0); RectF rect = new RectF(0, 0, width, height);
rect.Inset(PaddingLeft, PaddingTop); rect.Inset(PaddingLeft, PaddingTop);
@ -152,7 +171,8 @@ namespace Xamarin.Forms.Platform.Android
paint.Color = pressed ? PressedBackgroundColor.ToAndroid() : BackgroundColor.ToAndroid(); paint.Color = pressed ? PressedBackgroundColor.ToAndroid() : BackgroundColor.ToAndroid();
paint.SetStyle(Paint.Style.Fill); paint.SetStyle(Paint.Style.Fill);
paint.SetShadowLayer(shadowRadius, shadowDx, ShadowDy, PressedBackgroundColor.ToAndroid()); paint.SetShadowLayer(_shadowRadius, _shadowDx, _shadowDy, _shadowColor);
canvas.DrawPath(path, paint); canvas.DrawPath(path, paint);
} }

Просмотреть файл

@ -8,7 +8,7 @@ namespace Xamarin.Forms.Platform.UWP
{ {
public WindowsBasePage() public WindowsBasePage()
{ {
if (!DesignMode.DesignModeEnabled) if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
{ {
Windows.UI.Xaml.Application.Current.Suspending += OnApplicationSuspending; Windows.UI.Xaml.Application.Current.Suspending += OnApplicationSuspending;
Windows.UI.Xaml.Application.Current.Resuming += OnApplicationResuming; Windows.UI.Xaml.Application.Current.Resuming += OnApplicationResuming;

Просмотреть файл

@ -45,6 +45,7 @@ namespace Xamarin.Forms.Xaml.Internals
get { return xamlFileProvider; } get { return xamlFileProvider; }
internal set { internal set {
xamlFileProvider = value; xamlFileProvider = value;
Xamarin.Forms.DesignMode.IsDesignModeEnabled = true;
//¯\_(ツ)_/¯ the previewer forgot to set that bool //¯\_(ツ)_/¯ the previewer forgot to set that bool
DoNotThrowOnExceptions = value != null; DoNotThrowOnExceptions = value != null;
} }

Просмотреть файл

@ -0,0 +1,214 @@
<Type Name="Button" FullName="Xamarin.Forms.PlatformConfiguration.AndroidSpecific.Button">
<TypeSignature Language="C#" Value="public static class Button" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract sealed beforefieldinit Button extends System.Object" />
<AssemblyInfo>
<AssemblyName>Xamarin.Forms.Core</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
</Docs>
<Members>
<Member MemberName="GetUseDefaultPadding">
<MemberSignature Language="C#" Value="public static bool GetUseDefaultPadding (Xamarin.Forms.BindableObject element);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig bool GetUseDefaultPadding(class Xamarin.Forms.BindableObject element) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="element" Type="Xamarin.Forms.BindableObject" />
</Parameters>
<Docs>
<param name="element">To be added.</param>
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="GetUseDefaultShadow">
<MemberSignature Language="C#" Value="public static bool GetUseDefaultShadow (Xamarin.Forms.BindableObject element);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig bool GetUseDefaultShadow(class Xamarin.Forms.BindableObject element) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="element" Type="Xamarin.Forms.BindableObject" />
</Parameters>
<Docs>
<param name="element">To be added.</param>
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="SetUseDefaultPadding">
<MemberSignature Language="C#" Value="public static void SetUseDefaultPadding (Xamarin.Forms.BindableObject element, bool value);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void SetUseDefaultPadding(class Xamarin.Forms.BindableObject element, bool value) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="element" Type="Xamarin.Forms.BindableObject" />
<Parameter Name="value" Type="System.Boolean" />
</Parameters>
<Docs>
<param name="element">To be added.</param>
<param name="value">To be added.</param>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="SetUseDefaultPadding">
<MemberSignature Language="C#" Value="public static Xamarin.Forms.IPlatformElementConfiguration&lt;Xamarin.Forms.PlatformConfiguration.Android,Xamarin.Forms.Button&gt; SetUseDefaultPadding (this Xamarin.Forms.IPlatformElementConfiguration&lt;Xamarin.Forms.PlatformConfiguration.Android,Xamarin.Forms.Button&gt; config, bool value);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig class Xamarin.Forms.IPlatformElementConfiguration`2&lt;class Xamarin.Forms.PlatformConfiguration.Android, class Xamarin.Forms.Button&gt; SetUseDefaultPadding(class Xamarin.Forms.IPlatformElementConfiguration`2&lt;class Xamarin.Forms.PlatformConfiguration.Android, class Xamarin.Forms.Button&gt; config, bool value) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>Xamarin.Forms.IPlatformElementConfiguration&lt;Xamarin.Forms.PlatformConfiguration.Android,Xamarin.Forms.Button&gt;</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="config" Type="Xamarin.Forms.IPlatformElementConfiguration&lt;Xamarin.Forms.PlatformConfiguration.Android,Xamarin.Forms.Button&gt;" RefType="this" />
<Parameter Name="value" Type="System.Boolean" />
</Parameters>
<Docs>
<param name="config">To be added.</param>
<param name="value">To be added.</param>
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="SetUseDefaultShadow">
<MemberSignature Language="C#" Value="public static void SetUseDefaultShadow (Xamarin.Forms.BindableObject element, bool value);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void SetUseDefaultShadow(class Xamarin.Forms.BindableObject element, bool value) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="element" Type="Xamarin.Forms.BindableObject" />
<Parameter Name="value" Type="System.Boolean" />
</Parameters>
<Docs>
<param name="element">To be added.</param>
<param name="value">To be added.</param>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="SetUseDefaultShadow">
<MemberSignature Language="C#" Value="public static Xamarin.Forms.IPlatformElementConfiguration&lt;Xamarin.Forms.PlatformConfiguration.Android,Xamarin.Forms.Button&gt; SetUseDefaultShadow (this Xamarin.Forms.IPlatformElementConfiguration&lt;Xamarin.Forms.PlatformConfiguration.Android,Xamarin.Forms.Button&gt; config, bool value);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig class Xamarin.Forms.IPlatformElementConfiguration`2&lt;class Xamarin.Forms.PlatformConfiguration.Android, class Xamarin.Forms.Button&gt; SetUseDefaultShadow(class Xamarin.Forms.IPlatformElementConfiguration`2&lt;class Xamarin.Forms.PlatformConfiguration.Android, class Xamarin.Forms.Button&gt; config, bool value) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>Xamarin.Forms.IPlatformElementConfiguration&lt;Xamarin.Forms.PlatformConfiguration.Android,Xamarin.Forms.Button&gt;</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="config" Type="Xamarin.Forms.IPlatformElementConfiguration&lt;Xamarin.Forms.PlatformConfiguration.Android,Xamarin.Forms.Button&gt;" RefType="this" />
<Parameter Name="value" Type="System.Boolean" />
</Parameters>
<Docs>
<param name="config">To be added.</param>
<param name="value">To be added.</param>
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="UseDefaultPadding">
<MemberSignature Language="C#" Value="public static bool UseDefaultPadding (this Xamarin.Forms.IPlatformElementConfiguration&lt;Xamarin.Forms.PlatformConfiguration.Android,Xamarin.Forms.Button&gt; config);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig bool UseDefaultPadding(class Xamarin.Forms.IPlatformElementConfiguration`2&lt;class Xamarin.Forms.PlatformConfiguration.Android, class Xamarin.Forms.Button&gt; config) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="config" Type="Xamarin.Forms.IPlatformElementConfiguration&lt;Xamarin.Forms.PlatformConfiguration.Android,Xamarin.Forms.Button&gt;" RefType="this" />
</Parameters>
<Docs>
<param name="config">To be added.</param>
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="UseDefaultPaddingProperty">
<MemberSignature Language="C#" Value="public static readonly Xamarin.Forms.BindableProperty UseDefaultPaddingProperty;" />
<MemberSignature Language="ILAsm" Value=".field public static initonly class Xamarin.Forms.BindableProperty UseDefaultPaddingProperty" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>Xamarin.Forms.BindableProperty</ReturnType>
</ReturnValue>
<Docs>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="UseDefaultShadow">
<MemberSignature Language="C#" Value="public static bool UseDefaultShadow (this Xamarin.Forms.IPlatformElementConfiguration&lt;Xamarin.Forms.PlatformConfiguration.Android,Xamarin.Forms.Button&gt; config);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig bool UseDefaultShadow(class Xamarin.Forms.IPlatformElementConfiguration`2&lt;class Xamarin.Forms.PlatformConfiguration.Android, class Xamarin.Forms.Button&gt; config) cil managed" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="config" Type="Xamarin.Forms.IPlatformElementConfiguration&lt;Xamarin.Forms.PlatformConfiguration.Android,Xamarin.Forms.Button&gt;" RefType="this" />
</Parameters>
<Docs>
<param name="config">To be added.</param>
<summary>To be added.</summary>
<returns>To be added.</returns>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="UseDefaultShadowProperty">
<MemberSignature Language="C#" Value="public static readonly Xamarin.Forms.BindableProperty UseDefaultShadowProperty;" />
<MemberSignature Language="ILAsm" Value=".field public static initonly class Xamarin.Forms.BindableProperty UseDefaultShadowProperty" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>Xamarin.Forms.BindableProperty</ReturnType>
</ReturnValue>
<Docs>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
</Members>
</Type>

Просмотреть файл

@ -0,0 +1,34 @@
<Type Name="DesignMode" FullName="Xamarin.Forms.DesignMode">
<TypeSignature Language="C#" Value="public static class DesignMode" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi abstract sealed beforefieldinit DesignMode extends System.Object" />
<AssemblyInfo>
<AssemblyName>Xamarin.Forms.Core</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
</Docs>
<Members>
<Member MemberName="IsDesignModeEnabled">
<MemberSignature Language="C#" Value="public static bool IsDesignModeEnabled { get; }" />
<MemberSignature Language="ILAsm" Value=".property bool IsDesignModeEnabled" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>To be added.</summary>
<value>To be added.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
</Members>
</Type>

Разница между файлами не показана из-за своего большого размера Загрузить разницу