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
Developer
Posts: 38
Registered: ‎01-13-2013
My Device: BlackBerry Z10, Q10
My Carrier: Claro (Brazil)

SegmentedControl does not seem to request focus when touched

Greetings, BlackBerriers!

 

I'm playing with some UI that must change its behavior based on focus change. One of the ontrols I ise is a SegmentedControl but I noticed that contrary to other controls it does not request focus when touched. The code below shows the workaround I'm using right now.

 

Is the current behavior of SegmentedControl intentional or a bug?

 

// Default empty project template
import bb.cascades 1.0

// creates one page with a label
Page {
    Container {
        id: container
        background: Color.White
        topPadding: 15.0
        leftPadding: 20.0
        rightPadding: 20.0
        bottomPadding: 15.0
        DropDown {
            id: criteriaDD
            title: "Sort by"
            horizontalAlignment: HorizontalAlignment.Fill
            focusAutoShow: FocusAutoShow.None
            Option {
                text: "Name"
                selected: true
            }
            Option {
                text: "Date"
            }
            Option {
                text: "Type"
            }
            Option {
                text: "Size"
            }
            onFocusedChanged: {
                if (! focused) {
                    container.background = Color.LightGray
                }
            }
        }
        DropDown {
            id: orderDD
            title: "Order"
            horizontalAlignment: HorizontalAlignment.Fill
            Option {
                text: "Ascending"
                selected: true
            }
            Option {
                text: "Descending"
            }
            onFocusedChanged: {
                if (! focused) {
                    container.background = Color.DarkGray
                }
            }
        }
        SegmentedControl {
            id: typeSegCtrl
            Option {
                text: "Apples"
                selected: true
            }
            Option {
                text: "Oranges"
            }
            Option {
                text: "Bananas"
            }
            onTouch: {
                if (! focused && event.propagationPhase == PropagationPhase.AtTarget) {
                    requestFocus()
                }
            }
            onFocusedChanged: {
                if (! focused) {
                    container.background = Color.White
                }
            }
        }
    }
}