Add setNativeSelectedPosition command to ReactPickerManager

Summary:
Fabric doesn't support setNativeProps, so we have to use commands instead to set the value of the native component.

Changelog: [Android] [Added] - Add setNativeSelectedPosition command to ReactPickerManager

Reviewed By: mdvacca

Differential Revision: D18007791

fbshipit-source-id: dfa26792205189a336ab43b1c51f43f8f57c8e72
This commit is contained in:
Oleksandr Melnykov
2019-11-11 12:32:51 -08:00
committed by Facebook Github Bot
parent 60e91fa9ff
commit a62a685b14
4 changed files with 58 additions and 8 deletions
@@ -123,6 +123,15 @@ public class ReactPicker extends AppCompatSpinner {
mStagedSelection = selection;
}
/** Will set the "selection" value immediately as opposed to {@link #setStagedSelection(int)} */
/* package */ void setImmediateSelection(int selection) {
if (selection != getSelectedItemPosition()) {
setOnItemSelectedListener(null);
setSelection(selection, false);
setOnItemSelectedListener(mItemSelectedListener);
}
}
/* package */ void setStagedPrimaryTextColor(@Nullable Integer primaryColor) {
mStagedPrimaryTextColor = primaryColor;
}
@@ -8,6 +8,7 @@
package com.facebook.react.views.picker;
import android.widget.Spinner;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.uimanager.SimpleViewManager;
@@ -66,6 +67,18 @@ public abstract class ReactPickerManager extends SimpleViewManager<ReactPicker>
picker, reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()));
}
@Override
public void receiveCommand(
@NonNull ReactPicker view, String commandId, @Nullable ReadableArray args) {
switch (commandId) {
case "setNativeSelectedPosition":
if (args != null) {
view.setImmediateSelection(args.getInt(0));
break;
}
}
}
private static class PickerEventEmitter implements ReactPicker.OnSelectListener {
private final ReactPicker mReactPicker;