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

[RN 0.59.1] Android picker is always shown as dropdown #24055

Closed
xAlexV opened this issue Mar 20, 2019 · 47 comments
Closed

[RN 0.59.1] Android picker is always shown as dropdown #24055

xAlexV opened this issue Mar 20, 2019 · 47 comments
Labels
Bug Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@xAlexV
Copy link

xAlexV commented Mar 20, 2019

🐛 Bug Report

The picker on Android is always shown as a dropdown, even if the mode is set to dialog. On RN 0.58.6 it works according to the mode that is set ("dialog" or "dropdown").

RN 0.59.1
Screenshot_20190319-164006_testPicker

RN 0.58.6
Screenshot_20190320-073759_testPickerVersion58

To Reproduce

Initialize a new react native project: react-native init testPicker

Add the code example for the picker attached below to the return, as well in the constructor this.state = {language: "Java"};

Run the project: react-native run-android

Expected Behavior

I expect that when the picker mode is set to "dialog" (or not set, because the default mode is "dialog") to open the items in a new modal window, not as dropdown anchored to the picker view

Code Example

render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>To get started, edit App.js</Text>
<Text style={styles.instructions}>{instructions}</Text>
<Picker selectedValue={this.state.language} style={{height: 50, width: 100}} mode={"dialog"} onValueChange={(itemValue, itemIndex) => this.setState({language: itemValue}) }> <Picker.Item label="Java" value="java" /> <Picker.Item label="JavaScript" value="js" /> </Picker>
</View>
);
}

Environment

react-native --version
react-native-cli: 2.0.1
react-native: 0.59.1

react-native info
info
React Native Environment Info:
System:
OS: Windows 10
CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Memory: 23.85 GB / 31.88 GB
Binaries:
Yarn: 1.5.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.3.0.0 AI-182.5107.16.33.5314842

@ferrannp ferrannp added Platform: Android Android applications. Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. labels Mar 20, 2019
@ferrannp
Copy link
Contributor

ferrannp commented Mar 20, 2019

I see this is happening in master too now that we use AppCompatSpinner instead of Spinner in ReactPicker.java

api("androidx.appcompat:appcompat:1.0.2")

If you try to switch for RNTester to use the alpha though:

api("androidx.appcompat:appcompat:1.1.0-alpha03")

It works again. So I am hoping we can fix this just switching to 1.1.0 once it is stable

@xAlexV
Copy link
Author

xAlexV commented Mar 20, 2019

Hi @ferrannp,

Thanks a lot for your response, could you tell me how we can fix this on the current 0.59.1 version?
It is blocking our current release, it would be great if we don't have to revert the update :)

Thanks in advance.

@westcode

This comment has been minimized.

@turnrye
Copy link
Contributor

turnrye commented Mar 22, 2019

@xAlexV -- we'll need to wait for the release of androidx.appcompat to make stable and then update our dependencies. If you're hurting for a release and this is a blocker, reverting the update might be your best bet sadly.

@xAlexV
Copy link
Author

xAlexV commented Mar 23, 2019

@turnrye thanks for the update. I'll check with the team and hope that a downgrade is not required :D.

@ggenovese
Copy link

Any update on this issue?

@westcode
Copy link

westcode commented Apr 8, 2019

As stated by @ferranp and @turnrye the issue is related to a bug in the used androidx.appcompat version and should be solved by updating the reference to 1.10 once its final gets released. https://developer.android.com/jetpack/androidx/releases/appcompat shows another alpha (4) got out last week. Guess we just have to wait untill it comes out.

@jmheik
Copy link
Contributor

jmheik commented Apr 15, 2019

Would it be worthwhile to revert Picker from extending AppCompatSpinner until dependency with fix is available, if it solves this issue? Then it could be backported to 0.59.x releases.

@ferrannp
Copy link
Contributor

CC @dulmandakh. What do you think?

@janbuerling
Copy link

What is the current status of this bug?

@VinceBT
Copy link

VinceBT commented May 17, 2019

Any workaround ?

@mstllc
Copy link

mstllc commented May 17, 2019

