Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed prop type: Invalid prop source supplied to Image. React Native #152

Open
kanwar002 opened this issue Oct 2, 2020 · 2 comments
Open

Comments

@kanwar002
Copy link

Failed prop type: Invalid prop source supplied to Image I'm getting that error while uploading image.
I used image picker to pick image and made it component but it's not picking up source below is my code of image picker
FormImage.js

class FormImage extends Component {
state = {
hasCameraPermission: null,
};

async componentDidMount() {
const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
this.setState({ hasCameraPermission: status === "granted" });
}

_pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [4, 3],
});

if (!result.cancelled) {
  this.setState({ image: result.uri });
  this.props.formikProps.setFieldValue("image", result.uri);
}

};

render() {
return (


{!this.props.image && (

)}
{this.props.image && (
<Image style={styles.image} source={{ uri: this.props.image }} />
)}


);
}
Addpost.js

const validationSchema = Yup.object({
title: Yup.string().required().min(5).max(15).label("Title"),
des: Yup.string().required().min(15).max(200).label("Description"),
image: Yup.mixed(),
});

class AddPost extends Component {
render() {
return (
<Formik
initialValues={{ title: "", des: "", image: null }}
onSubmit={(values, actions) => {
this.props.addPost(values);
console.log(values);
}}
validationSchema={validationSchema}
>
{(value) => (
<KeyboardAvoidingView
behavior="position"
keyboardVerticalOffset={Platform.OS === "ios" ? 0 : 100}
>


{value.touched.image && value.errors.image}

<TextInput
placeholder="Title"
onChangeText={value.handleChange("title")}
style={styles.input}
value={value.values.title}
onBlur={value.handleBlur("title")}
/>

can anyone tell me what's going on?

@GwFreak01
Copy link

I dont think source is a valid prop for this package. It only accepts the following props:

  1. style
  2. defaultSource
  3. preview
  4. options
  5. uri
  6. transitionDuration
  7. tint
  8. onError

You should most likely set the uri prop in the Image component from result.uri

@amjed-ali-k
Copy link

Change

<Image style={styles.image} source={{ uri: this.props.image }} />

To

<Image style={styles.image} uri={this.props.image } />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants