This is a migrated thread and some comments may be shown as answers.
Android - Vertical scrolling is very slow
2 Answers 18 Views
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 15 Aug 2017, 12:10 AM

Hello! 

While using a Custom Renderer on Android the vertical scroll of the month calendar seems to be VERY slow, don't know what is happening but seems to me that using a Custom CustomizationRule or a CustomAdapter the Month Calendar behaves more slower than normal.

I am using latest Xamarin.Forms (2.3.5.256 pre-6), Visual Studio for Mac and Latest Xamarin.Android version (updates from 08/14/2017).

I am only using this on the custom renderer to experience the slowlness:

 

protected override void OnElementChanged(ElementChangedEventArgs<RadCalendar> e)
{
    base.OnElementChanged(e);
    if (Element == null || e.OldElement != null) return;
 
    _element = (CalendarCustomRenderer)Element;
    _control = Control;
    _control.CustomizationRule = new CustomizationRule();
 
}
 
public class CustomizationRule : Java.Lang.Object, IProcedure
{
    Java.Util.Calendar calendar = Java.Util.Calendar.Instance;
 
    public void Apply(Java.Lang.Object p0)
    {
        Calendar.CalendarDayCell cell = p0.JavaCast<Calendar.CalendarDayCell>();
         
        var boldTypeface = Typeface.CreateFromAsset(Forms.Context.Assets, "Branding-Bold.otf");
        var mediumTypeface = Typeface.CreateFromAsset(Forms.Context.Assets, "Branding-Medium.otf");
        var semiBoldTypeface = Typeface.CreateFromAsset(Forms.Context.Assets, "Branding-SemiBold.otf");
 
        if (cell is CalendarTitleCell titleCell)
        {
            cell.TextColor = Colors.DarkBlueColor.ToAndroid();
            cell.Typeface = boldTypeface;
            cell.TextSize = TypedValue.ApplyDimension(ComplexUnitType.Sp, 16, Forms.Context.Resources.DisplayMetrics);
            cell.Text = cell.Text.ToUpper();
        }
 
        else if (cell is Calendar.CalendarDayCell dayCell)
        {
            cell.Typeface = mediumTypeface;
            cell.TextSize = TypedValue.ApplyDimension(ComplexUnitType.Sp, 15, Forms.Context.Resources.DisplayMetrics);
        }
        calendar.TimeInMillis = cell.Date;
    }
}

2 Answers, 1 is accepted

Sort by
0
Adam
Top achievements
Rank 1
answered on 15 Aug 2017, 12:15 AM
It is important to note that I am using Telerik.UI.for.Xamarin.Lite 2017.2.721.2
0
Accepted
Nikolay
Telerik team
answered on 17 Aug 2017, 12:21 PM
Hello Adam,

I've tried the code sample you provided and the calendar scroll is very slow indeed. The reason for this unexpected behavior is that the tree custom fonts - bold, medium and normal - are loaded the assets every time the Apply() method of the CustomizationRule class is called and that seems to be a slow operation.

 A simple performance improvement you can apply is to load all the fonts only once when the CustomizationRule is created and reuse them for each cell. Here is a code snippet of the modified CustomizationRule class:

public class CustomizationRule : Java.Lang.Object, IProcedure
{
    Java.Util.Calendar calendar = Java.Util.Calendar.Instance;
    var boldTypeface = Typeface.CreateFromAsset(Forms.Context.Assets, "Branding-Bold.otf");
    var mediumTypeface = Typeface.CreateFromAsset(Forms.Context.Assets, "Branding-Medium.otf");
    var semiBoldTypeface = Typeface.CreateFromAsset(Forms.Context.Assets, "Branding-SemiBold.otf");
  
    public void Apply(Java.Lang.Object p0)
    {
        Calendar.CalendarDayCell cell = p0.JavaCast<Calendar.CalendarDayCell>();
  
        if (cell is CalendarTitleCell titleCell)
        {
            cell.TextColor = Colors.DarkBlueColor.ToAndroid();
            cell.Typeface = boldTypeface;
            cell.TextSize = TypedValue.ApplyDimension(ComplexUnitType.Sp, 16, Forms.Context.Resources.DisplayMetrics);
            cell.Text = cell.Text.ToUpper();
        }
  
        else if (cell is Calendar.CalendarDayCell dayCell)
        {
            cell.Typeface = mediumTypeface;
            cell.TextSize = TypedValue.ApplyDimension(ComplexUnitType.Sp, 15, Forms.Context.Resources.DisplayMetrics);
        }
        calendar.TimeInMillis = cell.Date;
    }
}

I hope I've been helpful.

Regards,
Nikolay
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
Adam
Top achievements
Rank 1
Answers by
Adam
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or