SlideShare une entreprise Scribd logo
1  sur  44
DEEP DIVE into FLEX
 MOBILE ITEM RENDERERS
                              Flex SDK 4.5 (Hero)




www.jasonhanson.com/360flex                         @jayfour000
• Jason Hanson
                • twitter @jayfour000
                • flexfood.blogspot.com
                • www.jasonhanson.com
             • Building for Flash Platform since 1999
             • Working with Hero SDK since Aug,
               2010 (beta)
www.jasonhanson.com/360flex                         @jayfour000
DISCLAIMER

             • Intended to be a 300 level session (I’ll
               let you judge that for yourself :)
             • You should be familiar with the
               concept of writing Flex components in
               AS3
             • Knowledge of the Flex component
               lifecycle helpful
             • We will be looking at CODE
www.jasonhanson.com/360flex                               @jayfour000
Stuff to check out if
                   you get bored

       • http://www.jasonhanson.com/360flex




                              © @atomic_playboy


www.jasonhanson.com/360flex                       @jayfour000
• Special thanks for technical review:

                • Ryan Frishberg for technical review.
                  @frishy

                • Stephen Shongrunden
                  www.flexponential.com/


             • All photos © Michael Schoenewies
               @atomic_playboy



www.jasonhanson.com/360flex                           @jayfour000
New Project Type in
                   Flash Builder 4.5
             • Flex Mobile Project




www.jasonhanson.com/360flex             @jayfour000
www.jasonhanson.com/360flex   @jayfour000
Rendering a List
                         of Items is Hard




www.jasonhanson.com/360flex                 @jayfour000
Scrolling a List
                      of Items is Harder




www.jasonhanson.com/360flex                @jayfour000
Scroll Performance
             & User Experience
             • Slow or jerky scrolling comes off as an
               error in your app
             • Makes your app seem sluggish
             • Distracting at best
             • Causes loss of user at worst




www.jasonhanson.com/360flex                          @jayfour000
www.jasonhanson.com/360flex   @jayfour000
Rendering Items is
                        Expensive
     • Look! new data.        • commitProperties()

     • How big am I?          • measure()

     • Update display         • updateDisplayList()

     • > Draw background      • > drawBackground()

     • > Layout               • > layoutContents()




www.jasonhanson.com/360flex                          @jayfour000
Draw Faster &
                         Draw Less Often
             • Regular Spark ItemRenderer just not
               fast enough for most mobile devices
             • Adobe SDK devs spent months
               optimizing List scrolling and mobile
               ItemRenderers
             • Slightly different approach then
               standard Flex


www.jasonhanson.com/360flex                           @jayfour000
What About the
                 MXML ItemRender.as
             • Extends Group
             • Has significant overhead
             • Encourages data binding (expensive)
             • Layouts are expensive
             • States add weight
             • Very convenient features, but they all
               add up to lower performance on
               mobile
www.jasonhanson.com/360flex                             @jayfour000
Demo of List on
                                 HTC G2




www.jasonhanson.com/360flex                     @jayfour000
New Classes on Next Slide
                              (Don’t Panic)




www.jasonhanson.com/360flex                   @jayfour000
New Classes
             • spark.components.supportClasses
              • StyleableTextField.as
             • spark.components
              • LabelItemRenderer.as
              • > IconItemRenderer.as
             • spark.primitives
              • BitmapImage.as (updated in 4.5)
             • spark.core
              • ContentCache.as
www.jasonhanson.com/360flex                       @jayfour000
StyleableTextField.as
             • Lightweight text control that
               supports Styles




www.jasonhanson.com/360flex                    @jayfour000
• The StyleableTextField class is a text
               primitive for use in ActionScript skins
               and item renderers.

             • It cannot be used in MXML markup
               and is not compatible with effects.

             • styleName

             • setStyle()

www.jasonhanson.com/360flex                          @jayfour000
LabelItemRenderer.as
             • Optimized default ItemRenderer




