Skip to content

Commit

Permalink
Add support for UnoSkipUserControlsInVisualTree msbuild property
Browse files Browse the repository at this point in the history
This is a preliminary workaround for #61. This is not enabled by default is may be breaking. The default value will be changed in the future as part of a larger set of breaking changes.
  • Loading branch information
jeromelaban committed Jul 15, 2019
1 parent fa24987 commit f32e2cf
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/SamplesApp/SamplesApp.Droid/SamplesApp.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<ResourcesDirectory>..\SamplesApp.Shared\Strings</ResourcesDirectory>
<!-- AndroidUseAapt2 is disabled until https://github.com/xamarin/xamarin-android/pull/3327 is resolved -->
<AndroidUseAapt2>false</AndroidUseAapt2>

<!-- https://github.com/unoplatform/uno/issues/61 -->
<UnoSkipUserControlsInVisualTree>false</UnoSkipUserControlsInVisualTree>
</PropertyGroup>
<PropertyGroup>
<IsUiAutomationMappingEnabled>true</IsUiAutomationMappingEnabled>
Expand Down
3 changes: 3 additions & 0 deletions src/SamplesApp/SamplesApp.Wasm/SamplesApp.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<NoWarn>NU1701,CS1998</NoWarn>
<LangVersion>7.3</LangVersion>
<MonoRuntimeDebuggerEnabled Condition="'$(Configuration)'=='Debug'">true</MonoRuntimeDebuggerEnabled>

<!-- https://github.com/unoplatform/uno/issues/61 -->
<UnoSkipUserControlsInVisualTree>false</UnoSkipUserControlsInVisualTree>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
7 changes: 5 additions & 2 deletions src/SamplesApp/SamplesApp.iOS/SamplesApp.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<ResourcesDirectory>..\SamplesApp.Shared\Strings</ResourcesDirectory>
</PropertyGroup>

<!-- https://github.com/unoplatform/uno/issues/61 -->
<UnoSkipUserControlsInVisualTree>false</UnoSkipUserControlsInVisualTree>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
Expand Down Expand Up @@ -162,4 +165,4 @@
<Import Project="..\SamplesApp.UnitTests.Shared\SamplesApp.UnitTests.Shared.projitems" Label="Shared" />
<Import Project="..\UITests.Shared\UITests.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ internal partial class XamlCodeGeneration
private readonly bool _isUiAutomationMappingEnabled;
private Dictionary<string, string> _legacyTypes;

// Determines if the source generator will skip the inclusion of UseControls in the
// visual tree. See https://github.com/unoplatform/uno/issues/61
private bool _skipUserControlsInVisualTree = true;

#pragma warning disable 649 // Unused member
private readonly bool _forceGeneration;
#pragma warning restore 649 // Unused member
Expand Down Expand Up @@ -95,6 +99,11 @@ public XamlCodeGeneration(Compilation sourceCompilation, ProjectInstance msbProj
XamlRedirection.XamlConfig.IsUnoXaml = useUnoXamlParser || XamlRedirection.XamlConfig.IsMono;
}

if (bool.TryParse(msbProject.GetProperty("UnoSkipUserControlsInVisualTree")?.EvaluatedValue, out var skipUserControlsInVisualTree))
{
_skipUserControlsInVisualTree = skipUserControlsInVisualTree;
}

if (bool.TryParse(msbProject.GetProperty("ShouldWriteErrorOnInvalidXaml")?.EvaluatedValue, out var shouldWriteErrorOnInvalidXaml))
{
XamlFileGenerator.ShouldWriteErrorOnInvalidXaml = shouldWriteErrorOnInvalidXaml;
Expand Down Expand Up @@ -179,7 +188,8 @@ public KeyValuePair<string, string>[] Generate()
uiAutomationMappings: _uiAutomationMappings,
defaultLanguage: _defaultLanguage,
isWasm: _isWasm,
isDebug: _isDebug
isDebug: _isDebug,
skipUserControlsInVisualTree: _skipUserControlsInVisualTree
)
.GenerateFile()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ internal partial class XamlFileGenerator
private readonly bool _isDebug;
private readonly string _relativePath;

// Determines if the source generator will skip the inclusion of UseControls in the
// visual tree. See https://github.com/unoplatform/uno/issues/61
private readonly bool _skipUserControlsInVisualTree;

private readonly List<INamedTypeSymbol> _xamlAppliedTypes = new List<INamedTypeSymbol>();

private readonly INamedTypeSymbol _elementStubSymbol;
Expand Down Expand Up @@ -107,7 +111,8 @@ public XamlFileGenerator(
Dictionary<string, string[]> uiAutomationMappings,
string defaultLanguage,
bool isWasm,
bool isDebug
bool isDebug,
bool skipUserControlsInVisualTree
)
{
_fileDefinition = file;
Expand All @@ -124,6 +129,7 @@ bool isDebug
_uiAutomationMappings = uiAutomationMappings;
_defaultLanguage = defaultLanguage.HasValue() ? defaultLanguage : "en-US";
_isDebug = isDebug;
_skipUserControlsInVisualTree = skipUserControlsInVisualTree;

InitCaches();

Expand Down Expand Up @@ -2212,7 +2218,7 @@ void writeEvent(string ownerPrefix)
// creation of a WeakReference.
//
writer.AppendLineInvariant($"var {member.Member.Name}_{member.Value}_That = ({eventSource} as global::Uno.UI.DataBinding.IWeakReferenceProvider).WeakReference;");
writer.AppendLineInvariant($"{closureName}.{member.Member.Name} += ({parms}) => ({member.Member.Name}_{member.Value}_That.Target as {_className.className}).{member.Value}({parms});");
writer.AppendLineInvariant($"{closureName}.{member.Member.Name} += ({parms}) => ({member.Member.Name}_{member.Value}_That.Target as {_className.className})?.{member.Value}({parms});");
}
else
{
Expand Down Expand Up @@ -3409,7 +3415,10 @@ private void BuildChild(IIndentedStringBuilder writer, XamlMemberDefinition owne
{
BuildComplexPropertyValue(writer, owner, "c.");
}
else if (IsDirectUserControlSubType(xamlObjectDefinition) && HasNoUserControlProperties(xamlObjectDefinition))
else if (
_skipUserControlsInVisualTree
&& IsDirectUserControlSubType(xamlObjectDefinition)
&& HasNoUserControlProperties(xamlObjectDefinition))
{
writer.AppendLineInvariant("new {0}(skipsInitializeComponents: true).GetContent()", GetGlobalizedTypeName(fullTypeName));

Expand Down

0 comments on commit f32e2cf

Please sign in to comment.