From a2a8d7f5da93ee10cf5eccfb944f581f43cfe0c0 Mon Sep 17 00:00:00 2001 From: Don Yu Date: Wed, 17 Aug 2016 22:07:33 -0700 Subject: [PATCH] Fix onItemSelected firing for ReactPicker on initial layout. Reviewed By: AaaChiuuu Differential Revision: D3732557 fbshipit-source-id: ed031dbf205996dab8cb0555af972e6f26c0d202 --- .../java/com/facebook/react/views/picker/ReactPicker.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPicker.java b/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPicker.java index 2871cd212..a5e4a12b7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPicker.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPicker.java @@ -79,6 +79,10 @@ public class ReactPicker extends Spinner { public void setOnSelectListener(@Nullable OnSelectListener onSelectListener) { if (getOnItemSelectedListener() == null) { + // onItemSelected gets fired immediately after layout because checkSelectionChanged() in + // AdapterView updates the selection position from the default INVALID_POSITION. To match iOS + // behavior, we don't want the event emitter for onItemSelected to fire right after layout. + mSuppressNextEvent = true; setOnItemSelectedListener( new OnItemSelectedListener() { @Override