You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by yi...@apache.org on 2016/11/16 07:58:48 UTC

git commit: [flex-asjs] [refs/heads/develop] - Add easing effect to accordion.

Repository: flex-asjs
Updated Branches:
  refs/heads/develop 2deb36992 -> c4eb090f0


Add easing effect to accordion.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/c4eb090f
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/c4eb090f
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/c4eb090f

Branch: refs/heads/develop
Commit: c4eb090f0270e70bef60db375ffee34bb80c7e53
Parents: 2deb369
Author: yishayw <yi...@hotmail.com>
Authored: Wed Nov 16 09:58:37 2016 +0200
Committer: yishayw <yi...@hotmail.com>
Committed: Wed Nov 16 09:58:37 2016 +0200

----------------------------------------------------------------------
 .../main/flex/org/apache/flex/html/Accordion.as | 55 ++++++-----
 .../flex/html/beads/AccordionCollapseBead.as    |  2 +-
 .../html/beads/EasyAccordionCollapseBead.as     | 98 ++++++++++++++++++++
 .../HTML/src/main/resources/basic-manifest.xml  |  1 +
 4 files changed, 131 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c4eb090f/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Accordion.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Accordion.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Accordion.as
index 20e3f96..3076d0c 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Accordion.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/Accordion.as
@@ -21,36 +21,36 @@ package org.apache.flex.html
 	import org.apache.flex.core.ValuesManager;
 	import org.apache.flex.html.beads.IAccordionCollapseBead;
 	
