Skip to content

Commit 5b9e8d1

Browse files
authored
cleanup LayoutAnimation example (#494)
1 parent 8c56a64 commit 5b9e8d1

1 file changed

Lines changed: 27 additions & 28 deletions

File tree

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

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
id: apis/LayoutAnimation
33
title: LayoutAnimation
4-
wip: false
54
---
65

76
`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.
@@ -19,7 +18,6 @@ configureNext(layoutAnimationConfig)
1918
configureNextWithEndCallback(layoutAnimationConfig, callback)
2019
```
2120

22-
2321
## Types
2422

2523
`layoutAnimationConfig` can be created with the `layoutAnimationConfig` constructor
@@ -52,7 +50,6 @@ create:
5250
```
5351

5452

55-
5653
`animationConfig` can in turn be created with the `animationConfig` constructor
5754

5855
```reason
@@ -76,8 +73,6 @@ animationConfig:
7673
)
7774
```
7875

79-
80-
8176
## Presets
8277

8378
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
@@ -92,8 +87,6 @@ LayoutAnimation.spring()
9287
9388
```
9489

95-
96-
9790
## Example
9891

9992
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).
@@ -109,6 +102,14 @@ type state = {register: bool};
109102
type action =
110103
| ToggleRegister;
111104
105+
let styles =
106+
Style.(
107+
StyleSheet.create({
108+
"container": style(~flex=1., ~flexDirection=`column, ()),
109+
"screen": style(~width=pt(windowWidth), ()),
110+
})
111+
);
112+
112113
[@react.component]
113114
let make = () => {
114115
let (state, dispatch) =
@@ -130,28 +131,26 @@ let make = () => {
130131
{register: false},
131132
);
132133
133-
<View style={Style.style(~flex=1., ~flexDirection=`column, ())}>
134+
<View style=styles##container>
134135
<View
135-
style={Style.style(
136-
~flex=1.,
137-
~width=Style.pt(2.0 *. windowWidth),
138-
~left=
139-
Style.pt(
140-
if (state.register) {
141-
0.;
142-
} else {
143-
0. -. windowWidth;
144-
},
145-
),
146-
~flexDirection=`row,
147-
(),
148-
)}>
149-
<View style={Style.style(~width=Style.pt(windowWidth), ())}>
150-
<Register />
151-
</View>
152-
<View style={Style.style(~width=Style.pt(windowWidth), ())}>
153-
<Login />
154-
</View>
136+
style=Style.(
137+
{style(
138+
~flex=1.,
139+
~width=pt(2.0 *. windowWidth),
140+
~left=
141+
pt(
142+
if (state.register) {
143+
0.;
144+
} else {
145+
0. -. windowWidth;
146+
},
147+
),
148+
~flexDirection=`row,
149+
(),
150+
)}
151+
)>
152+
<View style=styles##screen> <Register /> </View>
153+
<View style=styles##screen> <Login /> </View>
155154
</View>
156155
<Button onPress={_ => dispatch(ToggleRegister)} title={js|Toggle|js} />
157156
</View>;

0 commit comments

Comments
 (0)