Repository navigation
Conversation
…ications it posts today Summary: This adds `RCTTextLayoutManagerTests`, four iOS tests for `RCTTextLayoutManager`. It changes no production code. Two of the tests assert a defect that exists today, so they pass on the current code. The change that follows this one fixes the defect, renames these two tests, and inverts their assertions. The other two tests compare what `RCTTextLayoutManager` lays out and draws with a TextKit stack that the test builds on a plain `NSTextStorage`. The fix has to keep those two comparisons passing. **The defect** `RCTTextLayoutManager` creates an `NSTextStorage` for each layout call, on the JavaScript thread. `NSTextStorage` posts two notifications to the default notification center for every edit, including the one that gives it its text. If an observer was added for them with `addObserverForName:object:queue:usingBlock:` and the main queue, the thread that posts waits until the main thread has run the observer's block. UIKit adds such an observer for a search field, and that observer receives the notifications of every text storage in the process. The main thread blocks on the JavaScript thread when it flushes an event synchronously, for example an `experimental_onSafeAreaInsetsChange` event that a view emits from `layoutSubviews`. When a measurement and a synchronous flush overlap in an app that has such an observer, each thread waits for the other, and the app stops drawing and no longer answers touches. This was seen in a debug build. **The tests** - `testMeasuringPostsTextStorageNotifications` and `testMeasuringOffTheMainThreadWaitsForAMainQueueObserver` measure a plain text, a text with a line height, and a text that is shrunk to fit one line. The first asserts that the measurements post text storage notifications. The second adds a main-queue observer and measures on a background queue while the main thread is blocked for one second. It asserts that the measurements finish only after the main queue has run the observer. - `testLinesMatchAPlainTextStorage` and `testDrawingMatchesAPlainTextStorage` use ten texts (one word, a sentence that wraps, mixed font sizes, emoji, CJK, Arabic, Thai and Devanagari, explicit newlines, a line height, and a named font family) and three paragraph settings (no line limit, two lines with a truncated tail, and one line with `adjustsFontSizeToFit`). The first compares the text, rectangle, and baseline of every line at three widths. The second compares the drawn pixels. Changelog: [Internal] Differential Revision: D133310818
|
@ejc3 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D133310818. |
Visual regressionNo visual differences at android: no capture |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
This adds
RCTTextLayoutManagerTests, four iOS tests forRCTTextLayoutManager. It changes no production code.Two of the tests assert a defect that exists today, so they pass on the current code. The change that follows this one fixes the defect, renames these two tests, and inverts their assertions. The other two tests compare what
RCTTextLayoutManagerlays out and draws with a TextKit stack that the test builds on a plainNSTextStorage. The fix has to keep those two comparisons passing.The defect
RCTTextLayoutManagercreates anNSTextStoragefor each layout call, on the JavaScript thread.NSTextStorageposts two notifications to the default notification center for every edit, including the one that gives it its text. If an observer was added for them withaddObserverForName:object:queue:usingBlock:and the main queue, the thread that posts waits until the main thread has run the observer's block. UIKit adds such an observer for a search field, and that observer receives the notifications of every text storage in the process.The main thread blocks on the JavaScript thread when it flushes an event synchronously, for example an
experimental_onSafeAreaInsetsChangeevent that a view emits fromlayoutSubviews. When a measurement and a synchronous flush overlap in an app that has such an observer, each thread waits for the other, and the app stops drawing and no longer answers touches. This was seen in a debug build.The tests
testMeasuringPostsTextStorageNotificationsandtestMeasuringOffTheMainThreadWaitsForAMainQueueObservermeasure a plain text, a text with a line height, and a text that is shrunk to fit one line. The first asserts that the measurements post text storage notifications. The second adds a main-queue observer and measures on a background queue while the main thread is blocked for one second. It asserts that the measurements finish only after the main queue has run the observer.testLinesMatchAPlainTextStorageandtestDrawingMatchesAPlainTextStorageuse ten texts (one word, a sentence that wraps, mixed font sizes, emoji, CJK, Arabic, Thai and Devanagari, explicit newlines, a line height, and a named font family) and three paragraph settings (no line limit, two lines with a truncated tail, and one line withadjustsFontSizeToFit). The first compares the text, rectangle, and baseline of every line at three widths. The second compares the drawn pixels.Changelog: [Internal]
Differential Revision: D133310818