简体   繁体   中英

My react native app keeps crashing when selecting an image with expo-image-picker

    const Sell = ({navigation}) => { // sell page, user will be able to sell their OWNED foods.
  let [visible, setVisible] = useState(false);
  const [image, setImage] = useState(null);
  const toggleOverlay = () => {
    setVisible(!visible);
  }
  let openImagePickerAsync = async () => {
    let permissionResult = await ImagePicker.requestMediaLibraryPermissionsAsync();

    if (permissionResult.granted === false) {
      alert("Permission to access camera roll is required!");
      return;
    }

    let pickerResult = await ImagePicker.launchImageLibraryAsync();
    if(pickerResult.cancelled === true) {
      return;
    }
    setImage({localUri: pickerResult.uri});
  }
  if(image !== null) {
    return (
      <Image source={{uri: image.localUri}}/>
    );
  }
  return(
    <View style={styles.yourProfileContent}>
      <Overlay isVisible={visible} onBackdropPress={toggleOverlay} fullScreen={true}>
        <View style={styles.yourProfileChangePassword}>
            <TouchableOpacity style={{padding: 5}} onPress={openImagePickerAsync}>
            {image && <Image source={{ uri: image }} style={{ width: 200, height: 200 }} />}
              <MaterialCommunityIcons name='camera' size={50} color='#ff66ff'/>
            </TouchableOpacity>
            <View style={{flexDirection: 'row'}}> 
              <MaterialCommunityIcons name='pencil' size={20} color='#ff66ff' style={styles.sellIcons}/>
              <TextInput maxLength={20} style={styles.textInput} placeholder='Title' placeholderTextColor='#ff66ff' maxLength={20}/>
            </View>
            <View style={{flexDirection: 'row'}}> 
              <MaterialCommunityIcons name='cash' size={20} color='#ff66ff' style={styles.sellIcons}/>
              <TextInput style={styles.textInput} placeholderTextColor='#ff66ff' placeholder="Price (dollars)"
              />
            </View>
            <View style={{flexDirection: 'row'}}> 
              <MaterialCommunityIcons name='book' size={20} color='#ff66ff' style={styles.sellIcons}/>
              <TextInput style={styles.textInput} placeholderTextColor='#ff66ff' placeholder="Description" maxLength={200} multiline={true}
                />
            </View>
            <Button color='#ff66ff' title="POST"/>
            <Text style={styles.register} onPress={toggleOverlay}>Go back.</Text>
          </View>
      </Overlay>
      <Text style={{textAlign: 'center', fontSize: 20, fontWeight:'bold', marginBottom: 5, color: '#ff66ff'}}>Create new listing</Text>
      <TouchableOpacity style={styles.addListing} onPress={toggleOverlay}>
        <Text style={{color: 'white'}}>+</Text>
      </TouchableOpacity>
      
    </View>

  );
}

I read that expo managed react native apps dont have access to the androidmanifest.xml file to allow permission for camera picker, but I used expo-image-picker which says that In managed apps, the permissions to pick images, from camera (Permissions.CAMERA) or camera roll (Permissions.MEDIA_LIBRARY), are added automatically. My app still crashes and sometimes throws the error: Lateinit property stripe has not been initialized. I do not have access to the android files because it is an expo managed project. I am very stuck.

This error has to do with our most recent update to Expo Go on Android

Also a new version for the ExpoGo app has been released.

update your expo go app to Expo Go 2.19.6 .

Read full coversation here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM