Skip to content

Commit

Permalink
Merge pull request #8462 from hansemannn/TIMOB-23973-6_0_X
Browse files Browse the repository at this point in the history
[TIMOB-23973] (6_0_X) Fix event-issues in Ti.UI.ImageView
  • Loading branch information
cheekiatng committed Oct 4, 2016
2 parents b1d7386 + b8d3e7d commit 36ac435
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
14 changes: 14 additions & 0 deletions iphone/Classes/TiUIImageView.m
Expand Up @@ -222,6 +222,20 @@ -(void)startTimerWithEvent:(NSString *)eventName
}
}

#ifdef TI_USE_KROLL_THREAD
-(void)listenerAdded:(NSString *)type count:(int)count
{
if (count == 1 && [type isEqualToString:@"load"]) {
NSString *loadEventState = [(TiUIImageViewProxy*)[self proxy] loadEventState];
if (loadEventState) {
[[self proxy] fireEvent:@"load" withObject:@{@"state": loadEventState}];
}
} else {
[super listenerAdded:type count:count];
}
}
#endif

-(void)stopTimerWithEvent:(NSString *)eventName
{
if (!stopped) {
Expand Down
6 changes: 5 additions & 1 deletion iphone/Classes/TiUIImageViewProxy.h
Expand Up @@ -9,11 +9,15 @@
#import "TiViewProxy.h"
#import "ImageLoader.h"

@interface TiUIImageViewProxy : TiViewProxy<ImageLoaderDelegate, TiProxyDelegate> {
@interface TiUIImageViewProxy : TiViewProxy<ImageLoaderDelegate> {
ImageLoaderRequest *urlRequest;
NSURL* imageURL;
}

@property (nonatomic,retain) NSURL* imageURL;
#ifdef TI_USE_KROLL_THREAD
@property (nonatomic, assign) NSString* loadEventState;
#endif

-(void)cancelPendingImageLoads;
-(void)startImageLoad:(NSURL *)url;
Expand Down
32 changes: 9 additions & 23 deletions iphone/Classes/TiUIImageViewProxy.m
Expand Up @@ -16,12 +16,12 @@
#define DEBUG_IMAGEVIEW
#define DEFAULT_IMAGEVIEW_INTERVAL 200

@interface TiUIImageViewProxy ()
@property (nonatomic, copy) NSString* loadEventState;
@end

@implementation TiUIImageViewProxy
@synthesize imageURL, loadEventState;
@synthesize imageURL;

#ifdef TI_USE_KROLL_THREAD
@synthesize loadEventState;
#endif

static NSArray* imageKeySequence;

Expand Down Expand Up @@ -57,28 +57,12 @@ -(void)propagateLoadEvent:(NSString *)stateString
[self fireEvent:@"load" withObject:event];
#ifdef TI_USE_KROLL_THREAD
} else {
// Why do we do this?
// When running on kroll thread this is being called before the events are added.
// So we try to propagate this after the load event is added.
// TIMOB-20204
RELEASE_TO_NIL(self.loadEventState);
[self setLoadEventState:stateString];
[self setModelDelegate:self];
RELEASE_TO_NIL(loadEventState);
loadEventState = [stateString copy];
#endif
}
}

-(void)listenerAdded:(NSString*)type count:(int)count {
if ([self _hasListeners:@"load"]) {
[self setModelDelegate:nil];
[self fireEvent:@"load" withObject:@{@"state": [self loadEventState]}];
}
}

-(void)propertyChanged:(NSString*)key oldValue:(id)oldValue newValue:(id)newValue proxy:(TiProxy*)proxy {
DoProxyDelegateChangedValuesWithProxy((TiUIImageView*)[self view], key, oldValue, newValue, proxy);
}

-(void)_configure
{
[self replaceValue:NUMBOOL(NO) forKey:@"animating" notification:NO];
Expand Down Expand Up @@ -152,7 +136,9 @@ - (void) dealloc
[self replaceValue:nil forKey:@"image" notification:NO];

RELEASE_TO_NIL(imageURL);
#ifdef TI_USE_KROLL_THREAD
RELEASE_TO_NIL(loadEventState);
#endif
[super dealloc];
}

Expand Down

0 comments on commit 36ac435

Please sign in to comment.