简体   繁体   中英

TypeError: undefined is not an object (evaluating '_reactNative.Animated.Text.propTypes.style')

After upgrading React Native to 0.62.2 , and installing react-native-material-dropdown ` library, project is giving this error:

在此处输入图像描述

I solved this by,

  • Commenting itemTextStyle: Text.propTypes.style in
    ..\node_modules\react-native-material-dropdown\src\components\dropdown file.

  • And remove Animated in Animated.Text.propTypes.style in

    affix/index

    helper/index

    label/index

    of react-native-material-textfield .

  • And added import { Animated, Text} from 'react-native'; in each of above three files.

Here is another solution I've found.

  1. Remove installed package react-native-material-dropdown

    yarn remove react-native-material-dropdown

  2. Install new packages react-native-material-dropdown-v2 and react-native-paper

    yarn add react-native-material-dropdown-v2 react-native-paper

  3. Swap react-native-material-dropdown to react-native-material-dropdown-v2 in your code

    eg import { Dropdown } from 'react-native-material-dropdown' to import { Dropdown } from 'react-native-material-dropdown-v2'

I found the same problem while using @react-navigation/drawer

I've solved it by these steps.

  1. Open node_modules and then search for react-native-material-textfield open the file and go to src folder
  2. Under src you will see affix , helper , label folder - under each folder, there is an index.js
  3. open the index.js of the mentioned folders one by one (all 3 folders) and search for the text style: Animated.Text.propTypes.style , and replace it by style: Text.propTypes
  4. And import text form react-native like this import { Animated, Text} from 'react-native';
  5. And now reload the terminal, and you are good to go

There is an issue open on github about this problem. As mentioned in the comment, it is possible to use this option to edit node modules, or create a patch so that it is not necessary to edit the files every time you add a new library or run an npm install.

Instruction:

  • Create patches directory in your project's root
  • Copy patch to patches/react-native-material-textfield+0.16.1.patch
  • yarn add patch-package postinstall-postinstall or npm i patch-package
  • yarn patch-package or npx patch-package

Fix is already applied. Add the following to package.json to not repeat the same next time:

 "scripts": {
+  "postinstall": "patch-package"
 }

https://github.com/n4kz/react-native-material-textfield/issues/249#issuecomment-625791243

I faced the same issue while using react-native-material-dropdown.

Fix:

  • navigate to node_modules/react-native-material-textfield/src/components
  • Open files affix/index.js , helper/index.js and label/index.js
  • Replace style: Animated.Text.propTypes.style with style: Text.propType
  • import {Text} in each of these 3 files import { Animated,Text} from 'react-native'

This should fix the issue

react-native version: 0.64.0

Just update the library they updated their library with fixes here is the link https://www.npmjs.com/package/react-native-material-dropdown-v2-fixed

Im using react-native-material-textfield . Add in my js file before import:

import { Animated, Text } from 'react-native';
Animated.Text.propTypes = Animated.Text.propTypes || Text.propTypes;
import { TextField } from 'react-native-material-textfield';

在此处输入图像描述

I have faced the same issue while using react-native-material-dropdown.

Fixed using this:

navigate to node_modules/react-native-material-textfield/src/components
Open files affix/index.js, helper/index.js and label/index.js

I have resolved my issue by using this lib

react-native-material-dropdown-no-proptypes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM