terrylinla / react-native-sketch-canvas

A React Native component for drawing by touching on both iOS and Android.
MIT License
695 stars 453 forks source link

TypeError: null is not an object (evaluating 'this.modalRef.setModalVisible'), #196

Open harshakumar87 opened 3 years ago

harshakumar87 commented 3 years ago

Hi,

I am using canvas to edit the captured image. The implementation is working fine on iOS(Capture image and edit using sketch canvas but in Android I am getting the below error soon after capturing image. Please help

TypeError: null is not an object (evaluating 'this.modalRef.setModalVisible')

Below is my code snippet for your reference

 openDrawImageModal() {
    this.modalRef.setModalVisible(true);
  }
takeImage() {
 launchCamera({
                mediaType: 'photo',
                maxWidth: 400,
                maxHeigth: 300,
                quality: 0.5
              },(response) => {
                  if (response.didCancel) {
                  } else if (response.error) {
                    this.imageError(response.error);
                  } else if (response.customButton) {
                    if (response.customButton == "DeleteImage") this.deleteImage();
                  } else {
                    let source = response;
                    this.setState({ image: source });
                     this.openDrawImageModal();
                  }
                  },
                )
              }
}
<DrawImageModal
            setImageBase64={this.setImageBase64}
            imageUri={
              this.state.image != null && this.state.image.uri
                ? Platform.OS === "ios"
                  ? this.state.image.uri.replace("file://", "")
                  : this.state.image.uri.replace("content://", "")
                : ""
            }
            ref={(modalRef) => {
              this.modalRef = modalRef;
              console.log("render ~ this.modalRef", this.modalRef)
            }}
          />