From 96a9879fae8145cbaf67a6f5a0a12ba8496ec664 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Tue, 4 Feb 2025 08:07:53 -0500 Subject: [PATCH] fix(hr): Add dummy class at the end of the generated file Works around https://github.com/xamarin/xamarin-macios/issues/22102 --- .../XamlGenerator/XamlFileGenerator.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs index c639cb0aefb2..774afd521450 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs @@ -403,6 +403,26 @@ private SourceText InnerGenerateFile() BuildXBindTryGetDeclarations(writer); } } + + if (_isHotReloadEnabled && Generation.IOSViewSymbol.Value is not null) + { + // Workaround for HR behaving incorrectly on iOS + // https://github.com/xamarin/xamarin-macios/issues/22102 + + using (writer.BlockInvariant($"namespace __internal")) + { + writer.AppendLineIndented("/// Internal Use for iOS only."); + writer.AppendLineIndented("[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]"); + writer.AppendLineIndented("[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]"); + using (writer.BlockInvariant($"static partial class __{_xClassName.ClassName}_Dummy")) + { + using (writer.BlockInvariant("private static class Dummy_Bindings")) + { + writer.AppendLineIndented("private static object Owner { get; set; }"); + } + } + } + } } }