Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
Posts: 6
Registered: ‎10-23-2012
My Device: BB Dev Alpha
My Carrier: None

Implicit animation within ListView rows?

Beta3:

 

Does anyone know the best approach for animation within ListView rows?

I'm trying to do a simple implicit animation of opacity for a row, after it's been added, from 0.0 to 1.0.  I tried something in QML but it didn't work and this is as close as I could get in C++.  It changes the opacity to 1.0 but there is no animation of the opacity change.

----------
QML:
----------

ListView {
    id: test
    objectName: "test"

    // Add appearance definitions for the list items using the
    // listItemComponents list
    listItemComponents: [

        ListItemComponent {
            type: "test"
            Label {
                title: ListItemData.title
                opacity: 0.0
            }
        }
    ]
}

----------
C++:
----------

void View::addRow()
{
    if (root)
    {
        ListView * list = root->findChild<ListView*>("test");
 
        if (list)
        {
            ModelTest *model = (ModelTest *) list->dataModel();

            model->insertAtTop("test", "Hello");        

            const QObjectList children = list->children();

            for (int x = 0; x < children.size(); x++)
            {
                Control * child = qobject_cast<Control *>(children.at(x));
                if (child)
                  child->setOpacity(1.0);
            }

            if (!animationTimer)
            {
                animationTimer = new QTimer(this);
                connect(animationTimer, SIGNAL(timeout()), this, SLOT(timeoutAnimate()));
                animationTimer->start(200);
            }
            else
            {
                animationTimer->start(200);
            }
        }
    }
}   

void View::timeoutAnimation()
{
    if (root)
    {
        ListView * list = root->findChild<ListView*>("test");

        if (list)
        {
            const QObjectList children = list->children();

            for (int x = 0; x < children.size(); x++)
            {
                Control * child = qobject_cast<Control *>(children.at(x));
                if (child)
                    child->setOpacity(1.0);
            }

            animationTimer->stop();
        }
    }
}