Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-13000] Fixed load event on image view #4996

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 20 additions & 15 deletions iphone/Classes/TiViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "TiLocale.h"
#import "TiUIView.h"
#import "TiApp.h"
#import "TiUIImageViewProxy.h"

#import <QuartzCore/QuartzCore.h>
#import <libkern/OSAtomic.h>
Expand Down Expand Up @@ -1617,8 +1618,17 @@ -(BOOL)_hasListeners:(NSString *)type
return [self _hasListeners:type checkParent:YES];
}

//TODO: Remove once we've properly deprecated.
-(void)fireEvent:(NSString*)type withObject:(id)obj withSource:(id)source propagate:(BOOL)propagate reportSuccess:(BOOL)report errorCode:(int)code message:(NSString*)message;
-(NSArray *)stateEvents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole method is extremely inefficient. It essentially returns an autoreleased array every time it is invoked. You should initialize the array once. Easiest to initialize in the init method of the proxy. You can define a protected NSArray in TiViewProxy interface and initialize it accordingly in various proxies

{
NSMutableArray *arr = [NSMutableArray array];
[arr addObject:@"postlayout"];
if([self isKindOfClass:[TiUIImageViewProxy class]]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check should not be here. Instead the TiUIImageViewProxy class must override the method to return a different array

[arr addObject:@"load"];
}
return arr;
}

-(BOOL)viewProxyShouldFireEvent:(NSString *)type
{
// Note that some events (like movie 'complete') are fired after the view is removed/dealloc'd.
// Because of the handling below, we can safely set the view to 'nil' in this case.
Expand All @@ -1631,25 +1641,20 @@ -(void)fireEvent:(NSString*)type withObject:(id)obj withSource:(id)source propag
// Have to handle the situation in which the proxy's view might be nil... like, for example,
// with table rows. Automagically assume any nil view we're firing an event for is A-OK.
// NOTE: We want to fire postlayout events on ANY view, even those which do not allow interactions.
if (proxyView == nil || [proxyView interactionEnabled] || [type isEqualToString:@"postlayout"]) {
return (proxyView == nil || [proxyView interactionEnabled] || [[self stateEvents] containsObject:type]);
}

//TODO: Remove once we've properly deprecated.
-(void)fireEvent:(NSString*)type withObject:(id)obj withSource:(id)source propagate:(BOOL)propagate reportSuccess:(BOOL)report errorCode:(int)code message:(NSString*)message;
{
if ([self viewProxyShouldFireEvent:type]) {
[super fireEvent:type withObject:obj withSource:source propagate:propagate reportSuccess:report errorCode:code message:message];
}
}

-(void)fireEvent:(NSString*)type withObject:(id)obj propagate:(BOOL)propagate reportSuccess:(BOOL)report errorCode:(int)code message:(NSString*)message;
{
// Note that some events (like movie 'complete') are fired after the view is removed/dealloc'd.
// Because of the handling below, we can safely set the view to 'nil' in this case.
TiUIView* proxyView = [self viewAttached] ? view : nil;
//TODO: We have to do view instead of [self view] because of a freaky race condition that can
//happen in the background (See bug 2809). This assumes that view == [self view], which may
//not always be the case in the future. Then again, we shouldn't be dealing with view in the BG...


// Have to handle the situation in which the proxy's view might be nil... like, for example,
// with table rows. Automagically assume any nil view we're firing an event for is A-OK.
// NOTE: We want to fire postlayout events on ANY view, even those which do not allow interactions.
if (proxyView == nil || [proxyView interactionEnabled] || [type isEqualToString:@"postlayout"]) {
if ([self viewProxyShouldFireEvent:type]) {
if (eventOverrideDelegate != nil) {
obj = [eventOverrideDelegate overrideEventObject:obj forEvent:type fromViewProxy:self];
}
Expand Down