-
Notifications
You must be signed in to change notification settings - Fork 932
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
Implement support for React Native #185
Comments
Hi @sumorai! Thanks so much for filing this issue and taking up the challenge to bring downshift to React Native! I have no experience with React Native either. I'll reach out to folks on twitter and see if we can get some direction there. As mentioned to you privately, I would be totally fine to add a few lines of logic that make things compatible. I'd also be fine to add another build if that's necessary (though I'd prefer to avoid that).
Thanks for pointing that out. It's in |
I had a look around and I'm not having luck using But from what I can tell, making downshift support React Native is going to be trickier than it looks at first glance. Avoiding
The tricky part are going to be all those event listeners.
Finally, using Preact as the build target is going to be an issue. Preact purposefully drops support for React Native as part of the whole "be super small" thing. My assessment is that adapting the library itself for RN is doable, but it's almost certainly going to need a separate build target because of Preact. |
Agree with @Swizec 100%, accessibility would be different as well I think. It seems like a glamorous situation IMO, maybe make it another package altogether? |
Thank you so much for your audits @Swizec and @kkemple!
The reason for the global mousedown listener is to avoid this situation when the user clicks an item: input onblur -> menu isOpen set to false -> onclick event fired on whatever the menu was covering So we have the global mousedown to track whether the mouse is still down when the Will that be a problem with React Native?
The problem with using I suppose an alternative here would be to simply use
No worries, that's only used for the preact build. For the react build (which would be the one to support react native) it'll be
No worries there, preact isn't the target, it's a target. downshift supports both and simply has a separate build for preact :)
Yeah, I was thinking about that too. I don't expect that set-a11y-status.js would apply at all, and we'd need a different thing for React Native...
Let's see if we can make it work. downshift is a much simpler component, so I think we can make it work :) |
Awesome. Thanks for the input, everyone. :) I forked it and started fiddling around on the train this morning. I'll spend some more time on it tonight. |
From the RN docs it looks like we just need to apply some accessibility props to the component, and potentially to the list items. So, those could just be passed back in getInputProps() and getItemProps(), right? I'm curious exactly how set-a11y-status.js works. Why does it maintain an array of the statuses, and what are those statuses intended to be? I played around with one of the examples and sometimes it would be the most likely match in the list, and other times it had an informational message. I suppose I'd have to play around with it in a test app after it's working and see what makes sense. The AccessibilityInfo API can be queried to see if the screen reader is enabled, although, considering that the user can probably turn that on/off and go back to the app, it wouldn't likely make sense to use that API to decide whether or not to add a11y props to the elements. Input would have a prop "accessibilityTraits" of "search", and the items would have a "accessibilityTraits" value of "selected" when selected, otherwise, perhaps "text". Input and items would all have "accessible" prop set to true. The "accessibilityLabel" prop can also be used. I'm not sure if that would be a good place for the status, or not. |
@kentcdodds In validateGetRootPropsCalledCorrectly(), the onClick check there on the root node is probably not needed for React Native, right? At least, from reading the discussion above, that seems like the case. At any rate, I updated the repro code a bit and it a baby step towards functional with some changes to my fork of downshift. |
Thanks for your work on this @gricard!
Don't concern yourself as much with how It would be simple to add an
Possibly... If we rework downshift to use a click handler on the items rather than on the root node then we could probably get rid of the root's One last thing. My wife and I just had a baby, so I'll be pretty busy with that. I'll try to be as available as I can but I can't make any promises for the next few weeks. Good luck! |
@kentcdodds Congrats! Speaking as a dad of a toddler, get as much sleep as you can. :D I'll keep fiddling with things and keep this updated. |
With some of the changes recently I think that support will be even easier. Especially the new |
I'm pretty interested in this too! Currently reimplementing a set of Downshift-like inputs and filters in a React Native codebase. @gricard let me know if I can lend a hand at all! |
I honestly don't think that it'd take a whole lot of work to make this happen. Someone's just gotta put in the effort. It can't be me because I'm afraid that I don't have experience with React Native, but I look forward to seeing someone work on this :) |
@kentcdodds Sounds good! I'll take a stab at this next week after consuming some turkey. @gricard I assume your branch was here? https://github.com/gricard/downshift/tree/test/gr I'll grab that work and start to build off it a bit. |
I took a quick swipe at this here: #265 Feedback is welcome! |
Re-opening as what was just merged is experimental support. That means that things may break intentionally without a semver major bump. To get to official support we need:
|
I don't really use RN as much as I'd like either. But I whipped up a quick Expo Snack of Downshift in RN in action https://snack.expo.io/@donysukardi/downshift-basic-example just to try it out. Awesome work @Andarist, @eliperkins! We might also want consider adding a separate Example section for RN, @kentcdodds. |
Awesome! Thank you! Yes another example section would be wonderful! |
@donysukardi Heh, awesome! I had a very similar version of this I was using while working on #265.
I'm certainly committed to maintaining this, as we'll be using this in production at Clubhouse!
Agreed. I think we can put together some tests for this using Jest's React Native snapshot testing, to at least ensure we're able to render the React Native components we need.
Absolutely! What do you envision this looking like? The usage of Downshift on React Native is analogous to it's usage with ReactDOM, so I'm not sure that we need separate documentation for it. Would an example be enough?
We'll be launching our app in ~week that uses this in several places. I'll be sure to link ya'll to it. |
Let's have a section in the docs that talk about react native usage. It should mention any differences and show an example 👍 |
I have so many happy feelings about this that I tweeted a long thread: https://twitter.com/kentcdodds/status/964176513657724928 So here's what we've got:
|
Are you using a |
@wKovacs64 Yup, we're using This sounds similar to #363 that was just reported as well. Let's use that issue to track this, and see if it solves your problem, rather than overloading this issue. |
Hey folks! I'm getting things ready for a v2 release this week and would love react-native support to be official for it. Hope are we doing on that? |
@kentcdodds it looks like the last thing in that checklist of yours that we need is documentation and an example! Based on the discussion in #363, it might be helpful to note the fix to that problem (including the Beyond that, I would say this is good to go in v2! |
Awesome. I think it'd also be great to close existing react-native issues 👍 Can we get any of those resolved? |
downshift
version: 1.5.0node
version: 8.3.0npm
(oryarn
) version: yarn 1.0.1Relevant code or config
What you did:
Added an autocomplete input component to my React Native project and attached Downshift to it.
What happened:
window.addEventListener is not a function. (In 'window.addEventListener('mousedown', onMouseDown)', 'window.addEventListener' is undefined)
componentDidMount
downshift.cjs.js:699:30
measureLifeCyclePerf
ReactNativeStack-dev.js:1610:15
ReactNativeStack-dev.js:1657:33
notifyAll
ReactNativeStack-dev.js:2121:107
close
ReactNativeStack-dev.js:2138:8
closeAll
ReactNativeStack-dev.js:1412:101
perform
ReactNativeStack-dev.js:1388:52
batchedMountComponentIntoNode
ReactNativeStack-dev.js:2004:24
perform
ReactNativeStack-dev.js:1382:99
renderComponent
ReactNativeStack-dev.js:2032:45
renderApplication
renderApplication.js:34:4
runApplication
AppRegistry.js:191:26
__callFunction
MessageQueue.js:266:47
MessageQueue.js:103:26
__guard
MessageQueue.js:231:6
callFunctionReturnFlushedQueue
MessageQueue.js:102:17
Reproduction repository:
https://github.com/gricard/downshift-reactnative-repro
Problem description:
Downshift does not currently have support for the React Native environment, which has some minor differences to running in the browser.
Suggested solution:
I had a brief discussion about the issue with Kent, and he provided these three links which are areas where there will need to be changes in order to support React Native:
https://github.com/paypal/downshift/blob/a1490f070575ffcd71dac8c063fe7e092f840a67/src/downshift.js#L208-L209
https://github.com/paypal/downshift/blob/a1490f070575ffcd71dac8c063fe7e092f840a67/src/downshift.js#L150
https://github.com/paypal/downshift/blob/a1490f070575ffcd71dac8c063fe7e092f840a67/src/downshift.js#L655-L681
I'd like to take a shot at implementing a fix and providing a PR. I'm looking for guidance on that, as this is the first time I've taken the time to attempt contributing back to a project, and I'm also fairly new at RN as well.
(FYI, there is no CODE_OF_CONDUCT.md file that is mentioned in the issue template)
The text was updated successfully, but these errors were encountered: