Skip to content

Commit

Permalink
fix(ios): allow custom property getters to work in bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtcoolguy committed Jun 22, 2020
1 parent 3810921 commit a53f8c6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion iphone/TitaniumKit/TitaniumKit/Sources/Kroll/KrollObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ - (id)_valueForKey:(NSString *)key
return [[[KrollMethod alloc] initWithTarget:target selector:@selector(toString:) argcount:0 type:KrollMethodInvoke name:nil context:[self context]] autorelease];
}

// For something like TiUiTextWidgetProxy focused:(id)unused - this will assume it's a function/method
// So to work around this, we need to explicitly declare a property named "focused" with a different underlying getter
// to expose it as a property to JS
SEL selector = NSSelectorFromString([NSString stringWithFormat:@"%@:", key]);
if ([target respondsToSelector:selector]) {
return [[[KrollMethod alloc] initWithTarget:target
Expand Down Expand Up @@ -688,7 +691,15 @@ - (id)_valueForKey:(NSString *)key
}
} else {
NSString *attributes = [NSString stringWithCString:property_getAttributes(p) encoding:NSUTF8StringEncoding];
SEL selector = NSSelectorFromString([NSString stringWithCString:property_getName(p) encoding:NSUTF8StringEncoding]);
// look up getter name from the property attributes
SEL selector;
const char *getterName = property_copyAttributeValue(p, "G");
if (getterName != nil) {
selector = sel_getUid(getterName);
} else {
// not set, so use the property name
selector = NSSelectorFromString([NSString stringWithCString:property_getName(p) encoding:NSUTF8StringEncoding]);
}

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

0 comments on commit a53f8c6

Please sign in to comment.