Skip to content

Commit 3013405

Browse files
committed
fix(ios): fix for placeholder not “sticking”
1 parent f3c1433 commit 3013405

File tree

1 file changed

+28
-75
lines changed

1 file changed

+28
-75
lines changed

src/image.ios.ts

Lines changed: 28 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@ import { CLog, CLogTypes, EventData, ImageBase, ImageInfo as ImageInfoBase, Imag
77
@NativeClass
88
class SDImageRoundAsCircleTransformer extends NSObject implements SDImageTransformer {
99
public static ObjCProtocols = [SDImageTransformer];
10-
// _cornerRadius = 20;
11-
// get cornerRadius() {
12-
// return this._cornerRadius;
13-
// }
14-
// get corners() {
15-
// return UIRectCorner.AllCorners;
16-
// }
17-
// get borderWidth() {
18-
// return 0;
19-
// }
2010

2111
static transformer() {
2212
const transformer = SDImageRoundAsCircleTransformer.alloc().init();
@@ -241,11 +231,6 @@ export class Img extends ImageBase {
241231
return result;
242232
}
243233

244-
// public initNativeView(): void {
245-
// this.initDrawee();
246-
// // this.updateHierarchy();
247-
// }
248-
249234
_setNativeClipToBounds() {
250235
// Always set clipsToBounds for images
251236
this.nativeViewProtected.clipsToBounds = true;
@@ -260,9 +245,6 @@ export class Img extends ImageBase {
260245

261246
const image = this.nativeViewProtected.image;
262247

263-
// const measureWidth = Math.max(nativeWidth, this.effectiveMinWidth);
264-
// const measureHeight = Math.max(nativeHeight, this.effectiveMinHeight);
265-
266248
const finiteWidth: boolean = widthMode === layout.EXACTLY;
267249
const finiteHeight: boolean = heightMode === layout.EXACTLY;
268250
this._imageSourceAffectsLayout = !finiteWidth || !finiteHeight;
@@ -288,18 +270,7 @@ export class Img extends ImageBase {
288270
}
289271
}
290272
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
291-
292-
// const widthAndState = Img.resolveSizeAndState(measureWidth, width, widthMode, 0);
293-
// const heightAndState = Img.resolveSizeAndState(measureHeight, height, heightMode, 0);
294-
295-
// this.setMeasuredDimension(widthAndState, heightAndState);
296273
}
297-
298-
// public disposeNativeView() {
299-
// this._android.setImageURI(null, null);
300-
// this._android = undefined;
301-
// }
302-
303274
public updateImageUri() {
304275
const imagePipeLine = getImagePipeline();
305276
const src = this.src;
@@ -323,47 +294,38 @@ export class Img extends ImageBase {
323294
}
324295

325296
private handleImageLoaded = (image: UIImage, error: NSError, cacheType: number) => {
326-
// if (this.tintColor) {
327-
// image = image.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
328-
// }
329297
this.isLoading = false;
330-
if ((this.alwaysFade || cacheType !== SDImageCacheType.Memory) && this.fadeDuration > 0) {
331-
// switch (this.transition) {
332-
// case 'fade':
333-
this.nativeViewProtected.alpha = 0.0;
334-
this._setNativeImage(image);
335-
UIView.animateWithDurationAnimations(this.fadeDuration / 1000, () => {
336-
this.nativeViewProtected.alpha = this.opacity;
337-
});
338-
// break;
339-
// case 'curlUp':
340-
// UIView.transitionWithViewDurationOptionsAnimationsCompletion(
341-
// this.nativeViewProtected,
342-
// 0.3,
343-
// UIViewAnimationOptions.TransitionCrossDissolve,
344-
// () => {
345-
// this._setNativeImage(image);
346-
// },
347-
// null
348-
// );
349-
// break;
350-
// default:
351-
// this._setNativeImage(image);
352-
// }
353-
} else {
354-
// console.log("setting image", !!image, !!image && image.size);
355-
this._setNativeImage(image);
298+
if (image) {
299+
if ((this.alwaysFade || cacheType !== SDImageCacheType.Memory) && this.fadeDuration > 0) {
300+
// switch (this.transition) {
301+
// case 'fade':
302+
this.nativeViewProtected.alpha = 0.0;
303+
this._setNativeImage(image);
304+
UIView.animateWithDurationAnimations(this.fadeDuration / 1000, () => {
305+
this.nativeViewProtected.alpha = this.opacity;
306+
});
307+
// break;
308+
// case 'curlUp':
309+
// UIView.transitionWithViewDurationOptionsAnimationsCompletion(
310+
// this.nativeViewProtected,
311+
// 0.3,
312+
// UIViewAnimationOptions.TransitionCrossDissolve,
313+
// () => {
314+
// this._setNativeImage(image);
315+
// },
316+
// null
317+
// );
318+
// break;
319+
// default:
320+
// this._setNativeImage(image);
321+
// }
322+
} else {
323+
this._setNativeImage(image);
324+
}
356325
}
357326
if (!this.autoPlayAnimations) {
358327
this.nativeViewProtected.stopAnimating();
359328
}
360-
// if (image && cacheType !== SDImageCacheType.SDImageCacheTypeMemory)
361-
// {
362-
// this.nativeView.alpha = 0.0;
363-
// UIView.animateWithDurationAnimations(0.2, ()=>{
364-
// this.nativeView.alpha = this.opacity;
365-
// });
366-
// }
367329

368330
if (error) {
369331
const args = {
@@ -375,13 +337,8 @@ export class Img extends ImageBase {
375337
this.notify(args);
376338
if (this.failureImageUri) {
377339
image = this.getUIImage(this.failureImageUri);
378-
// this._setNativeImage();
379-
// } else {
380-
// console.log("clearing image");
381-
// this._setNativeImage(null);
382-
// this.nativeViewProtected.image = null;
383340
}
384-
} else {
341+
} else if (image) {
385342
const args = {
386343
eventName: ImageBase.finalImageSetEvent,
387344
object: this,
@@ -443,9 +400,6 @@ export class Img extends ImageBase {
443400
this._setNativeImage(ImageSource.fromFontIconCodeSync(fontIconCode, font, color).ios);
444401
}
445402
return;
446-
// } else if (src.startsWith(RESOURCE_PREFIX)) {
447-
// this._setNativeImage(ImageSource.fromResourceSync(src.));
448-
//
449403
}
450404

451405
}
@@ -493,7 +447,6 @@ export class Img extends ImageBase {
493447
if (transformers.length > 0) {
494448
context.setValueForKey(SDImagePipelineTransformer.transformerWithTransformers(transformers), SDWebImageContextImageTransformer);
495449
}
496-
497450
this.nativeViewProtected.sd_setImageWithURLPlaceholderImageOptionsContextProgressCompleted(
498451
uri,
499452
this.placeholderImage,

0 commit comments

Comments
 (0)