-
-
Notifications
You must be signed in to change notification settings - Fork 518
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
fix(Android): jumping content on fabric #2313
fix(Android): jumping content on fabric #2313
Conversation
Why do we want to merge this into |
Is there a reason you removed the checks for if the calculated values are the same as the ones returned by the system later? It is important source of information for if we do the calculations right. |
a69ae08
to
87097ea
Compare
@tboba You're right, we can merge it independently. |
87097ea
to
f9a647c
Compare
This comment was marked as outdated.
This comment was marked as outdated.
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.
LGTM! Just one remark about method ordering 😄
std::optional<std::reference_wrapper<const ShadowNode::Shared>> | ||
findHeaderConfigChild( | ||
const YogaLayoutableShadowNode &screenShadowNode) { | ||
for (const ShadowNode::Shared &child : screenShadowNode.getChildren()) { | ||
if (std::strcmp( | ||
child->getComponentName(), "RNSScreenStackHeaderConfig") == 0) { | ||
return {std::cref(child)}; | ||
} | ||
} | ||
return {}; | ||
} | ||
|
||
static constexpr const char *kScreenDummyLayoutHelperClass = | ||
"com/swmansion/rnscreens/utils/ScreenDummyLayoutHelper"; | ||
|
||
#ifdef ANDROID | ||
std::optional<float> findHeaderHeight( | ||
const int fontSize, | ||
const bool isTitleEmpty) { | ||
JNIEnv *env = facebook::jni::Environment::current(); | ||
|
||
if (env == nullptr) { | ||
LOG(ERROR) << "[RNScreens] Failed to retrieve env\n"; | ||
return {}; | ||
} | ||
|
||
jclass layoutHelperClass = env->FindClass(kScreenDummyLayoutHelperClass); | ||
|
||
if (layoutHelperClass == nullptr) { | ||
LOG(ERROR) << "[RNScreens] Failed to find class with id " | ||
<< kScreenDummyLayoutHelperClass; | ||
return {}; | ||
} | ||
|
||
jmethodID computeDummyLayoutID = | ||
env->GetMethodID(layoutHelperClass, "computeDummyLayout", "(IZ)F"); | ||
|
||
if (computeDummyLayoutID == nullptr) { | ||
LOG(ERROR) | ||
<< "[RNScreens] Failed to retrieve computeDummyLayout method ID"; | ||
return {}; | ||
} | ||
|
||
jmethodID getInstanceMethodID = env->GetStaticMethodID( | ||
layoutHelperClass, | ||
"getInstance", | ||
"()Lcom/swmansion/rnscreens/utils/ScreenDummyLayoutHelper;"); | ||
|
||
if (getInstanceMethodID == nullptr) { | ||
LOG(ERROR) << "[RNScreens] Failed to retrieve getInstanceMethodID"; | ||
return {}; | ||
} | ||
|
||
jobject packageInstance = | ||
env->CallStaticObjectMethod(layoutHelperClass, getInstanceMethodID); | ||
|
||
if (packageInstance == nullptr) { | ||
LOG(ERROR) | ||
<< "[RNScreens] Failed to retrieve packageInstance or the package instance was null on JVM side"; | ||
return {}; | ||
} | ||
|
||
jfloat headerHeight = env->CallFloatMethod( | ||
packageInstance, computeDummyLayoutID, fontSize, isTitleEmpty); | ||
|
||
return {headerHeight}; | ||
} | ||
#endif // ANDROID |
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.
Let's move these methods below appendChild
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.
@tboba I'm afraid those methods have to be declared before they're used in cpp
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.
@alduzy But didn't we achieve different order, but in RNSScreenComponentDescriptor.h? 😄
It's not a big deal to have them here though, so if it's really not possible, I think we can proceed with what we have right now.
fdb1834
to
aee2a1f
Compare
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.
Looks good! Thanks!
Description
This PR applies modifications to a previous fix: #2169 for fabric only, which has stopped working since RN
0.75
.In RN
0.74
theadopt
inRNSScreenComponentDescriptior.h
was once called withoutstateData
but with children and we could then check if theScreenStackHeaderConfig
is present among them and make adjustments based on it.When working on #2292 it became clear that the fix does not work anymore. Now the
adopt
is called either with no children and nostateData
or with both.The solution is to move the code to
appendChild
inRNSScreenShadowNode.cpp
so we can perform the adjustments as soon as the children append.Changes
adopt
inRNSScreenComponentDescriptior.h
to newly addedappendChild
override inRNSScreenShadowNode.cpp
Screenshots / GIFs
Before
Screen.Recording.2024-08-22.at.17.45.41.mov
After
Screen.Recording.2024-08-22.at.17.48.01.mov
Test code and steps to reproduce
TestHeader
to test this changeChecklist