-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Refactor TextFragmentList
into AttributedString
#42701
Conversation
bb434e9
to
37692d4
Compare
...preparing it to support another layer over fragments.
37692d4
to
a57ee9a
Compare
Base commit: cfc0ba0 |
Context, that you may have already found, is that I think some of the original naming around here, around bridge vs attributedstring, is because the Paper path is not backed by an For that reason, naming like |
|
||
package com.facebook.react.views.text.attributedstring | ||
|
||
/** Interface for an attributed string */ |
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.
This comment, and same for AttributedStringFragment
are not meaningful to someone who wants to learn what this interface represents and is used for.
It's a good point. I'm thinking about a fully-processed
Would you agree that this set of actions would result in consistent naming and semantics?
We would have two implementation paths for the same concept of denormalized text. In other words, I'm suggesting that what we do in Paper is the same thing we do in Fabric, just using a different programming language and different nomenclature. I will have to do (2) anyway, modulo the naming. (3) will be a follow-up to #42703, modulo the naming. (4) and (5) is this PR. |
Also, it's not a secret that my main point is extending this Technically, this layer could also be implemented both on Paper and Fabric. I have only a Fabric implementation, though. Whether we have to support Paper first-class in the context of my project is another topic. |
I would agree with that. Fabric layer has some other examples of that as well though (e.g. text attachments). "normalized" is overloaded enough that I think I would recommend keeping it's naming as is, as it's also relatively well-known, and often used at this point.
Splitting this up makes a lot of sense to me. It does seem like we are storing unrelated bits in each use case. |
I do not feel strongly about any particular name. What's more important is what is named is the same as something else. I'm suggesting that Paper builds the same data structure as Fabric, let it be named This foo text structure currently has one layer of foo fragments. I want to expand it so it's a built of foo shards, where each foo shard is built of foo fragments. As I see it, it would be more consistent if the Java class structure and the C++ class structure were named the same way, as it is the same thing (even if the implementation is not always shared). Please let me know what would be an acceptable way forward. Maybe we could "borrow" the name We could still shift some of the naming towards fragments (mainly Otherwise, we're blocked because the existing naming is unfortunate and/or inconsistent, and we can't change that because the names are relatively well-known. |
Word idea: flat / flattened |
Actually, wait. Line 289 in ab72950
Line 259 in d4c3311
I must admit that I'm sometimes lost in the forest of Paper, Fabric, bridges, |
It is serialized, but not over the bridge. Unlike on iOS, where we have separate Fabric and Paper implementations of components like Text, Android shares the same underlying view managers for both (in Java). So we need to go over a JNI boundary, to call Java from C++.
Note that while we use Java View Managers under Fabric/new architecture, the Java ShadowNode's are only used in Paper. So, Java ShadowNode logic is old architecture, and both IIRC we had rolled out the changes to use |
@NickGerleman Maybe let's focus on deserialization, because that's what the The Line 247 in d4c3311
And it uses Lines 28 to 29 in d4c3311
As I understood, this code is deserializing what was serialized here: Line 289 in ab72950
Did I get something wrong? Is this code "not using a bridge", although it uses Respectfully, is it possible that you also got lost in this labyrinth? 😃 |
As I understood this, Fabric and bridge are not mutually exclusive, and Fabric can be configured to use the bridge, although |
@NickGerleman Bump |
@NickGerleman Bump again. Let me know if I can help make anything clearer |
@cubuspl42 please see previous feedback. I don't think this change is a positive in terms of naming, wrt how existing structures are set up. |
Thank you for all of your feedback, including the explanations of the RN architecture. Unfortunately, I have a strong feeling that there's some misunderstanding going on here, and I cannot resolve it without your help. I might have contributed to the misunderstanding with my initial response to your feedback: #42701 (comment) Are you 100% confident that your feedback is relevant to the discussed code? As I see it, the new JVM
Do you see it differently? |
Could you share you insight regarding to what Nick asked here... #42701 (comment)
...and give this PR a second pair of eyes in general? I'd like to move this forward soon, as I think that the changes are less controversial than they appear. |
Hey @cubuspl42, there are several requests for changes, and comments on the PR, not addressed or reflected in the revision I am seeing at least. Please do not ping until these are addressed. There are some nuances to these names. Let's not rename them as part of this work, that you are trying to unlock. |
Some updates are from JS --> CPP --> Java using components APIs like AndroidTextInputState.cpp react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/StateWrapper.java Lines 15 to 20 in 6780e00
As explained in the below comments, you can add comments and log the values passed to cpp:
For example for a controlled TextInput component that send updates onChangeText from JS to Java function ControlledTextInput() {
const [value, setValue] = React.useState("")
const [errorMessage, setErrorMessage] = React.useState(null)
const onChangeCallback = (text) => {
setText(text);
if (text.length > 5) {
setErrorMessage("not valid text")
} else {
setErrorMessage(null)
}
}
return (
<TextInput onChange={onChangeCallback}>
<Text errorMessageAndroid={errorMessage}>{value}</Text>
</TextInput>
)
} Text, Selection and other updates triggered onChangeText are sent through the codegen action
which uses dispatchCommand to send updates from JS --> CPP --> Java Renderer dispatchCommand react-native/packages/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js Line 27633 in 8ff05b5
UIManager.cpp dispatchCommand react-native/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp Line 597 in 8ff05b5
and it is received from the Java ViewManager updateState or updateExtraData Lines 363 to 366 in 8ff05b5
Lines 252 to 263 in 8ff05b5
The implementation in ReactTextInputManager.java of updateState Line 1357 in 8ff05b5
The complete implementation is available at https://github.com/facebook/react-native/pull/33468/files. I did not work for a long time on this and some of the info may be not correct. NEXT STEPS:
|
Helllo Fabrizio, could I ask you what your role is on the React Native project and whether your comments are related to my PR? Thank you. |
Regarding this PR, I'm currently pivoting, and I'll likely close it. |
#42701 (comment) #42701 (comment) |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
1 similar comment
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This PR was closed because it has been stalled for 7 days with no activity. |
Summary:
Refactor
TextFragmentList
intoAttributedString
, preparing it to support another layer over fragments.This is a part of my work on #42602.
Changelog:
[INTERNAL] [CHANGED] - Refactor
TextFragmentList
intoAttributedString
Test Plan: