Skip to content
New issue

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

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

Already on GitHub? # to your account

[templates] fix broken/wrong item template contents #7366

Merged
merged 1 commit into from
Sep 12, 2022

Conversation

jonathanpeppers
Copy link
Member

After working on #7349, I found some really odd behavior if you name an Android layout, my_cool_layout.xml.

VS appears to generate:

<?xml version="1.0" encoding="utf-8"?>
<Linearmy_cool_layout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:my_cool_layout_width="match_parent"
    android:my_cool_layout_height="match_parent">

</Linearmy_cool_layout>

This is completely broken! It appears that anywhere the word Layout was replaced with my_cool_layout. I also get the same behavior with dotnet new android-layout -n my_cool_layout.

To solve this issue, I made the default name Layout1, so that <LinearLayout/> and android:layout_width, are not replaced.

Now I get a my_cool_layout.xml with the contents:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</LinearLayout>

Secondly, the android-activity template if you run:

dotnet new android-activity -n MyActivity

It will generate:

[Activity(Label = "@string/app_name", MainLauncher = true)]
public class MyActivity : Activity

Let's replace the label with the name passed in, and remove MainLauncher=true, so we instead get:

[Activity(Label = "MyActivity")]
public class MyActivity : Activity

I think this will prevent confusion with multiple app launchers, etc.

After working on dotnet#7349, I found some really odd behavior if you name
an Android layout, `my_cool_layout.xml`.

VS appears to generate:

    <?xml version="1.0" encoding="utf-8"?>
    <Linearmy_cool_layout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:my_cool_layout_width="match_parent"
        android:my_cool_layout_height="match_parent">

    </Linearmy_cool_layout>

This is completely broken! It appears that anywhere the word `Layout`
was replaced with `my_cool_layout`. I also get the same behavior with
`dotnet new android-layout -n my_cool_layout`.

To solve this issue, I made the default name `Layout1`, so that
`<LinearLayout/>` and `android:layout_width`, are not replaced.

Now I get a `my_cool_layout.xml` with the contents:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </LinearLayout>

Secondly, the `android-activity` template if you run:

    dotnet new android-activity -n MyActivity

It will generate:

    [Activity(Label = "@string/app_name", MainLauncher = true)]
    public class MyActivity : Activity

Let's replace the label with the name passed in, and remove
`MainLauncher=true`, so we instead get:

    [Activity(Label = "MyActivity")]
    public class MyActivity : Activity

I think this will prevent confusion with multiple app launchers, etc.
@jonathanpeppers jonathanpeppers merged commit 93411cf into dotnet:main Sep 12, 2022
@jonathanpeppers jonathanpeppers deleted the fix-item-templates branch September 12, 2022 20:37
grendello added a commit to grendello/xamarin-android that referenced this pull request Sep 13, 2022
* main:
  [templates] fix broken/wrong item template contents (dotnet#7366)
  [tests] export $DOTNET_gcServer as 0 (dotnet#7363)
  [templates] add `ide.host.json` files (dotnet#7349)
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants