【发布时间】:2021-09-08 14:02:05
【问题描述】:
我使用 react-native-fs 从服务器下载图像,然后使用 react-native-image-crop-picker 中的 openCropper() 进行裁剪。它在 iOS 中运行良好,但在 Android 运行时崩溃,没有任何错误消息或警报。
你有过这个问题吗?给我一个指导。谢谢大家。
const onCropImage = async () => {
setViewImageModal(false);
const uri = `${RNFS.DocumentDirectoryPath}/${fileName}`;
let options = {
fromUrl: viewImage && viewImage[0].url,
toFile: uri,
};
await RNFS.downloadFile(options).promise;
// App crashed when I call .openCropper() in Android running
ImageCropPicker.openCropper({
path: uri,
width: 300,
height: 400,
cropping: true,
freeStyleCropEnabled: true,
})
.then((image) => {
if (image) {
const temp = image.path.split("/");
const imageName = temp[temp.length - 1];
navigation.navigate("EditHostScreen", {
host,
type: "hosts",
info: { uri: image.path, typeImage: image.mime, name: imageName },
});
const time = setTimeout(() => {
ImageCropPicker.clean();
if (uri) {
RNFS.unlink(uri);
}
}, 100000);
clearTimeout(time);
}
})
.catch((err) => {
// console.log(err);
});
};
【问题讨论】:
-
你完成installation step for android了吗?另外,尝试清理和重建调试 apk
-
是的,我错过了指定的路径。 ... 路径:Platform.OS === 'android' ?
file://${uri}: uri 而不是 path: uri。感谢您的评论
标签: android react-native react-native-android