react native CameraRoll
react native 为我们调用本地的图片资源提供了一个api接口 CameraRoll
CameraRoll provides access to the local camera roll / gallery. Before using this you must link the RCTCameraRoll library. You can refer to Linking for help.
CameraRoll主要的作用在于我们可以利用他来展示我们的本地的图片,来做一个图片墙,你也可以将网络上的图片保存进你的本机 CameraRoll主要为我们提供了三个方法:如下: *Saves the photo or video to the camera roll / gallery. static getPhotos(params) @param {object} params See getPhotosParamChecker. Returns a Promise which when resolved will be of shape getPhotosReturnChecker. 前两个方法是用来保存图片的,具体用法我也没有用过,这边就不多做解释 源码展示: componentDidMount(){
CameraRoll.getPhotos({first: 5}).done(
(data) =>{
console.log(data);
this.setState({
photoSource: {uri: data.edges[3].node.image.uri}
})
},(error) => {
console.warn(error);
}
);
}
对了还要记住加权限 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |