VideoSpike / nativescript-web-image-cache

An image caching library for both Android and iOS that wraps Facebook Fresco and SDWebImageCache
MIT License
43 stars 22 forks source link

Add WebImage element by code #48

Closed abhayastudios closed 6 years ago

abhayastudios commented 6 years ago

Is it possible to add a WebImage element to say a GridLayout by code instead of markup? So for example for adding a Label element I could do something like this:

import { GridLayout, GridUnitType, ItemSpec} from "ui/layouts/grid-layout";
import { Label } from 'ui/label';

[...]

let grid = new GridLayout();
grid.addRow(new ItemSpec(150, GridUnitType.PIXEL));

let photo = new Label();
photo.setInlineStyle(`background-image: ${item.photoUrl};`);

grid.addChild(photo);
GridLayout.setRow(photo,0);

I see the plugin extends the tns-core-modules/ui/core/view so it must be possible, I just am unsure which imports to make to refer to WebImage.

Thanks for this great plugin!

abhayastudios commented 6 years ago

Oh never mind, I succeeded right after opening this issue:

import { WebImage } from "nativescript-web-image-cache";

[...]

let photo = new WebImage();
photo.src=item.photoUrl;
photo.stretch='aspectFill';

grid.addChild(photo);
GridLayout.setRow(photo,0);