forked from dotnet/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] Fragments & CodeBehind
While trying to repro Issue dotnet#1296, I had a brilliant idea: let's use the new CodeBehind support from 7c31899! Everything then fell apart. For starters, Issue dotnet#1296 deals with Fragments, and 7c31899 didn't support the presence of `<fragment/>` within Layout files. Plumb support for that, by adding: partial class MainActivity { partial void OnLayoutFragmentNotFound<T> (int resourceId, ref T type) where T : global::Android.App.Fragment; } Another issue was noticed as well: all the line numbers in the `#line` pragmas were always `1`. This was narrowed down to a bug in `GetLineInfo()`. Then there's an issue with where I was using the CodeBehind file: within the `src/Mono.Android/Test` project, which is in the `Xamarin.Android.RuntimeTests` namespace. This prompted all manner of namespace resolution failures: error CS0234: The type or namespace name 'App' does not exist in the namespace 'Xamarin.Android' (are you missing an assembly reference?) ... Fix this by using `CodeTypeReferenceOptions.GlobalReference` as much as is practical (which isn't enough), and by "kludging" up the `CodeNamespaceImport` construction so that we instead emit: using global::System; Finally, the generated codebehind had some weird nesting going on: partial class MainActivity { public __first_text_view_Views first_text_view {get;} public sealed partial class __first_text_view_Views { public __second_text_view_Views second_text_view {get;} public sealed partial class __second_text_view_Views { public sealed partial class __csharp_simple_fragment_Views { public sealed partial class __csharp_partial_assembly_Views { } } } } } It was bizarre *and* unusable: the `second_text_view` property -- corresponding to `<TextView android:id="@+id/second_text_view" />` -- was *nested within* a generated `MainActivity.__first_text_view_Views` type, and I'm not sure why that existed. Furthermore, it *can't* work, as the generated `MainActivity.__first_text_view_Views.__CreateClass___second_text_view_Views()` method depends on a constructor which doesn't exist: private @__second_text_view_Views @__CreateClass___second_text_view_Views() { // There *is* a __second_text_view_Views(Activity) constructor, // but not __second_text_view_Views(__first_text_view_Views). return new @__second_text_view_Views(this); } I "solved" (?) this by updating `LoadWidgets()` so that it always used `widgetRoot` for all recursive calls to `LoadWidgets()`, so that there is only ever one root. This removed all the nested types.
- Loading branch information
Showing
5 changed files
with
193 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
> | ||
<fragment | ||
android:name="Xamarin.Android.RuntimeTests.MyFragment" | ||
android:id="@+id/csharp_simple_fragment" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
/> | ||
<fragment | ||
android:name="xamarin.android.runtimetests.MyFragment" | ||
android:id="@+id/csharp_legacy_fragment" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
/> | ||
<fragment | ||
android:name="Xamarin.Android.RuntimeTests.MyFragment, Mono.Android-Tests" | ||
android:id="@+id/csharp_partial_assembly" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
/> | ||
<fragment | ||
android:name="Xamarin.Android.RuntimeTests.MyFragment, Mono.Android-Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" | ||
android:id="@+id/csharp_full_assembly" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
/> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters