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

Move all ReactSpan subclasses to a separate folder #42594

Closed
wants to merge 3 commits into from

Conversation

cubuspl42
Copy link
Contributor

Summary:

Move all ReactSpan subclasses to a separate folder.

This is a minor improvement in the context of my multi-PR work on react-native-community/discussions-and-proposals#695.

I'm adding a new span class later, which was the direct motivation for this change.

Changelog:

[INTERNAL] [CHANGE] - Move all ReactSpan subclasses to a separate folder

Test Plan:

@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. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Jan 22, 2024
@analysis-bot
Copy link

analysis-bot commented Jan 22, 2024

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 16,972,236 +8,459
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 20,355,997 +8,447
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 5f75e9b
Branch: main

@cubuspl42
Copy link
Contributor Author

@mdvacca Could you review this?

@cubuspl42
Copy link
Contributor Author

@mdvacca There were already quite a few Span subclasses in the package, and I'm about to add at least one more. I thought it would be clearer if we put it inside a sub-package. It's not a big deal actually 🙂

@mdvacca
Copy link
Contributor

mdvacca commented Jan 24, 2024

Unfortunately this is a breakage of compatibility, could you analyze the usage of these classes by Open Source third party libraries in github search?

cc @cortinico

@cubuspl42
Copy link
Contributor Author

cubuspl42 commented Jan 24, 2024

@mdvacca It's a great point! I agree that we should be careful here.

I actually gave a thought in the context of this PR, and I concluded that there's no reasonable reason to use our Span subclasses from the outside. They feel to be total implementation details.

But I'll search for usages anyway! Thanks for the tip.

@cortinico
Copy link
Contributor

Unfortunately this is a breakage of compatibility, could you analyze the usage of these classes by Open Source third party libraries in github search?
cc @cortinico

@cubuspl42 here some usages:
https://github.com/search?type=code&q=import+%2Fcom.facebook.react.views.text.*Span%2F+NOT+is%3Afork+language%3AJava&p=5

Most of the usages are copies of our classes (easily spottable if the filepath is com/facebook/react).
Other usages are related to old libraries, so the impact is limited IMHO.

@mdvacca could we move this to .internal maybe then?

@cubuspl42
Copy link
Contributor Author

cubuspl42 commented Jan 24, 2024

Moving anything to .internal hardly works, because the internal Meta build system doesn't allow cycles between Java packages. Yeah, I mean actual Java packages.

I had to revert all moving to .internal in #39630.

It would be great to figure this out.

@cubuspl42
Copy link
Contributor Author

Using Kotlin internal visibility modifier also doesn't work.

@cortinico
Copy link
Contributor

Moving anything to .internal hardly works, because the internal Meta build system doesn't allow cycles between Java packages. Yeah, I mean actual Java packages.

mmm how is com.facebook.react.views.text.span different from com.facebook.react.internal.text.span in terms of cycles?

@cortinico
Copy link
Contributor

Using Kotlin internal visibility modifier also doesn't work.

Using the internal modifier is sadly not an option for us because we use BUCK internally which treat each Java package as a separate library. So things will be internal to the package (i.e. same visibility as package private).

@cubuspl42
Copy link
Contributor Author

Moving anything to .internal hardly works, because the internal Meta build system doesn't allow cycles between Java packages. Yeah, I mean actual Java packages.

mmm how is com.facebook.react.views.text.span different from com.facebook.react.internal.text.span in terms of cycles?

I assumed we'd create a cycle between com.facebook.react.internal.views.text and com.facebook.react.views.text. It happened immediately in the previous PR. But maybe it indeed doesn't happen here. I can check.

@cortinico
Copy link
Contributor

I assumed we'd create a cycle between com.facebook.react.internal.views.text and com.facebook.react.views.text. It happened immediately in the previous PR. But maybe it indeed doesn't happen here. I can check.

Ah yeah that can be the case. Still if so, we'll have the cycle anyway between com.facebook.react.views.text and com.facebook.react.views.text.span.

As a last resort we could also use com.facebook.react.views.text.internal.span. It's not preferred as we tend to have everything internal in the top level .internal package, but when not possible that's also an option

@cubuspl42
Copy link
Contributor Author

cubuspl42 commented Jan 24, 2024

I'll try it.

Have you considered adding some annotation for React-internal APIs? Sure, it's not as bullet-proof as the .internal infix in the fully qualified name (someone might not notice the annotation), but at least it makes it clear from our side what is and what isn't considered stable and supported for the community dependencies with minimal changes to the RN actual code.

Also, it makes it possible to annotate methods inside an otherwise public class.

@cortinico
Copy link
Contributor

Have you considered adding some annotation for React-internal APIs?

Yes we do already have some:

binaryCompatibilityValidator.nonPublicMarkers=com.facebook.react.common.annotations.VisibleForTesting,\
com.facebook.react.common.annotations.UnstableReactNativeAPI

We've been discussing with @mdvacca to actually add an @Internal or @ReactNativeInternal annotation as well exactly for the reasons you mentioned

@cubuspl42
Copy link
Contributor Author

Yes we do already have some

I don't think that they match my use-case, though. @VisibleForTesting is clearly specific for stuff visible only for testing, while "unstable" sounds like "public, but experimental and might change".

We've been discussing with @mdvacca to actually add an @internal or @ReactNativeInternal

Interesting! A remaining question is whether this would be a replacement or a supplement to the .internal convention.

@cortinico
Copy link
Contributor

Interesting! A remaining question is whether this would be a replacement or a supplement to the .internal convention.

It's going to be a supplement as we intend to have .internal as primary way to indicate non public APIs

@cubuspl42 cubuspl42 force-pushed the extract-spans branch 2 times, most recently from 9febbe1 to 06dd2de Compare January 25, 2024 12:42
@cubuspl42
Copy link
Contributor Author

@cortinico Could you take a look now?

If the checks succeed, does it mean Buck accepted this code?

@cortinico
Copy link
Contributor

If the checks succeed, does it mean Buck accepted this code?

Nope till we import it. Let me look into it

@facebook-github-bot
Copy link
Contributor

@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.views.text;
package com.facebook.react.views.text.internal.span;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is problematic as ReactTextInlineImageShadowNode (which is public) has this method:

public abstract class ReactTextInlineImageShadowNode extends LayoutShadowNode {
  /**
   * Build a {@link TextInlineImageSpan} from this node. This will be added to the TextView in place
   * of this node.
   */
  public abstract TextInlineImageSpan buildInlineImageSpan();
}

so we'll be returning an .internal object from a public class.

We probably should move also ReactTextInlineImageShadowNode to .internal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

@cubuspl42 can we make sure the CI is green?

@facebook-github-bot
Copy link
Contributor

@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@cortinico
Copy link
Contributor

I'll drive this forward as there are various failures internally which needs to be handled.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jan 26, 2024
@facebook-github-bot
Copy link
Contributor

@cortinico merged this pull request in d4c3311.

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. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants