Skip to content

Commit 11b715f

Browse files
committed
Fix android example
1 parent 85105fd commit 11b715f

File tree

1 file changed

+69
-61
lines changed

1 file changed

+69
-61
lines changed

examples/Basic/index.js

Lines changed: 69 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
Image,
1515
View,
1616
Dimensions,
17+
Platform,
1718
} from 'react-native';
1819
import SortableList from 'react-native-sortable-list';
1920

@@ -82,64 +83,49 @@ class Basic extends Component {
8283
}
8384

8485
class Row extends Component {
85-
state = {
86-
style: {
87-
shadowRadius: new Animated.Value(2),
88-
transform: [{scale: new Animated.Value(1)}],
89-
}
90-
}
9186

92-
componentWillReceiveProps(nextProps) {
93-
if (this.props.active !== nextProps.active) {
94-
if (nextProps.active) {
95-
this.startActivationAnimation();
96-
} else {
97-
this.startDeactivationAnimation();
87+
constructor(props) {
88+
super(props);
89+
90+
this._active = new Animated.Value(0);
91+
this._style = Platform.OS === 'ios'
92+
? {
93+
shadowRadius: this._active.interpolate({
94+
inputRange: [0, 1],
95+
outputRange: [2, 10],
96+
}),
97+
transform: [{
98+
scale: this._active.interpolate({
99+
inputRange: [0, 1],
100+
outputRange: [1, 1.1],
101+
}),
102+
}],
98103
}
99-
}
104+
: {
105+
backgroundColor: this._active.interpolate({
106+
inputRange: [0, 1],
107+
outputRange: ['#fff', '#e9e9e9'],
108+
}),
109+
};
100110
}
101111

102-
startActivationAnimation = () => {
103-
const {style} = this.state;
104-
105-
Animated.parallel([
106-
Animated.timing(style.transform[0].scale, {
107-
duration: 100,
108-
easing: Easing.out(Easing.quad),
109-
toValue: 1.1
110-
}),
111-
Animated.timing(style.shadowRadius, {
112-
duration: 100,
113-
easing: Easing.out(Easing.quad),
114-
toValue: 10
115-
}),
116-
]).start();
117-
};
118-
119-
startDeactivationAnimation = () => {
120-
const {style} = this.state;
121-
122-
Animated.parallel([
123-
Animated.timing(style.transform[0].scale, {
124-
duration: 100,
125-
easing: Easing.out(Easing.quad),
126-
toValue: 1
127-
}),
128-
Animated.timing(style.shadowRadius, {
112+
componentWillReceiveProps(nextProps) {
113+
if (this.props.active !== nextProps.active) {
114+
Animated.timing(this._active, {
129115
duration: 100,
130116
easing: Easing.out(Easing.quad),
131-
toValue: 2
132-
}),
133-
]).start();
134-
};
117+
toValue: Number(nextProps.active),
118+
}).start();
119+
}
120+
}
135121

136122
render() {
137123
const {data, active} = this.props;
138124

139125
return (
140126
<Animated.View style={[
141127
styles.row,
142-
this.state.style,
128+
this._style,
143129
]}>
144130
<Image source={{uri: data.image}} style={styles.image} />
145131
<Text style={styles.text}>{data.text}</Text>
@@ -153,8 +139,18 @@ const styles = StyleSheet.create({
153139
flex: 1,
154140
justifyContent: 'center',
155141
alignItems: 'center',
156-
backgroundColor: '#eee',
157-
paddingTop: 60,
142+
143+
...Platform.select({
144+
ios: {
145+
backgroundColor: '#eee',
146+
paddingTop: 60,
147+
},
148+
149+
android: {
150+
backgroundColor: '#fff',
151+
paddingTop: 0,
152+
},
153+
}),
158154
},
159155

160156
list: {
@@ -163,35 +159,47 @@ const styles = StyleSheet.create({
163159

164160
contentContainer: {
165161
width: window.width,
166-
paddingHorizontal: 30,
162+
paddingHorizontal: Platform.OS === 'ios' ? 30 : 0,
167163
},
168164

169165
row: {
170166
flexDirection: 'row',
171167
alignItems: 'center',
172-
backgroundColor: 'white',
168+
backgroundColor: '#fff',
173169
padding: 16,
174-
marginVertical: 5,
175-
height: 90,
176-
width: window.width - 30 * 2,
177-
borderRadius: 4,
178-
shadowColor: 'rgba(0,0,0,0.2)',
179-
shadowOpacity: 1,
180-
shadowOffset: {height: 2, width: 2},
181-
shadowRadius: 2,
170+
171+
height: 80,
172+
173+
...Platform.select({
174+
ios: {
175+
width: window.width - 30 * 2,
176+
marginVertical: 5,
177+
borderRadius: 4,
178+
shadowColor: 'rgba(0,0,0,0.2)',
179+
shadowOpacity: 1,
180+
shadowOffset: {height: 2, width: 2},
181+
shadowRadius: 2,
182+
},
183+
184+
android: {
185+
width: window.width,
186+
borderTopWidth: StyleSheet.hairlineWidth,
187+
borderBottomWidth: StyleSheet.hairlineWidth,
188+
borderColor: '#e5e5e5',
189+
},
190+
})
182191
},
183192

184193
image: {
185-
width: 60,
186-
height: 60,
194+
width: 50,
195+
height: 50,
187196
marginRight: 30,
188-
borderRadius: 30,
197+
borderRadius: 25,
189198
},
190199

191200
text: {
192201
fontSize: 24,
193202
},
194-
195203
});
196204

197205
AppRegistry.registerComponent('Basic', () => Basic);

0 commit comments

Comments
 (0)