Browse Source
Merge branch 'master' into jmacato/missing-skia-api-lottie
pull/5683/head
Jumar Macato
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with
72 additions and
21 deletions
-
build/ReactiveUI.props
-
src/Avalonia.Build.Tasks/DeterministicIdGenerator.cs
-
src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs
-
src/Avalonia.Controls/Slider.cs
-
src/Avalonia.ReactiveUI/AppBuilderExtensions.cs
-
src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlCompilerConfiguration.cs
-
src/Markup/Avalonia.Markup.Xaml/Templates/DataTemplate.cs
-
src/Markup/Avalonia.Markup.Xaml/Templates/ItemsPanelTemplate.cs
-
src/Markup/Avalonia.Markup.Xaml/Templates/Template.cs
-
src/Markup/Avalonia.Markup.Xaml/Templates/TemplateContent.cs
-
src/Markup/Avalonia.Markup.Xaml/Templates/TreeDataTemplate.cs
-
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/DataTemplateTests.cs
|
|
|
@ -1,5 +1,5 @@ |
|
|
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|
|
|
<ItemGroup> |
|
|
|
<PackageReference Include="ReactiveUI" Version="12.1.1" /> |
|
|
|
<PackageReference Include="ReactiveUI" Version="13.2.10" /> |
|
|
|
</ItemGroup> |
|
|
|
</Project> |
|
|
|
|
|
|
|
@ -0,0 +1,12 @@ |
|
|
|
using System; |
|
|
|
using XamlX.Transform; |
|
|
|
|
|
|
|
namespace Avalonia.Build.Tasks |
|
|
|
{ |
|
|
|
public class DeterministicIdGenerator : IXamlIdentifierGenerator |
|
|
|
{ |
|
|
|
private int _nextId = 1; |
|
|
|
|
|
|
|
public string GenerateIdentifierPart() => (_nextId++).ToString(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -22,7 +22,6 @@ using XamlX.IL; |
|
|
|
|
|
|
|
namespace Avalonia.Build.Tasks |
|
|
|
{ |
|
|
|
|
|
|
|
public static partial class XamlCompilerTaskExecutor |
|
|
|
{ |
|
|
|
static bool CheckXamlName(IResource r) => r.Name.ToLowerInvariant().EndsWith(".xaml") |
|
|
|
@ -99,7 +98,8 @@ namespace Avalonia.Build.Tasks |
|
|
|
XamlXmlnsMappings.Resolve(typeSystem, xamlLanguage), |
|
|
|
AvaloniaXamlIlLanguage.CustomValueConverter, |
|
|
|
new XamlIlClrPropertyInfoEmitter(typeSystem.CreateTypeBuilder(clrPropertiesDef)), |
|
|
|
new XamlIlPropertyInfoAccessorFactoryEmitter(typeSystem.CreateTypeBuilder(indexerAccessorClosure))); |
|
|
|
new XamlIlPropertyInfoAccessorFactoryEmitter(typeSystem.CreateTypeBuilder(indexerAccessorClosure)), |
|
|
|
new DeterministicIdGenerator()); |
|
|
|
|
|
|
|
|
|
|
|
var contextDef = new TypeDefinition("CompiledAvaloniaXaml", "XamlIlContext", |
|
|
|
|
|
|
|
@ -341,7 +341,9 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
var pointNum = orient ? x.Position.X : x.Position.Y; |
|
|
|
var logicalPos = MathUtilities.Clamp(pointNum / pointDen, 0.0d, 1.0d); |
|
|
|
var invert = orient ? 0 : 1; |
|
|
|
var invert = orient ? |
|
|
|
IsDirectionReversed ? 1 : 0 : |
|
|
|
IsDirectionReversed ? 0 : 1; |
|
|
|
var calcVal = Math.Abs(invert - logicalPos); |
|
|
|
var range = Maximum - Minimum; |
|
|
|
var finalValue = calcVal * range + Minimum; |
|
|
|
|
|
|
|
@ -9,18 +9,22 @@ namespace Avalonia.ReactiveUI |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Initializes ReactiveUI framework to use with Avalonia. Registers Avalonia
|
|
|
|
/// scheduler and Avalonia activation for view fetcher. Always remember to
|
|
|
|
/// call this method if you are using ReactiveUI in your application.
|
|
|
|
/// scheduler, an activation for view fetcher, a template binding hook. Remember
|
|
|
|
/// to call this method if you are using ReactiveUI in your application.
|
|
|
|
/// </summary>
|
|
|
|
public static TAppBuilder UseReactiveUI<TAppBuilder>(this TAppBuilder builder) |
|
|
|
where TAppBuilder : AppBuilderBase<TAppBuilder>, new() |
|
|
|
{ |
|
|
|
return builder.AfterPlatformServicesSetup(_ => |
|
|
|
where TAppBuilder : AppBuilderBase<TAppBuilder>, new() => |
|
|
|
builder.AfterPlatformServicesSetup(_ => Locator.RegisterResolverCallbackChanged(() => |
|
|
|
{ |
|
|
|
if (Locator.CurrentMutable is null) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
PlatformRegistrationManager.SetRegistrationNamespaces(RegistrationNamespace.Avalonia); |
|
|
|
RxApp.MainThreadScheduler = AvaloniaScheduler.Instance; |
|
|
|
Locator.CurrentMutable.RegisterConstant(new AvaloniaActivationForViewFetcher(), typeof(IActivationForViewFetcher)); |
|
|
|
Locator.CurrentMutable.RegisterConstant(new AutoDataTemplateBindingHook(), typeof(IPropertyBindingHook)); |
|
|
|
}); |
|
|
|
} |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -14,8 +14,9 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions |
|
|
|
XamlXmlnsMappings xmlnsMappings, |
|
|
|
XamlValueConverter customValueConverter, |
|
|
|
XamlIlClrPropertyInfoEmitter clrPropertyEmitter, |
|
|
|
XamlIlPropertyInfoAccessorFactoryEmitter accessorFactoryEmitter) |
|
|
|
: base(typeSystem, defaultAssembly, typeMappings, xmlnsMappings, customValueConverter) |
|
|
|
XamlIlPropertyInfoAccessorFactoryEmitter accessorFactoryEmitter, |
|
|
|
IXamlIdentifierGenerator identifierGenerator = null) |
|
|
|
: base(typeSystem, defaultAssembly, typeMappings, xmlnsMappings, customValueConverter, identifierGenerator) |
|
|
|
{ |
|
|
|
ClrPropertyEmitter = clrPropertyEmitter; |
|
|
|
AccessorFactoryEmitter = accessorFactoryEmitter; |
|
|
|
|
|
|
|
@ -30,7 +30,7 @@ namespace Avalonia.Markup.Xaml.Templates |
|
|
|
|
|
|
|
public IControl Build(object data, IControl existing) |
|
|
|
{ |
|
|
|
return existing ?? TemplateContent.Load(Content).Control; |
|
|
|
return existing ?? TemplateContent.Load(Content)?.Control; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -10,8 +10,7 @@ namespace Avalonia.Markup.Xaml.Templates |
|
|
|
[TemplateContent] |
|
|
|
public object Content { get; set; } |
|
|
|
|
|
|
|
public IPanel Build() |
|
|
|
=> (IPanel)TemplateContent.Load(Content).Control; |
|
|
|
public IPanel Build() => (IPanel)TemplateContent.Load(Content)?.Control; |
|
|
|
|
|
|
|
object ITemplate.Build() => Build(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -10,7 +10,7 @@ namespace Avalonia.Markup.Xaml.Templates |
|
|
|
[TemplateContent] |
|
|
|
public object Content { get; set; } |
|
|
|
|
|
|
|
public IControl Build() => TemplateContent.Load(Content).Control; |
|
|
|
public IControl Build() => TemplateContent.Load(Content)?.Control; |
|
|
|
|
|
|
|
object ITemplate.Build() => Build(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,6 +1,4 @@ |
|
|
|
using System; |
|
|
|
using Avalonia.Controls; |
|
|
|
using System.Collections.Generic; |
|
|
|
using Avalonia.Controls.Templates; |
|
|
|
|
|
|
|
namespace Avalonia.Markup.Xaml.Templates |
|
|
|
@ -14,6 +12,12 @@ namespace Avalonia.Markup.Xaml.Templates |
|
|
|
{ |
|
|
|
return (ControlTemplateResult)direct(null); |
|
|
|
} |
|
|
|
|
|
|
|
if (templateContent is null) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
throw new ArgumentException(nameof(templateContent)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -51,8 +51,12 @@ namespace Avalonia.Markup.Xaml.Templates |
|
|
|
|
|
|
|
public IControl Build(object data) |
|
|
|
{ |
|
|
|
var visualTreeForItem = TemplateContent.Load(Content).Control; |
|
|
|
visualTreeForItem.DataContext = data; |
|
|
|
var visualTreeForItem = TemplateContent.Load(Content)?.Control; |
|
|
|
if (visualTreeForItem != null) |
|
|
|
{ |
|
|
|
visualTreeForItem.DataContext = data; |
|
|
|
} |
|
|
|
|
|
|
|
return visualTreeForItem; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -7,6 +7,31 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml |
|
|
|
{ |
|
|
|
public class DataTemplateTests : XamlTestBase |
|
|
|
{ |
|
|
|
[Fact] |
|
|
|
public void DataTemplate_Can_Be_Empty() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var xaml = @"
|
|
|
|
<Window xmlns='https://github.com/avaloniaui'
|
|
|
|
xmlns:sys='clr-namespace:System;assembly=netstandard' |
|
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|
|
|
<Window.DataTemplates> |
|
|
|
<DataTemplate DataType='{x:Type sys:String}' /> |
|
|
|
</Window.DataTemplates> |
|
|
|
<ContentControl Name='target' Content='Foo'/> |
|
|
|
</Window>";
|
|
|
|
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); |
|
|
|
var target = window.FindControl<ContentControl>("target"); |
|
|
|
|
|
|
|
window.ApplyTemplate(); |
|
|
|
target.ApplyTemplate(); |
|
|
|
((ContentPresenter)target.Presenter).UpdateChild(); |
|
|
|
|
|
|
|
Assert.Null(target.Presenter.Child); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void DataTemplate_Can_Contain_Name() |
|
|
|
{ |
|
|
|
|