Skip to content

Commit 9c76f21

Browse files
joshuapintergitim
authored andcommitted
Animate elevation when card is picked up.
Had to adjust a tonne of the styling to make this work and look good. Essentially, on iOS the shadows are just cast across any boundaries of the element, but with Android, you need to provide padding (or margin) for those shadows and scaling to come through. So, instead of having a horizontal margin on the entire SortableList, I set the horizontal margin on the rows themselves. This gives plenty of room to conduct those animations and shadows. I also added a similar scaling transform for Android, except a little smaller so we can get more of the shadow from elevation in. I tested out different elevation ranges and this looks to be about right.
1 parent f568a26 commit 9c76f21

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

examples/Basic/index.js

+34-22
Original file line numberDiff line numberDiff line change
@@ -89,25 +89,36 @@ class Row extends Component {
8989
super(props);
9090

9191
this._active = new Animated.Value(0);
92-
this._style = Platform.OS === 'ios'
93-
? {
94-
shadowRadius: this._active.interpolate({
95-
inputRange: [0, 1],
96-
outputRange: [2, 10],
97-
}),
98-
transform: [{
99-
scale: this._active.interpolate({
92+
93+
this._style = {
94+
...Platform.select({
95+
ios: {
96+
transform: [{
97+
scale: this._active.interpolate({
98+
inputRange: [0, 1],
99+
outputRange: [1, 1.1],
100+
}),
101+
}],
102+
shadowRadius: this._active.interpolate({
100103
inputRange: [0, 1],
101-
outputRange: [1, 1.1],
104+
outputRange: [2, 10],
102105
}),
103-
}],
104-
}
105-
: {
106-
backgroundColor: this._active.interpolate({
107-
inputRange: [0, 1],
108-
outputRange: ['#fff', '#e9e9e9'],
109-
}),
110-
};
106+
},
107+
108+
android: {
109+
transform: [{
110+
scale: this._active.interpolate({
111+
inputRange: [0, 1],
112+
outputRange: [1, 1.07],
113+
}),
114+
}],
115+
elevation: this._active.interpolate({
116+
inputRange: [0, 1],
117+
outputRange: [2, 6],
118+
}),
119+
},
120+
})
121+
};
111122
}
112123

113124
componentWillReceiveProps(nextProps) {
@@ -168,7 +179,7 @@ const styles = StyleSheet.create({
168179
},
169180

170181
android: {
171-
paddingHorizontal: 20,
182+
paddingHorizontal: 0,
172183
}
173184
})
174185
},
@@ -180,7 +191,8 @@ const styles = StyleSheet.create({
180191
padding: 16,
181192
height: 80,
182193
flex: 1,
183-
marginVertical: 5,
194+
marginTop: 7,
195+
marginBottom: 12,
184196
borderRadius: 4,
185197

186198

@@ -194,9 +206,9 @@ const styles = StyleSheet.create({
194206
},
195207

196208
android: {
197-
width: window.width - 25 * 2,
198-
elevation: 2,
199-
marginHorizontal: 5,
209+
width: window.width - 30 * 2,
210+
elevation: 0,
211+
marginHorizontal: 30,
200212
},
201213
})
202214
},

0 commit comments

Comments
 (0)