react-native-picker / picker

Picker is a cross-platform UI component for selecting an item from a list of options.
MIT License
1.47k stars 277 forks source link

fix: Issue 294 - selection color #474

Closed alburdette619 closed 1 year ago

alburdette619 commented 1 year ago

This PR addresses #294 by adding an iOS only property called selectionColor, which is then set to the proper sub-view of the UIPicker. The example project & docs have also been updated.

❓ My purposes for completing work on this functionality were to make the selection transparent so that I could show two pickers side by side with one a single selection indictor rendered in JS. In using the transparent color, I noticed the indicator still shows up, but I know that transparent is equal to #00000000 which seemingly should be the same as #FFFFFF00 but it's not... using the later gave me what I wanted.

The question being, would you like for me to account for this in the JS or let the user deal with it if they happen find it? I can easily make a single line that translates transparent, but someone may use it on a black background... could be based on theme if given?

alburdette619 commented 1 year ago

Also, note I'm not super confident in the native objective-c so please hit me up with any nuances I can make better there.

alburdette619 commented 1 year ago

@Naturalclar, No worries, but any ETA on a review?

Naturalclar commented 1 year ago

:tada: This PR is included in version 2.4.9 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

rlueder commented 1 year ago

@alburdette619 thanks for getting this PR open, unfortunately I wasn't able to change the selection color by using the selectionColor prop.

I'd happy to tweak this if I can get some steps on how to test it locally, for example, how do you you know which subview should be updated on ios/RNCPicker.m ?

pickerView.subviews[1].backgroundColor

I also think the typings or PickerIOS need updating as TS complains about selectionColor on PickerIOS but it works for Picker.

Thanks!

alburdette619 commented 1 year ago

I'd happy to tweak this if I can get some steps on how to test it locally, for example, how do you you know which subview should be updated on ios/RNCPicker.m ?

pickerView.subviews[1].backgroundColor

TBH I was a bit uncomfortable with this as well, but all research I did concerning this used a raw index & by all testing it seemed to work 🫠

I also think the typings or PickerIOS need updating as TS complains about selectionColor on PickerIOS but it works for Picker.

Definitely clean that up if I missed some typing. I thought I had added it.


Sorry it's not working for you @rlueder, we've been using my fork for our project since I submitted the PR. It's possible since we're using it for a transparent color I introduced a bug at the end.

keith-kurak commented 1 year ago

@alburdette619 @rlueder just wanted to let you know I was trying this out, and I was able to get it to work with rgba() color values and some solid color names (e.g., "orange"), but it would fall back to the default if I used hex or "transparent".

k1eu commented 9 months ago

@keith-kurak how did you get it working? Can't seem to achieve this on 2.6.1

AdePhil commented 8 months ago

I had to downgrade to v2.4.9 to get it working.