Android - Vertical scrolling is very slow

3 posts, 1 answers
  1. Adam
    Adam avatar
    24 posts
    Member since:
    Aug 2017

    Posted 14 Aug Link to this post

    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. Adam
    Adam avatar
    24 posts
    Member since:
    Aug 2017

    Posted 14 Aug Link to this post

    It is important to note that I am using Telerik.UI.for.Xamarin.Lite 2017.2.721.2
  3. Answer
    Nikolay
    Admin
    Nikolay avatar
    17 posts

    Posted 17 Aug Link to this post

    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 from 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
Back to Top