ui-image
ui-image copied to clipboard
Advanced and efficient image display plugin which uses Fresco (Android) and SDWebImage (iOS) to implement caching, placeholders, image effects, and much more.
This monorepo contains multiple packages:
Advanced and efficient image display plugin which uses Fresco (Android) and SDWebImage (iOS) to implement caching, placeholders, image effects, and much more.
Run the following command from the root of your project:
finalImageSet - arguments FinalEventData This event is fired after the final image has been set. When working with animated images you could use this event to start the animation by calling the FinalEventData.animatable.start() function. JavaScript: TypeScript: This event is fired after the fetch of the final image failed. JavaScript: TypeScript: This event is fired after any intermediate image has been set. JavaScript: TypeScript: This event is fired after the fetch of the intermediate image failed. JavaScript: TypeScript: This event is fired before the image request is submitted. JavaScript: TypeScript: This event is fired after the controller released the fetched image. JavaScript: TypeScript: Instances of this class are provided to the handlers of the finalImageSet. Instances of this class are provided to the handlers of the failure and intermediateImageFailed. Instances of this class are provided to the handlers of the intermediateImageSet. Instances of this class are provided to the handlers of the release and submit. String value used for the image URI. You can use this property to set the image to be loaded from remote location (http, https), from the resources and local files of your {N} application. String value used for the placeholder image URI. You can use this property to set a placeholder image loaded from the local and resources files of your {N} application. *Note: Currently there are limitations on how many different Images can be set to as 'placeholderImage' before OutOfMemoryError is thrown. For best results its recommended to use a single image for all String value used for the failure image URI. You can use this property to set a failure image loaded from the local and resources files of your {N} application that will be shown if the loading of the src is not successful. There are a couple of optional attributes that could be set on the Img instance to achieve advanced behaviors: String value used for the background image URI. Using this property has similar effect as the placeholderImageUri but the image is stretched to the size of the Img. *Note: Currently there are limitations on how many different Images can be set to as 'background' before OutOfMemoryError is thrown. For best results its recommended to use a single image for all String value used by Img image scale type. This property can be set to: 'center' - Performs no scaling. 'centerCrop' - Scales the child so that both dimensions will be greater than or equal to the corresponding dimension of the parent. 'centerInside' - Scales the child so that it fits entirely inside the parent. 'fitCenter' - Scales the child so that it fits entirely inside the parent. 'aspectFit' - Scales the child so that it fits entirely inside the parent. 'fitStart' - Scales the child so that it fits entirely inside the parent. 'fitEnd' - Scales the child so that it fits entirely inside the parent. 'fitXY' - Scales width and height independently, so that the child matches the parent exactly. 'fill' - Scales width and height independently, so that the child matches the parent exactly. 'focusCrop' - Scales the child so that both dimensions will be greater than or equal to the corresponding dimension of the parent. 'aspectFill' - Scales the child so that both dimensions will be greater than or equal to the corresponding dimension of the parent. Number value used for the fade-in duration. This value is in milliseconds. Number value greater than zero, used as input for the blur function. Larger value means slower processing. For example a value of Number value greater than zero, used to scale the image before applying the blur function. Larger value means faster processing. For example a value of Number value used as the aspect ratio of the image. This property is useful when you are working with different aspect ratio images and want to have a fixed Width or Height. The ratio of an image is calculated by dividing its width by its height. Note: In some layout scenarios it is necessary to set the Number value used as the downsampled width of the imageModule drawable. Number value used as the downsampled width of the imageModule drawable. Object that defines custom request headers to be sent with the image download request. Boolean value used for enabling or disabling the streaming of progressive JPEG images. This property is set to 'false' by default. Setting this property to 'true' while loading JPEG images not encoded in progressive format will lead to a standard loading of those images. Boolean value used for showing or hiding the progress bar. String value used for setting the color of the progress bar. You can set it to hex values ("#FF0000") and/or predefined colors ("green"). Boolean value used for determining if the image will be rounded as a circle. Its default value is false. If set to true the image will be rounder to a circle. Radius of the Top Left corner in Radius of the Top Right corner in Radius of the Bottom Left corner in Radius of the Bottom Right corner in Boolean value used for enabling the automatic playing of animated images. Note that rounding of such images is not supported and will be ignored. Boolean value used for enabling/disabling a tap to retry action for the download of the Img image. The @nativescript-community/ui-image {N} plugin has built-in cache mechanism which handles managing the images in the memory. There are two types of cache mechanisms Not so rarely you may have a scenario where the actual image on your remote service from the Managing the caches in @nativescript-community/ui-image is done via the If clearing the entire cache is not what you desired, you can clear only the images linked with a specific URI ( In very very rare occasions the native Android imageModule library may experience strange memory leak issues, in such scenarios as a last resort you may want to "shut down" the library forcing all of the managed memory to possibly be released. You can do that by calling the
Using core Other flavors are presented in the demo apps that you can find under
This repository includes Angular, Vue.js demos. In order to run these execute the following in your shell:
The repo uses submodules. If you did not clone with The package manager used to install and link dependencies must be To develop and test:
if you use Interactive Menu: To start the interactive menu, run WARNING: it seems Demo setup is a bit special in the sense that if you want to modify/add demos you dont work directly in
You can update the repo files quite easily First update the submodules Then commit the changes
Then update common files Then you can run The publishing is completely handled by The repo uses https:// for submodules which means you won't be able to push directly into the submodules.
One easy solution is t modify
If you have any questions/issues/comments please feel free to create an issue or start a conversation in the NativeScript Community Discord.
color matrix filters for @nativescript-community/ui-image
Run the following command from the root of your project:
It adds one property
This repository includes Angular, Vue.js demos. In order to run these execute the following in your shell:
The repo uses submodules. If you did not clone with The package manager used to install and link dependencies must be To develop and test:
if you use Interactive Menu: To start the interactive menu, run WARNING: it seems Demo setup is a bit special in the sense that if you want to modify/add demos you dont work directly in
You can update the repo files quite easily First update the submodules Then commit the changes
Then update common files Then you can run The publishing is completely handled by The repo uses https:// for submodules which means you won't be able to push directly into the submodules.
One easy solution is t modify
If you have any questions/issues/comments please feel free to create an issue or start a conversation in the NativeScript Community Discord.
Zoomable image view based on @nativescript-community/ui-image
Run the following command from the root of your project:
This component directly inherint It adds a few properties
This repository includes Angular, Vue.js demos. In order to run these execute the following in your shell:
The repo uses submodules. If you did not clone with The package manager used to install and link dependencies must be To develop and test:
if you use Interactive Menu: To start the interactive menu, run WARNING: it seems Demo setup is a bit special in the sense that if you want to modify/add demos you dont work directly in
You can update the repo files quite easily First update the submodules Then commit the changes
Then update common files Then you can run The publishing is completely handled by The repo uses https:// for submodules which means you won't be able to push directly into the submodules.
One easy solution is t modify
If you have any questions/issues/comments please feel free to create an issue or start a conversation in the NativeScript Community Discord.image
@nativescript-community/ui-image


iOS Demo
Android Demo
Table of Contents
Installation
ns plugin add @nativescript-community/ui-imagesetup
import imageModule = require("@nativescript-community/ui-image");
//do this before creating any image view
imageModule.initialize({ isDownsampleEnabled: true });
API
Events
<@nativescript-community/ui-image:Img finalImageSet="onFinalImageSet"/>
function onFinalImageSet(args) {
var imageModuleEventData = args;
var img = imageModuleEventData.object;
}
exports.onFinalImageSet = onFinalImageSet;
import {Img, FinalEventData } from "@nativescript-community/ui-image";
export function onFinalImageSet(args: FinalEventData) {
var img = args.object as Img;
}
<@nativescript-community/ui-image:Img failure="onFailure"/>
function onFailure(args) {
var img = args.object;
}
exports.onFailure = onFailure;
import {Img, FailureEventData } from "@nativescript-community/ui-image";
export function onFailure(args: FailureEventData) {
var img = args.object as Img;
}
<@nativescript-community/ui-image:Img intermediateImageSet="onIntermediateImageSet"/>
function onIntermediateImageSet(args) {
var img = args.object;
}
exports.onIntermediateImageSet = onIntermediateImageSet;
import {Img, IntermediateEventData } from "@nativescript-community/ui-image";
export function onIntermediateImageSet(args: IntermediateEventData) {
var img = args.object as Img;
}
<@nativescript-community/ui-image:Img intermediateImageFailed="onIntermediateImageFailed"/>
function intermediateImageFailed(args) {
var img = args.object;
}
exports.intermediateImageFailed = intermediateImageFailed;
import {Img, FailureEventData } from "@nativescript-community/ui-image";
export function intermediateImageFailed(args: FailureEventData) {
var img = args.object as Img;
}
<@nativescript-community/ui-image:Img submit="onSubmit"/>
function onSubmit(args) {
var img = args.object;
}
exports.onSubmit = onSubmit;
import {Img, EventData } from "@nativescript-community/ui-image";
export function onSubmit(args: EventData) {
var img = args.object as Img;
}
<@nativescript-community/ui-image:Img release="onRelease"/>
function onRelease(args) {
var img = args.object;
}
exports.onRelease = onRelease;
import {Img, EventData } from "@nativescript-community/ui-image";
export function onRelease(args: EventData) {
var img = args.object as Img;
}
Event arguments
import {Img, FinalEventData, ImageInfo, AnimatedImage } from "@nativescript-community/ui-image";
export function onFinalImageSet(args: FinalEventData) {
var info: ImageInfo = args.imageInfo;
var animatable: AnimatedImage = args.animatable;
var quality: number = info.getQualityInfo().getQuality();
var isFullQuality: boolean = info.getQualityInfo().isOfFullQuality();
var isOfGoodEnoughQuality: boolean = info.getQualityInfo().isOfGoodEnoughQuality();
}
import {Img, FailureEventData, imageModuleError } from "@nativescript-community/ui-image";
export function onFailure(args: FailureEventData) {
var error: imageModuleError = args.error;
var message: string = error.getMessage();
var type: string = error.getErrorType();
var fullError: string = error.toString();
}
import {Img, IntermediateEventData, ImageInfo } from "@nativescript-community/ui-image";
export function onIntermediateImageSet(args: IntermediateEventData) {
var info: ImageInfo = args.imageInfo;
var quality: number = info.getQualityInfo().getQuality();
var isFullQuality: boolean = info.getQualityInfo().isOfFullQuality();
var isOfGoodEnoughQuality: boolean = info.getQualityInfo().isOfGoodEnoughQuality();}
import {Img, EventData } from "@nativescript-community/ui-image";
export function onSubmit(args: EventData) {
var img = args.object as Img;
}
Properties
<@nativescript-community/ui-image:Img src="https://docs.nativescript.org/angular/img/cli-getting-started/angular/chapter0/NativeScript_logo.png"/>
placeholderImageUri of your Img instances.<@nativescript-community/ui-image:Img placeholderImageUri="~/placeholder.jpg"/>
<@nativescript-community/ui-image:Img failureImageUri="~/failure.jpg"/>
Advanced optional attributes
backgroundUri of your Img instances.<@nativescript-community/ui-image:Img backgroundUri="~/image.jpg"/>
<@nativescript-community/ui-image:Img stretch="centerInside"/>
<@nativescript-community/ui-image:Img fadeDuration="3000"/>
10 means that each pixel in the image will be blurred using all adjacent pixels up to a distance of 10.<@nativescript-community/ui-image:Img blurRadius="25"/>
2 means that the image will be scaled by a factor of two before applying blur.<@nativescript-community/ui-image:Img blurDownSampling="2"/>
verticalAlignment of the Img to 'top' or 'bottom' in order to "anchor" the img and achieve dynamic sizing.<@nativescript-community/ui-image:Img aspectRatio="1.33" verticalAlignment="top"/>
<@nativescript-community/ui-image:Img decodeWidth="100"/>
<@nativescript-community/ui-image:Img decodeHeight="100"/>
<@nativescript-community/ui-image:Img headers="{Authorization: 'bearer abcdefghijk'}"/>
<@nativescript-community/ui-image:Img progressiveRenderingEnabled="true"/>
<@nativescript-community/ui-image:Img showProgressBar="true"/>
<@nativescript-community/ui-image:Img progressBarColor="blue"/>
<@nativescript-community/ui-image:Img roundAsCircle="true"/>
<@nativescript-community/ui-image:Img roundTopLeftRadius="50"/>
<@nativescript-community/ui-image:Img roundTopRightRadius="50"/>
<@nativescript-community/ui-image:Img roundBottomLeftRadius="50"/>
<@nativescript-community/ui-image:Img roundBottomRightRadius="50"/>
<@nativescript-community/ui-image:Img autoPlayAnimations="true"/>
<@nativescript-community/ui-image:Img tapToRetryEnabled="true"/>
Cache
memory and disk, you can manually manage both of them with the following functionality.'Refresh' the 'src'
src of the Img has changed but the {N} app already has an image in its internal cache. In such scenario you can easily 'refresh' the src by calling the updateImageUri():// 'img' is the instance the 'Img' in the project.
img.updateImageUri();
Clear everything from the cache
ImagePipeline. In order to get the reference of the ImagePipeline simply call the getImagePipeline() function:var imageModuleModel = require("@nativescript-community/ui-image");
var imagePipeLine = imageModuleModel.getImagePipeline();
imagePipeLine.clearCaches();
imagePipeLine.clearMemoryCaches();
imagePipeLine.clearDiskCaches();
Evict all images with a specific URI from the cache
src). Evicting is done again via the ImagePipeline:var imageModuleModel = require("@nativescript-community/ui-image");
var imagePipeLine = imageModuleModel.getImagePipeline();
imagePipeLine.evictFromCache("<uri-to-a-photo-from-the-web>");
imagePipeLine.evictFromMemoryCache("<uri-to-a-photo-from-the-web>");
imagePipeLine.evictFromDiskCache("<uri-to-a-photo-from-the-web>");
Manually shut down the native imageModule library
shutDown function exposed by the @nativescript-community/ui-image module, one good application lifecycle event to call it inside may be in the exit event of the application:import * as app from "application";
import * as imageModuleModule from "@nativescript-community/ui-image";
if (app.android) {
app.on(app.exitEvent, (args) => {
imageModuleModule.shutDown();
});
}
Flavors
<Page
xmlns="http://www.nativescript.org/tns.xsd"
xmlns:@nativescript-community/ui-image="@nativescript-community/ui-image">
<@nativescript-community/ui-image:Img width="250" height="250"
src="<uri-to-a-photo-from-the-web-or-a-local-resource>"/>
</Page>
demo-snippetsDemos
$ git clone https://github.com/@nativescript-community/ui-image
$ cd ui-image
$ npm i
$ npm run setup
$ npm run build # && npm run build.angular
$ cd demo-ng # or demo-vue or demo-svelte
$ ns run ios|android
Demos and Development
Repo Setup
--recursive then you need to callgit submodule update --init
pnpm or yarn. npm wont work.yarn then run yarn
if you use pnpm then run pnpm inpm start (or yarn start or pnpm start). This will list all of the commonly used scripts.Build
npm run build.all
yarn build.all wont always work (not finding binaries in node_modules/.bin) which is why the doc explicitly uses npm runDemos
npm run demo.[ng|react|svelte|vue].[ios|android]
npm run demo.svelte.ios # Example
demo-[ng|react|svelte|vue]
Instead you work in demo-snippets/[ng|react|svelte|vue]
You can start from the install.ts of each flavor to see how to register new demosContributing
Update repo
npm run update
npm run sync
yarn|pnpm, commit changed files if anyUpdate readme
npm run readme
Update doc
npm run doc
Publish
lerna (you can add -- --bump major to force a major release)
Simply runnpm run publish
modifying submodules
~/.gitconfig and add[url "ssh://[email protected]/"]
pushInsteadOf = https://github.com/
Questions
image-colorfilter
@nativescript-community/ui-image-colorfilter


