Skip to content

Commit a53f8c6

Browse files
committed
fix(ios): allow custom property getters to work in bindings
1 parent 3810921 commit a53f8c6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

iphone/TitaniumKit/TitaniumKit/Sources/Kroll/KrollObject.m

+12-1
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,9 @@ - (id)_valueForKey:(NSString *)key
652652
return [[[KrollMethod alloc] initWithTarget:target selector:@selector(toString:) argcount:0type:KrollMethodInvoke name:nilcontext:[selfcontext]] autorelease];
653653
}
654654

655+
// For something like TiUiTextWidgetProxy focused:(id)unused - this will assume it's a function/method
656+
// So to work around this, we need to explicitly declare a property named "focused" with a different underlying getter
657+
// to expose it as a property to JS
655658
SEL selector = NSSelectorFromString([NSStringstringWithFormat:@"%@:", key]);
656659
if ([target respondsToSelector:selector]) {
657660
return [[[KrollMethod alloc] initWithTarget:target
@@ -688,7 +691,15 @@ - (id)_valueForKey:(NSString *)key
688691
}
689692
} else {
690693
NSString *attributes = [NSStringstringWithCString:property_getAttributes(p) encoding:NSUTF8StringEncoding];
691-
SEL selector = NSSelectorFromString([NSStringstringWithCString:property_getName(p) encoding:NSUTF8StringEncoding]);
694+
// look up getter name from the property attributes
695+
SEL selector;
696+
constchar *getterName = property_copyAttributeValue(p, "G");
697+
if (getterName != nil) {
698+
selector = sel_getUid(getterName);
699+
} else {
700+
// not set, so use the property name
701+
selector = NSSelectorFromString([NSStringstringWithCString:property_getName(p) encoding:NSUTF8StringEncoding]);
702+
}
692703

693704
if ([attributes hasPrefix:@"T@"]) {
694705
// this means its a return type of id

0 commit comments

Comments
 (0)
close