Skip to content

Instantly share code, notes, and snippets.

@marchbold
Created November 27, 2020 03:21
Show Gist options
  • Save marchbold/a19ced0825bd14e09e89b9d6e9334cf1 to your computer and use it in GitHub Desktop.
Save marchbold/a19ced0825bd14e09e89b9d6e9334cf1 to your computer and use it in GitHub Desktop.
Simple starling text input test case for the Application ANE keyboard show helper
// Init keyboard monitoring
Application.service.display.setDisplayMode( DisplayMode.NORMAL );
Application.service.keyboard.init();
FeathersControl.defaultTextEditorFactory = function():ITextEditor {
var editorMobile:StageTextTextEditor = new StageTextTextEditor();
editorMobile.fontSize = 50;
editorMobile.maintainTouchFocus = true;
return editorMobile;
};
var quad:Quad = new Quad(stage.stageWidth, stage.stageHeight, 0xffffff);
addChild(quad);
var textInput1:TextInput = new TextInput();
textInput1.verticalAlign = VerticalAlign.JUSTIFY;
textInput1.text = "Input 1";
textInput1.width = Starling.current.nativeStage.stageWidth;
textInput1.height = 100;
textInput1.y = 0;
textInput1.textEditorProperties.returnKeyLabel = "next";
addChild(textInput1);
textInput1.addEventListener( FeathersEventType.FOCUS_IN, function( e:Event ):void
{
trace( "focus in" );
// Show the keyboard here to ensure it is displayed for the text input
Application.service.keyboard.show();
});
textInput1.addEventListener( SoftKeyboardEvent.SOFT_KEYBOARD_ACTIVATING, function(e:Event):void
{
trace( "keyboard activating" );
});
textInput1.addEventListener( SoftKeyboardEvent.SOFT_KEYBOARD_ACTIVATE, function(e:Event):void
{
trace( "keyboard activate" );
// Alternatively can do it here which seems to be enough to ensure the keyboard is activated
// Application.service.keyboard.show();
});
textInput1.addEventListener( SoftKeyboardEvent.SOFT_KEYBOARD_DEACTIVATE, function(e:Event):void
{
trace( "keyboard deactivate" );
});
var button:Sprite = new Sprite();
button.addEventListener(TouchEvent.TOUCH, onButtonTouch);
button.addChild(new Quad(90, 90, 0xff0000));
button.y = 100;
addChild(button);
function onButtonTouch(event:TouchEvent):void {
if(event.getTouch(button, TouchPhase.ENDED)) {
textInput1.textEditorProperties.maintainTouchFocus = false;
textInput1.clearFocus();
textInput1.textEditorProperties.maintainTouchFocus = true;
}
}
var button1:Sprite = new Sprite();
button1.addChild(new Quad(90, 90, 0xffff00));
button1.y = 200;
addChild(button1);
button1.addEventListener(TouchEvent.TOUCH, function( event:TouchEvent ):void
{
if(event.getTouch(button1, TouchPhase.ENDED))
{
Application.service.keyboard.show();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment