Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Build.Tasks] Fragments & CodeBehind #1302

Closed
wants to merge 1 commit into from

Commits on Feb 14, 2018

  1. [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.
    jonpryor committed Feb 14, 2018
    Configuration menu
    Copy the full SHA
    c2f3c99 View commit details
    Browse the repository at this point in the history