-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
prototype(FastText): Add option to use TextBlock for simple text #1256
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1256 +/- ##
==========================================
- Coverage 31.84% 31.79% -0.05%
==========================================
Files 258 259 +1
Lines 18674 18703 +29
Branches 1580 1584 +4
==========================================
Hits 5947 5947
- Misses 12574 12603 +29
Partials 153 153
Continue to review full report at Codecov.
|
return frameworkElement.Parent; | ||
} | ||
#if !WINDOWS_UWP | ||
|
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.
maybe rename these two variables to just "element" with #if UWP for the different casts, and then deduplicate the if+return?
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.
I think you're reading it wrong, we had to add the extra check for WPF because there is a difference between RichTextBlock and TextBlock in WPF.
In reply to: 132557372 [](ancestors = 132557372)
Libraries/Text/Text.windows.js
Outdated
@@ -263,6 +275,14 @@ const Text = React.createClass({ | |||
if (this.context.isInAParentText) { | |||
return <RCTVirtualText {...newProps} />; | |||
} else { | |||
if (Platform.OS === 'windows' && typeof newProps.children === '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.props.children
can be an array of strings and in many cases this array can contain just one string. If such arrays are concatenated with .join("")
this fix covers 99% of text in S4L.
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 was fixed in S4L.
{ | ||
return frameworkContentElement.Parent; | ||
} | ||
#endif | ||
} |
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.
Deferring non FrameworkElement/FrameworkContentElement to VisualTreeHelper.GetParent seems to make total sense, the helper being smart enough to understand the intricacies of various elements, etc.
Well, nope. The call throws System.Exception(E_UNEXPECTED) if passed a correctly parented/in visual tree InlineUIContainer, for example.
This is Eric Rozell's [PR](microsoft#1256) with a couple fixes to make it work with S4L. This optimization [gives](aka.ms/V3mz2) a 10% speedup and reduces memory usage by 10%. Simple text, i.e., text with only a single raw text node as a child, can be transformed into a TextBlock with a Text property, instead of a RichTextBlock with a Paragraph of Inlines. This change detects in the React Native Text node has a single raw text child, and if so, uses the FastText native component. To test if your text nodes are "fast", set DebugSettings.IsTextPerformanceVisualizationEnabled to true while debugging your app; it changes optimized text color to green. Related work items: #1164947
9566a3b
to
96a49fa
Compare
Libraries/Text/Text.windows.js
Outdated
if (this.context.isInAParentText) { | ||
return <RCTVirtualText {...newProps} />; | ||
} else { | ||
if (Platform.OS === 'windows' && typeof newProps.children === '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.
Platform.OS === 'windows' & [](start = 10, length = 27)
Instead of platform check, use RCTSimpleText
or something else.
/// <summary> | ||
/// The shadow node implementation for text views. | ||
/// </summary> | ||
public class ReactSimpleTextShadowNode : LayoutShadowNode |
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.
ReactSimpleTextShadowNode [](start = 17, length = 25)
Revert file name to maintain diff.
@@ -172,6 +172,7 @@ | |||
<Compile Include="Views\Scroll\ScrollView.cs" /> | |||
<Compile Include="Views\Slider\ReactSliderManager.cs" /> | |||
<Compile Include="Views\TextInput\PlaceholderAdorner.cs" /> | |||
<Compile Include="Views\Text\ReactSimpleTextViewManager.cs" /> | |||
<Compile Include="Views\Text\ReactTextCompoundView.cs" /> |
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.
@rozele Where's the shadow node?
[edit]: Oh, it's a dummy implementation for WPF?
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.
if (this.context.isInAParentText) { | ||
return <RCTVirtualText {...newProps} />; | ||
} else { | ||
if (RCTSimpleText && typeof newProps.children === '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 can be an array of strings.
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.
@reseul - not sure if we are supposed to handle the array of strings. I don't know what the concatenation handling should be, whether we just inject a space, newline, etc. Also, I imagine this can vary based on culture/i18n. I'd like to keep this as a single space for now and force the client to specifically concatenate string arrays if they want text perf optimization.
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.
@rozele it's ok. We've been using this fast text for some months, but I'm not sure whether we have that case. If we do. we're going to reconcile on our end.
/// <returns>The view instance.</returns> | ||
protected override TextBlock CreateViewInstance(ThemedReactContext reactContext) | ||
{ | ||
var richTextBlock = new TextBlock |
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 text block is not exactly rich.
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.
I'll change to var poorTextBlock
:)
Simple text, i.e., text with only a single raw text node as a child, can be transformed into a `TextBlock` with a `Text` property, instead of a `RichTextBlock` with a `Paragraph` of `Inlines`. This change detects in the React Native Text node has a single raw text child, and if so, uses the FastText native component. To test if your text nodes are "fast", set `DebugSettings.IsTextPerformanceVisualizationEnabled` to true while debugging your app; it changes optimized text color to green. Fixes microsoft#1252
Also taking the latest from Text.js in [email protected].*
…simple text (microsoft#1256)" (microsoft#1939)" This reverts commit adb4539. Updated for the latest Text.js implementation
Simple text, i.e., text with only a single raw text node as a child, can be transformed into a
TextBlock
with aText
property, instead of aRichTextBlock
with aParagraph
ofInlines
. This change detects in the React Native Text node has a single raw text child, and if so, uses the FastText native component. To test if your text nodes are "fast", setDebugSettings.IsTextPerformanceVisualizationEnabled
to true while debugging your app; it changes optimized text color to green.Fixes #1252