yurkinh / Plugin.Maui.Calendar

.NET MAUI port of XF calendar plugin
MIT License
142 stars 13 forks source link

iOS Crash when you dismiss your app (nullref) #67

Closed edgiardina closed 1 month ago

edgiardina commented 5 months ago

I get Object reference not set to an instance of an object. when my app is dismissed on iOS using an upswipe when on a page that displays the calendar.

at Plugin.Maui.Calendar.Controls.MonthDaysView.UpdateDaysColors() at Plugin.Maui.Calendar.Controls.MonthDaysView.OnPropertyChanged(String propertyName) at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) at Microsoft.Maui.Controls.BindingExpression.ApplyCore(Object sourceObject, BindableObject target, BindableProperty property, Boolean fromTarget, SetterSpecificity specificity) at Microsoft.Maui.Controls.BindingExpression.Apply(Boolean fromTarget) at Microsoft.Maui.Controls.BindingExpression.BindingExpressionPart.b50_0() at Microsoft.Maui.Controls.DispatcherExtensions.DispatchIfRequired(IDispatcher dispatcher, Action action) at Microsoft.Maui.Controls.BindingExpression.BindingExpressionPart.PropertyChanged(Object sender, PropertyChangedEventArgs args) at Microsoft.Maui.Controls.BindingExpression.WeakPropertyChangedProxy.OnPropertyChanged(Object sender, PropertyChangedEventArgs e) at Microsoft.Maui.Controls.BindableObject.OnPropertyChanged(String propertyName) at Microsoft.Maui.Controls.Element.OnPropertyChanged(String propertyName) at Plugin.Maui.Calendar.Controls.Calendar.OnPropertyChanged(String propertyName) at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) at Microsoft.Maui.Controls.AppThemeBinding.<>c__DisplayClass11_0.gSet|0() at Microsoft.Maui.Controls.AppThemeBinding.ApplyCore(Boolean dispatch) at Microsoft.Maui.Controls.AppThemeBinding.Apply(Boolean fromTarget) at Microsoft.Maui.Controls.AppThemeBinding.AppThemeProxy.OnAppThemeChanged() at Microsoft.Maui.Controls.AppThemeBinding.AppThemeProxy.<>c.<.cctor>b__8_0(BindableObject bindable, Object oldValue, Object newValue) at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) at Microsoft.Maui.Controls.Element.OnResourceChanged(BindableProperty property, Object value, SetterSpecificity specificity) at Microsoft.Maui.Controls.Element.OnResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(Object sender, ResourcesChangedEventArgs e) at Microsoft.Maui.Controls.Element.OnResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.VisualElement.OnParentResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(Object sender, ResourcesChangedEventArgs e) at Microsoft.Maui.Controls.Element.OnResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.VisualElement.OnParentResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(Object sender, ResourcesChangedEventArgs e) at Microsoft.Maui.Controls.Element.OnResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.VisualElement.OnParentResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(Object sender, ResourcesChangedEventArgs e) at Microsoft.Maui.Controls.Element.OnResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(Object sender, ResourcesChangedEventArgs e) at Microsoft.Maui.Controls.Element.OnResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(Object sender, ResourcesChangedEventArgs e) at Microsoft.Maui.Controls.Element.OnResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(Object sender, ResourcesChangedEventArgs e) at Microsoft.Maui.Controls.Element.OnResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.VisualElement.OnParentResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(Object sender, ResourcesChangedEventArgs e) at Microsoft.Maui.Controls.Element.OnResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Element.OnParentResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Application.OnParentResourcesChanged(IEnumerable1 values) at Microsoft.Maui.Controls.Application.TriggerThemeChangedActual() at Microsoft.Maui.Controls.Application.set_PlatformAppTheme(AppTheme value) at Microsoft.Maui.Controls.Application.Microsoft.Maui.IApplication.ThemeChanged() at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.TraitCollectionDidChange(UITraitCollection previousTraitCollection) at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58 at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94 at Ifpa.Program.Main(String[] args) in C:\Users\ed_gi\source\repos\IfpaMaui\Platforms\iOS\Program.cs:line 13

