Skip to content

Commit b5703ce

Browse files
committed
Update value on animation end to avoid flickering
1 parent 0f9bc1f commit b5703ce

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/components/dropdown/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export default class Dropdown extends PureComponent {
168168

169169
this.keyExtractor = this.keyExtractor.bind(this);
170170

171-
this.blur = this.onClose;
171+
this.blur = () => this.onClose();
172172
this.focus = this.onPress;
173173

174174
let { value } = this.props;
@@ -309,7 +309,7 @@ export default class Dropdown extends PureComponent {
309309
});
310310
}
311311

312-
onClose() {
312+
onClose(value = this.state.value) {
313313
let { onBlur, animationDuration } = this.props;
314314
let { opacity } = this.state;
315315

@@ -327,7 +327,7 @@ export default class Dropdown extends PureComponent {
327327
}
328328

329329
if (this.mounted) {
330-
this.setState({ modal: false });
330+
this.setState({ value, modal: false });
331331
}
332332
});
333333
}
@@ -336,13 +336,11 @@ export default class Dropdown extends PureComponent {
336336
let { data, valueExtractor, onChangeText, animationDuration } = this.props;
337337
let value = valueExtractor(data[index], index);
338338

339-
this.setState({ value });
340-
341339
if ('function' === typeof onChangeText) {
342340
onChangeText(value, index, data);
343341
}
344342

345-
setTimeout(this.onClose, animationDuration);
343+
setTimeout(() => this.onClose(value), animationDuration);
346344
}
347345

348346
onLayout(event) {
@@ -709,10 +707,10 @@ export default class Dropdown extends PureComponent {
709707
<Modal
710708
visible={modal}
711709
transparent={true}
712-
onRequestClose={this.onClose}
710+
onRequestClose={this.blur}
713711
supportedOrientations={supportedOrientations}
714712
>
715-
<TouchableWithoutFeedback onPress={this.onClose}>
713+
<TouchableWithoutFeedback onPress={this.blur}>
716714
<View style={overlayStyle}>
717715
<Animated.View
718716
style={[styles.picker, pickerStyle, pickerStyleOverrides]}

0 commit comments

Comments
 (0)