Skip to content

Commit ff476f6

Browse files
sgnyMoOx
authored andcommitted
LayoutAnimation: Document step to enable it on Android (#499)
1 parent 048c062 commit ff476f6

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

reason-react-native/src/apis/LayoutAnimation.md

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,47 @@ id: apis/LayoutAnimation
33
title: LayoutAnimation
44
---
55

6-
`LayoutAnimation` API offers a simpler alternative to `Animated` API. Instead of directly manipulating values for various style props, it suffices to specify the animation to be run before the next render. Specification of the animation should happen in the reducer, before `state` is updated.
6+
`LayoutAnimation` API offers a simpler alternative to `Animated` API. Instead of
7+
directly manipulating values for various style props, it suffices to specify the
8+
animation to be run before the next render. Specification of the animation
9+
should happen in the reducer, before `state` is updated.
10+
11+
`LayoutAnimation` is still experimental on Android and needs to be explicitly
12+
enabled with the `UIManager` method `setLayoutAnimationEnabledExperimental`.
13+
However, as that method should be removed when `LayoutAnimation` is no longer
14+
experimental, the external declaration for it wraps its type in `option` to
15+
avoid runtime errors when that happens. `LayoutAnimation` may be enabled, if it
16+
is not already enabled by default, by means of a statement such as:
17+
18+
```reason
19+
switch (UIManager.setLayoutAnimationEnabledExperimental) {
20+
| None => ()
21+
| Some(setEnabled) => setEnabled(true)
22+
};
23+
```
724

825
## Methods
926

10-
- `configureNext` is the method to specify the animation, takes an argument of type `layoutAnimationConfig`.
27+
- `configureNext` is the method to specify the animation, takes an argument of
28+
type `layoutAnimationConfig`.
1129

1230
```reason
1331
configureNext(layoutAnimationConfig)
1432
```
1533

16-
- `configureNextWithEndCallback` is a convenience function, which allows specification of a callback function (of type `unit => unit`) to be run after the animation, in addition to `layoutAnimationConfig`.
34+
- `configureNextWithEndCallback` is a convenience function, which allows
35+
specification of a callback function (of type `unit => unit`) to be run after
36+
the animation, in addition to `layoutAnimationConfig`.
37+
1738
```reason
1839
configureNextWithEndCallback(layoutAnimationConfig, callback)
1940
```
2041

2142
## Types
2243

23-
`layoutAnimationConfig` can be created with the `layoutAnimationConfig` constructor
44+
`layoutAnimationConfig` can be created with the `layoutAnimationConfig`
45+
constructor
46+
2447
```reason
2548
layoutAnimationConfig:
2649
(
@@ -31,6 +54,7 @@ layoutAnimationConfig:
3154
unit
3255
)
3356
```
57+
3458
or by means of the helper function `create`
3559

3660
```reason
@@ -49,7 +73,6 @@ create:
4973
)
5074
```
5175

52-
5376
`animationConfig` can in turn be created with the `animationConfig` constructor
5477

5578
```reason
@@ -75,11 +98,15 @@ animationConfig:
7598

7699
## Presets
77100

78-
There are presets for `linear`, `spring` and `easeInEaseOut` transitions which allow a very straightforward way to setup animation. Presets may either be passed as ready-made `layoutAnimationConfig` to `configureNext` and `configureNextWithEndCallback` as below
101+
There are presets for `linear`, `spring` and `easeInEaseOut` transitions which
102+
allow a very straightforward way to setup animation. Presets may either be
103+
passed as ready-made `layoutAnimationConfig` to `configureNext` and
104+
`configureNextWithEndCallback` as below
79105

80106
```reason
81107
LayoutAnimation.configureNext(LayoutAnimation.Presets.spring)
82108
```
109+
83110
or equivalently as already passed to `configureNext` as
84111

85112
```reason
@@ -89,8 +116,9 @@ LayoutAnimation.spring()
89116

90117
## Example
91118

92-
The example below illustrates animated transition (`spring`) between two views, such as registration and login forms. Animation is specified in the reducer, as below. Making use of `presets` is also illustrated (commented out).
93-
119+
The example below illustrates animated transition (`spring`) between two views,
120+
such as registration and login forms. Animation is specified in the reducer, as
121+
below, before state is returned.
94122

95123
```reason
96124
open ReactNative;
@@ -157,11 +185,15 @@ let make = () => {
157185
};
158186
```
159187

160-
Above animation specification is that of the `spring` preset. Accordingly, the animation could have been specified as
188+
Note that above animation specification is that of the `spring` preset.
189+
Accordingly, the animation could have been specified as
190+
161191
```reason
162192
LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);
163193
```
194+
164195
or equivalently as
196+
165197
```reason
166198
LayoutAnimation.spring();
167199
```

0 commit comments

Comments
 (0)