Skip to content

Commit 1f872f5

Browse files
committed
Adjust animation guide includes and inline LazyValue snippet
1 parent c1f3944 commit 1f872f5

File tree

2 files changed

+30
-37
lines changed

2 files changed

+30
-37
lines changed

docs/demos/common/src/main/java/com/codenameone/developerguide/animations/LazyValueDocSnippet.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/developer-guide/Animations.asciidoc

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This sort of behavior creates a special case where setting the size/position mak
3535

3636
[source,java]
3737
----
38-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/LayoutAnimationsDemo.java[tag=layoutAnimations,indent=0]
38+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/LayoutAnimationsDemo.java[tag=layoutAnimations,indent=-8]
3939
----
4040

4141
There are a couple of things that you should notice about this example:
@@ -68,7 +68,7 @@ WARNING: An unlayout animation always leaves the container in an invalidated sta
6868
[[animateUnlayutSampleCode]]
6969
[source,java]
7070
----
71-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/UnlayoutAnimationsDemo.java[tag=unlayoutAnimation,indent=0]
71+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/UnlayoutAnimationsDemo.java[tag=unlayoutAnimation,indent=-8]
7272
----
7373

7474
You will notice some similarities with the unlayout animation but the differences represent the exact opposite of the layout animation:
@@ -90,7 +90,7 @@ This functionality might be undesirable which is why there is a version of the `
9090

9191
[source,java]
9292
----
93-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/HiddenComponentDemo.java[tag=hiddenComponent,indent=0]
93+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/HiddenComponentDemo.java[tag=hiddenComponent,indent=-8]
9494
----
9595

9696
TIP: Notice that the code above uses `setVisible()`, which shouldn't be confused with `setHidden`. `setVisible()` just toggles the visibility of the component it would still occupy the same amount of space
@@ -111,7 +111,7 @@ The `AndWait` variant blocks the calling thread until the animation completes. T
111111

112112
[source,java]
113113
----
114-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/AnimationSynchronicityDemo.java[tag=animationSequence,indent=0]
114+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/AnimationSynchronicityDemo.java[tag=animationSequence,indent=-8]
115115
----
116116

117117
First the UI goes thru an "unlayout" animation, once that completes the layout itself is performed.
@@ -132,7 +132,7 @@ The callback variant is similar to the `invokeAndBlock` variant but uses a more
132132

133133
[source,java]
134134
----
135-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/UnlayoutAnimationsDemo.java[tag=unlayoutCallback,indent=0]
135+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/UnlayoutAnimationsDemo.java[tag=unlayoutCallback,indent=-8]
136136
----
137137

138138
===== Animation Fade and Hierarchy
@@ -145,7 +145,7 @@ Some animate layout methods are hierarchy based. They work just like the regular
145145

146146
[source,java]
147147
----
148-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/HierarchyAnimationDemo.java[tag=hierarchyAnimation,indent=0]
148+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/HierarchyAnimationDemo.java[tag=hierarchyAnimation,indent=-8]
149149
----
150150

151151
The `demoComponents` `Vector` contains components from separate containers and this code would not work with a simple animate layout.
@@ -159,7 +159,7 @@ This effectively prevents two animations from mutating the UI in parallel so we
159159

160160
[source,java]
161161
----
162-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/AnimationManagerDemo.java[tag=animationManagerProblem,indent=0]
162+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/AnimationManagerDemo.java[tag=animationManagerProblem,indent=-8]
163163
----
164164

165165
The reason this happens is that the second remove gets postponed to the end of the animation so it won't break the animation. This works for remove and add operations on a https://www.codenameone.com/javadoc/com/codename1/ui/Container.html[Container] as well as other animations.
@@ -168,7 +168,7 @@ The simple *yet problematic* fix would be:
168168

169169
[source,java]
170170
----
171-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/AnimationManagerDemo.java[tag=animationManagerWait,indent=0]
171+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/AnimationManagerDemo.java[tag=animationManagerWait,indent=-8]
172172
----
173173

174174
So why that might still fail?
@@ -185,7 +185,7 @@ We can flush the animation queue and run synchronously after all the animations
185185

186186
[source,java]
187187
----
188-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/AnimationManagerDemo.java[tag=animationManagerFlush,indent=0]
188+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/AnimationManagerDemo.java[tag=animationManagerFlush,indent=-8]
189189
----
190190

191191
=== Low Level Animations
@@ -206,12 +206,12 @@ E.g. you can add additional animation logic using code like this:
206206

207207
[source,java]
208208
----
209-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/LowLevelAnimationDemo.java[tag=registerAnimated,indent=0]
209+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/LowLevelAnimationDemo.java[tag=registerAnimated,indent=-8]
210210
----
211211

212212
[source,java]
213213
----
214-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/LowLevelAnimationDemo.java[tag=lowLevelAnimate,indent=0]
214+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/LowLevelAnimationDemo.java[tag=lowLevelAnimate,indent=-8]
215215
----
216216

217217
==== Why Not Just Write Code In Paint?
@@ -273,7 +273,7 @@ To apply a transition to a component we can just use the `Container.replace()` m
273273

274274
[source,java]
275275
----
276-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/ReplaceTransitionDemo.java[tag=replaceTransition,indent=0]
276+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/ReplaceTransitionDemo.java[tag=replaceTransition,indent=-8]
277277
----
278278

279279
TIP: Replace even works when you have a layout constraint in place e.g. replacing a component in a border layout will do the "right thing". However, some layouts such as `TableLayout` might be tricky in such cases so we recommend wrapping a potentially replaceable `Component` in a border layout and replacing the content.
@@ -293,7 +293,7 @@ The code below demonstrates the usage of all the main transitions:
293293

294294
[source,java]
295295
----
296-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/SlideTransitionsDemo.java[tag=slideTransitions,indent=0]
296+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/SlideTransitionsDemo.java[tag=slideTransitions,indent=-8]
297297
----
298298

299299

@@ -340,7 +340,7 @@ NOTE: The code below manipulates styles and look. This is done to make the code
340340

341341
[source,java]
342342
----
343-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/BubbleTransitionDemo.java[tag=bubbleTransition,indent=0]
343+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/BubbleTransitionDemo.java[tag=bubbleTransition,indent=-8]
344344
----
345345

346346
.Bubble transition converting a circular button to a Dialog
@@ -371,7 +371,7 @@ forms so the transition will be able to find them.
371371

372372
[source,java]
373373
----
374-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/MorphTransitionDemo.java[tag=morphTransition,indent=0]
374+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/MorphTransitionDemo.java[tag=morphTransition,indent=-8]
375375
----
376376

377377
==== SwipeBackSupport
@@ -380,14 +380,26 @@ iOS7+ allows swiping back one form to the previous form, Codenmae One has an API
380380

381381
[source,java]
382382
----
383-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/SwipeBackSupportDemo.java[tag=swipeBackBind,indent=0]
383+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/SwipeBackSupportDemo.java[tag=swipeBackBind,indent=-8]
384384
----
385385

386386
That one command will enable swiping back from `currentForm`. https://www.codenameone.com/javadoc/com/codename1/util/LazyValue.html[LazyValue] allows us to pass a value lazily:
387387

388388
[source,java]
389389
----
390-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/LazyValueDocSnippet.java[tag=lazyValueInterface,indent=0]
390+
/**
391+
* Useful when passing a value that might not exist to a function, e.g. when we
392+
* pass a form that we might need to construct dynamically later on.
393+
*/
394+
public interface LazyValue<T> {
395+
/**
396+
* Returns the actual value.
397+
*
398+
* @param args optional arguments for the creation of the lazy value
399+
* @return the value
400+
*/
401+
T get(Object... args);
402+
}
391403
----
392404

393405
This effectively allows us to pass a form and only create it as necessary (e.g. for a GUI builder app we don't
@@ -398,5 +410,5 @@ The code below should work for the transition sample above. Notice that this API
398410

399411
[source,java]
400412
----
401-
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/SwipeBackSupportDemo.java[tag=swipeBackBindExample,indent=0]
413+
include::../demos/common/src/main/java/com/codenameone/developerguide/animations/SwipeBackSupportDemo.java[tag=swipeBackBindExample,indent=-8]
402414
----

0 commit comments

Comments
 (0)