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 Developer
Watman
Posts: 15
Registered: ‎02-12-2013
My Device: Bold 9900 - Z10 LE - DAC - Playbook
Accepted Solution

Programmatic scroll a textarea

Hello,

 

I'm fairly new to Cascades development, but have some ideas I want to implement.

I'm struggling for some days trying to scroll a textarea semi-automatically.

I have a ScrollView with a textarea inside.

ScrollView {
            id: scrView
            property double scale: 0.5
            scrollViewProperties.pinchToZoomEnabled: true
            TextArea {
                id: promptText
                text: <text here>  
                editable: false
                textStyle.fontSize: FontSize.XXLarge
                textStyle.color: Color.White
                scrollMode: TextAreaScrollMode.Stiff
            }
            gestureHandlers: [
                PinchHandler {
                    onPinchUpdated: {
                        scrView.contentScale = (scale * event.pinchratio)
                    }
                }
            ]
        }

 

What I want to do is to be able to push a play button, which starts scrolling the textarea.

I've looked in the forums, but in vain.

At this time I'm trying something like this in my QML:

 

function startScrolling() {
       while (location < 1000) {
            location = location + 0.5
            scrView.scrollToPoint(0, location)
        }

}

 

The textarea scrolls, but not fluidly; it waits for like 5 seconds and then jumps to the fifth line.

Am I missing something?

 

Thx,

Johan

---------------------------------------------------------------------------------------------
Prompter: BlackBerry World - Built for BlackBerry™
Prompter4Q: BlackBerry World - Built for BlackBerry™
Please use plain text.
Developer
Curahee
Posts: 224
Registered: ‎01-12-2013
My Device: z30
My Carrier: Mobile Vikings

Re: Programmatic scroll a textarea

You have to do the animation in a seperate thread I guess. Or maybe take a look at the explicit animations?

 

https://developer.blackberry.com/cascades/documentation/ui/animations/explicit_animations.html

 

Maybe their is something you can use for the thing you want.

______________________________________________________
beRail: BlackBerry World - GitHub
Mobile Vikings: BlackBerry World - GitHub
Park in Brussels: BlackBerry World
Please use plain text.
New Developer
Watman
Posts: 15
Registered: ‎02-12-2013
My Device: Bold 9900 - Z10 LE - DAC - Playbook

Re: Programmatic scroll a textarea

Thx Curahee for the swift response/suggestion.

 

I will see if this gets me back on track

---------------------------------------------------------------------------------------------
Prompter: BlackBerry World - Built for BlackBerry™
Prompter4Q: BlackBerry World - Built for BlackBerry™
Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Programmatic scroll a textarea

Hi,

 

You're sending all the updates at once so they're processed instantly and only the last one is seen. The delay is due to the processing of all the accumulated messages.

 

Starting a thread is probably an overkill in this situation and I think the GUI must be updated from main thread anyway.

 

I'd use a timer. There is a snippet for starting a timer in QML (search for 'QTimer'):

https://developer.blackberry.com/cascades/documentation/dev/integrating_cpp_qml/index.html

 

On button press start a timer with small interval, for example 50 msec.

In onTimeout handler call scrollToPoint once or stop the timer if the scrolling is done.

Store the current position in a property.

 

Please note that scrollToPoint scrolls smoothly to the destination by default, so if you're updating the position in small steps manually you'll have to disable smooth scrolling by passing a third parameter:

 

scrView.scrollToPoint(0, location, ScrollAnimation.None)

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
New Developer
Watman
Posts: 15
Registered: ‎02-12-2013
My Device: Bold 9900 - Z10 LE - DAC - Playbook

Re: Programmatic scroll a textarea

Thx for the suggestion.

 

I've been looking at the QTimer option, following directions from this tutorial:

http://developer.blackberry.com/cascades/documentation/dev/signals_slots/signals_slots_add_actions.h...

Everything compiles and builds, but my app is unresponsive the moment i include the CustomTimer or QTimer in my qml.

 

import bb.cascades 1.0
import bb.cascades.pickers 1.0
//import prompter.Timer 1.0
//import MyTimer 1.0
import CustomTimer 1.0

Page {

 

I've tried creating a CustomControl and registering the QTimer directly.

Without the import, everything builds, runs, but NO timer functionality.

With the import (without even creating a (Q)Timer element inside the Container element), it builds BUT on my Dev Alpha i keep on seeing the splashscreen of BlackBerry 10 after opening the app.

 

Any suggestions? How to debug this?

 

FYI: when importing the SignalsAndSlots sample in QNX and deploying it to my device, that app is running as it should...

---------------------------------------------------------------------------------------------
Prompter: BlackBerry World - Built for BlackBerry™
Prompter4Q: BlackBerry World - Built for BlackBerry™
Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Programmatic scroll a textarea

Could you post the code (QML & C++ functions where the timer is created and registered) so that we can try to spot the error?

Is there any errors in device logs when the app is started?

Is QML loaded successfully? You can check this by adding some logging or stepping through the code in debugger.

Andrey Fidrya, @zmeyc on twitter
Please use plain text.
New Developer
Watman
Posts: 15
Registered: ‎02-12-2013
My Device: Bold 9900 - Z10 LE - DAC - Playbook

Re: Programmatic scroll a textarea

Think I found the problem.

 

I have 3 classes:

 

app.cpp (containing some logic)

MyClass.cpp (Generated file for project)

main.cpp

 

What I did, was register the QTimer in MyClass.cpp, but app.cpp was the one that did all the GUI-glue ...

So adding qmlRegisterType<QTimer>("my.library", 1, 0, "QTimer"); as first line inside App::App resulted in a GUI.

Oh yeah ...And I also needed to add LIBS += -lbbsystem to my .pro file in order to be able to debug.


Next step ... implementing the timer logic :smileyhappy:

---------------------------------------------------------------------------------------------
Prompter: BlackBerry World - Built for BlackBerry™
Prompter4Q: BlackBerry World - Built for BlackBerry™
Please use plain text.
New Developer
Watman
Posts: 15
Registered: ‎02-12-2013
My Device: Bold 9900 - Z10 LE - DAC - Playbook

Re: Programmatic scroll a textarea

And we're scrolling!! :Punk:

 

 onTimeout: {
                location = location + 1
                scrView.scrollToPoint(0, location)
}

---------------------------------------------------------------------------------------------
Prompter: BlackBerry World - Built for BlackBerry™
Prompter4Q: BlackBerry World - Built for BlackBerry™
Please use plain text.