1

Situation: We've used patch-package to the react-native package in order to disable adding a new line when the user presses return in multiline TextInput.

Problem: We only want this behavior of TextInput in one section of the app but not anywhere else.

Question: How should I create a new component that mimics the original TextInput? In the end, I'd like to have two components named TextInput and OriginalTextInput. If the multiline prop is true, the former should not add a new line when pressing return and the opposite for the latter.

I'm all ears on other ways of solving this problem as long as it doesn't involve using the props of TextInput.

mysl
  • 1,003
  • 2
  • 9
  • 19
  • Show the sample code you did – sojin Sep 17 '21 at 15:39
  • @sojin it's one line edit to `textInputShouldChangeText` function of this file: `react-native/Libraries/Text/TextInput/RCTBaseTextInputView.m` that disables adding a new line when pressing return in multiline `TextInput` – mysl Sep 17 '21 at 15:47
  • Can you try this? https://stackoverflow.com/a/49176263/2247055 – FreakyCoder Sep 17 '21 at 15:49
  • @FreakyCoder unfortunately, your link involves using the props of `TextInput` – mysl Sep 17 '21 at 15:52
  • Why don't you want to utilize the props? – Elias Sep 17 '21 at 16:04
  • I don't know why do you need something like this but you can create your own custom text input directly from iOS and Android with the Native Modules. I do not suggest that just for this feature. https://mobilityquotient.com/article/creating-a-native-bridge-in-react-native This link should show you a way how to build a native module. – FreakyCoder Sep 17 '21 at 16:06

0 Answers0