Error when return to original code, after changes
marciordonez opened this issue · comments
Hello,
The hot reload stops when I change my code for the second time and save again, using IReloadable interface. I'm invoking a HttpClient API to load data using ListView.
Example:
Change label color and save 1st time (OK)
Change label color (again) and save 2nd time (Stop reloading)
Tested with iphone 11 pro ios 13.4 simulator.
Thanks
Does it work fine on a simple page? without IReloadable
Does it work fine on a simple page? without IReloadable
Yes, it works!
Maybe hot reload is being faster than API response
Probably yes.
Can you build a small sample and attach it to this issue?
.CS
[DesignTimeVisible(true)]
public partial class MainPage : ContentPage, IReloadable
{
private bool _isRefreshing = false;
public bool IsRefreshing
{
get { return _isRefreshing; }
set
{
_isRefreshing = value;
OnPropertyChanged(nameof(IsRefreshing));
}
}
public ICommand RefreshCommand
{
get
{
return new Command(async () =>
{
IsRefreshing = true;
await GetJsonDataAsync();
IsRefreshing = false;
});
}
}
public MainPage()
{
InitializeComponent();
}
public void OnLoaded()
{
BindingContext = this;
_ = GetJsonDataAsync();
}
private async Task GetJsonDataAsync()
{
// Check network status
if (NetworkCheck.IsInternet())
{
var endpoint = "https://webapicbc.azurewebsites.net/api/getmydata";
//Menu data
var client = new System.Net.Http.HttpClient();
var response = await client.GetAsync(endpoint);
string jsonString = await response.Content.ReadAsStringAsync(); //Getting response
ContactList ObjContactList = new ContactList();
try
{
ObjContactList = JsonConvert.DeserializeObject<ContactList>(jsonString);
listviewConacts.ItemsSource = ObjContactList.contacts;
}
catch
{
var msg = "No data to display.";
CreateAlertMessage(msg);
await DisplayAlert("CBC", msg, "OK");
}
}
else
{
await DisplayAlert("CBC", "Connect to internet.", "OK");
}
//Hide loader after server response
ProgressLoader.IsVisible = false;
}
XAML
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image Source="h61cbc.jpg" Aspect="AspectFill" />
<ListView IsPullToRefreshEnabled="True"
RefreshCommand="{Binding RefreshCommand}"
IsRefreshing="{Binding IsRefreshing}"
x:Name="listviewConacts"
Grid.Row="1"
HorizontalOptions="FillAndExpand"
Footer=""
HasUnevenRows="True"
ItemSelected="listviewContacts_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BackgroundColor="#eee" Orientation="Vertical" Padding="10">
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Icon}" FontFamily="{Binding FontType, Converter={StaticResource fontConvert}}" FontSize="28" WidthRequest="35" />
<Label Text="{Binding Name}"
VerticalTextAlignment="Center"
HorizontalOptions="FillAndExpand"
FontFamily="{StaticResource AmerikaSans}"
TextColor="#f35e20" />
<Label Text="{x:Static fontawesome:FontAwesomeIcons.CaretRight}" FontFamily="{StaticResource FontAwesomeSolid}" VerticalOptions="Center" VerticalTextAlignment="Center" FontSize="16" />
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
<ActivityIndicator x:Name="ProgressLoader" IsRunning="True"/>
</Grid>
Sorry, I cannot reproduce this issue. It works fine for me.
Build a sample project and attach it.
Hello, thanks for help.
Follow my poc project.
Sometimes it looks like the change is shown by Hot Reload, but something makes the contents of the listview disappear.