реагировать на собственный AwesomeAlert customView, выдавая ошибку - PullRequest
0 голосов
/ 02 февраля 2019

Я использую плагин 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.Поэтому я не могу отследить причину ошибки.Кто-нибудь сталкивался с такой же проблемой раньше?

Ответы [ 2 ]

0 голосов
/ 02 февраля 2019

В конце функции 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 голосов
/ 02 февраля 2019

Я не могу комментировать ваше сообщение из-за низкой репутации, поэтому я делаю это в качестве ответа.Насколько я знаю, реагировать на нативные и основанные на вашем коде Вы пропустите возврат в 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>
     )
   }
...