nativescript-image-cache
使用 Fresco 为 Android 和 SDWebImageCache 为 iOS 提供的 Nativescript 图像缓存插件
npm i --save nativescript-image-cache

Nativescript Image Cache

npm version

使用 Fresco 为 Android 和 SDWebImageCache 为 iOS 提供的 Nativescript 图像缓存插件

安装

tns plugin add nativescript-image-cache

支持 NativeScript ~3.0.0 与 Angular

属性

属性名称 平台
拉伸 填充、适应、填充、无 ios、android
src 字符串 ios、android
占位符 字符串 ios、android
占位符拉伸 填充、适应、填充、无 android
半径 数字 android
圆形 布尔值 android

基本用法

Nativescript Angular

初始化

import { initializeOnAngular } from 'nativescript-image-cache';

export class AppComponent {
constructor () {
initializeOnAngular();
}
}

示例用法

<NSImage #myImage stretch="aspectFill" radius="20" src="res://logo">
</NSImage>

Nativescript Vanilla

初始化(仅 android)

const imageCache = require('nativescript-image-cache');

if (application.android) {
application.on('launch', () => {
imageCache.initialize();
});
}

示例用法

<Page xmlns:IC="nativescript-image-cache">
<GridLayout rows='*' columns='*'>
<IC:NSImage stretch="fill" row="0"
col="0" placeholder="res://placeholder"
src="res://logo">

</IC:NSImage>
</GridLayout>
</Page>

缓存图像

默认缓存清除时间可以指定为天数。

import { setCacheLimit } from 'nativescript-image-cache';

const cacheLimitInDays : number = 7;
setCacheLimit(cacheLimitInDays);

清除缓存

SDWebImageCache 的默认缓存时间为 7 天,Fresco 为 60 天。

import { clearCache } from 'nativescript-image-cache';

clearCache();

(仅 Android),在清除缓存之前,您需要在应用的 onlaunch 事件中初始化

鸣谢

此插件的起点是 这个优秀的插件