-
Notifications
You must be signed in to change notification settings - Fork 492
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
RX.FastText for plain text? #347
Comments
Why not call it |
I agree that |
I'm against exposing this additional complexity within ReactXP. I'd also prefer not to expose it in React Native. I think we should try hard to hide this from callers. Can you provide more details about what you mean by "no markup"? Do you mean "no style information"? |
That's correct: "no markup" means plain text, i.e. a |
It would be very unusual for a plain-text element would be swapped for one that has markup or vice versa. In all of the ReactXP code we've written in Skype, I doubt if this case has ever come up. I don't think this justifies exposing additional complexity within RX or RN. We can document the issue with Navigator, and app code can easily avoid this unusual edge case if they care about this focus behavior. |
I think such a case exists: the last message preview in the conversation icon element. If Narrator is focusing on this text element and someone sends another message with styles, If RX exposes neither |
If I understand you correctly, TextBlock is used only for JSX text nodes that have no tags. Let's consider the following example.
This JSX would be translated to into code that constructs two nodes — a TextBlock with a value of "Raw Text" and a RichTextBlock that contains the first node as a child. Do I have that correct? If so, then I don't see the problem because the focus would be on the outer RichTextBlock. |
I think that's correct but I would confirm with @rozele |
I'm not particularly attached to either approach. I'm happy to expose additional props on for Windows that either enables or disables the optimization (i.e., whitelist or blacklist), or exposing a different component altogether. I like the idea of using a prop to disable the optimization because it's trivial to keep your components cross-platform, and platform-specific props are already a pervasive thing in React Native. That being said, it's pretty trivial to implement both, and call the TextBlock component something like I agree with @erictraut that creating different components for text makes end-user development more complex, especially for such a core component. Ideally we just hide the optimization. One approach might be to have a global toggle for whitelist vs. blacklist of the (defaulting to whitelist), so we can write up a performance doc that says "switch the TextOptimization toggle to true (i.e., blacklist mode) and your text rendering performance may improve (with a slight risk for breaking screen reader experiences)." |
If my understanding is correct, there's no need to expose anything or provide an optimization switch of any sort. Other RN implementations already differentiate between "RCTText" and "RCTRawText" nodes. Those are implementation details that are never exposed to RN users. It sounds like this is the same thing. |
I think it should be enough to mention in the docs this behavior and tell to wrap the text into a
|
@rozele What's the difference between <View style={styles.container}>
<Text>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
{'\n'}To get started, edit index.windows.js
</Text>
<Text style={styles.instructions}>
Shake or press Shift+F10 for dev menu
</Text>
</View> turns into
so
@erictraut, regarding your earlier question about With all that in mind, I think the global flag to turn on the optimization, is the best solution if we don't want to modify the |
@antonkh The view container would need to set importantForAccessibility to "yes" to disallow screen readers to get to the real text element which can be replaced dynamically. We can also automagically do this for user even if the view wrapping textblock does not have the importantForAccessibility property set, that is when it has the default "auto" value. But since user will have to manually wrap the textblock anyway I do not think it brings any value at least matching the lost predictability. |
Do we have a clear sense for how much perf this optimization gains in real-world scenarios (as opposed to simple synthetic benchmarks)? If it's not significant, I'd still prefer not to expose any of this complexity. I will need to see a really compelling argument to justify exposing any of this in ReactXP's interface or documentation. |
In S4L the gain is visible: ~1.3x speedup in conversations switching. It's also interesting that it saves a lot of memory: the RichTextBlock version of S4L can easily go up to 1.5 GB, while the TextBlock version hardly gets to 0.5 GB. |
OK, those impacts are too significant to ignore. Sounds like we need to expose this in some manner. Let's try to keep it minimal such that 99.9% of ReactXP usage doesn't need to know about this complexity. It's very rare that a component both 1) dynamically switches between RX.Text with multiple children and a single raw text child and 2) cares about retaining the screen navigator focus across such a switch. We know of one such example in the Skype app, but we'd probably be hard pressed to find a second real-world example. |
I agree that enabling this optimization by default (with a note in the docs to wrap such mutable texts into views) should be fine. @rigdern? |
@antonkh Let's wait until @zholobov finishes his accessibility implementation. Then you can verify your proposed strategy for fixing the accessibility issue caused by the |
Sounds like this won't be needed. Closing for now. We can re-open if it turns out to be required. |
In UWP there are two elements for rendering text: RichTextBlock and TextBlock. The latter is faster, but supports only plain text. Hence there is a proposal to implement this in RNW: microsoft/react-native-windows#1256
The original idea was to choose RichTextBlock or TextBlock on the fly, based on the text content: if text has no markup, RNW creates a TextBlock. However it was pointed out that this will cause problems with Narrator: if a TextBlock is swapped with a RichTextBlock while Narrator had a focus on it, the focus will be lost. This is why it was decided to make this feature opt-in.
We've been discussing two options:
<RX.Text fast=true>abc</RX.Text>
would tell RNW to dynamically switch between RichTextBlock and TextBlock.<RX.FastText value="abc"/>
would render only plain text and would always create a XAML TextBlock.Any thoughts?
The text was updated successfully, but these errors were encountered: