无法读取null的属性'props'-React Native

时间:2019-08-07 20:43:45

标签: javascript react-native

我有一个像2个月前发布的移动应用程序。我现在必须进行一些更改。在此之前,我升级了android studio,因此我的sdk也升级到了28。因此,我遇到了几个问题,但是我可以找到解决方法。

但是现在,当我在模拟器上运行应用程序时,某些事件发生了错误。

TypeError: TypeError: Cannot read property 'props' of null

This error is located at:
    in PickerAndroid (at Picker.js:159)
    in Picker (at Picker.android.js:11)
    in PickerNB (at connectStyle.js:384)
    in Styled(PickerNB) (at HomeScreen.js:626)
    in RCTView (at View.js:45)
    in View (at createAnimatedComponent.js:153)
    in AnimatedComponent (at TouchableOpacity.js:256)
    in TouchableOpacity (at Item.js:383)
    in Item (at connectStyle.js:384)
    in Styled(Item) (at HomeScreen.js:624)
    in RCTView (at View.js:45)
    in View (at ScrollView.js:852)
    in RCTScrollView (at ScrollView.js:977)
    in ScrollView (at HomeScreen.js:623)
    in RCTView (at View.js:45)
    in View (at HomeScreen.js:622)
    in RCTView (at View.js:45)
    in View (at HomeScreen.js:620)
    in RCTView (at View.js:45)
    in View (at createAnimatedComponent.js:153)
    in AnimatedComponent (at createAnimatableComponent.js:571)
    in withAnimatable(View) (at src/index.js:455)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:98)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:115)
    in AppContainer (at Modal.js:230)
    in RCTView (at View.js:45)
    in View (at Modal.js:250)
    in RCTModalHostView (at Modal.js:238)
    in Modal (at src/index.js:468)
    in ReactNativeModal (at HomeScreen.js:619)
    in RCTView (at View.js:45)
    in View (at react-native-drawer/index.js:579)
    in RCTView (at View.js:45)
    in View (at react-native-drawer/index.js:566)
    in Drawer (at Drawer/index.js:10)
    in Drawer (at HomeScreen.js:614)
    in HomeScreen (at navigationStore.js:448)
    in Wrapped (at SceneView.js:9)
    in SceneView (at StackViewLayout.js:478)
    in RCTView (at View.js:45)
    in View (at StackViewLayout.js:477)
    in RCTView (at View.js:45)
    in View (at StackViewLayout.js:476)
    in RCTView (at View.js:45)
    in View (at createAnimatedComponent.js:153)
    in AnimatedComponent (at screens.native.js:59)
    in Screen (at StackViewCard.js:42)
    in Card (at createPointerEventsContainer.js:26)
    in Container (at StackViewLayout.js:507)
    in RCTView (at View.js:45)
    in View (at screens.native.js:83)
    in ScreenContainer (at StackViewLayout.js:401)
    in RCTView (at View.js:45)
    in View (at StackViewLayout.js:400)
    in StackViewLayout (at withOrientation.js:30)
    in withOrientation (at StackView.js:49)
    in RCTView (at View.js:45)
    in View (at Transitioner.js:141)
    in Transitioner (at StackView.js:19)
    in StackView (at createNavigator.js:57)
    in Navigator (at createKeyboardAwareNavigator.js:11)
    in KeyboardAwareNavigator (at createNavigationContainer.js:376)
    in NavigationContainer (at Router.js:97)
    in App (at Router.js:122)
    in Router (at App.js:59)
    in App (at renderApplication.js:34)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:98)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:115)
    in AppContainer (at renderApplication.js:33)

This error is located at:
    in NavigationContainer (at Router.js:97)
    in App (at Router.js:122)
    in Router (at App.js:59)
    in App (at renderApplication.js:34)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:98)
    in RCTView (at View.js:45)
    in View (at AppContainer.js:115)
    in AppContainer (at renderApplication.js:33)
