-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
[Blur & Focus] Support relinquishing focus from multiple views via container #113
Comments
I'm not sure I understand. You can do .blur() on Text ref right now. Do you want to do blur() on an arbitrary View? |
Yeah, it blurs any descendant that has focus. The descendant could be a TextInput but could also be any other kind of input element that can become the first responder. |
You can actually call blur() on a View today. See NativeMethodMixin::blur. Can you tell me if it's doing what you want? |
ping @ide |
Confirmed that
you want to write
|
@brentvatne I came up with a simple solution for this internally where I wrote a component that essentially just extends @implementation KBCloserView
- (void)didMoveToSuperview
{
self.userInteractionEnabled = TRUE;
[super didMoveToSuperview];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
for (UIView *subview in self.subviews) {
[subview endEditing:YES];
}
}
@end So I just convert my container I share this because I think adding a |
Nice on @dhrrgn! Seems simple enough. Might be worth putting into a library on npm until a solution is integrated into core |
@brentvatne I will do that tomorrow...right after I figure out how to create an Xcode project people can just add to their's (bit of an Xcode "noob") haha. (Side note: it would be awesome if their was a "Creating Distributable Native Components" section of the docs for this sort of thing). |
@dhrrgn - I have something about that on my blog: Packaging a React Native component, I hesitated to add it to the docs because it seemed like a temporary solution, but we haven't worked out a better one yet (aside from |
@brentvatne Awesome, thanks. |
Any updates on that? Calling My use case: |
Yeah, can do. Just need to dig into the source code as I haven't contributed yet but would love to. Another thing worth noticing is that the method signature is actually After doing a couple of more tests it looks like the Sample structure returned from render:
and the invocation:
|
Not sure why that's happening. Maybe something changed. Feel free to close this if it just works now. |
@ide - seems to be a false alarm, still not working for me with 0.5: https://rnplay.org/apps/SwEnTw - tried it against master as well, same thing: https://rnplay.org/apps/AxZnJw @grabbou - can you reproduce that fix on rnplay.org? Still an outstanding issue as far as I can tell |
Not working for me either - an outstanding issue I'm afraid. |
Anyone up for fixing this? Would be a great way to learn about some of the React Native internals |
It is still outstanding, I made another rnplay: https://rnplay.org/apps/aAb8aA/ to showcase the problem with 0.6.0 and can reproduce with 0.8.0-rc, I'm going to give this a try with my limited Objective-C skills. |
It looks like nobody on the team at Facebook has a need for this at the moment so I've tagged it as Community Responsibility 😄 |
@brentvatne So i went off and tried to do it, and I have something working but wanted to show you first as this is my first time messing with the internals so want to see if I should change my approach. In NativeMethodsMixin.js I added the following under blur():
In RCTUIManager.m I did the following:
My test case:
Everything seems to work okay and the functionality works as expected. What do you think? I'll submit a proper PR if you think it's good. |
@josebalius - this looks very reasonable to me, @tadeuzagallo what do you think? One comment about the API: it would be nice if this was just a modification of |
@brentvatne roger on the API, i thought about the same thing shouldn't be a problem. If @tadeuzagallo is fine with the code i'll submit the PR with an API like Actually maybe we don't need the extra param at all, if it's on a text field that you are calling it on the loop should have to search once so I think that works as well.....we can just replace the blur functionality altogether. |
@josebalius - yeah I agree, if it's just a TextField then we don't have to be concerned about traversing any children |
This can be closed, no? var dismissKeyboard = require('dismissKeyboard')
...
onClose: function() {
dismissKeyboard();
} |
@wluxion Looks interesting, how do you require the dismissKeyboard Utility in a project? I didn't see Utilities or that particular one in the docs. Will it work on iOS and Android? |
@brentvatne Looks great, I look forward to it. |
@brentvatne Any update on this? I am upgrading a couple of projects to the latest RN and running into blur issues not hiding the keyboard, do we have docs on the proper way to do it? |
@josebalius - hmmm I'm not sure about this, could you put together a small example and create a new issue? |
Fixes facebook#113. 20 looks more natural on iPad
If you have two text inputs in a container view, calling
container.blur()
could make both of the text inputs try to resign their first responder status. In UIKit this is built-in as-[UIView endEditing:animated]
. This way you can just blur the root view if you want the keyboard to go away.The text was updated successfully, but these errors were encountered: