本机真棒警报自定义视图抛出错误

问题描述 投票:0回答:2

我正在使用react-native-awesome-alerts插件在我的屏幕上显示警报。我已经为警报创建了一个自定义视图,但它会抛出这个错误

没有测量功能,无法将没有YogaNode的孩子添加到父级! (尝试将'RCTRawText [text:}]'添加到'RCTView')

我的代码是这样的:

_displayNotifyAlert(){
  if(this.state.notifyAlert == true){
    return (
      <AwesomeAlert
        show={true}
        title="Service Cancellation"
        message="Tell the shop why are you cancelling their services."
        messageStyle={{ textAlign: 'center' }}
        customView={this.renderCustomAlertView()}
        showCancelButton={true}
        showConfirmButton={true}
        cancelText="Cancel"
        confirmText="Cancel Service"
        confirmButtonColor={Colors.default}
        onCancelPressed={() => this._closeNotifyAlert()}
        onConfirmPressed={() => this._cancelServices()}
      />
    )
  }
}

renderCustomAlertView = () => (
  <View style={[ AppStyles.input ]}>
    <TextInput
      placeholder="Write your reason briefly."
      underlineColorAndroid="transparent"
      style={{ textAlignVertical: 'top', height: 100 }}
      numberOfLines={5}
      multiline={true}
      maxLength={200}
      onChangeText={(cancel_reason) => this.setState({cancel_reason})} />
    }
  </View>
)

如果我删除此行customView={this.renderCustomAlertView()},错误将消失。我没有在renderCustomAlertView函数中看到任何不正确的代码。所以我无法追查错误的原因。以前有人遇到过同样的问题吗?

react-native plugins alert custom-view
2个回答
0
投票

你的renderCustomAlertView函数末尾有一个额外的“}”。将此功能更改为以下内容,它应该工作:

renderCustomAlertView = () => (
  <View style={[ AppStyles.input ]}>
    <TextInput
      placeholder="Write your reason briefly."
      underlineColorAndroid="transparent"
      style={{ textAlignVertical: 'top', height: 100 }}
      numberOfLines={5}
      multiline={true}
      maxLength={200}
      onChangeText={(cancel_reason) => this.setState({cancel_reason})} />
  </View>
)

0
投票

我不能在你的帖子中发表评论,因为声誉很低,所以我把它作为一个答案。根据我的反应本机和基于您的代码的知识您在renderCustomAlertView中缺少返回。

所以你的代码必须是这样的

   renderCustomAlertView = () => {
             return(
              <View style={[ AppStyles.input ]}>
                  <TextInput
                     placeholder="Write your reason briefly."
                     underlineColorAndroid="transparent"
                     style={{ textAlignVertical: 'top', height: 100 }}
                     numberOfLines={5}
                     multiline={true}
                     maxLength={200}
                     onChangeText={(cancel_reason) => this.setState({cancel_reason})} />
           </View>
     )
   }
© www.soinside.com 2019 - 2024. All rights reserved.