SlideShare a Scribd company logo
Animations - Part II
Layout animations are some of the most important yet easy to use animations in Codename One. They make the application flow feel reactive and responsive.
Layout Animation
© Codename One 2017 all rights reserved
✦Layout animations rely on the behavior of Codename
One which doesn’t implicitly “reflow” components
✦Instead of calling revalidate() we can call
animateLayout(int) or equivalent to animate the
components to their final correct place/size
✦This is useful for smooth UI’s where components
should “flow” into place rather than jump into it
At the core of layout animations is the concept of explicit reflow. In Codename One layouts determine the position of components. That means that if you add a new
component it will be positioned by the layout, however there is a big caveat. If you add the component after the form was shown it won’t position itself unless you do
something like rotate the device which implicitly lays out the component. You need to ask for layout explicitly. You can invoke revalidate to force layout, this is valuable for
cases where you can add multiple components. In those cases the layout logic can happen only once and can be much simpler.

Layout animation works by animating the validate effect. It takes the components from their previously invalid or incorrect positions and moves them into their real final
position. Normally when you add a component you won’t set a size or position to it as those will be determined by the layout manager, but with layout animations this
can be useful as you can position a component explicitly and then it will animate from that position.

This allows you to create a flow in the UI so components “settle” into place, this serves to draw attention to changes in the UI in most cases
Unlayout Animations
© Codename One 2017 all rights reserved
✦ animateUnlayout() and equivalent methods do the
opposite, they move an element to an “illegal” place from
the valid position thru an animation
✦ This is useful if we want to remove a component, we can
move it offscreen then call animateUnlayoutAndWait() to
animate that process then remove the component
✦ It’s assumed that animateUnlayout will be followed by code
to correct the UI after it completes
Animate unlayout is the exact opposite or evil twin of the animate layout method. Animate layout takes layout in an invalid state and returns it to normal layout with an
animation. Animate unlayout takes layout in an invalid state, returns it to normal instantly then animates it into the invalid state. 

So if we want to move a component out of the form with an animation we can set its X position to the screen width. If we call animate layout we will get an effect of the
component sliding into the screen from right to left. If we invoke animate unlayout we get the effect of the component sliding out of the screen.

When we run animateLayout we do something that’s effectively the equivalent of revalidate() so the UI is valid once we finished. With animate unlayout the situation is the
exact opposite. The UI becomes invalid when we are done which means a typical animateUnlayout will be followed by an animate layout or revalidate. The purpose of
animateUnlayout is strictly as a visual effect unlike the its animateLayout counterpart
Variations
© Codename One 2017 all rights reserved
✦ There are several variations of both animate layout &
unlayout
✦ AndWait versions use invokeAndBlock, they are useful for
chaining effects e.g. unlayout and wait followed by layout
✦ Fade versions of the method also add a fade in or fade out
effect respectively
✦ Hierarchy animates a full hierarchy, this is a complicated
proposition and should normally be avoided
There are a few varieties and a bit of noise but layout animations generally fall into the two categories I mentioned

AndWait versions of the methods use invoke and block to help you serialize calls to layout and unlayout. This is useful when you want to create an elaborate effect with
one piece relying on the completion of the next piece

Fade versions of the layout methods can fade components in or out. For unlayout components are faded out and for layout they are faded in. This allows components to
materialize or dematerialize gracefully

