-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Invoking TextInput methods via ref produces errors. #28459
Comments
This happened to me as well after updating from 0.61.5 to 0.62 |
Same. I came from react-native v0.59.9 then upgraded to 0.62.0. Didn't encounter this one on previous version.. |
Same here. Because of these lines: react-native/Libraries/Components/TextInput/TextInput.js Lines 946 to 979 in 3a11f05
with the following type definition: react-native/Libraries/Components/TextInput/TextInput.js Lines 694 to 698 in 3a11f05
I think most of these changes were introduced here: bbc5c35 more specifically: bbc5c35#diff-b48972356bc8dca4a00747d002fc3dd5L909-L937 I suppose only |
Let's maybe tag @TheSavior |
Thanks for the tag. This wasn't an intentional breaking change. The repro has the code:
Does it work if you
Or call the function instead of passing the function?
|
Hey man!
is working?.. Am i missing some JS/ES6 basics? Anyway thank you. Thank you also @TuurDutoit for pointing out the change in the codebase didn't have the time to check that one out and I immediately created an issue because i thought that, if there is some changes, it is somehow be indicated in the changelog or at least at the 0.62 documentation.. |
Can you show me in an expo snack an example that worked on 0.61 but not 0.62? It’s possible that when this was refactored we need to bind it. In which case we need to land this fix and get it picked into a 0.62 patch release. I’ll leave this open for now because this is potentially an issue in 0.62 |
v0.61: https://github.com/TuurDutoit/rn-text-input-61 It seems that it does work on 62, because the methods are on the prototype chain. However, the Flow types are failing for them; that's what set me off in the first place. If you open the v0.62 in an editor, you'll get a Flow error on this line: https://github.com/TuurDutoit/rn-text-input-62/blob/ba5a5b05e39d524bc2df8d8dca34a5e9bf951b5b/App.js#L17
|
I am also encountering errors on Got this error when try to test my component that has a TextInput |
Shouldn't it be |
@TuurDutoit src.js const mobileNumberRef = useRef<TextInput>(null);
<TextInput testID={"mobileNumberTextInput"} ref={mobileNumberRef} .../> test.js const { queryByTestId } = render(<SomeScreen />);
const textInput = queryByTestId("mobileNumberTextInput")!;
expect(textInput.instance.isFocused()).toEqual(true); // fails due to TypeError: textInput.instance.isFocused is not a function Used to work on RN 0.61.5. Broke on 0.62.1 |
@hxiongg, your issue is different. It looks like this fix didn't get picked to 0.62, I've requested it get picked here: react-native-community/releases#184 (comment) |
@TuurDutoit thanks for the demo. I've run it on snack (pre 62), master, your 62 project, and a new 62 project, and I haven't gotten it to give me that error in any example... |
This is the output from Flow ran on the rn-text-input-62 project:
|
This is what I did: $ git clone [email protected]:TuurDutoit/rn-text-input-62.git
$ cd rn-text-input-62
$ yarn
$ node_modules/.bin/flow |
Oh, this is a flow issue? I thought it was a runtime issue you were reporting |
Alright, I think there are three different problems mentioned in this thread.
|
@trglairnarra, I wouldn't say the issue is part of the basics, but it is a common JavaScript issue. See this MDN page for more information: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout#The_this_problem |
@TheSavior Not sure if this is the cause of this issue, but I just observed a weird behaviour for This is the App component:
You can find the full project for Both are created from scratch with |
Any updates on this? I'm getting the same error while trying to call |
@nicolas-amabile it isn't clear which error you are saying you are getting. See this comment where I broke down the three different types of errors reported in this thread: #28459 (comment) As the error reported in the original post is a known breaking change due to the functions not being bound anymore to be consistent with other functions in React Native, I'm going to close this post. If you have errors unrelated to the OP please open a new issue with context. |
We add `typeof` in several places to address this Flow error that starts appearing at the RN and Flow upgrade: ``` Cannot use `TextInput` as a type. A name can be used as a type only if it refers to a type definition, an interface definition, or a class definition. To get the type of a non-class value, use `typeof`. ``` I'm not sure if this is due to the Flow upgrade or to changes React Native made to `TextInput`, or both. Several changes to `TextInput` are announced in the changelog [1], including three that are breaking, but I haven't been able to identify any in particular that would start giving us that error. With that dealt with, we also get this new error on calling various methods on the instance stored at a `TextInput` ref (e.g., `textInputRef.current.focus()`): ``` Cannot call textInputRef.current.focus because: • Either property focus is missing in AbstractComponent [1]. • Or property focus is missing in object type [2]. ``` At first, I thought something was wrong with how we're annotating the variable storing the ref, or that Flow didn't fully understand the `React.createRef` API (we started using that in a recent commit before the main upgrade commit). But rather, it seems to be an issue that's known to occur at RN v0.61.1, and which didn't occur on `master` as of 2020-04-06 [2]. Checking commits around that date in `react-native`, I'm pretty sure we'll have a fix in RN v0.63 (zulip#4245). [1] https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#0620 [2] See point 2 at facebook/react-native#28459 (comment).
We add `typeof` in several places to address this Flow error that starts appearing at the RN and Flow upgrade: ``` Cannot use `TextInput` as a type. A name can be used as a type only if it refers to a type definition, an interface definition, or a class definition. To get the type of a non-class value, use `typeof`. ``` I'm not sure if this is due to the Flow upgrade or to changes React Native made to `TextInput`, or both. Several changes to `TextInput` are announced in the changelog [1], including three that are breaking, but I haven't been able to identify any in particular that would start giving us that error. With that dealt with, we also get this new error on calling various methods on the instance stored at a `TextInput` ref (e.g., `textInputRef.current.focus()`): ``` Cannot call textInputRef.current.focus because: • Either property focus is missing in AbstractComponent [1]. • Or property focus is missing in object type [2]. ``` At first, I thought something was wrong with how we're annotating the variable storing the ref, or that Flow didn't fully understand the `React.createRef` API (we started using that in a recent commit before the main upgrade commit). But rather, it seems to be an issue that's known to occur at RN v0.61.1, and which didn't occur on `master` as of 2020-04-06 [2]. Checking commits around that date in `react-native`, I'm pretty sure we'll have a fix in RN v0.63 (zulip#4245). [1] https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#0620 [2] See point 2 at facebook/react-native#28459 (comment).
We add `typeof` in several places to address this Flow error that starts appearing at the RN and Flow upgrade: ``` Cannot use `TextInput` as a type. A name can be used as a type only if it refers to a type definition, an interface definition, or a class definition. To get the type of a non-class value, use `typeof`. ``` I'm not sure if this is due to the Flow upgrade or to changes React Native made to `TextInput`, or both. Several changes to `TextInput` are announced in the changelog [1], including three that are breaking, but I haven't been able to identify any in particular that would start giving us that error. With that dealt with, we also get this new error on calling various methods on the instance stored at a `TextInput` ref (e.g., `textInputRef.current.focus()`): ``` Cannot call textInputRef.current.focus because: • Either property focus is missing in AbstractComponent [1]. • Or property focus is missing in object type [2]. ``` At first, I thought something was wrong with how we're annotating the variable storing the ref, or that Flow didn't fully understand the `React.createRef` API (we started using that in a recent commit before the main upgrade commit). But rather, it seems to be an issue that's known to occur at RN v0.61.1, and which didn't occur on `master` as of 2020-04-06 [2]. Checking commits around that date in `react-native`, I'm pretty sure we'll have a fix in RN v0.63 (zulip#4245). [1] https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#0620 [2] See point 2 at facebook/react-native#28459 (comment).
We add `typeof` in several places to address this Flow error that starts appearing at the RN and Flow upgrade: ``` Cannot use `TextInput` as a type. A name can be used as a type only if it refers to a type definition, an interface definition, or a class definition. To get the type of a non-class value, use `typeof`. ``` I'm not sure if this is due to the Flow upgrade or to changes React Native made to `TextInput`, or both. Several changes to `TextInput` are announced in the RN changelog [1], including three that are breaking, but I haven't been able to identify any in particular that would start giving us that error. With that dealt with, we also get this new error on calling various methods on the instance stored at a `TextInput` ref (e.g., `textInputRef.current.focus()`): ``` Cannot call textInputRef.current.focus because: • Either property focus is missing in AbstractComponent [1]. • Or property focus is missing in object type [2]. ``` At first, I thought something was wrong with how we're annotating the variable storing the ref, or that Flow didn't fully understand the `React.createRef` API (we started using that in a recent commit before the main upgrade commit). But rather, it seems to be an issue that's known to occur at RN v0.61.1, and which didn't occur on `master` as of 2020-04-06 [2]. Checking commits around that date in `react-native`, I'm pretty sure we'll have a fix in RN v0.63 (zulip#4245). [1] https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#0620 [2] See point 2 at facebook/react-native#28459 (comment).
We add `typeof` in several places to address this Flow error that starts appearing at the RN and Flow upgrade: ``` Cannot use `TextInput` as a type. A name can be used as a type only if it refers to a type definition, an interface definition, or a class definition. To get the type of a non-class value, use `typeof`. ``` I'm not sure if this is due to the Flow upgrade or to changes React Native made to `TextInput`, or both. Several changes to `TextInput` are announced in the RN changelog [1], including three that are breaking, but I haven't been able to identify any in particular that would start giving us that error. With that dealt with, we also get this new error on calling various methods on the instance stored at a `TextInput` ref (e.g., `textInputRef.current.focus()`): ``` Cannot call textInputRef.current.focus because: • Either property focus is missing in AbstractComponent [1]. • Or property focus is missing in object type [2]. ``` At first, I thought something was wrong with how we're annotating the variable storing the ref, or that Flow didn't fully understand the `React.createRef` API (we started using that in a recent commit before the main upgrade commit). But rather, it seems to be an issue that's known to occur at RN v0.61.1, and which didn't occur on `master` as of 2020-04-06 [2]. Checking commits around that date in `react-native`, I'm pretty sure we'll have a fix in RN v0.63 (zulip#4245). [1] https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#0620 [2] See point 2 at facebook/react-native#28459 (comment).
We add `typeof` in several places to address this Flow error that starts appearing at the RN and Flow upgrade: ``` Cannot use `TextInput` as a type. A name can be used as a type only if it refers to a type definition, an interface definition, or a class definition. To get the type of a non-class value, use `typeof`. ``` I'm not sure if this is due to the Flow upgrade or to changes React Native made to `TextInput`, or both. Several changes to `TextInput` are announced in the RN changelog [1], including three that are breaking, but I haven't been able to identify any in particular that would start giving us that error. With that dealt with, we also get this new error on calling various methods on the instance stored at a `TextInput` ref (e.g., `textInputRef.current.focus()`): ``` Cannot call textInputRef.current.focus because: • Either property focus is missing in AbstractComponent [1]. • Or property focus is missing in object type [2]. ``` At first, I thought something was wrong with how we're annotating the variable storing the ref, or that Flow didn't fully understand the `React.createRef` API (we started using that in a recent commit before the main upgrade commit). But rather, it seems to be an issue that's known to occur at RN v0.61.1, and which didn't occur on `master` as of 2020-04-06 [2]. Checking commits around that date in `react-native`, I'm pretty sure we'll have a fix in RN v0.63 (zulip#4245). [1] https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#0620 [2] See point 2 at facebook/react-native#28459 (comment).
We add `typeof` in several places to address this Flow error that starts appearing at the RN and Flow upgrade: ``` Cannot use `TextInput` as a type. A name can be used as a type only if it refers to a type definition, an interface definition, or a class definition. To get the type of a non-class value, use `typeof`. ``` I'm not sure if this is due to the Flow upgrade or to changes React Native made to `TextInput`, or both. Several changes to `TextInput` are announced in the RN changelog [1], including three that are breaking, but I haven't been able to identify any in particular that would start giving us that error. With that dealt with, we also get this new error on calling various methods on the instance stored at a `TextInput` ref (e.g., `textInputRef.current.focus()`): ``` Cannot call textInputRef.current.focus because: • Either property focus is missing in AbstractComponent [1]. • Or property focus is missing in object type [2]. ``` At first, I thought something was wrong with how we're annotating the variable storing the ref, or that Flow didn't fully understand the `React.createRef` API (we started using that in a recent commit before the main upgrade commit). But rather, it seems to be an issue that's known to occur at RN v0.61.1, and which didn't occur on `master` as of 2020-04-06 [2]. Checking commits around that date in `react-native`, I'm pretty sure we'll have a fix in RN v0.63 (zulip#4245). [1] https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#0620 [2] See point 2 at facebook/react-native#28459 (comment).
We add `typeof` in several places to address this Flow error that starts appearing at the RN and Flow upgrade: ``` Cannot use `TextInput` as a type. A name can be used as a type only if it refers to a type definition, an interface definition, or a class definition. To get the type of a non-class value, use `typeof`. ``` I'm not sure if this is due to the Flow upgrade or to changes React Native made to `TextInput`, or both. Several changes to `TextInput` are announced in the RN changelog [1], including three that are breaking, but I haven't been able to identify any in particular that would start giving us that error. With that dealt with, we also get this new error on calling various methods on the instance stored at a `TextInput` ref (e.g., `textInputRef.current.focus()`): ``` Cannot call textInputRef.current.focus because: • Either property focus is missing in AbstractComponent [1]. • Or property focus is missing in object type [2]. ``` At first, I thought something was wrong with how we're annotating the variable storing the ref, or that Flow didn't fully understand the `React.createRef` API (we started using that in a recent commit before the main upgrade commit). But rather, it seems to be an issue that's known to occur at RN v0.61.1, and which didn't occur on `master` as of 2020-04-06 [2]. Checking commits around that date in `react-native`, I'm pretty sure we'll have a fix in RN v0.63 (zulip#4245). I posted at the RN v0.63 upgrade issue (zulip#4245) with these observations [3]. [1] https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#0620 [2] See point 2 at facebook/react-native#28459 (comment). [3] zulip#4245 (comment)
We add `typeof` in several places to address this Flow error that starts appearing at the RN and Flow upgrade: ``` Cannot use `TextInput` as a type. A name can be used as a type only if it refers to a type definition, an interface definition, or a class definition. To get the type of a non-class value, use `typeof`. ``` I'm not sure if this is due to the Flow upgrade or to changes React Native made to `TextInput`, or both. Several changes to `TextInput` are announced in the RN changelog [1], including three that are breaking, but I haven't been able to identify any in particular that would start giving us that error. With that dealt with, we also get this new error on calling various methods on the instance stored at a `TextInput` ref (e.g., `textInputRef.current.focus()`): ``` Cannot call textInputRef.current.focus because: • Either property focus is missing in AbstractComponent [1]. • Or property focus is missing in object type [2]. ``` At first, I thought something was wrong with how we're annotating the variable storing the ref, or that Flow didn't fully understand the `React.createRef` API (we started using that in a recent commit before the main upgrade commit). But rather, it seems to be an issue that's known to occur at RN v0.61.1, and which didn't occur on `master` as of 2020-04-06 [2]. Checking commits around that date in `react-native`, I'm pretty sure we'll have a fix in RN v0.63 (zulip#4245). I posted at the RN v0.63 upgrade issue (zulip#4245) with these observations [3]. [1] https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#0620 [2] See point 2 at facebook/react-native#28459 (comment). [3] zulip#4245 (comment)
Description
After invoking the focus method of the TextInput component of react native this one shows.
Tried other methods based on the documentation. different error shows per method..
React Native version:
System:
OS: macOS Mojave 10.14.6
CPU: (4) x64 Intel(R) Core(TM) i5-4570R CPU @ 2.70GHz
Memory: 468.52 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
Yarn: 1.22.0 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.15.3/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.1, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
Android SDK:
API Levels: 22, 23, 24, 26, 27, 28, 29
Build Tools: 23.0.1, 26.0.3, 27.0.0, 27.0.1, 27.0.3, 28.0.0, 28.0.3, 29.0.0
System Images: android-26 | Google Play Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-29 | Intel x86 Atom, android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom_64
Android NDK: Not Found
IDEs:
Android Studio: 3.4 AI-183.5429.30.34.5452501
Xcode: 11.1/11A1027 - /usr/bin/xcodebuild
Languages:
Python: 2.7.16 - /usr/local/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: 0.62.0 => 0.62.0
npmGlobalPackages:
react-native: Not Found
Steps To Reproduce
Given the following code:
Expected Results
Should focus on the input and then show the keyboard.
The text was updated successfully, but these errors were encountered: