Skip to content
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 inspector reporting wrong frames when using DrawerLayoutAndroid on the new arch #44426

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

j-piasecki
Copy link
Contributor

Summary:

Due to getContentOriginOffset not being overridden by AndroidDrawerLayoutShadowNode, findNodeAtPoint function from UIManagerBinding was also taking into account the content of the drawer even if it was closed. This was also causing the frames always to be reported as if the drawer was on the left side.

This PR adds a custom shadow node and native state, so that getContentOriginOffset can return the correct values depending on the state of the drawer.

Fixes #44425

Changelog:

[ANDROID] [FIXED] - Fixed layout inspector reporting wrong frames when using DrawerLayoutAndroid on the new arch

Test Plan:

Tested on the reproducer from the issue.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Software Mansion Partner: Software Mansion Partner labels May 6, 2024
@analysis-bot
Copy link

analysis-bot commented May 6, 2024

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 19,429,762 -65,523
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 22,802,088 -65,519
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 362abb9
Branch: main


if (isOpen != stateDrawerOpened || onLeft != stateOnLeft || Math.abs(stateContainerWidth - containerWidth) > delta || Math.abs(stateDrawerWidth - drawerWidth) > delta) {
WritableNativeMap newState = new WritableNativeMap();
newState.putBoolean("drawerOnLeft", onLeft);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about assigning these strings to private final static fields to eliminate risk of typos?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what's the convention, in other places plain strings are used as well:

newStateData.putDouble("screenWidth", realWidth.toDouble())
newStateData.putDouble("screenHeight", realHeight.toDouble())

newStateData.putInt("mostRecentEventCount", mEditText.incrementAndGetEventCounter());
newStateData.putInt("opaqueCacheId", mEditText.getId());


folly::dynamic getDynamic() const;
MapBuffer getMapBuffer() const {
return MapBufferBuilder::EMPTY();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really safe to remove an empty map buffer here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is, as long as we're not calling stateWrapper.getStateDataMapBuffer(), which we're not doing, instead calling getStateData which returns the dynamic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's done exactly the same way in modal component:

MapBuffer getMapBuffer() const {
return MapBufferBuilder::EMPTY();
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Software Mansion Partner: Software Mansion Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Layout inspector shows wrong frames when using DrawerLayoutAndroid
4 participants