Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code to hide dropdown icon on Android #539

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,19 @@ public void setDropdownIconRippleColor(@Nullable int color) {
backgroundDrawable.setColor(ColorStateList.valueOf(color));
}

public void setDropdownIconVisible(@Nullable boolean visible) {
LayerDrawable drawable = (LayerDrawable) this.getBackground();
RippleDrawable backgroundDrawable = (RippleDrawable) drawable.findDrawableByLayerId(R.id.dropdown_icon);

if (Boolean.TRUE.equals(visible)) {
backgroundDrawable.setAlpha(255);
}
else {
backgroundDrawable.setAlpha(0);
}

}

public void setBackgroundColor(@Nullable int color) {
LayerDrawable drawable = (LayerDrawable) this.getBackground();
GradientDrawable backgroundDrawable = (GradientDrawable) drawable.findDrawableByLayerId(R.id.dropdown_background);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ public void setDropdownIconRippleColor(ReactPicker view, @Nullable int color) {
view.setDropdownIconRippleColor(color);
}

@ReactProp(name = "dropdownIconVisible")
public void setDropdownIconVisible(ReactPicker view, @Nullable boolean visible) {
view.setDropdownIconVisible(visible);
}

@ReactProp(name = ViewProps.NUMBER_OF_LINES, defaultInt = 1)
public void setNumberOfLines(ReactPicker view, int numberOfLines) {
ReactPickerAdapter adapter = (ReactPickerAdapter) view.getAdapter();
Expand Down
2 changes: 2 additions & 0 deletions android/src/main/jni/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace facebook
values["backgroundColor"] = props.backgroundColor;
values["dropdownIconColor"] = props.dropdownIconColor;
values["dropdownIconRippleColor"] = props.dropdownIconRippleColor;
values["dropdownIconVisible"] = props.dropdownIconVisible;
values["numberOfLines"] = props.numberOfLines;
values["mode"] = "dialog";

Expand Down Expand Up @@ -97,6 +98,7 @@ namespace facebook
values["backgroundColor"] = props.backgroundColor;
values["dropdownIconColor"] = props.dropdownIconColor;
values["dropdownIconRippleColor"] = props.dropdownIconRippleColor;
values["dropdownIconVisible"] = props.dropdownIconVisible;
values["numberOfLines"] = props.numberOfLines;
values["mode"] = "dropdown";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "dropdownIconRippleColor":
mViewManager.setDropdownIconRippleColor(view, value == null ? 0 : ((Double) value).intValue());
break;
case "dropdownIconVisible":
mViewManager.setDropdownIconVisible(view, value == null ? true : (boolean) value);
break;
case "numberOfLines":
mViewManager.setNumberOfLines(view, value == null ? 0 : ((Double) value).intValue());
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface RNCAndroidDialogPickerManagerInterface<T extends View> {
void setBackgroundColor(T view, int value);
void setDropdownIconColor(T view, int value);
void setDropdownIconRippleColor(T view, int value);
void setDropdownIconVisible(T view, boolean value);
void setNumberOfLines(T view, int value);
void focus(T view);
void blur(T view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "dropdownIconRippleColor":
mViewManager.setDropdownIconRippleColor(view, value == null ? 0 : ((Double) value).intValue());
break;
case "dropdownIconVisible":
mViewManager.setDropdownIconVisible(view, value == null ? true : (boolean) value);
break;
case "numberOfLines":
mViewManager.setNumberOfLines(view, value == null ? 0 : ((Double) value).intValue());
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface RNCAndroidDropdownPickerManagerInterface<T extends View> {
void setBackgroundColor(T view, int value);
void setDropdownIconColor(T view, int value);
void setDropdownIconRippleColor(T view, int value);
void setDropdownIconVisible(T view, boolean value);
void setNumberOfLines(T view, int value);
void focus(T view);
void blur(T view);
Expand Down
1 change: 1 addition & 0 deletions js/AndroidDialogPickerNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type NativeProps = $ReadOnly<{|
backgroundColor?: Int32,
dropdownIconColor?: Int32,
dropdownIconRippleColor?: Int32,
dropdownIconVisible?: ?boolean,
numberOfLines?: ?Int32,
onSelect?: BubblingEventHandler<PickerAndroidChangeEvent, 'topSelect'>,
onFocus?: BubblingEventHandler<null, 'topFocus'>,
Expand Down
1 change: 1 addition & 0 deletions js/AndroidDropdownPickerNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type NativeProps = $ReadOnly<{|
backgroundColor?: Int32,
dropdownIconColor?: Int32,
dropdownIconRippleColor?: Int32,
dropdownIconVisible?: ?boolean,
numberOfLines?: ?Int32,
onSelect?: BubblingEventHandler<PickerAndroidChangeEvent, 'topSelect'>,
onFocus?: BubblingEventHandler<null, 'topFocus'>,
Expand Down
2 changes: 2 additions & 0 deletions js/PickerAndroid.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type PickerAndroidProps = $ReadOnly<{|
prompt?: ?string,
testID?: string,
dropdownIconColor?: string,
dropdownIconVisible?: ?boolean,
numberOfLines?: ?number,
|}>;

Expand Down Expand Up @@ -230,6 +231,7 @@ function PickerAndroid(props: PickerAndroidProps, ref: PickerRef): React.Node {
style: props.style,
dropdownIconColor: processColor(props.dropdownIconColor),
dropdownIconRippleColor: processColor(props.dropdownIconRippleColor),
dropdownIconVisible: props.dropdownIconVisible,
testID: props.testID,
numberOfLines: props.numberOfLines,
};
Expand Down
5 changes: 5 additions & 0 deletions typings/Picker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ export interface PickerProps<T = ItemValue> extends ViewProps {
* @platform android
*/
dropdownIconRippleColor?: number | ColorValue;
/**
* Visibility of spinner's arrow
* @platform android
*/
dropdownIconVisible?: boolean;
/**
* On Android & iOS, used to truncate the text with an ellipsis after computing the text layout, including line wrapping,
* such that the total number of lines does not exceed this number. Default is '1'
Expand Down
Loading