blob: 5b26b987a5af9d080ddf78b23cfaf689b67e63c7 [file] [log] [blame]
////////////////////////////////////////////////////////////////////////////////
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
package skins
{
import mx.core.FlexGlobals;
import spark.components.ButtonBar;
import spark.components.Group;
import spark.components.Scroller;
import spark.components.TabbedViewNavigator;
import spark.components.TabbedViewNavigatorApplication;
import spark.components.supportClasses.ButtonBarBase;
import spark.skins.mobile.supportClasses.MobileSkin;
/**
* The ActionScript-based skin used for TabbedViewNavigator components.
*
* @langversion 3.0
* @playerversion AIR 2.5
* @productversion Flex 4.5
*
*/
public class TabbedViewNavigatorSkin extends MobileSkin
{
//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------
/**
* Constructor.
*
* @langversion 3.0
* @playerversion AIR 2.5
* @productversion Flex 4.5
*
*/
public function TabbedViewNavigatorSkin()
{
super();
}
//--------------------------------------------------------------------------
//
// Variables
//
//--------------------------------------------------------------------------
/**
* @copy spark.skins.spark.ApplicationSkin#hostComponent
*/
public var hostComponent:TabbedViewNavigator;
//--------------------------------------------------------------------------
//
// Properties
//
//--------------------------------------------------------------------------
/**
* @copy spark.components.SkinnableContainer#contentGroup
*/
public var contentGroup:Group;
/**
* @copy spark.components.TabbedViewNavigator#tabBar
*/
public var tabBar:ButtonBarBase;
//--------------------------------------------------------------------------
//
// Methods
//
//--------------------------------------------------------------------------
private var _isOverlay:Boolean;
/**
* @private
*/
override protected function createChildren():void
{
if (!contentGroup)
{
contentGroup = new Group();
contentGroup.id = "contentGroup";
addChild(contentGroup);
}
if (!tabBar)
{
tabBar = new ButtonBar();
tabBar.id = "tabBar";
tabBar.requireSelection = true;
this.addChild(tabBar);
}
}
/**
* @private
*/
override protected function commitCurrentState():void
{
super.commitCurrentState();
_isOverlay = (currentState.indexOf("Overlay") >= 1);
// Force a layout pass on the components
invalidateProperties();
invalidateSize();
invalidateDisplayList();
}
/**
* @private
*/
override protected function measure():void
{
super.measure();
measuredWidth = Math.max(tabBar.getPreferredBoundsWidth(),
contentGroup.getPreferredBoundsWidth());
if (currentState == "portraitAndOverlay" || currentState == "landscapeAndOverlay")
{
measuredHeight = Math.max(tabBar.getPreferredBoundsHeight(),
contentGroup.getPreferredBoundsHeight());
}
else
{
measuredHeight = tabBar.getPreferredBoundsHeight() +
contentGroup.getPreferredBoundsHeight();
}
}
/**
* @private
*/
override protected function layoutContents(unscaledWidth:Number, unscaledHeight:Number):void
{
super.layoutContents(unscaledWidth, unscaledHeight);
var tabBarHeight:Number = 0;
if (tabBar.includeInLayout)
{
trace("INcludetab bar " + " setting pos to " + (unscaledHeight - tabBarHeight));
tabBarHeight = Math.min(tabBar.getPreferredBoundsHeight(), unscaledHeight);
tabBar.setLayoutBoundsSize(unscaledWidth, tabBarHeight);
//tabBar.setLayoutBoundsPosition(0, unscaledHeight - tabBarHeight);
tabBar.setLayoutBoundsPosition(0,0 );
tabBarHeight = tabBar.getLayoutBoundsHeight();
// backgroundAlpha is not a declared style on ButtonBar
// TabbedViewNavigatorButtonBarSkin implements for overlay support
var backgroundAlpha:Number = (_isOverlay) ? 0.75 : 1;
tabBar.setStyle("backgroundAlpha", backgroundAlpha);
}
if (contentGroup.includeInLayout)
{
trace("INclude content group - height " + Math.max(unscaledHeight - tabBarHeight, 0));
var contentGroupHeight:Number = (_isOverlay) ? unscaledHeight : Math.max(unscaledHeight - tabBarHeight, 0);
contentGroup.setLayoutBoundsSize(unscaledWidth, contentGroupHeight);
//contentGroup.setLayoutBoundsPosition(0, 0);
trace("Tab bar height " + tabBarHeight);
contentGroup.setLayoutBoundsPosition(0, tabBarHeight);
}
}
}
}