<unknown>
    PickerAndroid.android.js:87:16
mapSingleChildIntoContext
    react.development.js:1170:25
traverseAllChildrenImpl
    react.development.js:1043:4
traverseAllChildrenImpl
    react.development.js:1059:22
traverseAllChildren
    react.development.js:1114:9
mapIntoWithKeyPrefixInternal
    react.development.js:1192:2
Object.mapChildren [as map]
    react.development.js:1214:2
PickerAndroid._this._stateFromProps
    PickerAndroid.android.js:86:33
new
    PickerAndroid.android.js:69:23
<unknown>
    createClassProxy.js:98:23

我在使用此组件时看到此错误。

    import React, { Component } from "react";
    import {
        View,
        Text,
        StyleSheet,
        TouchableOpacity,
TouchableHighlight
    } from "react-native";

    import Modal from "react-native-modal";

    import { Item, Label, Input, Textarea, Button } from 'native-base';

    import { HEADERBG } from './../Helper/config';

    import FontAwesome from 'react-native-vector-icons/FontAwesome';

    import ImagePicker from 'react-native-image-crop-picker';

    class NewPost extends Component {

        constructor(props){
            super(props);
            this.state = {
                category: null,
                messageText: null,
                isModalVisible: this.props.isVisible
            }

            this._toggleModal = this._toggleModal.bind(this);
        }

        _toggleModal(){
            this.setState({
                isModalVisible: !this.state.isModalVisible
            })
        }



        render() {
            return (
                <Modal style={{ flexDirection: 'column', justifyContent: 'flex-start' }} isVisible={this.props.isVisible}>
                    <View style={styles.container}>
                        <Text allowFontScaling={false} style={styles.headText}>Yeni Paylaşım Yap</Text>
                        <View style={styles.form}>
                            <Item style={styles.item} stackedLabel>
                                <Label style={styles.label}>Mesaj Kategorisi2</Label>
                                <Input onChangeText={(text) => this.setState({ email: text })} style={{padding: 10, borderWidth: 1/3, borderColor: 'gray', color: '#212121'}} blurOnSubmit={false} placeholder="E-Posta adresiniz" />
                            </Item>
                            <Item style={styles.item} stackedLabel>
                                <Label style={styles.label}>Mesajınız</Label>
                                <Text allowFontScaling={false}area rowSpan={5} bordered placeholder="Textarea" style={{ borderWidth: 1/4, color: '#212121', width: '100%' }} />
                            </Item>
                            <Item style={styles.item} stackedLabel>
                                <TouchableOpacity onPress={() => this.openPicker()} style={styles.imageButton}>
                                    <Text allowFontScaling={false} style={styles.imageText}>Görsel Seçin</Text>
                                </TouchableOpacity>
                            </Item>
                            <Button style={styles.sendButton} block>
                                <FontAwesome name="paper-plane" size={20} color="#fff" />
                                <Text allowFontScaling={false} style={{marginLeft: 5, fontSize: 16, color: '#fff'}}>Kapıyı Tıklat!</Text>
                            </Button>
                            <Button onPress={() => this._toggleModal()} style={{backgroundColor: '#E74C3C', marginVertical: 10}} block>
                                <FontAwesome name="times-circle" size={20} color="#fff" />
                                <Text allowFontScaling={false} style={{marginLeft: 5, fontSize: 16, color: '#fff'}}>Vazgeç!</Text>
                            </Button>
                        </View>
                    </View>
                </Modal>
            );
        }
    }

2 个答案:

答案 0 :(得分:0)

您的错误可能在这里:isModalVisible: this.props.isVisible

如果您没有通过道具传递任何内容,则应在状态下写isModalVisible: false

为什么要投票3次?如果有人是新来的,我们应该尝试了解他们的问题并解决问题

答案 1 :(得分:0)

我认为问题在于react-native-image-crop-picker包!尝试更新并重新配置!