mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fixed the memory leaks in iOS.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<ListView.itemTemplate>
|
||||
<!-- Binding in template property of an component will use the bindingContext provided by the component. -->
|
||||
<GridLayout columns="auto, *, auto" rows="auto, 25">
|
||||
<Image imageSource="{{ thumbnailImageSource || defaultThumbnailImageSource }}" cssClass="thumbnail" rowSpan="2"/>
|
||||
<Image src="{{ thumbnailImage }}" cssClass="thumbnail" rowSpan="2"/>
|
||||
<Label text="{{ title || 'Downloading...' }}" textWrap="true" cssClass="title" col="1" colSpan="2" minHeight="50" />
|
||||
<Label text="{{ author ? 'by ' + author : '' }}" cssClass="author" col="1" row="1" />
|
||||
<Label text="{{ num_comments ? num_comments + ' comments' : '' }}" cssClass="comments" col="2" row="1" />
|
||||
|
||||
@@ -8,7 +8,7 @@ var firstThumbnailImageSource = imageSource.fromFile("~/res/first-image.png");
|
||||
var defaultImageSource = imageSource.fromFile("~/res/reddit-logo-transparent.png");
|
||||
|
||||
var ISLOADING = "isLoading";
|
||||
var THUMBNAIL_IMAGE_SOURCE = "thumbnailImageSource";
|
||||
var THUMBNAIL_IMAGE = "thumbnailImage";
|
||||
var IMAGE_SOURCE = "imageSource";
|
||||
|
||||
export class RedditViewModel extends observable.Observable {
|
||||
@@ -42,45 +42,39 @@ export class RedditViewModel extends observable.Observable {
|
||||
}
|
||||
}
|
||||
|
||||
private _thumbnailImageSource: imageSource.ImageSource;
|
||||
get thumbnailImageSource(): imageSource.ImageSource {
|
||||
if (this._source) {
|
||||
if (this._source.title === "reddit 101") {
|
||||
this._thumbnailImageSource = firstThumbnailImageSource;
|
||||
} else if (redditAppViewModel.cache) {
|
||||
var url = this._source.thumbnail;
|
||||
|
||||
var imgSource: imageSource.ImageSource;
|
||||
var image = redditAppViewModel.cache.get(url);
|
||||
if (image) {
|
||||
imgSource = imageSource.fromNativeSource(image);
|
||||
}
|
||||
|
||||
if (imgSource) {
|
||||
this._thumbnailImageSource = imgSource;
|
||||
}
|
||||
else if (_isValidImageUrl(url)) {
|
||||
this.isLoading = true;
|
||||
|
||||
redditAppViewModel.cache.push({
|
||||
key: url,
|
||||
url: url,
|
||||
completed: (image: any, key: string) => {
|
||||
if (url === key) {
|
||||
this.isLoading = false;
|
||||
var imgSource = imageSource.fromNativeSource(image);
|
||||
this._thumbnailImageSource = imgSource;
|
||||
this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: THUMBNAIL_IMAGE_SOURCE, value: imgSource });
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this._thumbnailImageSource = redditAppViewModel.defaultNoThumbnailImageSource;
|
||||
}
|
||||
}
|
||||
get thumbnailImage(): imageSource.ImageSource {
|
||||
if (!this._source) {
|
||||
return redditAppViewModel.defaultThumbnailImageSource;
|
||||
}
|
||||
|
||||
return this._thumbnailImageSource || redditAppViewModel.defaultThumbnailImageSource;
|
||||
if (this._source.title === "reddit 101") {
|
||||
return firstThumbnailImageSource;
|
||||
}
|
||||
|
||||
var url = this._source.thumbnail;
|
||||
|
||||
if (!_isValidImageUrl(url)) {
|
||||
return redditAppViewModel.defaultNoThumbnailImageSource
|
||||
}
|
||||
|
||||
var image = redditAppViewModel.cache.get(url);
|
||||
if (image) {
|
||||
return image;
|
||||
}
|
||||
|
||||
this.isLoading = true;
|
||||
redditAppViewModel.cache.push({
|
||||
key: url,
|
||||
url: url,
|
||||
completed: (image: any, key: string) => {
|
||||
if (url === key) {
|
||||
this.isLoading = false;
|
||||
this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: THUMBNAIL_IMAGE, value: image });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return redditAppViewModel.defaultThumbnailImageSource;
|
||||
}
|
||||
|
||||
get imageSource(): imageSource.ImageSource {
|
||||
|
||||
Reference in New Issue
Block a user