Skip to content

Commit

Permalink
- Fix InputAccessoryView crash on Android (#33803)
Browse files Browse the repository at this point in the history
Summary:
`InputAccessoryView` works fine on iOS, but crashes on Android - you can see that by using an Android device on the [Expo Snack from the official doc](https://reactnative.dev/docs/inputaccessoryview).
It forces the developer not to render the component on Android, which is usually good, but other components have implemented other, safer ways to deal with incompatibility issues.

I am of course open to discussion about this change, as well as other implementation ideas.

## Changelog

[Android] [Fixed] - Fix InputAccessoryView crash on Android

Pull Request resolved: #33803

Test Plan:
`yarn test` gives out the following output:
![image](https://user-images.githubusercontent.com/3397791/167677057-3fda5b53-78bf-4bab-976f-c2e624f4a264.png)

Reviewed By: cipolleschi

Differential Revision: D37215394

Pulled By: cortinico

fbshipit-source-id: 66c4401f7c61b745ea893969d69c8dde3e5afb03
  • Loading branch information
hduprat authored and facebook-github-bot committed Jun 28, 2022
1 parent 7fb0bb4 commit afa5df1
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions Libraries/Components/TextInput/InputAccessoryView.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,23 @@ type Props = $ReadOnly<{|

class InputAccessoryView extends React.Component<Props> {
render(): React.Node {
if (Platform.OS !== 'ios') {
console.warn('<InputAccessoryView> is only supported on iOS.');
}
if (Platform.OS === 'ios') {
if (React.Children.count(this.props.children) === 0) {
return null;
}

if (React.Children.count(this.props.children) === 0) {
return (
<RCTInputAccessoryViewNativeComponent
style={[this.props.style, styles.container]}
nativeID={this.props.nativeID}
backgroundColor={this.props.backgroundColor}>
{this.props.children}
</RCTInputAccessoryViewNativeComponent>
);
} else {
console.warn('<InputAccessoryView> is only supported on iOS.');
return null;
}

return (
<RCTInputAccessoryViewNativeComponent
style={[this.props.style, styles.container]}
nativeID={this.props.nativeID}
backgroundColor={this.props.backgroundColor}>
{this.props.children}
</RCTInputAccessoryViewNativeComponent>
);
}
}

Expand Down

0 comments on commit afa5df1

Please sign in to comment.