{"id":18866412,"url":"https://github.com/quenice/react-native-cacheimage","last_synced_at":"2025-09-12T02:11:25.146Z","repository":{"id":57339593,"uuid":"152690315","full_name":"quenice/react-native-cacheimage","owner":"quenice","description":"A cacheable image component for react native","archived":false,"fork":false,"pushed_at":"2018-10-22T06:21:43.000Z","size":18,"stargazers_count":26,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T14:17:34.449Z","etag":null,"topics":["android","cache-image","ios","react-native"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quenice.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-12T03:40:19.000Z","updated_at":"2022-11-15T07:32:37.000Z","dependencies_parsed_at":"2022-09-18T23:51:30.220Z","dependency_job_id":null,"html_url":"https://github.com/quenice/react-native-cacheimage","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quenice%2Freact-native-cacheimage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quenice%2Freact-native-cacheimage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quenice%2Freact-native-cacheimage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quenice%2Freact-native-cacheimage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quenice","download_url":"https://codeload.github.com/quenice/react-native-cacheimage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248897087,"owners_count":21179535,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","cache-image","ios","react-native"],"created_at":"2024-11-08T05:06:28.425Z","updated_at":"2025-04-14T14:31:11.110Z","avatar_url":"https://github.com/quenice.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Getting started\n\n## rn-fecth-blob\n\n[rn-fetch-blob](https://github.com/joltup/rn-fetch-blob) is a dependency for this package that you'll need to add to your project. To install, run the following commands:\n\n```\n$ npm install rn-fetch-blob --save\n$ react-native link rn-fetch-blob\n```\nAnd I recommend you install `rn-fetch-blob` base on [official guide](https://github.com/joltup/rn-fetch-blob)\n\n## installation\n\n`$ npm install react-native-rn-cacheimage --save`\n\n\n# Usage\n\n## Register and unregister\n\n- Before mount the `\u003cCacheImage/\u003e` or `\u003cAnimatedCacheImage/\u003e` component, should initialize and config some base params. Recommend initialize in the `componentDidMount()` inside of the top `react componet` in your App.\n- When all components of your App will been unmounted, you should unregister this package. Recommend do this in the `componentWillMount()` inside of the top `react componet` in your App.\n\n\n```jsx\nimport React from 'react'\nimport {AppRegistry} from 'react-native'\nimport {Provider} from 'react-redux'\nimport ReduxStore from './src/configuration/reduxStore'\nimport App from './src/App'\nimport {CacheHelper} from \"react-native-rn-cacheimage\";\n\nconst store = ReduxStore\n\nclass MyApp extends React.Component {\n    componentDidMount() {\n        CacheHelper.register({overwrite:false}).catch(e =\u003e console.log(e))\n    }\n\n    componentWillUnmount() {\n        CacheHelper.unregister().catch(e=\u003econsole.log(e))\n    }\n\n    render() {\n        return (\n            \u003cProvider store={store}\u003e\n                \u003cApp/\u003e\n            \u003c/Provider\u003e\n        )\n    }\n}\n\nAppRegistry.registerComponent(\"YourAppName\", () =\u003e MyApp);\n\n```\n\n## Replace `\u003cImage/\u003e` with `\u003cCacheImage/\u003e`\n\nWe can use `\u003cCacheImage/\u003e` just like `\u003cImage/\u003e` component, and everything is all the same besides this\n\n```jsx\nimport {CacheImage} from 'react-native-rn-cacheimage'\nexport default class Example extends React.Component {\n...\n\trender() {\n\n\t\treturn\n\t\t(\n\t\t...\n\t\t\u003cCacheImage\n\t\t\tsource={{uri:'https://xxx.xxx'}}\n\t\t\tdefaultSource={placeholder._800x400}\n\t\t\tstyle={styles.image}\n\t\t/\u003e\n\t\t...\n\t\t)\n\n\t}\n...\n}\n```\n\n\n## Replace `\u003cImageBackground/\u003e` with `\u003cCacheImage/\u003e`\n\nWe can use `\u003cImageBackground/\u003e` just like `\u003cCacheImage/\u003e` component, and everything is all the same besides this\n\n```jsx\nimport {CacheImage} from 'react-native-rn-cacheimage'\n\nexport default class Example extends React.Component {\n...\n\trender() {\n\n\t\treturn\n\t\t(\n\t\t...\n\t\t\u003cCacheImage\n\t\t\tsource={{uri:'https://xxx.xxx'}}\n\t\t\tdefaultSource={placeholder._800x400}\n\t\t\tstyle={styles.image}\n\t\t\u003e\n\t\t\t\u003cText\u003eHello World!\u003c/Text\u003e\n\t\t\u003c/CacheImage\u003e\n\t\t...\n\t\t)\n\n\t}\n...\n}\n```\n\n## Replace `\u003cAnimated.Image/\u003e` component with `\u003cAnimatedCacheImage/\u003e`\n\nWe can use `\u003cAnimatedCacheImage/\u003e` just like `\u003cAnimated.Image/\u003e` component, and everything is all the same besides this\n\n```jsx\nimport {AnimatedCacheImage} from 'react-native-rn-cacheimage'\n\nexport default class Example extends React.Component {\n...\n\trender() {\n\n\t\treturn\n\t\t(\n\t\t...\n\t\t\u003cAnimatedCacheImage\n\t\t\tsource={{uri:'https://xxx.xxx'}}\n\t\t\tdefaultSource={placeholder._800x400}\n\t\t\tstyle={styles.image}\n\t\t/\u003e\n\t\t...\n\t\t)\n\n\t}\n...\n}\n```\n\n\n# API\n\n## Components\n\nAbout below two components, can see the detail in [Usage](#usage)\n\n- `CacheImage`\n- `AnimatedCacheImage`\n\n## CacheHelper\n\n\n### register(config:Object):Promise\\\u003cVoid\\\u003e\n\nInit necessary things of current package(`react-native-rn-cacheimage`). Should call this method before mount `\u003cCacheImage/\u003e` or `\u003cAnimatedCacheImage/\u003e`. Recommend call this method in the TOP component of your App.\n\nname | desc | defaultValue\n---|---|---\n`config.overwrite` | Overwirte or not when the pre-cached(be downloaded just now) file has exists in the local path.  | `false`\n`config.dirsQuantity` | Quantity of all dirs where cached file be saved in. Recommend set a prime number | `17`\n\n### getImagePath(uri:String):Promise\\\u003cImagePath:Object\\\u003e\n\nGet the image cached local path.\n\nname | desc | defaultValue\n---|---|---\n`uri` | Image uri. example: [https://xxx.xxx/xxx.jpg](#)  |\n`ImagePath.uri` | Image cached local path. |\n`ImagePath.task` | It's the task that fetch the remote image, and you can call `task.cancel()` to cancel the fetch task manually |\n\n### getCacheSize():Promise\\\u003cNumber\\\u003e\n\nGet the size of used space of all cached images. The unit of result number is `Byte`\n\n### getCacheSizeFormat():Promise\\\u003cString\\\u003e\n\nSimilarity to `getCacheSize()`, and difference is that the result is been formatted.\n\nThe format rule is as below:\n\n- `0KB` \u003c= `result` \u003c `1024KB`, format to `KB`, eg: `134KB`\n- `result` \u003e= `1024KB`, format to `MB`, eg: `109.3MB`\n\n### clearCache():Promise\\\u003cVoid\\\u003e\n\nClear all cached images.\n\n### unregister():Promise\\\u003cVoid\\\u003e\n\nUn-register current package, cancel all uncompleted tasks which fetch image.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquenice%2Freact-native-cacheimage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquenice%2Freact-native-cacheimage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquenice%2Freact-native-cacheimage/lists"}