Xamarin.Plugin.Calendar icon indicating copy to clipboard operation
Xamarin.Plugin.Calendar copied to clipboard

[Bug] Some properties do not behave as expected

Open kuririn2001 opened this issue 4 years ago • 3 comments

Hello. I'm using your Calendar control. Thank you very much. I have 2 concerns and will report them along with the code (please feel free to use the code). The platforms are iOS and Android. The source code and bugs are based on version 1.2.2936 of Calendar Plugin for Xamarin.

  • Setting AppThemeBinding to DaysTitleColor and switching between dark mode and light mode is not reflected. Reproduction Procedure: 0.Add the properties "TextColorLight" and "TextColorDark" to App.xaml in advance.

    1. Set the properties as follows: DaysTitleColor="{AppThemeBinding Light={StaticResource TextColorLight}, Dark={StaticResource TextColorDark}}" and run the program.
    2. Switch from light mode to dark mode. But, the colors will still be displayed in light mode. The reverse is also true.
    3. If you quit the application and start it again in dark mode, it will be displayed in dark mode colors this time. From the above, it seems that dynamically switching the color is not supported. Other than this, I have not tried any other color properties. Since themes are sometimes switched dynamically, it would be helpful if the color property could support dynamic switching.
  • Even if you set the SelectedDateTextFormat property (for example, "yyyy/MM/dd (ddd)"), the first time the date is displayed, it will be formatted as "d MMM yyyy", which is the default setting. This can be reproduced with the Simple and Advanced programs that are included as samples. Reproduce the following steps.

    1. In SampleApp/Views/SimplePage.xaml, add the SelectedDateTextFormat to the plugin:Calendar section as follows. <plugin:Calendar Padding="10,0" Events="{Binding Events}" HorizontalOptions="FillAndExpand" MaximumDate="{Binding MaximumDate}" MinimumDate="{Binding MinimumDate}" Month="{Binding Month}" SelectedDate="{Binding SelectedDate}" VerticalOptions="FillAndExpand" SelectedDateTextFormat="yyyy/MM/dd (ddd)" <- Add this

    2. Compile and display the calendar.

    3. The date format displayed below the calendar will be in "d MMM yyyy" format (e.g., 1 Jan 2021).

    4. Tap the appropriate date. Then, the date will be displayed in the format you set in SelectedDateTextFormat, and you will be able to see the date. Even if you tap other dates below, the date will be displayed in the format set by SelectedDateTextFormat.

    The modified code is as follows. (It's not a large amount, so I'll write it here.) CalendarPlugin/Shared/Controls/Calendar.xaml.cs From around line 354

     old source: public static readonly BindableProperty SelectedDateTextFormatProperty = BindableProperty.Create(nameof(SelectedDateTextFormat), typeof(string), typeof(Calendar), "d MMM yyyy");

      public string SelectedDateTextFormat
      {
          get => (string)GetValue(SelectedDateTextFormatProperty);
          set => SetValue(SelectedDateTextFormatProperty, value);
      }
    

     new source: public static readonly BindableProperty SelectedDateTextFormatProperty = BindableProperty.Create(nameof(SelectedDateTextFormat), typeof(string), typeof(Calendar), "d MMM yyyy", propertyChanged: (bindable, oldValue, newValue) => (bindable as Calendar).ChangeSelectedDateTextFormat((string)newValue, (string)oldValue));

      protected void ChangeSelectedDateTextFormat(string newValue, string oldValue)
      {
          if (newValue.Equals(oldValue)) return;
          SelectedDateText = SelectedDate.ToString(SelectedDateTextFormat, Culture);
      }
    
      public string SelectedDateTextFormat
      {
          get => (string)GetValue(SelectedDateTextFormatProperty);
          set => SetValue(SelectedDateTextFormatProperty, value);
      }
    

Thank you very much.

kuririn2001 avatar Jan 31 '21 05:01 kuririn2001

@kuririn2001 can you test this in latest nuget release?

antonioseric avatar Jul 11 '21 13:07 antonioseric

Hello.

I'm sorry I haven't been able to respond to your questions, I've been busy with work. Thank you for fixing the Calendar control. I tested the DaysTitleColor property. The version is 1.4.5304. This worked fine. In addition to this, I also tried using the DeselectedDayTextColor property, which is also OK.

Next, the SelectedDateTextFormat property. This also worked well. Thank you for the correction. As for the above, I think the problem is good to be closed.

However, it seems that the OtherMonthDayIsVisible property is not working in this version 1.4.5304. In the sample program AdvancedPage.xaml(ADVANCED EVENT CALENDAR), this property is set to False, but the dates of the previous and following months are displayed. It worked fine in the previous version 1.2.2936. It would be great if you could fix it.

Well, thank you very much.

kuririn2001 avatar Aug 13 '21 00:08 kuririn2001

I fixed this by updating the DayViewSize to 0 if it's not in this month as the following: https://github.com/lilcodelab/Xamarin.Plugin.Calendar/blob/2fc44d910aedb6affe42ff24e80a6a884712ab1a/src/Calendar.Plugin/Shared/Controls/MonthDaysView.cs#L624

            foreach (var dayView in _dayViews)
            {
                var currentDate = firstDate.AddDays(addDays++);
                var dayModel = dayView.BindingContext as DayModel;
                dayModel.Date = currentDate.Date;
                dayModel.DayTappedCommand = DayTappedCommand;
                dayModel.EventIndicatorType = EventIndicatorType;                
                dayModel.DayViewCornerRadius = DayViewCornerRadius;
                dayModel.DaysLabelStyle = DaysLabelStyle;
                dayModel.OtherMonthIsVisible = (CalendarLayout != WeekLayout.Month) || OtherMonthDayIsVisible;
                dayModel.IsThisMonth = (CalendarLayout != WeekLayout.Month) || currentDate.Month == ShownDate.Month;
                if(dayModel.OtherMonthIsVisible)
                {
                    dayModel.DayViewSize = DayViewSize;
                }
                else
                {
                    if (!dayModel.IsThisMonth)
                    {
                        dayModel.DayViewSize = 0;
                    }
                    else
                    {
                        dayModel.DayViewSize = DayViewSize;
                    }
                }
                dayModel.HasEvents = Events.ContainsKey(currentDate);
                dayModel.IsDisabled = currentDate < MinimumDate || currentDate > MaximumDate;

                ChangePropertySilently(nameof(dayModel.IsSelected), () => dayModel.IsSelected = CurrentSelectionEngine.IsDateSelected(dayModel.Date));
                AssignIndicatorColors(ref dayModel);
            }

ali-h2010 avatar Mar 15 '22 07:03 ali-h2010