-
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
Merged
Naturalclar
merged 9 commits into
react-native-progress-view:master
from
j-piasecki:@jpiasecki/add-fabric
Jun 20, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0676b37
Add fabric example
j-piasecki 7f39730
Setup codegen
j-piasecki 959200a
Add custom state
j-piasecki 9a54f65
Add progress bar measurement
j-piasecki 0f39e58
Add paper interop
j-piasecki 722b62f
Add explaination comment
j-piasecki e1e2ab2
Use codegen config in the `react-native.config.js` only when CLI supp…
j-piasecki fc6ec7a
Remove unused property
j-piasecki 45c5d5e
Restore `customType = "Color"`
j-piasecki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
) |
78 changes: 78 additions & 0 deletions
78
android/src/main/jni/RNCProgressBarMeasurementsManager.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#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 | ||
{ | ||
// Based on react-native/ReactCommon/react/renderer/components/switch/androidswitch/react/renderer/components/androidswitch/AndroidSwitchMeasurementsManager.cpp | ||
// This class is shared between the shadow nodes and allows us to measure the progress bar. | ||
// It calls the measure method of the ReactProgressBarViewManager.java which is responsible for the actual | ||
// measurement of the progress bar. | ||
Size RNCProgressBarMeasurementsManager::measure( | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 722b62f.