www.jasonhanson.com/360flex                     @jayfour000
www.jasonhanson.com/360flex   @jayfour000
• Extends UIComponent

             • Limited Style Support
                 alternatingItemColors, chromeColor, downColor,
                 focusColor, paddingBottom, paddingTop, rollOverColor,
                 selectionColor, symbolColor, verticalAlign


             • Great for simple text renderers

             • Renders the ‘data’ property as a string

             • Inherits the labelField and
               labelFunction from the s:List
www.jasonhanson.com/360flex                                              @jayfour000
IconItemRenderer
             • Image and text




www.jasonhanson.com/360flex               @jayfour000
www.jasonhanson.com/360flex   @jayfour000
• Uses ContentCache to cache the ‘icon’
               images so that they don’t flash when
               scrolled to again

             • The ‘decorator’ and ‘iconPlaceholder’
               should be an embeded asset for best
               performance

             • Supports both a ‘label’ and ‘message’


www.jasonhanson.com/360flex                            @jayfour000
BitmapImage
             • Lightweight image component




www.jasonhanson.com/360flex                  @jayfour000
ContentCache
             • LIFO Cache Object




www.jasonhanson.com/360flex                  @jayfour000
• .maxCacheEntries

             • .maxActiveRequests




www.jasonhanson.com/360flex         @jayfour000
What If I’m Special?




www.jasonhanson.com/360flex               @jayfour000
www.jasonhanson.com/360flex   @jayfour000
Roll Your Own
             • Options
                • Extend UIComponent
                • Extend LabelItemRenderer
                • Extend IconItemRenderer




www.jasonhanson.com/360flex                   @jayfour000
• Write the custom component in AS3,
               not in MXML

             • Look to LabelItemRenderer and
               IconItemRenderer for best practices

             • Extending UIComponent is more
               complicated since you have to
               implement IItemRenderer




www.jasonhanson.com/360flex                          @jayfour000
www.jasonhanson.com/360flex   @jayfour000
www.jasonhanson.com/360flex   @jayfour000
iconDisplay




www.jasonhanson.com/360flex   @jayfour000
labelDisplay
               iconDisplay




www.jasonhanson.com/360flex                  @jayfour000
labelDisplay
               iconDisplay




        messageDisplay


www.jasonhanson.com/360flex                  @jayfour000
labelDisplay
               iconDisplay




                                   decoratorDisplay
        messageDisplay


www.jasonhanson.com/360flex                   @jayfour000
Custom Component
                                  starRating
www.jasonhanson.com/360flex                      @jayfour000
ItemPreviewImageRenderer
                              (Show Code)

             •   ItemPreviewImageRenderer.as
             •   set defaults in constructor
             •   override createChildren()
             •   override createLabelDisplay()
             •   override createMessageDisplay()
             •   set labelFunction
             •   set messageFunction
             •   set iconFunction
             •   override layoutContents()
             •   override measure()

www.jasonhanson.com/360flex                        @jayfour000
Renderer
                              Virtualization
             • Ensure useVirtualLayout="true"
             • Recycles itemRenderers by setting the
               data property to null when off screen
             • Saves time on createChildren() calls
             • Essential for longs lists of data
             • Set to true by default


www.jasonhanson.com/360flex                           @jayfour000
www.jasonhanson.com/360flex   @jayfour000
Tips!
             • getting style cheaper then setting style
             • setElementSize()
               is cheaper then setting width / height
             • setElementPosition()
               is cheaper then setting x / y
             • Use ContentCache to prevent image
               flicker

www.jasonhanson.com/360flex                           @jayfour000
END




www.jasonhanson.com/360flex         @jayfour000

Contenu connexe

En vedette

Making mobile flex apps blazing fast
Making mobile flex apps blazing fastMaking mobile flex apps blazing fast
Making mobile flex apps blazing fastMichał Wróblewski
 
Max 2010: Having Fun Flex4 Layouts
Max 2010: Having Fun Flex4 LayoutsMax 2010: Having Fun Flex4 Layouts
Max 2010: Having Fun Flex4 LayoutsXavi Beumala
 
Flex4 component lifecycle
Flex4 component lifecycleFlex4 component lifecycle
Flex4 component lifecycleRJ Owen
 
Qcon flex体系架构深度剖析
Qcon flex体系架构深度剖析Qcon flex体系架构深度剖析
Qcon flex体系架构深度剖析youzitang
 
Building apps for multiple devices
Building apps for multiple devicesBuilding apps for multiple devices
Building apps for multiple devicesTerry Ryan
 
FXG and Flex Mobile Development
FXG and Flex Mobile DevelopmentFXG and Flex Mobile Development
FXG and Flex Mobile DevelopmentVicker Leung
 
Restful communication with Flex
Restful communication with FlexRestful communication with Flex
Restful communication with FlexChristian Junk
 
Flex 4 Component Lifecycle
Flex 4 Component LifecycleFlex 4 Component Lifecycle
Flex 4 Component LifecycleMrinal Wadhwa
 

En vedette (8)

Making mobile flex apps blazing fast
Making mobile flex apps blazing fastMaking mobile flex apps blazing fast
Making mobile flex apps blazing fast
 
Max 2010: Having Fun Flex4 Layouts
Max 2010: Having Fun Flex4 LayoutsMax 2010: Having Fun Flex4 Layouts
Max 2010: Having Fun Flex4 Layouts
 
Flex4 component lifecycle
Flex4 component lifecycleFlex4 component lifecycle
Flex4 component lifecycle
 
Qcon flex体系架构深度剖析
Qcon flex体系架构深度剖析Qcon flex体系架构深度剖析
Qcon flex体系架构深度剖析
 
Building apps for multiple devices
Building apps for multiple devicesBuilding apps for multiple devices
Building apps for multiple devices
 
FXG and Flex Mobile Development
FXG and Flex Mobile DevelopmentFXG and Flex Mobile Development
FXG and Flex Mobile Development
 
Restful communication with Flex
Restful communication with FlexRestful communication with Flex
Restful communication with Flex
 
Flex 4 Component Lifecycle
Flex 4 Component LifecycleFlex 4 Component Lifecycle
Flex 4 Component Lifecycle
 

Similaire à Deep Dive into Flex Mobile Item Renderers

Maximizing Code Reuse Across Screens
Maximizing Code Reuse Across ScreensMaximizing Code Reuse Across Screens
Maximizing Code Reuse Across ScreensJason Hanson
 
JavaScript for ASP.NET programmers (webcast) upload
JavaScript for ASP.NET programmers (webcast) uploadJavaScript for ASP.NET programmers (webcast) upload
JavaScript for ASP.NET programmers (webcast) uploadRuss Fustino
 
A Responsive Design Case Study - What We Did Wrong Building ResponsiveDesign....
A Responsive Design Case Study - What We Did Wrong Building ResponsiveDesign....A Responsive Design Case Study - What We Did Wrong Building ResponsiveDesign....
A Responsive Design Case Study - What We Did Wrong Building ResponsiveDesign....Aidan Foster
 
Trendsetting: Web Design and Beyond
Trendsetting: Web Design and BeyondTrendsetting: Web Design and Beyond
Trendsetting: Web Design and BeyondAndy Stratton
 
User Profiles: I Didn't Know I Could Do That!! @SPSHI
User Profiles:  I Didn't Know I Could Do That!! @SPSHIUser Profiles:  I Didn't Know I Could Do That!! @SPSHI
User Profiles: I Didn't Know I Could Do That!! @SPSHIStacy Deere
 
Building Responsive Applications Using XPages
Building Responsive Applications Using XPagesBuilding Responsive Applications Using XPages
Building Responsive Applications Using XPagesTeamstudio
 
CUST-2 New Client Configuration & Extension Points in Share
CUST-2 New Client Configuration & Extension Points in ShareCUST-2 New Client Configuration & Extension Points in Share
CUST-2 New Client Configuration & Extension Points in ShareAlfresco Software
 