I've been following this one as I really wanted that modal picker for an app I started with 0.59 as well. Seems like the comment above pretty much says what the RN team is thinking, they're waiting for Appcompat version 1.1.0 to drop a stable release before updating RN to use that version, which should solve this issue. You can keep checking here for progress on that: https://developer.android.com/jetpack/androidx/releases/appcompat

Other than that, I don't think you have any options other than using an older version of RN (pre-hooks 😢 ) or writing a custom native plugin. I ended up writing a native plugin because I really wanted this feature and was approaching a deadline. It was pretty straightforward, but may be more challenging if you don't have any experience working on the native side of RN.

I'm no expert and I'm not sure how much this will help you, but here's the relevant code for the native module I wrote. Follow the Native Modules guide in the docs for the initial native module setup on Android. Here's the code for the native method you want to expose:

    @ReactMethod
    public void alertPicker(String title, ReadableArray items, Promise promise) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getCurrentActivity());
        builder.setTitle(title);
        builder.setCancelable(false);

        String[] values = new String[items.size()];
        for (int i = 0; i < items.size(); i++) {
            values[i] = items.getArray(i).getString(1);
        }

        builder.setItems(values, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                WritableArray result = Arguments.createArray();

                result.pushString(items.getArray(which).getString(0));
                result.pushString(items.getArray(which).getString(1));

                promise.resolve(result);
            }
        });

        AlertDialog dialog = builder.create();
        dialog.show();
    }

Again, this is probably not the best way to do this, but you can then call this from the JS side like
const [value, label] = await alertPicker("Picker Title", [ ["value1", "label1"], ["value2", "label2"] ])

@german970814
Copy link

@thorsonmscott Thanks

@wuifdesign
Copy link

wuifdesign commented Jun 7, 2019

any new updates/workarounds on this?

@AlexSeoven
Copy link

Any new workarounds / fixes on this issue?

@lucascardial
Copy link

Nothing here?

@ishaq-aym
Copy link

any updates about this issue? i can't downgrade my react version because of 64 bit support .

@ailton-moreira
Copy link

any one was able to resolve this bug?

@Firetuy
Copy link

Firetuy commented Jul 4, 2019

Bug still ocurring

@stvmachine
Copy link

+1

@satheeshwaran
Copy link

+1 Need a workaround for this. My designer wants picker as it looks at 0.58.6.

@lucasgouvea
Copy link

Any workaround on this issue?

@sousaprogramador
Copy link

Notthing here ?

@ferrannp
Copy link
Contributor

To everybody having problems with this, have you tried using https://github.com/react-native-community/react-native-picker ?

@manhthepixta
Copy link

To everybody having problems with this, have you tried using https://github.com/react-native-community/react-native-picker ?

I cannot install @react-native-community/picker via npm or yarn. "Not found" error occurs.

@BrandonKerr
Copy link

To everybody having problems with this, have you tried using https://github.com/react-native-community/react-native-picker ?

I cannot install @react-native-community/picker via npm or yarn. "Not found" error occurs.

This issue with npm appears to be resolved now: react-native-picker/picker#9

I'm personally running into errors for "Tried to register two views with the same name AndroidDropdownPicker" which I'm guessing is due to something else using the native-base version as a dependency. Others may want to give the react-native-community version a try and see if it resolves this issue for them.

@deserthurricane
Copy link

To everybody having problems with this, have you tried using https://github.com/react-native-community/react-native-picker ?

For me https://github.com/react-native-community/react-native-picker works just the same - only dropdown is shown despite the selected dialog mode.

@andrewsadowski
Copy link

Tried out the @react-native-community/picker package as suggested above on RN v59.1. Still showing Picker as dropdown only, even when mode='dialog' is set.

@janczizikow
Copy link

As a temporary workaround I've created a native-module as @thorsonmscott suggested. I'm also quite new to native modules, but it was interesting to try it out. Not sure if it will help anyone here (my use case was pretty simple), but I published it as a package to npm. You can find the repo here.

@amalsaad
Copy link

Any update on this issue?

@ricardo-mobiquity
Copy link

