scaffold.libs_as.feathers.controls.ScrollScreen.as Maven / Gradle / Ivy
/*
Feathers
Copyright 2012-2015 Bowler Hat LLC. All Rights Reserved.
This program is free software. You can redistribute and/or modify it in
accordance with the terms of the accompanying license agreement.
*/
package feathers.controls
{
import feathers.skins.IStyleProvider;
import feathers.utils.display.getDisplayObjectDepthFromStage;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import starling.core.Starling;
import starling.events.Event;
/**
* Dispatched when the transition animation begins as the screen is shown
* by the screen navigator.
*
* The properties of the event object have the following values:
*
* Property Value
* bubbles
false
* currentTarget
The Object that defines the
* event listener that handles the event. For example, if you use
* myButton.addEventListener()
to register an event listener,
* myButton is the value of the currentTarget
.
* data
null
* target
The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* currentTarget
property to always access the Object
* listening for the event.
*
*
* @eventType feathers.events.FeathersEventType.TRANSITION_IN_START
*/
[Event(name="transitionInStart",type="starling.events.Event")]
/**
* Dispatched when the transition animation finishes as the screen is shown
* by the screen navigator.
*
* The properties of the event object have the following values:
*
* Property Value
* bubbles
false
* currentTarget
The Object that defines the
* event listener that handles the event. For example, if you use
* myButton.addEventListener()
to register an event listener,
* myButton is the value of the currentTarget
.
* data
null
* target
The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* currentTarget
property to always access the Object
* listening for the event.
*
*
* @eventType feathers.events.FeathersEventType.TRANSITION_IN_COMPLETE
*/
[Event(name="transitionInComplete",type="starling.events.Event")]
/**
* Dispatched when the transition animation begins as a different screen is
* shown by the screen navigator and this screen is hidden.
*
* The properties of the event object have the following values:
*
* Property Value
* bubbles
false
* currentTarget
The Object that defines the
* event listener that handles the event. For example, if you use
* myButton.addEventListener()
to register an event listener,
* myButton is the value of the currentTarget
.
* data
null
* target
The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* currentTarget
property to always access the Object
* listening for the event.
*
*
* @eventType feathers.events.FeathersEventType.TRANSITION_OUT_START
*/
[Event(name="transitionOutStart",type="starling.events.Event")]
/**
* Dispatched when the transition animation finishes as a different screen
* is shown by the screen navigator and this screen is hidden.
*
* The properties of the event object have the following values:
*
* Property Value
* bubbles
false
* currentTarget
The Object that defines the
* event listener that handles the event. For example, if you use
* myButton.addEventListener()
to register an event listener,
* myButton is the value of the currentTarget
.
* data
null
* target
The Object that dispatched the event;
* it is not always the Object listening for the event. Use the
* currentTarget
property to always access the Object
* listening for the event.
*
*
* @eventType feathers.events.FeathersEventType.TRANSITION_OUT_COMPLETE
*/
[Event(name="transitionOutComplete",type="starling.events.Event")]
/**
* A screen for use with ScreenNavigator
, based on
* ScrollContainer
in order to provide scrolling and layout.
*
* This component is generally not instantiated directly. Instead it is
* typically used as a super class for concrete implementations of screens.
* With that in mind, no code example is included here.
*
* The following example provides a basic framework for a new scroll screen:
*
*
* package
* {
* import feathers.controls.ScrollScreen;
*
* public class CustomScreen extends ScrollScreen
* {
* public function CustomScreen()
* {
* super();
* }
*
* override protected function initialize():void
* {
* //runs once when screen is first added to the stage
* //a good place to add children and customize the layout
*
* //don't forget to call this!
* super.initialize()
* }
* }
* }
*
* @see ../../../help/scroll-screen.html How to use the Feathers ScrollScreen component
* @see feathers.controls.StackScreenNavigator
* @see feathers.controls.ScreenNavigator
*/
public class ScrollScreen extends ScrollContainer implements IScreen
{
/**
* @private
* DEPRECATED: Replaced by feathers.controls.ScrollPolicy.AUTO
.
*
* DEPRECATION WARNING: This constant is deprecated
* starting with Feathers 3.0. It will be removed in a future version of
* Feathers according to the standard
* Feathers deprecation policy.
*/
public static const SCROLL_POLICY_AUTO:String = "auto";
/**
* @private
* DEPRECATED: Replaced by feathers.controls.ScrollPolicy.ON
.
*
* DEPRECATION WARNING: This constant is deprecated
* starting with Feathers 3.0. It will be removed in a future version of
* Feathers according to the standard
* Feathers deprecation policy.
*/
public static const SCROLL_POLICY_ON:String = "on";
/**
* @private
* DEPRECATED: Replaced by feathers.controls.ScrollPolicy.OFF
.
*
* DEPRECATION WARNING: This constant is deprecated
* starting with Feathers 3.0. It will be removed in a future version of
* Feathers according to the standard
* Feathers deprecation policy.
*/
public static const SCROLL_POLICY_OFF:String = "off";
/**
* @private
* DEPRECATED: Replaced by feathers.controls.ScrollBarDisplayMode.FLOAT
.
*
* DEPRECATION WARNING: This constant is deprecated
* starting with Feathers 3.0. It will be removed in a future version of
* Feathers according to the standard
* Feathers deprecation policy.
*/
public static const SCROLL_BAR_DISPLAY_MODE_FLOAT:String = "float";
/**
* @private
* DEPRECATED: Replaced by feathers.controls.ScrollBarDisplayMode.FIXED
.
*
* DEPRECATION WARNING: This constant is deprecated
* starting with Feathers 3.0. It will be removed in a future version of
* Feathers according to the standard
* Feathers deprecation policy.
*/
public static const SCROLL_BAR_DISPLAY_MODE_FIXED:String = "fixed";
/**
* @private
* DEPRECATED: Replaced by feathers.controls.ScrollBarDisplayMode.NONE
.
*
* DEPRECATION WARNING: This constant is deprecated
* starting with Feathers 3.0. It will be removed in a future version of
* Feathers according to the standard
* Feathers deprecation policy.
*/
public static const SCROLL_BAR_DISPLAY_MODE_NONE:String = "none";
/**
* @private
* DEPRECATED: Replaced by feathers.layout.RelativePosition.RIGHT
.
*
* DEPRECATION WARNING: This constant is deprecated
* starting with Feathers 3.0. It will be removed in a future version of
* Feathers according to the standard
* Feathers deprecation policy.
*/
public static const VERTICAL_SCROLL_BAR_POSITION_RIGHT:String = "right";
/**
* @private
* DEPRECATED: Replaced by feathers.layout.RelativePosition.LEFT
.
*
* DEPRECATION WARNING: This constant is deprecated
* starting with Feathers 3.0. It will be removed in a future version of
* Feathers according to the standard
* Feathers deprecation policy.
*/
public static const VERTICAL_SCROLL_BAR_POSITION_LEFT:String = "left";
/**
* @private
* DEPRECATED: Replaced by feathers.controls.ScrollInteractionMode.TOUCH
.
*
* DEPRECATION WARNING: This constant is deprecated
* starting with Feathers 3.0. It will be removed in a future version of
* Feathers according to the standard
* Feathers deprecation policy.
*/
public static const INTERACTION_MODE_TOUCH:String = "touch";
/**
* @private
* DEPRECATED: Replaced by feathers.controls.ScrollInteractionMode.MOUSE
.
*
* DEPRECATION WARNING: This constant is deprecated
* starting with Feathers 3.0. It will be removed in a future version of
* Feathers according to the standard
* Feathers deprecation policy.
*/
public static const INTERACTION_MODE_MOUSE:String = "mouse";
/**
* @private
* DEPRECATED: Replaced by feathers.controls.ScrollInteractionMode.TOUCH_AND_SCROLL_BARS
.
*
* DEPRECATION WARNING: This constant is deprecated
* starting with Feathers 3.0. It will be removed in a future version of
* Feathers according to the standard
* Feathers deprecation policy.
*/
public static const INTERACTION_MODE_TOUCH_AND_SCROLL_BARS:String = "touchAndScrollBars";
/**
* @private
* DEPRECATED: Replaced by feathers.controls.DecelerationRate.NORMAL
.
*
* DEPRECATION WARNING: This constant is deprecated
* starting with Feathers 3.0. It will be removed in a future version of
* Feathers according to the standard
* Feathers deprecation policy.
*/
public static const DECELERATION_RATE_NORMAL:Number = 0.998;
/**
* @private
* DEPRECATED: Replaced by feathers.controls.DecelerationRate.FAST
.
*
* DEPRECATION WARNING: This constant is deprecated
* starting with Feathers 3.0. It will be removed in a future version of
* Feathers according to the standard
* Feathers deprecation policy.
*/
public static const DECELERATION_RATE_FAST:Number = 0.99;
/**
* @copy feathers.controls.ScrollContainer#AUTO_SIZE_MODE_STAGE
*
* @see feathers.controls.ScrollContainer#autoSizeMode
*/
public static const AUTO_SIZE_MODE_STAGE:String = "stage";
/**
* @copy feathers.controls.ScrollContainer#AUTO_SIZE_MODE_CONTENT
*
* @see feathers.controls.ScrollContainer#autoSizeMode
*/
public static const AUTO_SIZE_MODE_CONTENT:String = "content";
/**
* The default IStyleProvider
for all ScrollScreen
* components.
*
* @default null
* @see feathers.core.FeathersControl#styleProvider
*/
public static var globalStyleProvider:IStyleProvider;
/**
* Constructor.
*/
public function ScrollScreen()
{
this.addEventListener(Event.ADDED_TO_STAGE, scrollScreen_addedToStageHandler);
super();
}
/**
* @private
*/
override protected function get defaultStyleProvider():IStyleProvider
{
return ScrollScreen.globalStyleProvider;
}
/**
* @private
*/
protected var _screenID:String;
/**
* @inheritDoc
*/
public function get screenID():String
{
return this._screenID;
}
/**
* @private
*/
public function set screenID(value:String):void
{
this._screenID = value;
}
/**
* @private
*/
protected var _owner:Object;
/**
* @inheritDoc
*/
public function get owner():Object
{
return this._owner;
}
/**
* @private
*/
public function set owner(value:Object):void
{
this._owner = value;
}
/**
* Optional callback for the back hardware key. Automatically handles
* keyboard events to cancel the default behavior.
*
* This function has the following signature:
*
* function():void
*
* In the following example, a function will dispatch Event.COMPLETE
* when the back button is pressed:
*
*
* this.backButtonHandler = onBackButton;
*
* private function onBackButton():void
* {
* this.dispatchEvent( Event.COMPLETE );
* };
*
* @default null
*/
protected var backButtonHandler:Function;
/**
* Optional callback for the menu hardware key. Automatically handles
* keyboard events to cancel the default behavior.
*
* This function has the following signature:
*
* function():void
*
* In the following example, a function will be called when the menu
* button is pressed:
*
*
* this.menuButtonHandler = onMenuButton;
*
* private function onMenuButton():void
* {
* //do something with the menu button
* };
*
* @default null
*/
protected var menuButtonHandler:Function;
/**
* Optional callback for the search hardware key. Automatically handles
* keyboard events to cancel the default behavior.
*
* This function has the following signature:
*
* function():void
*
* In the following example, a function will be called when the search
* button is pressed:
*
*
* this.searchButtonHandler = onSearchButton;
*
* private function onSearchButton():void
* {
* //do something with the search button
* };
*
* @default null
*/
protected var searchButtonHandler:Function;
/**
* @private
*/
protected function scrollScreen_addedToStageHandler(event:Event):void
{
this.addEventListener(Event.REMOVED_FROM_STAGE, scrollScreen_removedFromStageHandler);
//using priority here is a hack so that objects higher up in the
//display list have a chance to cancel the event first.
var priority:int = -getDisplayObjectDepthFromStage(this);
Starling.current.nativeStage.addEventListener(KeyboardEvent.KEY_DOWN, scrollScreen_nativeStage_keyDownHandler, false, priority, true);
}
/**
* @private
*/
protected function scrollScreen_removedFromStageHandler(event:Event):void
{
this.removeEventListener(Event.REMOVED_FROM_STAGE, scrollScreen_removedFromStageHandler);
Starling.current.nativeStage.removeEventListener(KeyboardEvent.KEY_DOWN, scrollScreen_nativeStage_keyDownHandler);
}
/**
* @private
*/
protected function scrollScreen_nativeStage_keyDownHandler(event:KeyboardEvent):void
{
if(event.isDefaultPrevented())
{
//someone else already handled this one
return;
}
if(this.backButtonHandler != null &&
event.keyCode == Keyboard.BACK)
{
event.preventDefault();
this.backButtonHandler();
}
if(this.menuButtonHandler != null &&
event.keyCode == Keyboard.MENU)
{
event.preventDefault();
this.menuButtonHandler();
}
if(this.searchButtonHandler != null &&
event.keyCode == Keyboard.SEARCH)
{
event.preventDefault();
this.searchButtonHandler();
}
}
}
}