About Layout in Firefox
About Layout in FirefoxAbout Layout in Firefox
About Layout in FirefoxJia Mi
 
Flex 4 Overview
Flex 4 OverviewFlex 4 Overview
Flex 4 OverviewRJ Owen
 
Famo.us introduction
Famo.us introductionFamo.us introduction
Famo.us introductionAllen Wu
 
DelveNYC: Flash Catalyst
DelveNYC: Flash CatalystDelveNYC: Flash Catalyst
DelveNYC: Flash CatalystRyan Stewart
 
PRDC12 advanced design patterns
PRDC12 advanced design patternsPRDC12 advanced design patterns
PRDC12 advanced design patternsAmir Barylko
 
SPSHawaii: Navigation: A Step Towards Success in SharePoint
SPSHawaii:  Navigation: A Step Towards Success in SharePointSPSHawaii:  Navigation: A Step Towards Success in SharePoint
SPSHawaii: Navigation: A Step Towards Success in SharePointStacy Deere
 
Easier and faster Plone theming with Deliverance and xdv
Easier and faster Plone theming with Deliverance and xdvEasier and faster Plone theming with Deliverance and xdv
Easier and faster Plone theming with Deliverance and xdvJazkarta, Inc.
 
Introduction to Xamarin Forms
Introduction to Xamarin Forms Introduction to Xamarin Forms
Introduction to Xamarin Forms Russ Fustino
 

Similaire à Deep Dive into Flex Mobile Item Renderers (20)

Migrating fx3tofx4
Migrating fx3tofx4Migrating fx3tofx4
Migrating fx3tofx4
 
Maximizing Code Reuse Across Screens
Maximizing Code Reuse Across ScreensMaximizing Code Reuse Across Screens
Maximizing Code Reuse Across Screens
 
JavaScript for ASP.NET programmers (webcast) upload
JavaScript for ASP.NET programmers (webcast) uploadJavaScript for ASP.NET programmers (webcast) upload
JavaScript for ASP.NET programmers (webcast) upload
 
Titanium Alloy Tutorial
Titanium Alloy TutorialTitanium Alloy Tutorial
Titanium Alloy Tutorial
 
A Responsive Design Case Study - What We Did Wrong Building ResponsiveDesign....
A Responsive Design Case Study - What We Did Wrong Building ResponsiveDesign....A Responsive Design Case Study - What We Did Wrong Building ResponsiveDesign....
A Responsive Design Case Study - What We Did Wrong Building ResponsiveDesign....
 
HTML5: Introduction
HTML5: IntroductionHTML5: Introduction
HTML5: Introduction
 
Trendsetting: Web Design and Beyond
Trendsetting: Web Design and BeyondTrendsetting: Web Design and Beyond
Trendsetting: Web Design and Beyond
 
User Profiles: I Didn't Know I Could Do That!! @SPSHI
User Profiles:  I Didn't Know I Could Do That!! @SPSHIUser Profiles:  I Didn't Know I Could Do That!! @SPSHI
User Profiles: I Didn't Know I Could Do That!! @SPSHI
 
Building Responsive Applications Using XPages
Building Responsive Applications Using XPagesBuilding Responsive Applications Using XPages
Building Responsive Applications Using XPages
 
CUST-2 New Client Configuration & Extension Points in Share
CUST-2 New Client Configuration & Extension Points in ShareCUST-2 New Client Configuration & Extension Points in Share
CUST-2 New Client Configuration & Extension Points in Share
 
About Layout in Firefox
About Layout in FirefoxAbout Layout in Firefox
About Layout in Firefox
 
Flex 4 Overview
Flex 4 OverviewFlex 4 Overview
Flex 4 Overview
 
Famo.us introduction
Famo.us introductionFamo.us introduction
Famo.us introduction
 
DelveNYC: Flash Catalyst
DelveNYC: Flash CatalystDelveNYC: Flash Catalyst
DelveNYC: Flash Catalyst
 
PRDC12 advanced design patterns
PRDC12 advanced design patternsPRDC12 advanced design patterns
PRDC12 advanced design patterns
 
Jquery Mobile
Jquery MobileJquery Mobile
Jquery Mobile
 
jQuery Mobile
jQuery MobilejQuery Mobile
jQuery Mobile
 
SPSHawaii: Navigation: A Step Towards Success in SharePoint
SPSHawaii:  Navigation: A Step Towards Success in SharePointSPSHawaii:  Navigation: A Step Towards Success in SharePoint
SPSHawaii: Navigation: A Step Towards Success in SharePoint
 
Easier and faster Plone theming with Deliverance and xdv
Easier and faster Plone theming with Deliverance and xdvEasier and faster Plone theming with Deliverance and xdv
Easier and faster Plone theming with Deliverance and xdv
 
Introduction to Xamarin Forms
Introduction to Xamarin Forms Introduction to Xamarin Forms
Introduction to Xamarin Forms
 

Dernier

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 

Dernier (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 

Deep Dive into Flex Mobile Item Renderers

  • 1. DEEP DIVE into FLEX MOBILE ITEM RENDERERS Flex SDK 4.5 (Hero) www.jasonhanson.com/360flex @jayfour000
  • 2. • Jason Hanson • twitter @jayfour000 • flexfood.blogspot.com • www.jasonhanson.com • Building for Flash Platform since 1999 • Working with Hero SDK since Aug, 2010 (beta) www.jasonhanson.com/360flex @jayfour000
  • 3. DISCLAIMER • Intended to be a 300 level session (I’ll let you judge that for yourself :) • You should be familiar with the concept of writing Flex components in AS3 • Knowledge of the Flex component lifecycle helpful • We will be looking at CODE www.jasonhanson.com/360flex @jayfour000
  • 4. Stuff to check out if you get bored • http://www.jasonhanson.com/360flex © @atomic_playboy www.jasonhanson.com/360flex @jayfour000
  • 5. • Special thanks for technical review: • Ryan Frishberg for technical review. @frishy • Stephen Shongrunden www.flexponential.com/ • All photos © Michael Schoenewies @atomic_playboy www.jasonhanson.com/360flex @jayfour000
  • 6. New Project Type in Flash Builder 4.5 • Flex Mobile Project www.jasonhanson.com/360flex @jayfour000
  • 8. Rendering a List of Items is Hard www.jasonhanson.com/360flex @jayfour000
  • 9. Scrolling a List of Items is Harder www.jasonhanson.com/360flex @jayfour000
  • 10. Scroll Performance & User Experience • Slow or jerky scrolling comes off as an error in your app • Makes your app seem sluggish • Distracting at best • Causes loss of user at worst www.jasonhanson.com/360flex @jayfour000
  • 12. Rendering Items is Expensive • Look! new data. • commitProperties() • How big am I? • measure() • Update display • updateDisplayList() • > Draw background • > drawBackground() • > Layout • > layoutContents() www.jasonhanson.com/360flex @jayfour000
  • 13. Draw Faster & Draw Less Often • Regular Spark ItemRenderer just not fast enough for most mobile devices • Adobe SDK devs spent months optimizing List scrolling and mobile ItemRenderers • Slightly different approach then standard Flex www.jasonhanson.com/360flex @jayfour000
  • 14. What About the MXML ItemRender.as • Extends Group • Has significant overhead • Encourages data binding (expensive) • Layouts are expensive • States add weight • Very convenient features, but they all add up to lower performance on mobile www.jasonhanson.com/360flex @jayfour000
  • 15. Demo of List on HTC G2 www.jasonhanson.com/360flex @jayfour000
  • 16. New Classes on Next Slide (Don’t Panic) www.jasonhanson.com/360flex @jayfour000
  • 17. New Classes • spark.components.supportClasses • StyleableTextField.as • spark.components • LabelItemRenderer.as • > IconItemRenderer.as • spark.primitives • BitmapImage.as (updated in 4.5) • spark.core • ContentCache.as www.jasonhanson.com/360flex @jayfour000
  • 18. StyleableTextField.as • Lightweight text control that supports Styles www.jasonhanson.com/360flex @jayfour000
  • 19. • The StyleableTextField class is a text primitive for use in ActionScript skins and item renderers. • It cannot be used in MXML markup and is not compatible with effects. • styleName • setStyle() www.jasonhanson.com/360flex @jayfour000
  • 20. LabelItemRenderer.as • Optimized default ItemRenderer www.jasonhanson.com/360flex @jayfour000
  • 22. • Extends UIComponent • Limited Style Support alternatingItemColors, chromeColor, downColor, focusColor, paddingBottom, paddingTop, rollOverColor, selectionColor, symbolColor, verticalAlign • Great for simple text renderers • Renders the ‘data’ property as a string • Inherits the labelField and labelFunction from the s:List www.jasonhanson.com/360flex @jayfour000
  • 23. IconItemRenderer • Image and text www.jasonhanson.com/360flex @jayfour000
  • 25. • Uses ContentCache to cache the ‘icon’ images so that they don’t flash when scrolled to again • The ‘decorator’ and ‘iconPlaceholder’ should be an embeded asset for best performance • Supports both a ‘label’ and ‘message’ www.jasonhanson.com/360flex @jayfour000
  • 26. BitmapImage • Lightweight image component www.jasonhanson.com/360flex @jayfour000
  • 27. ContentCache • LIFO Cache Object www.jasonhanson.com/360flex @jayfour000
  • 28. • .maxCacheEntries • .maxActiveRequests www.jasonhanson.com/360flex @jayfour000
  • 29. What If I’m Special? www.jasonhanson.com/360flex @jayfour000
  • 31. Roll Your Own • Options • Extend UIComponent • Extend LabelItemRenderer • Extend IconItemRenderer www.jasonhanson.com/360flex @jayfour000
  • 32. • Write the custom component in AS3, not in MXML • Look to LabelItemRenderer and IconItemRenderer for best practices • Extending UIComponent is more complicated since you have to implement IItemRenderer www.jasonhanson.com/360flex @jayfour000
  • 36. labelDisplay iconDisplay www.jasonhanson.com/360flex @jayfour000
  • 37. labelDisplay iconDisplay messageDisplay www.jasonhanson.com/360flex @jayfour000
  • 38. labelDisplay iconDisplay decoratorDisplay messageDisplay www.jasonhanson.com/360flex @jayfour000
  • 39. Custom Component starRating www.jasonhanson.com/360flex @jayfour000
  • 40. ItemPreviewImageRenderer (Show Code) • ItemPreviewImageRenderer.as • set defaults in constructor • override createChildren() • override createLabelDisplay() • override createMessageDisplay() • set labelFunction • set messageFunction • set iconFunction • override layoutContents() • override measure() www.jasonhanson.com/360flex @jayfour000
  • 41. Renderer Virtualization • Ensure useVirtualLayout="true" • Recycles itemRenderers by setting the data property to null when off screen • Saves time on createChildren() calls • Essential for longs lists of data • Set to true by default www.jasonhanson.com/360flex @jayfour000
  • 43. Tips! • getting style cheaper then setting style • setElementSize() is cheaper then setting width / height • setElementPosition() is cheaper then setting x / y • Use ContentCache to prevent image flicker www.jasonhanson.com/360flex @jayfour000

Notes de l'éditeur

  1. Welcome to Deep Dive into Flex Mobile Item Renderers.\n
  2. My name is Jason Hanson. If you are interested in learning more about me, what I do, or have questions after this presentation please feel free contact me via Twitter, my blog, or web site.\nA little about me. I have been building for the Flash Platform since 1999, back when I used FlashScript and really had no idea what I was doing. I have stuck with the platform for the past 10+ years, started working with Flex Builder 2 when the beta came out and have been building projects with Hero / Burrito since August of 2010.\n
  3. \n
  4. If you bet bored during the presentation and want to look at some of the code samples you can check out some stuff I posted up at my web site. There are also some Android APK files there you can install and play with on your Android 2.2 device running AIR 2.6.\n
  5. \n
  6. There is a new project type in Flash Builder 4.5; Flex Mobile Project. This type of project should be selected when building Mobile Flex applications that will take advantage of the mobile-optimized Spark components. This session will focus on targeting AIR for Android. \nEverything I am going to talk about from this point forward assumes that you are working with Flash Builder 4.5 and Flex SDK 4.5 (v. i6 or greater) with code in a Flex Mobile Project. Certain new classes and skins are included in only the mobile libraries that are added to the class that when creating a Flex Mobile Project.\n\n
  7. Many of the components used in mobile Flex development are the same as the Spark components you use for any app. The mobilecomponents.swc contains components and skins that have been optimized specially for mobile use-cases. You do not need to learn a whole new component set.\n
  8. So, rendering a list of items is hard. There are all those little images and little bits of text, star icons, etc. \nNot only do you have to render all that for one item, you usually need to support anywhere between 1 item and 10,000 items. Yes, my QA team always seems to run a test with 10,000 list items ...\nNext Slide.\n
  9. Scrolling a List of Items is Harder.\nNow, after you have the list rendered the user is going to want to scroll it. And that is where the problems start. Scrolling on a modern computer is pretty straight forward these days. Mostly we just brute-force our way through it all and don’t have too many issues. \nWhen it comes to mobile our computing resources often very restricted, AND the users get to use their fingers to swipe scroll. Instead of just ‘click to scroll up’ / ‘click to scroll down’ actions, we need to support a crazed 14 year old treating our scrollable list as practice for some new finger breakdancing fad that I, unfortunately, will never be cool enough to perform.\nBottom line, users expect immediate response to tactile gestures.\n
  10. I cannot stress enough how important smooth and responsive scrolling is for the lists in your apps. A poorly written itemRender can ruin a whole app. If you only have time / budget to optimize one part of your application I strongly suggest spending the time writing efficient and fast itemRenderers\n
  11. \n
  12. If you have written components before, or read about component lifecyle, you may know that there is a whole list of ‘stuff’ that happens when RENDER kicks off. Some of that ‘stuff’ can be really expensive.\nThat is fine if I am doing it once, but if I am doing it 30 times a second for 6 items at a time I start to run into trouble. Every line of code in my ItemRenderer may be firing off over 100 times a second during a quick scroll of a long list. It is important to make every line of code count.\nNote that in the code we will be looking at today updateDisplayList() calls both drawBackground() and layoutContents() to make each easier to override without having to duplicate as much code as you would in overriding updateDispalyList() (Thanks! Adobe SDK team!)\n
  13. It turns out a regular Spark ItemRenderer written in MXML is just not fast enough to for most mobile devices. To get around this some smart SDK devs at Adobe spent months optimizing the Spark List scrolling behavior and creating new ItemRenderers optimized specifically for mobile. The scrolling performance you may have seen in the MAX builds last fall has greatly improved. The rest of this talk will go into that.\n\n\n
  14. While the Spark class ItemRenderer.as is still a good choice for easily creating itemRenderers for desktop and web apps there are some things about it that are not a good fit for mobile. It extends Group, and that brings along a decent amount of baggage when it comes to layout. It also encourages use of relatively expensive convenience features like states, binding, and relative layouts. In the ItemRendererSample project you can see an example of an MXML ItemRender for comparison.\n
  15. \n
  16. Here are the stars. Shiny new classes to learn about. During the beta process documentation really did not keep up with the code that was been written / changed each iteration. So, I just dove right in to reading the SDK code line by line to see what was going on. Building custom mobile item renderers is much easier now then it was in the early builds thanks to an attentive and responsive dev team at Adobe many of the pain points have been resolved. Hopefully I can save you some of the pain I went through today by explaining what these new super-star classes do and how / when to use them. If you get nothing else of of this session today hopefully it will be the names of these classes to read up on later.\n
  17. Let’s look at some code. I am going to show off the code for the itemRenderer we saw a few slides back, do a quick tour, and then dive into the new classes I just mentioned. \n(show MobileShoppingCart > ItemPreviewImageRenderer.as)\n\n
  18. Ahh, my good old friend TextField. For all the wiz-bang features that TLF text primitives have to offer TextField performs better in lists on Mobile. StyleableTextField adds a few handy features. Like \nsetting a styleDeclaration or styleName.\n
  19. Exposes setting of the styleName property and the setStyle() method to easily change the style of the text.\n
  20. The default itemRenderer for lists in mobile is the LabelItemRenderer. It was created specifically for rendering text in a List.\n
  21. Here is an example of what the LabelItemRenderer looks like with default styles. \nTake a look at the way the itemRenderer is declared in MXML. This is a very convenient way to set styles and properties on your itemRenderer without impacting performance. Please note that this is different then writing an entire itemRenderer in MXML syntax. This code only instantiates the AS3 component. This is a great place to set the styles.\n
  22. Base component that does not bring as much baggage that ItemRenderer does by extending from UIComponent.\nThere is rather limited support for styles. If it is not in the list above, the style is probably not supported. You may be able to set it in MXML or CSS, but it will do nothing at runtime.\nNothing too fancy, just renders that data property as a String. \n
  23. Use IconItemRenderer when your item renderer has an image. Notice it extends from LabelItemRenderer\n
  24. Here is an example of what the default IconItemRenderer might look like. Notice the image on the left is the ‘icon’ and the image on the right is the ‘decorator’.\nNotice the convenance of setting properties on the itemRenderer when instantiated in MXML syntax.\n
  25. \n
  26. I am not going to get too far into BitmapImage, but just be aware that it is a high performance component that performs well in mobile itemRenderers. It does not extend from DispalyObject and is a bit tricky to use. \nSide Note: using Image component, or wrapping BitmapImage in a Group is a simpler way to go, just a bit less optimal. \n
  27. Last in, first out cache system added to Flex Framework. It is used to cache the bitmaps loaded in IconItemRenderer. If you have had to load lots of images in Flex before you probably have written a similar caching system in the past. Nothing super-fancy here. Note, however that it implements IContentLoader so that it can be used as ‘source’ value for Image components.\nYou can set the iconContentLoader to a ContentCache instance on IconItemRenderer.\n
  28. Usage from IconItemRenderer. The imageCache object is set to the iconContentLoader so that images that get loaded are also cached. Handy!\n
  29. \n
  30. \n
  31. If your itemRenderer has more then two bits of text and two images you will need to make a custom one. You have some options here. If your itemRenderer will be similar to either LabelItemRenderer or IconItemRenderer I recommend extending that class. Otherwise start with UIComponent and follow the structure of one of those default item renderers.\n
  32. Component written in AS3 tend to perform better as item renderers when compared to components written in MXML. Use AS3. LabelItemRenderer and IconItemRenderer are highly optimized component, take advantage of what you can from those classes by extending or copying.\n
  33. So I built a custom item renderer. I showed it in a screenshot a few slides back. I am going to detail out how I went about that.\nFirst I decided to extend IconItemRenderer since it would be easy to reuse some of the displayObjects. Next I wrote a custom component for displaying the star rating.\n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. set defaults in constructor\noverride createChildren()\noverride createLabelDisplay()\noverride createMessageDisplay()\nset labelFunction\nset messageFunction\nset iconFunction\noverride layoutContents()\noverride measure()\n
  40. \n
  41. \n
  42. setElementSize() and setElementPosition() are helper methods that underneath the hood call the appropriate methods to change the size or position -- setLayoutBoundsSize() / setLayoutBoundsPosition() in many cases. Alway try to use these methods when resizing or positioning components.\nAlways call setElementSize() before setElementPosition()\n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n