iOS Demo
Android Demo
Table of Contents
Installation
ns plugin add @nativescript-community/ui-image-colorfiltersetup
import { installMixins } from "@nativescript-community/ui-image-colorfilter";
//do this before creating any image view
installMixins();
colorMatrix which is a number[]
You can find samples color matrix hereDemos
$ git clone https://github.com/@nativescript-community/ui-image
$ cd ui-image
$ npm i
$ npm run setup
$ npm run build # && npm run build.angular
$ cd demo-ng # or demo-vue or demo-svelte
$ ns run ios|android
Demos and Development
Repo Setup
--recursive then you need to callgit submodule update --init
pnpm or yarn. npm wont work.yarn then run yarn
if you use pnpm then run pnpm inpm start (or yarn start or pnpm start). This will list all of the commonly used scripts.Build
npm run build.all
yarn build.all wont always work (not finding binaries in node_modules/.bin) which is why the doc explicitly uses npm runDemos
npm run demo.[ng|react|svelte|vue].[ios|android]
npm run demo.svelte.ios # Example
demo-[ng|react|svelte|vue]
Instead you work in demo-snippets/[ng|react|svelte|vue]
You can start from the install.ts of each flavor to see how to register new demosContributing
Update repo
npm run update
npm run sync
yarn|pnpm, commit changed files if anyUpdate readme
npm run readme
Update doc
npm run doc
Publish
lerna (you can add -- --bump major to force a major release)
Simply runnpm run publish
modifying submodules
~/.gitconfig and add[url "ssh://[email protected]/"]
pushInsteadOf = https://github.com/
Questions
zoomimage
@nativescript-community/ui-zoomimage


