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

Adobe AIR Development

Reply
Developer
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

BB10TextFix.as - Fixes TextField Issues in 10.2

[ Edited ]

I've created a static class that implements several workarounds for Input TexfField's in 10.2:

 https://gist.github.com/esDotDev/9203598

 

1. Adds "space-hack" to make sure there is always at least one space. This avoids a device lockup on FOCUS_IN.

 

2. Set's textfield.visible = false, if the user initiates a drag-and-release on it. This prevents another device lockup on mouseDrag shown here.

        2.1 Optional: Display's a cached bitmapData copy of the textfield while it is hidden.

 

3. Adds fix for "long press" bug: If you hold your finger on an InputText  for 3 seconds, all text is selected, and device will lock up.

 

4. [Bonus] Tracks stage.mouseX and stage.mouseY to help you workaround mouse position bug.

 

 

USAGE

//Init 
BB10Fixes.init(stage);

 

//Add a textField to be 'fixed':

BB10Fixes.add(textField);

 

//Remove a textfield so it can be gc'd

BB10Fixes.remove(textField);

 

 

 

Highlighted
Contributor
Posts: 15
Registered: ‎08-05-2013
My Device: Simulator
My Carrier: Telekom

Re: BB10TextFix.as - Fixes TextField Issues in 10.2

[ Edited ]

Thanks for this, should there not be a onFocusOut check on the textfield as well? At least that's what I read in the forums.

 

Also you can make your life even easier by performing an automated check for textfields. This way, you only have to add a single line to your project in a blackberry context, and not add multiple checks scattered through your code:

 

package de.rgerlach.bberry
{
    import flash.display.Stage;
    import flash.events.Event;
    import flash.events.FocusEvent;
    import flash.text.TextField;
    
    /**
     * ...
     * @author Ruben Gerlach
     */
    public function blackberryTextfieldFix(stage:Stage):void
    {
        stage.addEventListener(Event.ADDED, onAdded);
        
    }    
}
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.events.Event;
import flash.events.FocusEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.utils.getQualifiedClassName;

function onAdded(e:Event):void
{
    checkForTextfields(e.target);
}

function checkForTextfields(target:Object):void
{    
    var tf:TextField = target as TextField;
    var container:DisplayObjectContainer = target as DisplayObjectContainer;
    
    if (tf && tf.type == TextFieldType.INPUT)
    {
        tf.addEventListener(Event.REMOVED_FROM_STAGE, onRemoved);
        tf.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
        tf.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
    }
    else if (container)
    {
        for (var i:uint = 0; i < container.numChildren; ++i)
            checkForTextfields(container.getChildAt(i));
    }
}

function onRemoved(e:Event):void
{
    var tf:TextField = TextField(e.currentTarget);
    
    tf.removeEventListener(Event.REMOVED_FROM_STAGE, onRemoved);
    tf.removeEventListener(FocusEvent.FOCUS_IN, onFocusIn);
    tf.removeEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
}

function onFocusOut(e:FocusEvent):void
{
    var tf:TextField = TextField(e.currentTarget);
    
    if (tf.text == "") tf.text = " ";
    else if (tf.text != " " && tf.text.charAt(0) == " ") tf.text = tf.text.substr(1);
}
    


function onFocusIn(e:FocusEvent):void
{
    var tf:TextField = TextField(e.currentTarget);
    if (tf.text == "") tf.text = " ";
}