yurkinh commented 5 months ago

Hi @edgiardina As a temporary workaround I would suggest downgrading to version 1.1.6 while I'm working on a solution for this issue. It's related to an events unsubscription that was changed.

yurkinh commented 5 months ago

Hi @edgiardina Check please version 1.1.9

edgiardina commented 5 months ago

Thanks! I no longer receive the exception. However I am seeing missing numbers in the calendar on iOS which I've seen for a bit now. image

yurkinh commented 4 months ago

Hi @edgiardina Check please new v 1.2.0 Could you please provide a repro sample?

edgiardina commented 4 months ago

The new version unfortunately does not fix the missing numbers bug.

https://github.com/edgiardina/IfpaMaui (see the calendarviewmodel)

My repo shows the use case, although my repo isn't straight up runnable without a few api keys.

The issue is very reproducible. View a page with the calendar, swipe up to select a different app, come back and the numbers have disappeared.

yurkinh commented 4 months ago

Hi @edgiardina I was not able to run this app because of missing key. Could you please extract it to some blank app with simple steps to reproduce it?

edgiardina commented 4 months ago

https://github.com/edgiardina/PluginMauiCalendar-67-repro

Here is the repro repo, along with a video of the behavior and way to trigger it. as you can see, the text is white on initial load but when you press home it goes black. which is invisible on my layout's background but I made it purple here https://github.com/yurkinh/Plugin.Maui.Calendar/assets/3627193/6c353c71-210d-4ad8-8c74-f95df7ddbb85

yurkinh commented 4 months ago

Hi @edgiardina This is happening because of this line 43: OnPropertyChanged(nameof(Events)); No need to manually trigger Events property changes. Take a look at AdavancedCalendar page in the sample app

edgiardina commented 4 months ago

When I remove the OnPropertyChanged in my actual project, then the calendar items never appear. If I comment out OnPropertyChanged(nameof(TournamentCalendarItems)); in the below code the items never appear on the calendar.

        public EventCollection TournamentCalendarItems { get; set; } = new EventCollection();

        ...
 public async Task ExecuteLoadItemsCommand(){
  var items = await pinballRankingApi.TournamentSearch(latitude, 
                                                       longitude, 
                                                       distance, DistanceType.Miles, 
                                                       startDate: DateTime.Now, 
                                                       endDate: DateTime.Now.AddYears(1), 
                                                       rankingSystem: rankingSystem, 
                                                       totalReturn: 500);

  logger.LogDebug("Api call completed at {0}", sw.ElapsedMilliseconds);

  if (items.Tournaments.Any())
  {
      Tournaments.AddRange(items.Tournaments.OrderBy(n => n.EventStartDate));

      //Limit calendar to 100 future items. otherwise this page chugs
      foreach (var detail in Tournaments)
      {
          LoadEventOntoCalendar(detail);
      }

      TournamentCalendarItems = new EventCollection();

      items.Tournaments
                    .Where(item => item.EventEndDate - item.EventStartDate <= 5.Days())
                    .Select(n => new TournamentWithDistance(n, (long)Location.CalculateDistance(latitude.Value, longitude.Value, n.Latitude, n.Longitude, DistanceUnits.Miles)))
                    .GroupBy(item => item.EventStartDate.Date)
                    .ToList()
                    .ForEach(date => TournamentCalendarItems.Add(date.Key, date.ToList()));

      OnPropertyChanged(nameof(TournamentCalendarItems));
      OnPropertyChanged(nameof(Pins));
      OnPropertyChanged(nameof(SelectedRankingSystem));
  }
  }
edgiardina commented 4 months ago

@yurkinh Have you tried this with ViewModel code that does NOT load in the constructor? Your sample loads all data in the Constructor. However, my ViewModel loads the data in OnAppearing, because its loaded async and you can't mark a constructor async. When I load my data OnAppearing, if I don't fire a OnPropertyChanged, the data never appears.