Skip to content

Commit 786930a

Browse files
Upgrade to 1.9.0 version of the native library (#77)
* chore: Upgrade native library to 1.9.0 * chore: Upgrade demo with import for native Fresco typings chore: Add npmignore fix: Add warrning message if imageUri is set to incorrect value chore: Update tsconfig file according to plugin seed * chore: Remove commented out code * chore: Bump version * chore: Returned productFlavors * chore: Returned the 'IAnimatedImage' to be used rather than native class in wrapper * docs: Update readme with migration guide from 3.x.x to 4.x.x * chore: Add example that shows how to manually start animating image * chore: Rename interfaces to TypeScript best practices docs: Update readme with migration process chore: Made demo logs more informative * chore: Rename interface name in d.ts
1 parent 49db2d8 commit 786930a

19 files changed

+111
-166
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,19 @@ Use `fresco` in the XML definition of the page as follows:
9797
## Examples
9898
You can refer the [demo-angular](https://github.com/NativeScript/nativescript-fresco/tree/master/demo-angular) folder of the repo for runnable {N} project that demonstrates the nativescript-fresco plugin with all of its features in action.
9999

100+
## Migrating from 3.x.x to 4.x.x
101+
- If you are using the `AnimatedImage` class you can continue to cast to this type just note that it is now an interface rather than a class
102+
- If you are using the `IAnimatedImage` interface simply change all of your references to be `AnimatedImage`
103+
- If you are using the `IImageInfo` interface simply change all of your references to be `ImageInfo`
104+
- If you are using the `IError` interface simply change all of your references to be `FrescoError`
105+
100106
## Features
101107

108+
### Native Fresco library typings
109+
If you find yourself in the need to access directly the native library of the nativescript-fresco plugin you can import the android.d.ts from the plugin in your `references.d.ts`:
110+
111+
```/// <reference path="./node_modules/nativescript-fresco/android.d.ts" />```
112+
102113
As documented by the Fresco library setting the **height and width** are **mandatory**, more details on this topic could be found [here](http://frescolib.org/docs/using-drawees-xml.html#height-and-width-mandatory). So the first this you should do when declaring the FrescoDrawee is set its *width* and *height* attributes or set only one of them and set the FrescoDrawee's **aspectRatio**. The width and height of the FrescoDrawee in your {N} application supports percentages which makes it possible to declare for example *width="50%"* and *aspectRatio="1.33"* achieving exactly 50% width with dynamically calculated height based on the aspect ration of the loaded image from the *imageUri*.
103114

104115
### Basic attributes

demo/app/examples/animating.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { FrescoDrawee, FinalEventData, AnimatedImage} from "nativescript-fresco";
2+
import { writeToOutputLabel } from "./appLogger";
3+
4+
export function onFinalImageSet(args: FinalEventData) {
5+
let drawee = args.object as FrescoDrawee;
6+
let message = ">>>>>> onFinalImageSet ";
7+
writeToOutputLabel(drawee, message);
8+
let animatedImage = args.animatable as AnimatedImage;
9+
if (animatedImage) {
10+
writeToOutputLabel(drawee, ">>>>>> animatedImage: isRunning(): " + animatedImage.isRunning());
11+
writeToOutputLabel(drawee, ">>>>>> animatedImage: start() ");
12+
animatedImage.start();
13+
writeToOutputLabel(drawee, ">>>>>> animatedImage: isRunning(): " + animatedImage.isRunning());
14+
}
15+
}

demo/app/examples/animating.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<ScrollView>
2+
<GridLayout rows="*, auto">
3+
<fresco:FrescoDrawee xmlns:fresco="nativescript-fresco"
4+
width="119"
5+
height="120"
6+
placeholderImageUri="res://ns_logo"
7+
verticalAlignment="top"
8+
imageUri="res://animation"
9+
finalImageSet="onFinalImageSet"/>
10+
<Label id="outputLabel" text="output: " row="1" textWrap="true"/>
11+
</GridLayout>
12+
</ScrollView>

demo/app/examples/failure.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { writeToOutputLabel } from "./appLogger";
55

66
export function onFailure(args: FailureEventData) {
77
let drawee = args.object as FrescoDrawee;
8-
let message = ">>>>> onFailure ";
9-
console.log(message);
8+
let message = ">>>>> onFailure " + args.error;
109
writeToOutputLabel(drawee, message);
1110
}

demo/app/home/home-page.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575
<examples:autoplayanimations />
7676
</TabViewItem.view>
7777
</TabViewItem>
78+
<TabViewItem title="animating">
79+
<TabViewItem.view>
80+
<examples:animating />
81+
</TabViewItem.view>
82+
</TabViewItem>
7883
<TabViewItem title="events">
7984
<TabViewItem.view>
8085
<examples:events />

demo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"raw-loader": "~0.5.1",
3232
"resolve-url-loader": "~2.3.0",
3333
"typescript": "~2.7.2",
34+
"tns-platform-declarations": "^4.1.0",
3435
"uglifyjs-webpack-plugin": "~1.2.4",
3536
"webpack": "~4.5.0",
3637
"webpack-bundle-analyzer": "^2.9.1",

demo/references.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
2+
/// <reference path="./node_modules/nativescript-fresco/android.d.ts" />

demo/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"exclude": [
2525
"node_modules",
26+
"../src/node_modules",
2627
"platforms"
2728
]
2829
}

src/.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.map
2+
*.ts
3+
!*.d.ts
4+
tsconfig.json
5+
sync

src/nativescript-fresco.android-map.d.ts renamed to src/android.d.ts

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
declare namespace android {
2-
namespace net {
3-
class Uri {
4-
static parse(orientation);
5-
}
6-
7-
namespace Uri {
8-
class Builder {
9-
scheme(scheme: string);
10-
path(path: string);
11-
}
12-
}
13-
}
14-
15-
namespace graphics {
16-
namespace drawable {
17-
class BitmapDrawable {
18-
constructor(resources, image);
19-
}
20-
}
21-
class Color {
22-
static parseColor(color: string);
23-
}
24-
}
25-
}
26-
271
declare namespace com {
282
namespace facebook {
293
namespace drawee {
@@ -172,11 +146,11 @@ declare namespace com {
172146

173147
namespace core {
174148
class ImagePipeline {
175-
isInBitmapMemoryCache(uri: string): boolean;
176-
isInDiskCacheSync(uri: string): boolean;
177-
evictFromMemoryCache(uri: string): void;
178-
evictFromDiskCache(uri: string): void;
179-
evictFromCache(uri: string): void;
149+
isInBitmapMemoryCache(uri: android.net.Uri): boolean;
150+
isInDiskCacheSync(uri: android.net.Uri): boolean;
151+
evictFromMemoryCache(uri: android.net.Uri): void;
152+
evictFromDiskCache(uri: android.net.Uri): void;
153+
evictFromCache(uri: android.net.Uri): void;
180154
clearCaches(): void;
181155
clearMemoryCaches(): void;
182156
clearDiskCaches(): void;
@@ -197,20 +171,3 @@ declare namespace com {
197171
}
198172
}
199173
}
200-
201-
declare namespace java {
202-
namespace lang {
203-
class String {
204-
static valueOf(identifier);
205-
}
206-
207-
class Class {
208-
getName(): string;
209-
}
210-
211-
class Throwable {
212-
getClass(): java.lang.Class;
213-
getMessage(): string;
214-
}
215-
}
216-
}

src/index.d.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class ImageInfo {
186186
/**
187187
* Interface of the common abstraction behind a platform specific error object that is used by the FrescoDrawee's events.
188188
*/
189-
export interface IError {
189+
export interface FrescoError {
190190
/**
191191
* Returns the message of the Error.
192192
*/
@@ -306,7 +306,7 @@ export class FailureEventData {
306306
/**
307307
* Interface of the common abstraction behind a platform specific animated image object.
308308
*/
309-
export interface IAnimatedImage {
309+
export interface AnimatedImage {
310310
/**
311311
* Starts the AnimatedDrawable image.
312312
*/
@@ -322,27 +322,6 @@ export interface IAnimatedImage {
322322
*/
323323
isRunning(): boolean;
324324
}
325-
326-
/**
327-
* Encapsulates the common abstraction behind a platform specific animated image object.
328-
*/
329-
export class AnimatedImage {
330-
/**
331-
* Starts the AnimatedImage image.
332-
*/
333-
start(): void;
334-
335-
/**
336-
* Stops the AnimatedImage image.
337-
*/
338-
stop(): void;
339-
340-
/**
341-
* Returns boolean value representing the if the AnimatedImage's is being animated.
342-
*/
343-
isRunning(): boolean;
344-
}
345-
346325
/**
347326
* The entry point for the image pipeline..
348327
*/

src/nativescript-fresco-common.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/// <reference path="references.d.ts" />
21
import { View, Property } from "tns-core-modules/ui/core/view";
32
import * as observableModule from "tns-core-modules/data/observable";
43
export declare namespace ScaleType {
@@ -11,16 +10,16 @@ export declare namespace ScaleType {
1110
const FitXY = "fitXY";
1211
const FocusCrop = "focusCrop";
1312
}
14-
export interface IAnimatedImage {
13+
export interface AnimatedImage {
1514
start(): void;
1615
stop(): void;
1716
isRunning(): boolean;
1817
}
19-
export interface IImageInfo {
18+
export interface ImageInfo {
2019
getHeight(): number;
2120
getWidth(): number;
2221
}
23-
export interface IError {
22+
export interface FrescoError {
2423
getMessage(): string;
2524
getErrorType(): string;
2625
toString(): string;

src/nativescript-fresco-common.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference path="references.d.ts" />
2-
31
import { View, Property, booleanConverter } from "tns-core-modules/ui/core/view";
42
import * as observableModule from "tns-core-modules/data/observable";
53

@@ -14,25 +12,25 @@ export namespace ScaleType {
1412
export const FocusCrop = "focusCrop";
1513
}
1614

17-
export interface IAnimatedImage {
15+
export interface AnimatedImage {
1816
start(): void;
1917
stop(): void;
2018
isRunning(): boolean;
2119
}
2220

23-
export interface IImageInfo {
21+
export interface ImageInfo {
2422
getHeight(): number;
2523
getWidth(): number;
2624
}
2725

28-
export interface IError {
26+
export interface FrescoError {
2927
getMessage(): string;
3028
getErrorType(): string;
3129
toString(): string;
3230
}
3331

3432
export interface ImagePipelineConfigSetting {
35-
isDownsampleEnabled?: boolean;
33+
isDownsampleEnabled?: boolean;
3634
}
3735

3836
export class EventData implements observableModule.EventData {

src/nativescript-fresco.android.d.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ export declare class ImagePipeline {
1414
clearDiskCaches(): void;
1515
android: any;
1616
}
17-
export interface AnimatedImage extends com.facebook.imagepipeline.animated.base.AnimatedDrawable, commonModule.IAnimatedImage {
18-
new (): AnimatedImage;
19-
start(): void;
20-
stop(): void;
21-
isRunning(): boolean;
22-
}
23-
export declare let AnimatedImage: AnimatedImage;
24-
export declare class FrescoError implements commonModule.IError {
17+
export declare class FrescoError implements commonModule.FrescoError {
2518
private _stringValue;
2619
private _message;
2720
private _errorType;
@@ -35,7 +28,7 @@ export interface QualityInfo {
3528
isOfFullQuality(): any;
3629
isOfGoodEnoughQuality(): any;
3730
}
38-
export declare class ImageInfo implements commonModule.IImageInfo {
31+
export declare class ImageInfo implements commonModule.ImageInfo {
3932
private _nativeImageInfo;
4033
constructor(imageInfo: any);
4134
getHeight(): number;
@@ -46,7 +39,7 @@ export declare class FinalEventData extends commonModule.EventData {
4639
private _imageInfo;
4740
private _animatable;
4841
imageInfo: ImageInfo;
49-
animatable: commonModule.IAnimatedImage;
42+
animatable: commonModule.AnimatedImage;
5043
}
5144
export declare class IntermediateEventData extends commonModule.EventData {
5245
private _imageInfo;

0 commit comments

Comments
 (0)