1
votes

I needed TextView which would flash on text change - so I made CustomTextView like described in here. It works great but I have problem when I set that CustomTextView in list item. Because of ListView items are being reused my CustomTextView keeps flashing when scrolling up/down because it's context changes and now it 'points' to another list item.

Problem is I don't know how to determine when context of the item is changed, so I cannot put noFlash flag (Text property of the CustomTextView is not set to null, so I cannot use that either)

1
What triggers the animation? Setting the text property? That can be problematic as you found out because the text property can be set for many reasons: changing the text, populating an existing value not a change, and recycling the view. It sounds like only the first case should trigger the animation. I would expose animate as a method and let the caller, who knows more about the current context, determine when to animate.Kiliman
Animation is triggered by setting new property AnimationText. AnimationText is binded (over mvvmcross) to UI. AnimationText sets Text property of the control. All that is described in link I provided (it's just other kind of animation) but you got the point - I want to know what methods are used to set AnimatingText property during reusing list item, recycling the view ...ozapa
You could try implementing some kind of tracking of the reuse of the cell yourself in OnAttachedToWindow and OnDetachedFromWindow github.com/MvvmCross/MvvmCross/blob/3.5/Cirrious/… - or maybe in some custom Adapter codeStuart

1 Answers

0
votes

On the end I had to make custom adapter with some code in BindBindbleCode

 protected override void BindBindableView(object source, IMvxListItemView viewToUse)
 {
     var newValue = source as ListItemVM;
     var oldValue = viewToUse.DataContext as ListItemVM;

     if (newValue.ItemID != oldValue.ItemID)
         newValue.Rebinded = true;

     base.BindBindableView(source, viewToUse);
 }

then I added NotLoaded property on CustomTextView and binded those two together. So when Rebinded is true it sets NotLoaded to true signalizing that data in that TextView is not loaded. If data is not loaded there's no need to flash background of CustomTextView.

public string AnimatingText
{
    get { return Text; }
    set
    {
        if (Text == value)
            return;


        if (NotLoaded)
        {
            Text = value;
            NotLoaded = false;
            return;
        }

        Text = value;
        // Do your animation here
    }
}