MCPcopy Create free account
hub / github.com/Snapchat/Valdi / setValueForAttribute

Method setValueForAttribute

valdi/src/valdi/android/NativeBridge.cpp:1456–1500  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1454 auto attributeValue = ValdiAndroid::toValue(javaEnv, ValdiAndroid::JavaEnv::newLocalRef(value));
1455
1456 runtime->updateAttributeState(*viewNode, attributeName, attributeValue);
1457}
1458
1459void ValdiAndroid::NativeBridge::setValueForAttribute( // NOLINT
1460 fbjni::alias_ref<fbjni::JClass> /* clazz */, // NOLINT
1461 jlong viewNodeHandle,
1462 jstring attribute,
1463 jobject value,
1464 jboolean keepAsOverride) {
1465 auto viewNode = getViewNode(viewNodeHandle);
1466 if (viewNode == nullptr) {
1467 return;
1468 }
1469
1470 auto javaEnv = ValdiAndroid::JavaEnv();
1471
1472 auto attributeName = ValdiAndroid::toInternedString(javaEnv, attribute);
1473 auto attributeValue = ValdiAndroid::toValue(javaEnv, ValdiAndroid::JavaEnv::newLocalRef(value));
1474
1475 auto attributeId = viewNode->getAttributeIds().getIdForName(attributeName);
1476
1477 auto* viewNodeTree = viewNode->getViewNodeTree();
1478
1479 Valdi::AttributeOwner* attributeOwner;
1480 if (static_cast<bool>(keepAsOverride)) {
1481 attributeOwner = Valdi::AttributeOwner::getNativeOverridenAttributeOwner();
1482 } else {
1483 attributeOwner = viewNodeTree;
1484 }
1485
1486 if (viewNodeTree == nullptr) {
1487 // TODO: is this a valid state?
1488 // should we still call setAttribute, just without flush (since, presumably, this ViewNode wouldn't have a View
1489 // to flush to?)
1490 } else {
1491 viewNodeTree->withLock([&]() {
1492 auto& viewTransactionScope = viewNodeTree->getCurrentViewTransactionScope();
1493 viewNode->setAttribute(viewTransactionScope, attributeId, attributeOwner, attributeValue, nullptr);
1494 viewNode->getAttributesApplier().flush(viewTransactionScope);
1495
1496 // TODO: does onAttributeChange have to be under the getViewNodeTree lock?
1497 if (!static_cast<bool>(keepAsOverride)) {
1498 viewNodeTree->getContext()->onAttributeChange(
1499 viewNode->getRawId(), attributeName, attributeValue, false);
1500 }
1501 });
1502 }
1503}

Callers

nothing calls this directly

Calls 12

getViewNodeFunction · 0.85
toInternedStringFunction · 0.85
toValueFunction · 0.85
getIdForNameMethod · 0.80
getViewNodeTreeMethod · 0.80
withLockMethod · 0.80
getRawIdMethod · 0.80
setAttributeMethod · 0.65
flushMethod · 0.65
JavaEnvClass · 0.50
onAttributeChangeMethod · 0.45
getContextMethod · 0.45

Tested by

no test coverage detected