The hierarchy related animate methods such as animateHierarchy are very problematic. They recurse into a hierarchy and try to layout all of the elements within but this is
tricky as you can run into a lot of edge cases such as a component that moves from outside the clipping bounds of its parent container.
© Codename One 2017 all rights reserved
In this video I activated slow motion mode which is very useful for debugging animations but for some reason the unlayout effect wasn’t slowed down so you can only
see the deletion briefly and then the animate layout that follows is slow. Lets go over the code that creates this animation
CheckoutForm
quantityButton.addActionListener(e -> {
String sel = quantityButton.getSelectedString();
if(sel == null) {
return;
}
if(sel.equals(PICKER_STRINGS[0])) {
Display.getInstance().callSerially(() -> {
dishContainer.setX(getDisplayWidth());
Container p = dishContainer.getParent();
p.animateUnlayoutAndWait(250, 255);
dishContainer.remove();
p.animateLayoutAndWait(200);
Restaurant.getInstance().cart.get().
dishQuantity.remove(di);
updatePrice();
});
} else {
This entire animation is done in 5 lines of code. Lets go over them one by one. First we set the deleted dish container to the display width which pushes it out of the
visible range with a setX call.
CheckoutForm
quantityButton.addActionListener(e -> {
String sel = quantityButton.getSelectedString();
if(sel == null) {
return;
}
if(sel.equals(PICKER_STRINGS[0])) {
Display.getInstance().callSerially(() -> {
dishContainer.setX(getDisplayWidth());
Container p = dishContainer.getParent();
p.animateUnlayoutAndWait(250, 255);
dishContainer.remove();
p.animateLayoutAndWait(200);
Restaurant.getInstance().cart.get().
dishQuantity.remove(di);
updatePrice();
});
} else {
We now perform animate unlayout and wait. We maintain full opacity which corresponds to the second argument. This animates the removal of the dish from the screen
by sliding it to the right.
CheckoutForm
quantityButton.addActionListener(e -> {
String sel = quantityButton.getSelectedString();
if(sel == null) {
return;
}
if(sel.equals(PICKER_STRINGS[0])) {
Display.getInstance().callSerially(() -> {
dishContainer.setX(getDisplayWidth());
Container p = dishContainer.getParent();
p.animateUnlayoutAndWait(250, 255);
dishContainer.remove();
p.animateLayoutAndWait(200);
Restaurant.getInstance().cart.get().
dishQuantity.remove(di);
updatePrice();
});
} else {
We next remove the component that we animated out. This is important as we are currently in an invalid state but the component is still in the hierarchy.
CheckoutForm
quantityButton.addActionListener(e -> {
String sel = quantityButton.getSelectedString();
if(sel == null) {
return;
}
if(sel.equals(PICKER_STRINGS[0])) {
Display.getInstance().callSerially(() -> {
dishContainer.setX(getDisplayWidth());
Container p = dishContainer.getParent();
p.animateUnlayoutAndWait(250, 255);
dishContainer.remove();
p.animateLayoutAndWait(200);
Restaurant.getInstance().cart.get().
dishQuantity.remove(di);
updatePrice();
});
} else {
Now we can animate the other element into their new place, since the dish was removed there is more available space and we can use it by shifting everything into the
new location

More Related Content

Similar to Animations - Part 2 - Transcript.pdf

Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»
Sigma Software
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animations
Naman Dwivedi
 
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...
Shift Conference
 
Animations - Part 3.pdf
Animations - Part 3.pdfAnimations - Part 3.pdf
Animations - Part 3.pdf
ShaiAlmog1
 
AngularJS Animations
AngularJS AnimationsAngularJS Animations
AngularJS Animations
Eyal Vardi
 
What is the Hero Class in Flutter Development.pptx
What is the Hero Class in Flutter Development.pptxWhat is the Hero Class in Flutter Development.pptx
What is the Hero Class in Flutter Development.pptx
BOSC Tech Labs
 
Motion graphics Terminology
Motion graphics TerminologyMotion graphics Terminology
Motion graphics Terminology
Joe Nasr
 
Unity 3d scripting tutorial
Unity 3d scripting tutorialUnity 3d scripting tutorial
Unity 3d scripting tutorial
Blaž Gregorčič
 
2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial
tutorialsruby
 
2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial
tutorialsruby
 
004
004004
Programming-In-Alice.pptx
Programming-In-Alice.pptxProgramming-In-Alice.pptx
Programming-In-Alice.pptx
Carlos134964
 
Procedure of animation in 3 d autodesk maya tools & techniques
Procedure of animation in 3 d autodesk maya tools & techniquesProcedure of animation in 3 d autodesk maya tools & techniques
Procedure of animation in 3 d autodesk maya tools & techniques
ijcga
 
Unity3d scripting tutorial
Unity3d scripting tutorialUnity3d scripting tutorial
Unity3d scripting tutorial
hungnttg
 
Swift
SwiftSwift
Swift
Larry Ball
 
How to create ui using droid draw
How to create ui using droid drawHow to create ui using droid draw
How to create ui using droid draw
info_zybotech
 
iOS Transition Animations The proper way to do it.pdf
iOS Transition Animations The proper way to do it.pdfiOS Transition Animations The proper way to do it.pdf
iOS Transition Animations The proper way to do it.pdf
SatawareTechnologies4
 
Custom components
Custom componentsCustom components
Custom components
nazmulhossain32
 
Animation in iOS
Animation in iOSAnimation in iOS
Animation in iOS
Alexis Goldstein
 
UILayout plug-in for APEX
UILayout plug-in for APEXUILayout plug-in for APEX
UILayout plug-in for APEX
Tobias Arnhold
 

Similar to Animations - Part 2 - Transcript.pdf (20)

Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animations
 
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...
Shift Remote: Mobile - Introduction to MotionLayout on Android - Denis Fodor ...
 
Animations - Part 3.pdf
Animations - Part 3.pdfAnimations - Part 3.pdf
Animations - Part 3.pdf
 
AngularJS Animations
AngularJS AnimationsAngularJS Animations
AngularJS Animations
 
What is the Hero Class in Flutter Development.pptx
What is the Hero Class in Flutter Development.pptxWhat is the Hero Class in Flutter Development.pptx
What is the Hero Class in Flutter Development.pptx
 
Motion graphics Terminology
Motion graphics TerminologyMotion graphics Terminology
Motion graphics Terminology
 
Unity 3d scripting tutorial
Unity 3d scripting tutorialUnity 3d scripting tutorial
Unity 3d scripting tutorial
 
2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial
 
2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial2%20-%20Scripting%20Tutorial
2%20-%20Scripting%20Tutorial
 
004
004004
004
 
Programming-In-Alice.pptx
Programming-In-Alice.pptxProgramming-In-Alice.pptx
Programming-In-Alice.pptx
 
Procedure of animation in 3 d autodesk maya tools & techniques
Procedure of animation in 3 d autodesk maya tools & techniquesProcedure of animation in 3 d autodesk maya tools & techniques
Procedure of animation in 3 d autodesk maya tools & techniques
 
Unity3d scripting tutorial
Unity3d scripting tutorialUnity3d scripting tutorial
Unity3d scripting tutorial
 
Swift
SwiftSwift
Swift
 
How to create ui using droid draw
How to create ui using droid drawHow to create ui using droid draw
How to create ui using droid draw
 
iOS Transition Animations The proper way to do it.pdf
iOS Transition Animations The proper way to do it.pdfiOS Transition Animations The proper way to do it.pdf
iOS Transition Animations The proper way to do it.pdf
 
Custom components
Custom componentsCustom components
Custom components
 
Animation in iOS
Animation in iOSAnimation in iOS
Animation in iOS
 
UILayout plug-in for APEX
UILayout plug-in for APEXUILayout plug-in for APEX
UILayout plug-in for APEX
 

More from ShaiAlmog1

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
ShaiAlmog1
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
ShaiAlmog1
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
ShaiAlmog1
 

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 

Recently uploaded

Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 

Recently uploaded (20)

Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 

Animations - Part 2 - Transcript.pdf

  • 1. Animations - Part II Layout animations are some of the most important yet easy to use animations in Codename One. They make the application flow feel reactive and responsive.
  • 2. Layout Animation © Codename One 2017 all rights reserved ✦Layout animations rely on the behavior of Codename One which doesn’t implicitly “reflow” components ✦Instead of calling revalidate() we can call animateLayout(int) or equivalent to animate the components to their final correct place/size ✦This is useful for smooth UI’s where components should “flow” into place rather than jump into it At the core of layout animations is the concept of explicit reflow. In Codename One layouts determine the position of components. That means that if you add a new component it will be positioned by the layout, however there is a big caveat. If you add the component after the form was shown it won’t position itself unless you do something like rotate the device which implicitly lays out the component. You need to ask for layout explicitly. You can invoke revalidate to force layout, this is valuable for cases where you can add multiple components. In those cases the layout logic can happen only once and can be much simpler. Layout animation works by animating the validate effect. It takes the components from their previously invalid or incorrect positions and moves them into their real final position. Normally when you add a component you won’t set a size or position to it as those will be determined by the layout manager, but with layout animations this can be useful as you can position a component explicitly and then it will animate from that position. This allows you to create a flow in the UI so components “settle” into place, this serves to draw attention to changes in the UI in most cases
  • 3. Unlayout Animations © Codename One 2017 all rights reserved ✦ animateUnlayout() and equivalent methods do the opposite, they move an element to an “illegal” place from the valid position thru an animation ✦ This is useful if we want to remove a component, we can move it offscreen then call animateUnlayoutAndWait() to animate that process then remove the component ✦ It’s assumed that animateUnlayout will be followed by code to correct the UI after it completes Animate unlayout is the exact opposite or evil twin of the animate layout method. Animate layout takes layout in an invalid state and returns it to normal layout with an animation. Animate unlayout takes layout in an invalid state, returns it to normal instantly then animates it into the invalid state. So if we want to move a component out of the form with an animation we can set its X position to the screen width. If we call animate layout we will get an effect of the component sliding into the screen from right to left. If we invoke animate unlayout we get the effect of the component sliding out of the screen. When we run animateLayout we do something that’s effectively the equivalent of revalidate() so the UI is valid once we finished. With animate unlayout the situation is the exact opposite. The UI becomes invalid when we are done which means a typical animateUnlayout will be followed by an animate layout or revalidate. The purpose of animateUnlayout is strictly as a visual effect unlike the its animateLayout counterpart
  • 4. Variations © Codename One 2017 all rights reserved ✦ There are several variations of both animate layout & unlayout ✦ AndWait versions use invokeAndBlock, they are useful for chaining effects e.g. unlayout and wait followed by layout ✦ Fade versions of the method also add a fade in or fade out effect respectively ✦ Hierarchy animates a full hierarchy, this is a complicated proposition and should normally be avoided There are a few varieties and a bit of noise but layout animations generally fall into the two categories I mentioned AndWait versions of the methods use invoke and block to help you serialize calls to layout and unlayout. This is useful when you want to create an elaborate effect with one piece relying on the completion of the next piece Fade versions of the layout methods can fade components in or out. For unlayout components are faded out and for layout they are faded in. This allows components to materialize or dematerialize gracefully The hierarchy related animate methods such as animateHierarchy are very problematic. They recurse into a hierarchy and try to layout all of the elements within but this is tricky as you can run into a lot of edge cases such as a component that moves from outside the clipping bounds of its parent container.
  • 5. © Codename One 2017 all rights reserved In this video I activated slow motion mode which is very useful for debugging animations but for some reason the unlayout effect wasn’t slowed down so you can only see the deletion briefly and then the animate layout that follows is slow. Lets go over the code that creates this animation
  • 6. CheckoutForm quantityButton.addActionListener(e -> { String sel = quantityButton.getSelectedString(); if(sel == null) { return; } if(sel.equals(PICKER_STRINGS[0])) { Display.getInstance().callSerially(() -> { dishContainer.setX(getDisplayWidth()); Container p = dishContainer.getParent(); p.animateUnlayoutAndWait(250, 255); dishContainer.remove(); p.animateLayoutAndWait(200); Restaurant.getInstance().cart.get(). dishQuantity.remove(di); updatePrice(); }); } else { This entire animation is done in 5 lines of code. Lets go over them one by one. First we set the deleted dish container to the display width which pushes it out of the visible range with a setX call.
  • 7. CheckoutForm quantityButton.addActionListener(e -> { String sel = quantityButton.getSelectedString(); if(sel == null) { return; } if(sel.equals(PICKER_STRINGS[0])) { Display.getInstance().callSerially(() -> { dishContainer.setX(getDisplayWidth()); Container p = dishContainer.getParent(); p.animateUnlayoutAndWait(250, 255); dishContainer.remove(); p.animateLayoutAndWait(200); Restaurant.getInstance().cart.get(). dishQuantity.remove(di); updatePrice(); }); } else { We now perform animate unlayout and wait. We maintain full opacity which corresponds to the second argument. This animates the removal of the dish from the screen by sliding it to the right.
  • 8. CheckoutForm quantityButton.addActionListener(e -> { String sel = quantityButton.getSelectedString(); if(sel == null) { return; } if(sel.equals(PICKER_STRINGS[0])) { Display.getInstance().callSerially(() -> { dishContainer.setX(getDisplayWidth()); Container p = dishContainer.getParent(); p.animateUnlayoutAndWait(250, 255); dishContainer.remove(); p.animateLayoutAndWait(200); Restaurant.getInstance().cart.get(). dishQuantity.remove(di); updatePrice(); }); } else { We next remove the component that we animated out. This is important as we are currently in an invalid state but the component is still in the hierarchy.
  • 9. CheckoutForm quantityButton.addActionListener(e -> { String sel = quantityButton.getSelectedString(); if(sel == null) { return; } if(sel.equals(PICKER_STRINGS[0])) { Display.getInstance().callSerially(() -> { dishContainer.setX(getDisplayWidth()); Container p = dishContainer.getParent(); p.animateUnlayoutAndWait(250, 255); dishContainer.remove(); p.animateLayoutAndWait(200); Restaurant.getInstance().cart.get(). dishQuantity.remove(di); updatePrice(); }); } else { Now we can animate the other element into their new place, since the dish was removed there is more available space and we can use it by shifting everything into the new location