Skip to content

Commit 2b5ec0a

Browse files
committed
fix: persist UIAppearance proxy setter values
1 parent c0acd15 commit 2b5ec0a

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

NativeScript/ffi/shared/bridge/HostObjects.mm

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,29 @@ bool objectGetPathCanReadRuntimeProperty(id object,
563563
return false;
564564
}
565565

566+
Class appearanceProxyCustomizableClass(id object) {
567+
if (object == nil) {
568+
return Nil;
569+
}
570+
571+
NSString* description = [object description];
572+
NSString* prefix = @"<Customizable class: ";
573+
if (description.length <= prefix.length + 1 ||
574+
![description hasPrefix:prefix] || ![description hasSuffix:@">"]) {
575+
return Nil;
576+
}
577+
578+
NSRange classNameRange =
579+
NSMakeRange(prefix.length, description.length - prefix.length - 1);
580+
NSString* className = [description substringWithRange:classNameRange];
581+
return NSClassFromString(className);
582+
}
583+
584+
std::string appearanceProxyExpandoPropertyKey(
585+
const std::string& property) {
586+
return "__nativeApiAppearance:" + property;
587+
}
588+
566589
class NativeApiSuperHostObject final : public HostObject {
567590
public:
568591
NativeApiSuperHostObject(std::shared_ptr<NativeApiBridge> bridge,
@@ -1246,6 +1269,13 @@ Value get(Runtime& runtime, const PropNameID& name) override {
12461269
if (!expando.isUndefined()) {
12471270
return expando;
12481271
}
1272+
if (Class appearanceClass = appearanceProxyCustomizableClass(object_)) {
1273+
Value appearanceExpando = bridge_->findObjectExpando(
1274+
runtime, appearanceClass, appearanceProxyExpandoPropertyKey(property));
1275+
if (!appearanceExpando.isUndefined()) {
1276+
return appearanceExpando;
1277+
}
1278+
}
12491279

12501280
// Fast path: cached metadata property-getter resolution. Skips the
12511281
// special-name chain + per-access metadata discovery for hot getters
@@ -1725,6 +1755,11 @@ throw JSError(
17251755
Value args[] = {Value(runtime, value)};
17261756
callObjCSelector(runtime, bridge_, object_, false,
17271757
*setterSelectorName, nullptr, args, 1);
1758+
if (Class appearanceClass = appearanceProxyCustomizableClass(object_)) {
1759+
bridge_->setObjectExpando(
1760+
runtime, appearanceClass,
1761+
appearanceProxyExpandoPropertyKey(property), value);
1762+
}
17281763
if (!objectGetPathCanReadRuntimeProperty(object_, property)) {
17291764
bridge_->setObjectExpando(runtime, object_, property, value);
17301765
}

0 commit comments

Comments
 (0)