|
@@ -1,40 +1,140 @@
|
1
|
|
-# Animations (Preview API)
|
|
1
|
+# Animations
|
2
|
2
|
|
|
3
|
+## Shared element transition
|
|
4
|
+
|
|
5
|
+Shared element transitions allows us to provide visual continuity when navigating between destinations. It also
|
|
6
|
+focuses the user's attention on a significant element which gives the user better context when transitioning to
|
|
7
|
+another destination.
|
|
8
|
+
|
|
9
|
+!> At the moment, the transition is available on iOS for push and pop while on Android it's available only for push commands.
|
|
10
|
+We will soon add parity and expand the supported commands to show/dismiss modal and changing BottomTabs.
|
|
11
|
+
|
|
12
|
+### Example
|
|
13
|
+In the sections below we will use the following example from the playground app:
|
|
14
|
+* [Source screen](https://github.com/wix/react-native-navigation/blob/master/playground/src/screens/sharedElementTransition/CocktailsList.js)
|
|
15
|
+* [Destination screen](https://github.com/wix/react-native-navigation/blob/master/playground/src/screens/sharedElementTransition/CocktailDetailsScreen.js)
|
|
16
|
+
|
|
17
|
+<img src="https://github.com/wix/react-native-navigation/blob/master/docs/_images/sharedElement.gif?raw=true"/>
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+#### Transition breakdown
|
|
23
|
+Four elements are animated in this example.
|
|
24
|
+
|
|
25
|
+* **image** - the item's image is animated to the next screen.
|
|
26
|
+ * Image scale (resizeMode)
|
|
27
|
+ * position on screen
|
|
28
|
+
|
|
29
|
+* **image background** - each item has a "shadow" view which transitions to the next screen and turns into a colorful header.
|
|
30
|
+ * scale
|
|
31
|
+ * position on screen
|
|
32
|
+
|
|
33
|
+* **title** - the item's title is animated to the next screen.
|
|
34
|
+ * font size
|
|
35
|
+ * font color
|
|
36
|
+ * position on screen
|
|
37
|
+
|
|
38
|
+* **Description** - the item's description in the destination screen.
|
|
39
|
+ * fade-in
|
|
40
|
+ * translation y
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+### API
|
|
44
|
+#### Step 1 - set a nativeID prop to elements in the source screen
|
|
45
|
+In order for RNN to be able to detect the corresponding native views of the elements,
|
|
46
|
+each element must include a unique `nativeID` prop.
|
|
47
|
+
|
|
48
|
+```jsx
|
|
49
|
+<Image
|
|
50
|
+ source={item.image}
|
|
51
|
+ nativeID={`image${item.id}`}
|
|
52
|
+ style={styles.image}
|
|
53
|
+ resizeMode={'contain'} />
|
|
54
|
+```
|
|
55
|
+
|
|
56
|
+#### Step 2 - set a nativeID prop to elements in the destination screen
|
3
|
57
|
|
4
|
|
-## Shared element
|
5
|
|
-In order to animate shared element between two screens you need to wrap your element with `Navigation.Element` in both screens with different `elementId`.
|
6
|
|
-For example, to animate `Image` element wrap it in your first screen like this:
|
7
|
58
|
```jsx
|
8
|
|
-<Navigation.Element elementId='image1'>
|
9
|
|
- <Image source={require('img/icon.png')} />
|
10
|
|
-</Navigation.Element>
|
|
59
|
+<Image
|
|
60
|
+ source={this.props.image}
|
|
61
|
+ nativeID={`image${this.props.id}Dest`}
|
|
62
|
+ style={styles.image} />
|
11
|
63
|
```
|
12
|
64
|
|
13
|
|
-And in your second screen:
|
|
65
|
+#### Step 3 - Declare the shared element animation when pushing the screen
|
|
66
|
+
|
14
|
67
|
```jsx
|
15
|
|
-<Navigation.Element elementId='image2'>
|
16
|
|
- <Image source={require('img/icon.png')} />
|
17
|
|
-</Navigation.Element>
|
|
68
|
+Navigation.push(this.props.componentId, {
|
|
69
|
+ component: {
|
|
70
|
+ name: Screens.CocktailDetailsScreen,
|
|
71
|
+ passProps: { ...item },
|
|
72
|
+ options: {
|
|
73
|
+ animations: {
|
|
74
|
+ push: {
|
|
75
|
+ sharedElementTransitions: [
|
|
76
|
+ {
|
|
77
|
+ fromId: `image${item.id}`,
|
|
78
|
+ toId: `image${item.id}Dest`
|
|
79
|
+ }
|
|
80
|
+ ]
|
|
81
|
+ }
|
|
82
|
+ }
|
|
83
|
+ }
|
|
84
|
+ }
|
|
85
|
+});
|
18
|
86
|
```
|
19
|
87
|
|
20
|
|
-Then call `push` or `showModal` with `customTransition.animations` options:
|
21
|
|
-```js
|
|
88
|
+## Element Transitions
|
|
89
|
+Element transitions allow you to animate elements during shared element transitions.
|
|
90
|
+
|
|
91
|
+### Example
|
|
92
|
+In the sections below we will use the following example from the playground app:
|
|
93
|
+* [Source screen](https://github.com/wix/react-native-navigation/blob/master/playground/src/screens/sharedElementTransition/CocktailsList.js)
|
|
94
|
+* [Destination screen](https://github.com/wix/react-native-navigation/blob/master/playground/src/screens/sharedElementTransition/CocktailDetailsScreen.js)
|
|
95
|
+
|
|
96
|
+### API
|
|
97
|
+#### Step 1 - set a nativeID prop to elements either source or destination screens
|
|
98
|
+
|
|
99
|
+```jsx
|
|
100
|
+<Text
|
|
101
|
+ nativeID='description'
|
|
102
|
+ style={styles.description}>
|
|
103
|
+ {this.props.description}
|
|
104
|
+</Text>
|
|
105
|
+```
|
|
106
|
+
|
|
107
|
+#### Step 2 - Declare the element animation when pushing the screen
|
|
108
|
+
|
|
109
|
+```jsx
|
22
|
110
|
Navigation.push(this.props.componentId, {
|
23
|
111
|
component: {
|
24
|
|
- name: 'second.screen',
|
|
112
|
+ name: Screens.CocktailDetailsScreen,
|
|
113
|
+ passProps: { ...item },
|
25
|
114
|
options: {
|
26
|
|
- customTransition: {
|
27
|
|
- animations: [
|
28
|
|
- { type: 'sharedElement', fromId: 'image1', toId: 'image2', startDelay: 0, springVelocity: 0.2, duration: 0.5 }
|
29
|
|
- ],
|
30
|
|
- duration: 0.8
|
|
115
|
+ animations: {
|
|
116
|
+ push: {
|
|
117
|
+ elementTransitions: [
|
|
118
|
+ {
|
|
119
|
+ id: 'description',
|
|
120
|
+ alpha: {
|
|
121
|
+ from: 0, // We don't declare 'to' value as that is the element's current alpha value, here we're essentially animating from 0 to 1
|
|
122
|
+ duration: SHORT_DURATION
|
|
123
|
+ },
|
|
124
|
+ translationY: {
|
|
125
|
+ from: 16, // Animate translationY from 16dp to 0dp
|
|
126
|
+ duration: SHORT_DURATION
|
|
127
|
+ }
|
|
128
|
+ }
|
|
129
|
+ ]
|
|
130
|
+ }
|
31
|
131
|
}
|
32
|
132
|
}
|
33
|
133
|
}
|
34
|
134
|
});
|
35
|
135
|
```
|
36
|
136
|
|
37
|
|
-## Peek and Pop (iOS 11.4+)
|
|
137
|
+## Peek and Pop (iOS 11.4+) (Preview API)
|
38
|
138
|
|
39
|
139
|
react-native-navigation supports the [Peek and pop](
|
40
|
140
|
https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/Adopting3DTouchOniPhone/#//apple_ref/doc/uid/TP40016543-CH1-SW3) feature in iOS 11.4 and newer.
|