dotnet / Comet

Comet is an MVU UIToolkit written in C#
MIT License
1.65k stars 117 forks source link

Comet.iOS.Sample HotReload not working properly #132

Open Miiite opened 5 years ago

Miiite commented 5 years ago

After cloning the repository and opening the Comet.Mac.sln file, I restored the nuget packages, built and deployed the Comet.iOS.Sample project to an iPhone 6s emulator.

When I make a change inside the RideTheCometSample.cs file, I get the following output in the console window:

Handling request Loaded assembly: eval-19 [External] Loaded assembly: eval-20 [External] Loaded assembly: eval-21 [External] Loaded assembly: eval-22 [External] Loaded assembly: eval-23 [External] Loaded assembly: eval-24 [External] Loaded assembly: eval-25 [External] Loaded assembly: eval-26 [External] using System; using System.Collections.Generic; using System.Text;

/*

import SwiftUI

struct ContentView: View { var body: some View { Text("Hello SwiftUI!") } }

*/

namespace Cometf10c544a92ec462e85f17c1482e6ad8b.Samples.Comparisons { public class RideSampleebb0b0c9a67f406eb13179ae85677a9c : View { public RideSampleebb0b0c9a67f406eb13179ae85677a9c() { //View.SetGlobalEnvironment(EnvironmentKeys.Colors.Color, Color.Black); comet = new Cometf10c544a92ec462e85f17c1482e6ad8b(); }

    [State]
    readonly Cometf10c544a92ec462e85f17c1482e6ad8b comet;

    [Body]
    View body()
        => new VStack {
            new Text(()=> $"({comet.Rides}) rides took: {comet.CometTrain}")
                .Frame(width:300)
                .LineBreakMode(LineBreakMode.CharacterWrap)
                ,

            new Button("   Ride the Comet!☄️   ", ()=>{
                comet.Rides++;
            })
                .Frame(height:44)
                .Padding(8)
                .Color(Color.White)
                .Background("#1d1d1d")
        };
}

public class Cometf10c544a92ec462e85f17c1482e6ad8b : BindingObject
{
    public int Rides
    {
        get => GetProperty<int>();
        set => SetProperty(value);
    }

    public string CometTrain
    {
        get
        {
            return "☄️".Repeat(Rides);
        }
    }
}

}

Loaded assembly: eval-27 [External] Loaded assembly: eval-28 [External] Loaded assembly: eval-29 [External] Loaded assembly: eval-30 [External] Loaded assembly: eval-31 [External] Loaded assembly: eval-32 [External] Loaded assembly: eval-33 [External] Loaded assembly: eval-34 [External] Loaded assembly: eval-35 [External] using System; using System.Collections.Generic; using System.Text;

/*

import SwiftUI

struct ContentView: View { var body: some View { Text("Hello SwiftUI!") } }

*/

namespace Comet3c16a29689534f5c8d949c46a90a539b.Samples.Comparisons { public class RideSample8e490877bd014ede9f2a56d8fc44f0c1 : View { public RideSample8e490877bd014ede9f2a56d8fc44f0c1() { //View.SetGlobalEnvironment(EnvironmentKeys.Colors.Color, Color.Black); comet = new Comet3c16a29689534f5c8d949c46a90a539b(); }

    [State]
    readonly Comet3c16a29689534f5c8d949c46a90a539b comet;

    [Body]
    View body()
        => new VStack {
            new Text(()=> $"({comet.Rides}) rides took: {comet.CometTrain}")
                .Frame(width:300)
                .LineBreakMode(LineBreakMode.CharacterWrap)
                ,

            new Button("   Ride the Comet!☄️   ", ()=>{
                comet.Rides++;
            })
                .Frame(height:44)
                .Padding(8)
                .Color(Color.White)
                .Background("#1d1d1d")
        };
}

public class Comet3c16a29689534f5c8d949c46a90a539b : BindingObject
{
    public int Rides
    {
        get => GetProperty<int>();
        set => SetProperty(value);
    }

    public string CometTrain
    {
        get
        {
            return "☄️".Repeat(Rides);
        }
    }
}

}

Evaluating: False - 0 The type or namespace name View' could not be found. Are you missingComet' using directive?

The only modification I've made is playing with the "rides taken" label.

Any idea what might be happening here ?

Miiite commented 5 years ago

Of course I found a workaround about 12 seconds after I posted this.

So to fix this I simply added a using Comet; directive inside the sample namespace.

So for anyone facing this, this simple modification seems to be enough:

`namespace Comet.Samples.Comparisons { using Comet;

public class RideSample : View
{
    public RideSample()
    {`
Clancey commented 5 years ago

Oh wow, this is an interesting one! I pushed a simple fix to fix that one sample that was broken, but I need to fix this in a different manner to prevent this from happening.

using System;
using System.Collections.Generic;
using System.Text;

/*

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello SwiftUI!")
    }
}

 */

namespace Comet.Samples.Comparisons
{
    public class RideSample : View
    {
        public RideSample()
        {
            //View.SetGlobalEnvironment(EnvironmentKeys.Colors.Color, Color.Black);
            comet = new Comet();
        }

        [State]
        readonly Comet comet;

        [Body]
        View body()
            => new VStack {
                new Text(()=> $"({comet.Rides}) rides taken: {comet.CometTrain}")
                    .Frame(width:300)
                    .LineBreakMode(LineBreakMode.CharacterWrap)
                    ,

                new Button("   Ride the Comet!☄️   ", ()=>{
                    comet.Rides++;
                })
                    .Frame(height:44)
                    .Padding(8)
                    .Color(Color.White)
                    .Background("#1d1d1d")
            };
    }

    public class Comet : BindingObject
    {
        public int Rides
        {
            get => GetProperty<int>();
            set => SetProperty(value);
        }

        public string CometTrain
        {
            get
            {
                return "☄️".Repeat(Rides);
            }
        }
    }
}

When this gets reloaded, since it has a class called comet, the Rename all references of Comet, also renames the namespace! Which breaks everything

I need to make sure when I generate a new class name, I only replace instances of classes not Namespaces

Clancey commented 5 years ago

Also, this will be fixed when I fix Debugging during HotReload