-
-    /**
-     *  The Accordion class used to display a list of collapsible components
+	
+	/**
+	 *  The Accordion class used to display a list of collapsible components
 	 *  All but the selected item are expected to be collapsed.
-     *  
-     *  @langversion 3.0
-     *  @playerversion Flash 10.2
-     *  @playerversion AIR 2.6
-     *  @productversion FlexJS 0.0
-     */    
+	 *  
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion FlexJS 0.0
+	 */    
 	public class Accordion extends List
 	{
 		private var _collapseBead:IAccordionCollapseBead;
-        /**
-         *  Constructor.
-         *  
-         *  @langversion 3.0
-         *  @playerversion Flash 10.2
-         *  @playerversion AIR 2.6
-         *  @productversion FlexJS 0.0
-         */
+		/**
+		 *  Constructor.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
 		public function Accordion()
 		{
 			super();
-			accordionCollapseBead; // make sure it's initialized
 		}
 		
 		override public function addedToParent():void
 		{
 			super.addedToParent();
+			accordionCollapseBead; // make sure it's initialized
 			if (selectedIndex < 0)
 			{
 				selectedIndex = 0;
@@ -61,19 +61,26 @@ package org.apache.flex.html
 		{
 			if (_collapseBead == null)
 			{
-				var c:Class = ValuesManager.valuesImpl.getValue(this, "iAccordionCollapseBead") as Class;
-				if (c)
+				_collapseBead = getBeadByType(IAccordionCollapseBead) as IAccordionCollapseBead;
+				if (_collapseBead == null)
 				{
+					var c:Class = ValuesManager.valuesImpl.getValue(this, "iAccordionCollapseBead") as Class;
 					if (c)
 					{
-						_collapseBead = (new c()) as IAccordionCollapseBead;
-						addBead(_collapseBead);
+						if (c)
+						{
+							_collapseBead = (new c()) as IAccordionCollapseBead;
+						}
 					}
 				}
 			}
+			if (_collapseBead)
+			{
+				addBead(_collapseBead);
+			}
 			return _collapseBead;
 		}
-
-				
+		
+		
 	}
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c4eb090f/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/AccordionCollapseBead.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/AccordionCollapseBead.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/AccordionCollapseBead.as
index 4222ab6..d666fc1 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/AccordionCollapseBead.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/AccordionCollapseBead.as
@@ -39,7 +39,7 @@ package org.apache.flex.html.beads
 			host.model.addEventListener("selectedIndexChanged", selectedIndexChangedHandler);
 		}
 		
-		private function get host():Accordion
+		protected function get host():Accordion
 		{
 			return _strand as Accordion;
 		}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c4eb090f/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/EasyAccordionCollapseBead.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/EasyAccordionCollapseBead.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/EasyAccordionCollapseBead.as
new file mode 100644
index 0000000..0d0702f
--- /dev/null
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/EasyAccordionCollapseBead.as
@@ -0,0 +1,98 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 org.apache.flex.html.beads
+{
+	
+	import flash.events.IEventDispatcher;
+	
+	import org.apache.flex.core.ILayoutChild;
+	import org.apache.flex.core.IStrand;
+	import org.apache.flex.core.UIBase;
+	import org.apache.flex.effects.Effect;
+	import org.apache.flex.effects.Parallel;
+	import org.apache.flex.effects.Resize;
+	import org.apache.flex.events.Event;
+	import org.apache.flex.html.beads.layouts.IOneFlexibleChildLayout;
+	import org.apache.flex.html.supportClasses.ICollapsible;
+	
+	public class EasyAccordionCollapseBead extends AccordionCollapseBead
+	{
+		private var _strand:IStrand;
+		private var lastSelectedIndex:int = -1;
+		public function EasyAccordionCollapseBead()
+		{
+			super();
+		}
+		
+		private function findPreviousNonCollapsed():ICollapsible
+		{
+			var n:int = view.dataGroup.numElements;
+			for (var i:int = 0; i < n; i++)
+			{
+				var collapsible:ICollapsible = view.dataGroup.getElementAt(i) as ICollapsible;
+				if (collapsible.collapsedHeight != (collapsible as ILayoutChild).height)
+				{
+					return collapsible;
+				}
+			}
+			return null;
+		}
+		
+		private function get view():IListView
+		{
+			return host.view as IListView;			
+		}
+		
+		override protected function selectedIndexChangedHandler(event:Event):void
+		{
+			var newChild:UIBase = view.dataGroup.getElementAt(host.selectedIndex) as UIBase;
+			var oldChild:UIBase = findPreviousNonCollapsed() as UIBase;
+			if (!newChild || !oldChild)
+			{
+				return;
+			}
+			var effect:Effect = getResize(newChild, oldChild);
+			effect.addEventListener(Effect.EFFECT_END, effectEndHandler);
+			layout.flexibleChild = newChild.id;
+			effect.play();
+		}
+		
+		private function get layout():IOneFlexibleChildLayout
+		{
+			return host.getBeadByType(IOneFlexibleChildLayout) as IOneFlexibleChildLayout;
+		}
+		
+		protected function effectEndHandler(event:Event):void
+		{
+			(event.target as IEventDispatcher).removeEventListener(Effect.EFFECT_END, effectEndHandler);
+			layout.layout();
+		}
+		
+		private function getResize(newChild:UIBase, oldChild:UIBase):Effect
+		{
+			var resizeNew:Resize = new Resize(newChild);
+			resizeNew.heightTo = oldChild.height;
+			var resizeOld:Resize = new Resize(oldChild);
+			resizeOld.heightTo = (oldChild as ICollapsible).collapsedHeight;
+			var parallel:Parallel = new Parallel();
+			parallel.children = [resizeNew, resizeOld];
+			return parallel;
+		}
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c4eb090f/frameworks/projects/HTML/src/main/resources/basic-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/resources/basic-manifest.xml b/frameworks/projects/HTML/src/main/resources/basic-manifest.xml
index dd713ca..b109ce5 100644
--- a/frameworks/projects/HTML/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/HTML/src/main/resources/basic-manifest.xml
@@ -74,6 +74,7 @@
     <component id="StringItemRenderer" class="org.apache.flex.html.supportClasses.StringItemRenderer"/>
     <component id="AccordionItemRenderer" class="org.apache.flex.html.supportClasses.AccordionItemRenderer"/>
     <component id="AccordionCollapseBead" class="org.apache.flex.html.beads.AccordionCollapseBead"/>
+    <component id="EasyAccordionCollapseBead" class="org.apache.flex.html.beads.EasyAccordionCollapseBead"/>
     <component id="TreeItemRenderer" class="org.apache.flex.html.supportClasses.TreeItemRenderer"/>
     <component id="DataItemRenderer" class="org.apache.flex.html.supportClasses.DataItemRenderer"/>
     <component id="MXMLItemRenderer" class="org.apache.flex.html.supportClasses.MXMLItemRenderer"/>


Re: git commit: [flex-asjs] [refs/heads/develop] - Add easing effect to accordion.

Posted by Alex Harui <ah...@adobe.com>.

On 11/16/16, 10:06 AM, "Yishay Weiss" <yi...@hotmail.com> wrote:

>Hi Alex,
>
>
>
>Accordion, as I wrote it, will not function properly without some
>mechanism for collapsing items. This code calls get
>accordionCollapseBead() which searches for beads that implement
>ICollapseBead, either in the beads collection or in CSS. It’s similar to
>the way UIBase initializes models, views, and controllers.
>
>
>
>What dependencies are you worried about?

It looked like a way to generate a dependency rather than a getter call.

I'm hoping that effects for component transitions can be implemented by
intercepting events.  In theory, an Accordion should just send out a
"change" event that its selectedIndex changed and the AccordionView should
cause the affected child views to either resize or change visibility.  An
effects bead should be watching each child view for a resize or show/hide
event, reset the size or visibility, then apply the appropriate effect.

This is all theory, of course.  In might require "pre" events like an
"aboutToResize" or "aboutToHide" that can be cancelled if you get
flickering.

IOW, the basic implementations should not assume there are an effects and
just instantaneously change the view.  But a bead should be able to alter
that without any tight coupling other than events (or some sort of
notification).

My 2 cents,
-Alex


RE: git commit: [flex-asjs] [refs/heads/develop] - Add easing effect to accordion.

Posted by Yishay Weiss <yi...@hotmail.com>.
Hi Alex,



Accordion, as I wrote it, will not function properly without some mechanism for collapsing items. This code calls get accordionCollapseBead() which searches for beads that implement ICollapseBead, either in the beads collection or in CSS. It’s similar to the way UIBase initializes models, views, and controllers.



What dependencies are you worried about?



Thanks.







From: Alex Harui<ma...@adobe.com>
Sent: Wednesday, November 16, 2016 5:56 PM
To: dev@flex.apache.org<ma...@flex.apache.org>; commits@flex.apache.org<ma...@flex.apache.org>
Subject: Re: git commit: [flex-asjs] [refs/heads/develop] - Add easing effect to accordion.




On 11/15/16, 11:58 PM, "yishayw@apache.org" <yi...@apache.org> wrote:

>               override public function addedToParent():void
>               {
>                       super.addedToParent();
>+                      accordionCollapseBead; // make sure it's initialized
>                       if (selectedIndex < 0)
>

Hi Yishay,

What does this code do?  Seems like it would bake in some dependencies.

-Alex


Re: git commit: [flex-asjs] [refs/heads/develop] - Add easing effect to accordion.

Posted by Alex Harui <ah...@adobe.com>.

On 11/15/16, 11:58 PM, "yishayw@apache.org" <yi...@apache.org> wrote:

>		override public function addedToParent():void
>		{
>			super.addedToParent();
>+			accordionCollapseBead; // make sure it's initialized
>			if (selectedIndex < 0)
>

Hi Yishay, 

What does this code do?  Seems like it would bake in some dependencies.

-Alex


Re: git commit: [flex-asjs] [refs/heads/develop] - Add easing effect to accordion.

Posted by Alex Harui <ah...@adobe.com>.

On 11/15/16, 11:58 PM, "yishayw@apache.org" <yi...@apache.org> wrote:

>		override public function addedToParent():void
>		{
>			super.addedToParent();
>+			accordionCollapseBead; // make sure it's initialized
>			if (selectedIndex < 0)
>

Hi Yishay, 

What does this code do?  Seems like it would bake in some dependencies.

-Alex