iOS Demo
Android Demo
Table of Contents
Installation
ns plugin add @nativescript-community/ui-zoomimagesetup
import imageModule = require("@nativescript-community/ui-zoomimage");
//do this before creating any image view
imageModule.initialize({ isDownsampleEnabled: true });
@nativescript-community/ui-image so you can find the doc hereDemos
$ git clone https://github.com/@nativescript-community/ui-image
$ cd ui-image
$ npm i
$ npm run setup
$ npm run build # && npm run build.angular
$ cd demo-ng # or demo-vue or demo-svelte
$ ns run ios|android
Demos and Development
Repo Setup
--recursive then you need to callgit submodule update --init
pnpm or yarn. npm wont work.yarn then run yarn
if you use pnpm then run pnpm inpm start (or yarn start or pnpm start). This will list all of the commonly used scripts.Build
npm run build.all
yarn build.all wont always work (not finding binaries in node_modules/.bin) which is why the doc explicitly uses npm runDemos
npm run demo.[ng|react|svelte|vue].[ios|android]
npm run demo.svelte.ios # Example
demo-[ng|react|svelte|vue]
Instead you work in demo-snippets/[ng|react|svelte|vue]
You can start from the install.ts of each flavor to see how to register new demosContributing
Update repo
npm run update
npm run sync
yarn|pnpm, commit changed files if anyUpdate readme
npm run readme
Update doc
npm run doc
Publish
lerna (you can add -- --bump major to force a major release)
Simply runnpm run publish
modifying submodules
~/.gitconfig and add[url "ssh://[email protected]/"]
pushInsteadOf = https://github.com/
Questions
Demos and Development
Repo Setup
The repo uses submodules. If you did not clone with --recursive then you need to call
git submodule update --init
The package manager used to install and link dependencies must be pnpm or yarn. npm wont work.
To develop and test:
if you use yarn then run yarn
if you use pnpm then run pnpm i
Interactive Menu:
To start the interactive menu, run npm start (or yarn start or pnpm start). This will list all of the commonly used scripts.
Build
npm run build.all
WARNING: it seems yarn build.all wont always work (not finding binaries in node_modules/.bin) which is why the doc explicitly uses npm run
Demos
npm run demo.[ng|react|svelte|vue].[ios|android]
npm run demo.svelte.ios # Example
Demo setup is a bit special in the sense that if you want to modify/add demos you dont work directly in demo-[ng|react|svelte|vue]
Instead you work in demo-snippets/[ng|react|svelte|vue]
You can start from the install.ts of each flavor to see how to register new demos
Contributing
Update repo
You can update the repo files quite easily
First update the submodules
npm run update
Then commit the changes Then update common files
npm run sync
Then you can run yarn|pnpm, commit changed files if any
Update readme
npm run readme
Update doc
npm run doc
Publish
The publishing is completely handled by lerna (you can add -- --bump major to force a major release)
Simply run
npm run publish
modifying submodules
The repo uses https:// for submodules which means you won't be able to push directly into the submodules.
One easy solution is t modify ~/.gitconfig and add
[url "ssh://[email protected]/"]
pushInsteadOf = https://github.com/
Questions
If you have any questions/issues/comments please feel free to create an issue or start a conversation in the NativeScript Community Discord.