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

InputAccessoryView doesn't work inside React Native Modal #21363

Closed
kadoshms opened this issue Sep 27, 2018 · 11 comments
Closed

InputAccessoryView doesn't work inside React Native Modal #21363

kadoshms opened this issue Sep 27, 2018 · 11 comments
Labels
Bug Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.

Comments

@kadoshms
Copy link

Environment

Environment:
OS: macOS Sierra 10.12.6
Node: 8.6.0
Yarn: 1.7.0
npm: 5.3.0
Watchman: 4.9.0
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz => https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz

Description

InputAccessoryView doesn't work when used inside a react-native Modal.

Reproducible Demo

https://snack.expo.io/@kadoshms/inputaccessoryview-inside-modal

@leiz-me
Copy link

leiz-me commented Dec 25, 2018

Facing the same issue. Any idea?

@euroclydon37
Copy link

Just ran into this.

@euroclydon37
Copy link

euroclydon37 commented Jan 10, 2019

Best I Could Do

I'm not proficient with Objective-C and I had a friend look this over with me.

From what I could tell, it seems like rootView is nil here.

if (rootView) {
UIView *accessoryView = [strongSelf->_bridge.uiManager viewForNativeID:nativeID
withRootTag:rootView.reactTag];
if (accessoryView && [accessoryView isKindOfClass:[RCTInputAccessoryView class]]) {
strongSelf.backedTextInputView.inputAccessoryView = ((RCTInputAccessoryView *)accessoryView).inputAccessoryView;
[strongSelf reloadInputViewsIfNecessary];
}
}

Also found this. Perhaps the rootView wasn't found because of some problem here?

// TODO: this is kinda dumb - let's come up with a
// better way of identifying root React views please!
static inline BOOL RCTIsReactRootView(NSNumber *reactTag)
{
return reactTag.integerValue % 10 == 1;
}

UI Heirarchy Screenshots

The InputAccessoryView simply doesn't get inserted into UIInputSetHostView. Here are some screenshots on the UI hierarchy

In a normal View
markedup

In a modal
screen shot 2019-01-10 at 1 13 57 pm

@euroclydon37
Copy link

euroclydon37 commented Jan 10, 2019

So I did some xcode debugging and found that it's searching the wrong root view. I'm further convinced that this section of code is the issue. I think that Modals aren't adhering to the reactTag pattern here. This would lead a Modal to not be counted as a root view (because, perhaps, it has a reactTag of 22 or 12 instead of 21 or 11) and for the app to keep looking. Once a rootView is found, the app ends up crawling the wrong view, and thus not finding the InputAccessoryView to associate with the textInput.

// TODO: this is kinda dumb - let's come up with a
// better way of identifying root React views please!
static inline BOOL RCTIsReactRootView(NSNumber *reactTag)
{
return reactTag.integerValue % 10 == 1;
}

Here's the code that goes looking

- (void)setCustomInputAccessoryViewWithNativeID:(NSString *)nativeID
{
#if !TARGET_OS_TV
__weak RCTBaseTextInputView *weakSelf = self;
[_bridge.uiManager rootViewForReactTag:self.reactTag withCompletion:^(UIView *rootView) {
RCTBaseTextInputView *strongSelf = weakSelf;
if (rootView) {
UIView *accessoryView = [strongSelf->_bridge.uiManager viewForNativeID:nativeID
withRootTag:rootView.reactTag];
if (accessoryView && [accessoryView isKindOfClass:[RCTInputAccessoryView class]]) {
strongSelf.backedTextInputView.inputAccessoryView = ((RCTInputAccessoryView *)accessoryView).inputAccessoryView;
[strongSelf reloadInputViewsIfNecessary];
}
}
}];
#endif /* !TARGET_OS_TV */
}

@gbalduzzi
Copy link

I'm facing the same issue and it's actually blocking in my situation.

Are there any ways to workaround this issue?

@kotomono
Copy link

any news on this? i'm facing the problem as the numeric textinput is inside a modal and it's blocking me

@thymikee
Copy link
Contributor

@euroclydon37 are you able to preare a PR with a fix using your findings?

@thymikee thymikee added Platform: iOS iOS applications. Follow Up labels Mar 19, 2019
@cpojer
Copy link
Contributor

cpojer commented Mar 26, 2019

This is a real bug but it is unlikely we'll be able to spend any time on a fix so I'm going to close this issue. It seems that you already have a way to fix it so if you could send a Pull Request, we are happy to review and land it.

@cpojer cpojer closed this as completed Mar 26, 2019
@schvenk
Copy link

schvenk commented Apr 10, 2019

I know this is closed but am blocked by this myself and would love a fix. @euroclydon37 any chance of a PR?

@EmilyRagan
Copy link

Interested as well! I'm running into this problem

@roger-ngx
Copy link

any update with this ?

@facebook facebook locked as resolved and limited conversation to collaborators Mar 26, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests