-
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
Add a Span
layer to AttributedString
#41283
Conversation
@NickGerleman @cortinico @mdvacca We can now start the fun part of the project. This is a draft, but it's enough to start talking about the high-level direction we're going. I haven't actually touched the JavaScript layer yet. Read just the top commit. I'm suggesting a model where the new features (fill-line-gap, inline borders, ...) are supported in the following scheme: Let's call the Let's call the new properties like <Text style={{ color: 'red', fontSize: 20, fillLineGap: true }}>
<Text style={{ color: 'blue', fontSize: 18, fillLineGap: true }}>
Level 2
<Text style={{ color: 'green', fontSize: 16 }}>
Level 3
<Text style={{ color: 'orange', fontSize: 14 }}>
Level 4
</Text>
</Text>
</Text>
<Text style={{ color: 'blue', fontSize: 12, fillLineGap: false }}>
Level 2 (line gap not filled!)
<Text style={{ color: 'green', fontSize: 16, fillLineGap: true }}>
Level 3 (fillLineGap ignored!)
<Text style={{ color: 'orange', fontSize: 14 }}>
Level 4
</Text>
</Text>
</Text>
</Text> For the root node, I suggest:
For the span nodes, I suggest:
For the inner nodes, I suggest:
I suggest ignoring span properties for This is the least invasive model I could think of. It's not the only possible one. We could think of a new hierarchy of components like <SpannedText color="red" fontSize={20}>
Level 1
<TextSpan color="blue" fontSize={18}>
Level 2
<Text color="green" fontSize={16}>
Level 3
<Text color="orange" fontSize={14}>
Level 4
</Text>
</Text>
</TextSpan>
</SpannedText> Of course, I'm not saying to drop backward compatibility with the "old-style" nesting, just to require the new style when someone wants fancy borders and such. Pros:
Cons:
Please share your thought! |
@NickGerleman @mdvacca I would be extremely grateful for quick thoughts on the API sketch above |
The more I think about the second approach ( Damn, we could even extract a separate kind of component for this purpose, I know these are pretty drastic changes, but if a new API was to be added, we could at least ensure it's designed properly. Let me know if it is realistic in any way to add a new core component family like this. It would be great to hear at least a few words from you about these ideas, as implementing them just to hear "absolutely no way" after things are done would be an enormous waste of time on my side. |
@cortinico Would you find some time to quickly look at this draft PR and say if it's going in the right direction? It's a sketch of an implementation of this idea |
It's a 2K LOC change, sadly not the easiest thing to review :/ |
It's built on top of the other PR. Would you just peek at the top commit in the single commit view? |
Actually, I'm not using the base commits yet, I can force-push this with only the top commit |
c89913e
to
9b35462
Compare
@cortinico Done. This is a single commit which aims to build the |
Essentially, this is a new model, where a rich text is not annotated with a sequence of adjacent ranges (the fragments), as it was before, but with a sequence of spans (containers), which hold a sequence of adjacent ranges (the fragments). These spans will be holding the styles of different nature; i.e. those that span around the text (like borders), instead of just providing cascading per-character styles. There are consequences. I suggest not supporting spans-within-spans initially. It's an open question how |
Base commit: a3f238a |
I'm closing this, as too much code changed in the meantime. Right now, I'm in the process of submitting smaller PRs. Eventually we'll get back to this subject. |
Summary:
Add a
Span
layer toAttributedString
Changelog:
[INTERNAL] [CHANGED] - TODO
Test Plan:
TODO