janczizikow's workaround works great! Thank you.

@chrisk8er
Copy link

any update?

@jesxr44
Copy link

jesxr44 commented Sep 3, 2019

Any expected date about when this will be fixed?

@wamry
Copy link

wamry commented Sep 3, 2019

@janczizikow thanks bro, it worked

@BrandonKerr
Copy link

According to https://developer.android.com/jetpack/androidx/releases/appcompat the 1.1.0 stable released today. Is there any idea of a timeframe for RN to update accordingly?

@dulmandakh
Copy link
Contributor

I would be happy to review a PR that would upgrade appcompat version

@AlirezaAzizi145
Copy link

@janczizikow thanks for your help. but how can i change styles and cancel text

@allanzi
Copy link

allanzi commented Sep 25, 2019

any new updates/workarounds on this?

@iYahya
Copy link

iYahya commented Oct 7, 2019

i found this work around an it works for me in [RN > 0.60]

in

android/app/src/main/res/value

if there is no 'styles.xml' file then create your own 'styles.xml'

and put the code below :

<resources>
<style name="SpinnerStyle" parent="@android:style/Widget.Spinner">
        <item name="android:background">@null</item>
    </style>
    <style name="SpinnerItem" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:gravity">right</item>
        <item name="android:textColor">#a2a2a2</item>
        <item name="android:textSize">12dp</item>
    </style>
    <style name="SpinnerDropDownItem" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:gravity">center</item>
        <item name="android:textColor">#000</item>
        <item name="android:textSize">13dp</item>
    </style>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:textColor">#000000</item>
        <item name="android:spinnerStyle">@style/SpinnerStyle</item>
        <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
        <item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
    </style>
</resources>

@idhowardgj94
Copy link

I had this same issue...
and thank @thorsonmscott again...

so when can react-native solve this solution, if this bug is solve here lol

@luiza-avelino
Copy link

@iYahya worked for me ! Thanks.

@AyeshaIftikharr
Copy link

Is there any update on this issue?

@lunaleaps
Copy link
Contributor

Picker has been removed from react-native.
I'm trying to find the relevant issue in https://github.com/react-native-picker/picker/issues so we can push to get it fixed there but I can't find a similar issue -- if anyone else knows or wants to create an issue in that repo?

facebook-github-bot pushed a commit that referenced this issue Mar 24, 2022
Summary:
This sync includes the following changes:
- **[3f8990898](facebook/react@3f8990898 )**: Fix test-build-devtools if build was generated by build-for-devtools ([#24088](facebook/react#24088)) //<Sebastian Silbermann>//
- **[577f2de46](facebook/react@577f2de46 )**: enableCacheElement flag ([#24131](facebook/react#24131)) //<David McCabe>//
- **[2e0d86d22](facebook/react@2e0d86d22 )**: Allow updating dehydrated root at lower priority without forcing client render ([#24082](facebook/react#24082)) //<Andrew Clark>//
- **[dbe9e732a](facebook/react@dbe9e732a )**: Avoid conditions where control flow is sufficient ([#24126](facebook/react#24126)) //<Sebastian Markbåge>//
- **[b075f9742](facebook/react@b075f9742 )**: Fix dispatch config type for skipBubbling ([#24109](facebook/react#24109)) //<Luna>//
- **[ef23a9ee8](facebook/react@ef23a9ee8 )**: Flag for text hydration mismatch ([#24107](facebook/react#24107)) //<salazarm>//
- **[0412f0c1a](facebook/react@0412f0c1a )**: add offscreen state node ([#24026](facebook/react#24026)) //<Luna Ruan>//
- **[43eb28339](facebook/react@43eb28339 )**: Add skipBubbling property to dispatch config ([#23366](facebook/react#23366)) //<Luna>//
- **[832e2987e](facebook/react@832e2987e )**: Revert accdientally merged PR ([#24081](facebook/react#24081)) //<Andrew Clark>//
- **[02b65fd8c](facebook/react@02b65fd8c )**: Allow updates at lower pri without forcing client render //<Andrew Clark>//
- **[83b941a51](facebook/react@83b941a51 )**: Add isRootDehydrated function //<Andrew Clark>//
- **[c8e4789e2](facebook/react@c8e4789e2 )**: Pass children to hydration root constructor //<Andrew Clark>//
- **[581f0c42e](facebook/react@581f0c42e )**: [Flight] add support for Lazy components in Flight server ([#24068](facebook/react#24068)) //<Josh Story>//
- **[72a933d28](facebook/react@72a933d28 )**: Gate legacy hidden ([#24047](facebook/react#24047)) //<Sebastian Markbåge>//
- **[b9de50d2f](facebook/react@b9de50d2f )**: Update test to reset modules instead of using private state ([#24055](facebook/react#24055)) //<Sebastian Markbåge>//
- **[c91892ec3](facebook/react@c91892ec3 )**: [Fizz] Don't flush empty segments ([#24054](facebook/react#24054)) //<Sebastian Markbåge>//
- **[d5f1b067c](facebook/react@d5f1b067c )**: [ServerContext] Flight support for ServerContext ([#23244](facebook/react#23244)) //<salazarm>//
- **[6edd55a3f](facebook/react@6edd55a3f )**: Gate unstable_expectedLoadTime on enableCPUSuspense ([#24038](facebook/react#24038)) //<Sebastian Markbåge>//
- **[57799b912](facebook/react@57799b912 )**: Add more feature flag checks ([#24037](facebook/react#24037)) //<Sebastian Markbåge>//
- **[e09518e5b](facebook/react@e09518e5b )**: [Fizz] write chunks to a buffer with no re-use ([#24034](facebook/react#24034)) //<Josh Story>//
- **[14c2be8da](facebook/react@14c2be8da )**: Rename Node SSR Callbacks to onShellReady/onAllReady and Other Fixes ([#24030](facebook/react#24030)) //<Sebastian Markbåge>//
- **[cb1e7b1c6](facebook/react@cb1e7b1c6 )**: Move onCompleteAll to .allReady Promise ([#24025](facebook/react#24025)) //<Sebastian Markbåge>//
- **[566285761](facebook/react@566285761 )**: [Fizz] Export debug function for FB ([#24024](facebook/react#24024)) //<salazarm>//
- **[05c283c3c](facebook/react@05c283c3c )**: Fabric HostComponent as EventEmitter: support add/removeEventListener (unstable only) ([#23386](facebook/react#23386)) //<Joshua Gross>//
- **[08644348b](facebook/react@08644348b )**: Added unit Tests in the ReactART, increasing the code coverage ([#23195](facebook/react#23195)) //<BIKI DAS>//
- **[feefe437f](facebook/react@feefe437f )**: Refactor Cache Code ([#23393](facebook/react#23393)) //<Luna Ruan>//

Changelog:
[General][Changed] - React Native sync for revisions 1780659...1159ff6

jest_e2e[run_all_tests]

Reviewed By: lunaleaps

Differential Revision: D34928167

fbshipit-source-id: 8c386f2be5871981d217ab9a514892ed88eafcfb
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this issue Jan 15, 2023
Summary:
This sync includes the following changes:
- **[3f8990898](facebook/react@3f8990898 )**: Fix test-build-devtools if build was generated by build-for-devtools ([facebook#24088](facebook/react#24088)) //<Sebastian Silbermann>//
- **[577f2de46](facebook/react@577f2de46 )**: enableCacheElement flag ([facebook#24131](facebook/react#24131)) //<David McCabe>//
- **[2e0d86d22](facebook/react@2e0d86d22 )**: Allow updating dehydrated root at lower priority without forcing client render ([facebook#24082](facebook/react#24082)) //<Andrew Clark>//
- **[dbe9e732a](facebook/react@dbe9e732a )**: Avoid conditions where control flow is sufficient ([facebook#24126](facebook/react#24126)) //<Sebastian Markbåge>//
- **[b075f9742](facebook/react@b075f9742 )**: Fix dispatch config type for skipBubbling ([facebook#24109](facebook/react#24109)) //<Luna>//
- **[ef23a9ee8](facebook/react@ef23a9ee8 )**: Flag for text hydration mismatch ([facebook#24107](facebook/react#24107)) //<salazarm>//
- **[0412f0c1a](facebook/react@0412f0c1a )**: add offscreen state node ([facebook#24026](facebook/react#24026)) //<Luna Ruan>//
- **[43eb28339](facebook/react@43eb28339 )**: Add skipBubbling property to dispatch config ([facebook#23366](facebook/react#23366)) //<Luna>//
- **[832e2987e](facebook/react@832e2987e )**: Revert accdientally merged PR ([facebook#24081](facebook/react#24081)) //<Andrew Clark>//
- **[02b65fd8c](facebook/react@02b65fd8c )**: Allow updates at lower pri without forcing client render //<Andrew Clark>//
- **[83b941a51](facebook/react@83b941a51 )**: Add isRootDehydrated function //<Andrew Clark>//
- **[c8e4789e2](facebook/react@c8e4789e2 )**: Pass children to hydration root constructor //<Andrew Clark>//
- **[581f0c42e](facebook/react@581f0c42e )**: [Flight] add support for Lazy components in Flight server ([facebook#24068](facebook/react#24068)) //<Josh Story>//
- **[72a933d28](facebook/react@72a933d28 )**: Gate legacy hidden ([facebook#24047](facebook/react#24047)) //<Sebastian Markbåge>//
- **[b9de50d2f](facebook/react@b9de50d2f )**: Update test to reset modules instead of using private state ([facebook#24055](facebook/react#24055)) //<Sebastian Markbåge>//
- **[c91892ec3](facebook/react@c91892ec3 )**: [Fizz] Don't flush empty segments ([facebook#24054](facebook/react#24054)) //<Sebastian Markbåge>//
- **[d5f1b067c](facebook/react@d5f1b067c )**: [ServerContext] Flight support for ServerContext ([facebook#23244](facebook/react#23244)) //<salazarm>//
- **[6edd55a3f](facebook/react@6edd55a3f )**: Gate unstable_expectedLoadTime on enableCPUSuspense ([facebook#24038](facebook/react#24038)) //<Sebastian Markbåge>//
- **[57799b912](facebook/react@57799b912 )**: Add more feature flag checks ([facebook#24037](facebook/react#24037)) //<Sebastian Markbåge>//
- **[e09518e5b](facebook/react@e09518e5b )**: [Fizz] write chunks to a buffer with no re-use ([facebook#24034](facebook/react#24034)) //<Josh Story>//
- **[14c2be8da](facebook/react@14c2be8da )**: Rename Node SSR Callbacks to onShellReady/onAllReady and Other Fixes ([facebook#24030](facebook/react#24030)) //<Sebastian Markbåge>//
- **[cb1e7b1c6](facebook/react@cb1e7b1c6 )**: Move onCompleteAll to .allReady Promise ([facebook#24025](facebook/react#24025)) //<Sebastian Markbåge>//
- **[566285761](facebook/react@566285761 )**: [Fizz] Export debug function for FB ([facebook#24024](facebook/react#24024)) //<salazarm>//
- **[05c283c3c](facebook/react@05c283c3c )**: Fabric HostComponent as EventEmitter: support add/removeEventListener (unstable only) ([facebook#23386](facebook/react#23386)) //<Joshua Gross>//
- **[08644348b](facebook/react@08644348b )**: Added unit Tests in the ReactART, increasing the code coverage ([facebook#23195](facebook/react#23195)) //<BIKI DAS>//
- **[feefe437f](facebook/react@feefe437f )**: Refactor Cache Code ([facebook#23393](facebook/react#23393)) //<Luna Ruan>//

Changelog:
[General][Changed] - React Native sync for revisions 1780659...1159ff6

jest_e2e[run_all_tests]

Reviewed By: lunaleaps

Differential Revision: D34928167

fbshipit-source-id: 8c386f2be5871981d217ab9a514892ed88eafcfb
@github-actions
Copy link

github-actions bot commented Mar 5, 2023

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 5, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

@facebook facebook locked as resolved and limited conversation to collaborators Mar 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests