-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Fabric support #90
Changes from 5 commits
0676b37
7f39730
959200a
9a54f65
0f39e58
722b62f
e1e2ab2
fc6ec7a
45c5d5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
set(CMAKE_VERBOSE_MAKEFILE ON) | ||
|
||
set(LIB_LITERAL rnandroidprogressbar) | ||
set(LIB_TARGET_NAME react_codegen_${LIB_LITERAL}) | ||
|
||
set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) | ||
set(LIB_COMMON_DIR ${LIB_ANDROID_DIR}/../common/cpp) | ||
set(LIB_ANDROID_GENERATED_JNI_DIR ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni) | ||
set(LIB_ANDROID_GENERATED_COMPONENTS_DIR ${LIB_ANDROID_GENERATED_JNI_DIR}/react/renderer/components/${LIB_LITERAL}) | ||
|
||
add_compile_options( | ||
-fexceptions | ||
-frtti | ||
-std=c++17 | ||
-Wall | ||
-Wpedantic | ||
-Wno-gnu-zero-variadic-macro-arguments | ||
) | ||
|
||
file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS *.cpp) | ||
file(GLOB LIB_CODEGEN_SRCS CONFIGURE_DEPENDS ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}/*.cpp) | ||
|
||
add_library( | ||
${LIB_TARGET_NAME} | ||
SHARED | ||
${LIB_CUSTOM_SRCS} | ||
${LIB_CODEGEN_SRCS} | ||
) | ||
|
||
target_include_directories( | ||
${LIB_TARGET_NAME} | ||
PUBLIC | ||
. | ||
${LIB_ANDROID_GENERATED_JNI_DIR} | ||
${LIB_ANDROID_GENERATED_COMPONENTS_DIR} | ||
) | ||
|
||
target_link_libraries( | ||
${LIB_TARGET_NAME} | ||
fbjni | ||
folly_runtime | ||
glog | ||
jsi | ||
react_codegen_rncore | ||
react_debug | ||
react_nativemodule_core | ||
react_render_core | ||
react_render_debug | ||
react_render_graphics | ||
react_render_mapbuffer | ||
rrc_view | ||
turbomodulejsijni | ||
yoga | ||
) | ||
|
||
target_compile_options( | ||
${LIB_TARGET_NAME} | ||
PRIVATE | ||
-DLOG_TAG=\"ReactNative\" | ||
-fexceptions | ||
-frtti | ||
-std=c++17 | ||
-Wall | ||
) | ||
|
||
target_include_directories( | ||
${CMAKE_PROJECT_NAME} | ||
PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "RNCProgressBarMeasurementsManager.h" | ||
|
||
#include <fbjni/fbjni.h> | ||
#include <react/renderer/core/conversions.h> | ||
#include <react/renderer/components/view/conversions.h> | ||
#include <react/jni/ReadableNativeMap.h> | ||
|
||
using namespace facebook::jni; | ||
|
||
namespace facebook | ||
{ | ||
namespace react | ||
{ | ||
|
||
Size RNCProgressBarMeasurementsManager::measure( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you write a comment from where did you take analogous code with some links and a short explanation of what is done here if needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 722b62f. |
||
SurfaceId surfaceId, | ||
LayoutConstraints layoutConstraints, | ||
RNCProgressBarProps props) const | ||
{ | ||
{ | ||
std::lock_guard<std::mutex> lock(mutex_); | ||
if (cachedMeasurements_.find(props.styleAttr) != cachedMeasurements_.end()) | ||
{ | ||
return cachedMeasurements_[props.styleAttr]; | ||
} | ||
} | ||
|
||
const jni::global_ref<jobject> &fabricUIManager = | ||
contextContainer_->at<jni::global_ref<jobject>>("FabricUIManager"); | ||
|
||
static auto measure = | ||
jni::findClassStatic("com/facebook/react/fabric/FabricUIManager") | ||
->getMethod<jlong( | ||
jint, | ||
jstring, | ||
ReadableMap::javaobject, | ||
ReadableMap::javaobject, | ||
ReadableMap::javaobject, | ||
jfloat, | ||
jfloat, | ||
jfloat, | ||
jfloat)>("measure"); | ||
|
||
auto minimumSize = layoutConstraints.minimumSize; | ||
auto maximumSize = layoutConstraints.maximumSize; | ||
|
||
local_ref<JString> componentName = make_jstring("RNCProgressBar"); | ||
|
||
folly::dynamic serializedProps = folly::dynamic::object(); | ||
serializedProps["styleAttr"] = props.styleAttr; | ||
|
||
local_ref<ReadableNativeMap::javaobject> propsRNM = | ||
ReadableNativeMap::newObjectCxxArgs(serializedProps); | ||
local_ref<ReadableMap::javaobject> propsRM = | ||
make_local(reinterpret_cast<ReadableMap::javaobject>(propsRNM.get())); | ||
|
||
auto measurement = yogaMeassureToSize(measure( | ||
fabricUIManager, | ||
surfaceId, | ||
componentName.get(), | ||
nullptr, | ||
propsRM.get(), | ||
nullptr, | ||
minimumSize.width, | ||
maximumSize.width, | ||
minimumSize.height, | ||
maximumSize.height)); | ||
|
||
std::lock_guard<std::mutex> lock(mutex_); | ||
cachedMeasurements_[props.styleAttr] = measurement; | ||
return measurement; | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <react/renderer/components/rnandroidprogressbar/Props.h> | ||
#include <react/renderer/core/ConcreteComponentDescriptor.h> | ||
#include <react/renderer/core/LayoutConstraints.h> | ||
#include <react/utils/ContextContainer.h> | ||
|
||
namespace facebook | ||
{ | ||
namespace react | ||
{ | ||
|
||
class RNCProgressBarMeasurementsManager | ||
{ | ||
public: | ||
RNCProgressBarMeasurementsManager( | ||
const ContextContainer::Shared &contextContainer) | ||
: contextContainer_(contextContainer) {} | ||
|
||
Size measure(SurfaceId surfaceId, LayoutConstraints layoutConstraints, RNCProgressBarProps props) const; | ||
|
||
private: | ||
const ContextContainer::Shared contextContainer_; | ||
mutable std::mutex mutex_; | ||
mutable std::unordered_map<std::string, Size> cachedMeasurements_ = {}; | ||
}; | ||
|
||
} // namespace react | ||
} // namespace facebook |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "RNCProgressBarShadowNode.h" | ||
#include "RNCProgressBarMeasurementsManager.h" | ||
|
||
namespace facebook | ||
{ | ||
namespace react | ||
{ | ||
|
||
extern const char RNCProgressBarComponentName[] = "RNCProgressBar"; | ||
|
||
void RNCProgressBarShadowNode::setProgressBarMeasurementsManager( | ||
const std::shared_ptr<RNCProgressBarMeasurementsManager> | ||
&measurementsManager) | ||
{ | ||
ensureUnsealed(); | ||
measurementsManager_ = measurementsManager; | ||
} | ||
|
||
#pragma mark - LayoutableShadowNode | ||
|
||
Size RNCProgressBarShadowNode::measureContent( | ||
LayoutContext const &layoutContext, | ||
LayoutConstraints const &layoutConstraints) const | ||
{ | ||
return measurementsManager_->measure(getSurfaceId(), layoutConstraints, getConcreteProps()); | ||
} | ||
} // namespace react | ||
} // namespace facebook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is
customType = "Color"
gone here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of adding
processColor
in JS the prop stopped working whencustomType = "Color"
was there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm looking e.g. here: https://github.com/software-mansion/react-native-svg/blob/1126079425a1b1a6c6094434f1c199c52ded1817/src/fabric/AndroidSvgViewNativeComponent.ts#L33 and then here: https://github.com/software-mansion/react-native-svg/blob/18a2f93e4057bae3dbdb604d9590861450f23b11/android/src/main/java/com/horcrux/svg/SvgViewManager.java#L101 and here: https://github.com/software-mansion/react-native-svg/blob/18a2f93e4057bae3dbdb604d9590861450f23b11/android/src/main/java/com/horcrux/svg/SvgViewManager.java#L101 and here: https://github.com/software-mansion/react-native-svg/blob/1126079425a1b1a6c6094434f1c199c52ded1817/src/elements/Svg.tsx#L179, maybe we should not use
processColor
in JS but just do something similar to how it is done in svg?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was
processColor
added in the first place?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 45c5d5e. I don't particularly remember why I've done it this way 😅.