Texture icon indicating copy to clipboard operation
Texture copied to clipboard

ASNetworkImageNode, gif image disappear for a second when scroll back

Open yang152412 opened this issue 7 years ago • 17 comments

gif image disappear for a second and then show again when scroll back in a tableView or collectionView.

example example gif

error image

yang152412 avatar Jun 25 '18 09:06 yang152412

Try to setup shouldCacheImage property as false(objc: NO)

GeekTree0101 avatar Jun 25 '18 10:06 GeekTree0101

@GeekTree0101 it doesn't work

yang152412 avatar Jun 25 '18 10:06 yang152412

When did you set gif resource url onto ASNetworkImageNode ?

GeekTree0101 avatar Jun 26 '18 00:06 GeekTree0101

@GeekTree0101 just in the init method. use the examples/ASCollectionView.

string is a gif resource ` - (instancetype)initWithString:(NSString *)string { self = [super init]; if (self != nil) { .......

  self.imageNode.defaultImage = nil;
  self.imageNode.URL = [NSURL URLWithString:string];
  
  [self addSubnode:self.imageNode];

...... } } `

yang152412 avatar Jun 26 '18 02:06 yang152412

self.imageNode.URL = [NSURL URLWithString:string]; In this case, resetToDefault is YES. try to use this method imageNode.setURL(gifURL, resetToDefault: false)

GeekTree0101 avatar Jun 26 '18 04:06 GeekTree0101

@GeekTree0101 It doesn't work either. notice the show example gif , Why the first gif is OK?

I upload an demo at here

yang152412 avatar Jun 26 '18 06:06 yang152412

You may download "t plus one" from app store, it use ASNetworkImageNode for all images, just simply set imageNode.URL = [NSURL URLWithString:imageURLInText]; App version 1.0.12 = Texture 2.7 by cocoapods

qiaoyan avatar Jun 26 '18 09:06 qiaoyan

@yang152412 Have you resolved the problem? I have the same problem. I'm using Texture/IGListKit...

mixdesign avatar Sep 09 '18 13:09 mixdesign

I have the same issue, it happens in the latest version of Texture.

SolorzanoJose avatar Sep 18 '18 19:09 SolorzanoJose

Finally, I find where is the problem.

The code at ASNetworkImageNode.mm 334~371:

- (void)displayWillStartAsynchronously:(BOOL)asynchronously
{
  [super displayWillStartAsynchronously:asynchronously];
  
  if (asynchronously == NO && _cacheFlags.cacheSupportsSynchronousFetch) {
    ASLockScopeSelf();

    NSURL *url = _URL;
    if (_imageLoaded == NO && url && _downloadIdentifier == nil) {
      UIImage *result = [[_cache synchronouslyFetchedCachedImageWithURL:url] asdk_image];
      if (result) {
     }
 ...
}

[self didEnterPreloadState];
}

ASDisplayNode will display asynchronously if we set the displaysAsynchronously to NO according the document. So, I set displaysAsynchronously to NO,and implement - (nullable id <ASImageContainerProtocol>)synchronouslyFetchedCachedImageWithURL:(NSURL *)URL method.

But the problem is _imageLoaded == NO, _imageLoaded has been set to YES before the code goes here, here is the stack:

#1	0x000000010b6c8bb9 in -[ImageManager cachedImageWithURL:callbackQueue:completion:] 75
#2	0x000000010b8ec403 in ::-[ASNetworkImageNode _lazilyLoadImageIfNecessary]() 793
#3	0x000000010b8ea95a in ::-[ASNetworkImageNode didEnterPreloadState]() 432
#4	0x000000010b881cd8 in ::-[ASDisplayNode applyPendingInterfaceState:](ASInterfaceState) 3135
#5	0x000000010b8815bc in ::-[ASDisplayNode setInterfaceState:](ASInterfaceState) 3076
#6	0x000000010b8814d7 in ::__46-[ASDisplayNode recursivelySetInterfaceState:]_block_invoke(ASDisplayNode *) 3060
#7	0x000000010b88d685 in ::ASDisplayNodePerformBlockOnEveryNode(CALayer *, ASDisplayNode *, BOOL, void (^)(ASDisplayNode *)) 103
#8	0x000000010b88da6e in ::ASDisplayNodePerformBlockOnEveryNode(CALayer *, ASDisplayNode *, BOOL, void (^)(ASDisplayNode *)) 117
#9	0x000000010b881449 in ::-[ASDisplayNode recursivelySetInterfaceState:](ASInterfaceState) 3059
#10	0x000000010b8fbc77 in ::-[ASRangeController _updateVisibleNodeIndexPaths]() at ASRangeController.mm:389
#11	0x000000010b8f9e6b in ::-[ASRangeController updateRanges]() at ASRangeController.mm:164
#12	0x000000010b8f9e29 in ::-[ASRangeController updateIfNeeded]() at ASRangeController.mm:157
#13	0x000000010b8f9d8d in ::__35-[ASRangeController setNeedsUpdate]_block_invoke() at ASRangeController.mm:149
#14	0x000000010fec65d1 in _dispatch_call_block_and_release ()
#15	0x000000010fec763e in _dispatch_client_callout ()
#16	0x000000010fed49d6 in _dispatch_main_queue_callback_4CF ()
#17	0x000000010ef757f9 in __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ ()
#18	0x000000010ef6fe86 in __CFRunLoopRun ()
#19	0x000000010ef6f221 in CFRunLoopRunSpecific ()
#20	0x0000000114f7b1dd in GSEventRunModal ()
#21	0x000000011834f115 in UIApplicationMain ()
#22	0x000000010b6cdbc0 in main 
#23	0x000000010ff3d551 in start ()

So UIImage *result = [[_cache synchronouslyFetchedCachedImageWithURL:url] asdk_image]; will never be executed. ASNetworkImageNode will always read cache asynchronously. That's why the animated image flashed when scroll.

At last,my solution is use an ASImageNode to display image, and an ASNetworkImageNode to download.I use synchronouslyFetchedCachedImageWithURL to read cache. use the ASImageNode to display if cache is exist, or defaultImage if not. And update the image in delegate method - (void)imageNode:(ASNetworkImageNode *)imageNode didLoadImage:(UIImage *)image info:(ASNetworkImageNodeDidLoadInfo)info. but this method has a bug at 2.7 version. It does not be called if an url is a gif,(it's ok at 2.6). So i create a pull request#1121 to fix it.

yang152412 avatar Sep 19 '18 02:09 yang152412

I meet this problem only when the gif has single frame, gif with multi-frame works fine

ruixingchen avatar Mar 25 '19 07:03 ruixingchen

Can someone please upload a sample project which reproduces this issue?

garrettmoon avatar Mar 25 '19 21:03 garrettmoon

@garrettmoon I make a sample project to reproduce this problem, see: https://drive.google.com/file/d/1_YZUm8AGnLCy13hzz-t9gO0KquiCmaUE/view?usp=sharing

and the gif: Untitled 2019-03-29 10_54_02

ruixingchen avatar Mar 29 '19 02:03 ruixingchen

Two years later and this still isn't fixed :(

SolorzanoJose avatar Apr 17 '20 04:04 SolorzanoJose

No fixes?

SolorzanoJose avatar Oct 22 '20 07:10 SolorzanoJose

same problem....

MeGaPk avatar Apr 21 '21 13:04 MeGaPk