/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #pragma once #include #include #include #ifdef ANDROID #include #include #include #endif #include namespace facebook { namespace react { #ifdef ANDROID using namespace facebook::jni; Size measureAndroidComponent( const ContextContainer::Shared &contextContainer, Tag rootTag, std::string componentName, folly::dynamic localData, folly::dynamic props, folly::dynamic state, float minWidth, float maxWidth, float minHeight, float maxHeight, jfloatArray attachmentPositions) { const jni::global_ref &fabricUIManager = contextContainer->at>("FabricUIManager"); static auto measure = jni::findClassStatic("com/facebook/react/fabric/FabricUIManager") ->getMethod("measure"); auto componentNameRef = make_jstring(componentName); local_ref localDataRNM = ReadableNativeMap::newObjectCxxArgs(localData); local_ref propsRNM = ReadableNativeMap::newObjectCxxArgs(props); local_ref stateRNM = ReadableNativeMap::newObjectCxxArgs(state); local_ref localDataRM = make_local(reinterpret_cast(localDataRNM.get())); local_ref propsRM = make_local(reinterpret_cast(propsRNM.get())); local_ref stateRM = make_local(reinterpret_cast(stateRNM.get())); auto size = yogaMeassureToSize(measure( fabricUIManager, rootTag, componentNameRef.get(), localDataRM.get(), propsRM.get(), stateRM.get(), minWidth, maxWidth, minHeight, maxHeight, attachmentPositions)); // Explicitly release smart pointers to free up space faster in JNI tables componentNameRef.reset(); localDataRM.reset(); localDataRNM.reset(); propsRM.reset(); propsRNM.reset(); stateRM.reset(); stateRNM.reset(); return size; } Size measureAndroidComponentMapBuffer( const ContextContainer::Shared &contextContainer, Tag rootTag, std::string componentName, MapBuffer &localData, MapBuffer &props, float minWidth, float maxWidth, float minHeight, float maxHeight, jfloatArray attachmentPositions) { const jni::global_ref &fabricUIManager = contextContainer->at>("FabricUIManager"); auto componentNameRef = make_jstring(componentName); static auto measure = jni::findClassStatic("com/facebook/react/fabric/FabricUIManager") ->getMethod("measureMapBuffer"); auto localDataMap = ReadableMapBuffer::createWithContents(std::move(localData)); auto propsMap = ReadableMapBuffer::createWithContents(std::move(props)); auto size = yogaMeassureToSize(measure( fabricUIManager, rootTag, componentNameRef.get(), localDataMap.get(), propsMap.get(), minWidth, maxWidth, minHeight, maxHeight, attachmentPositions)); // Explicitly release smart pointers to free up space faster in JNI tables componentNameRef.reset(); localDataMap.reset(); propsMap.reset(); return size; } #endif } // namespace react } // namespace facebook