mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook Github Bot
parent
60e91fa9ff
commit
a62a685b14
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user