-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add breaking change page for soft hyphen rendering #13945
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
Open
dbebawy
wants to merge
4
commits into
flutter:main
Choose a base branch
from
dbebawy:hyphens-breaking-change
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fe73a7e
Add breaking change page for soft hyphen rendering
dbebawy 66bb0b3
Clarify soft hyphen page: no hit-testing change, web and editable text
dbebawy 9ad6772
Address review: rendering wording and landed-in version
dbebawy 8efe6b4
Clarify which widgets can't opt out of soft hyphen rendering
dbebawy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
139 changes: 139 additions & 0 deletions
139
sites/docs/src/content/release/breaking-changes/soft-hyphen-rendering.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| --- | ||
| title: Soft hyphens render at line breaks | ||
| description: >- | ||
| Text now shows a hyphen when a line breaks at a soft hyphen (U+00AD), | ||
| and TextStyle.getParagraphStyle has a new hyphens parameter. | ||
| --- | ||
|
|
||
| {% render "docs/breaking-changes.md" %} | ||
|
|
||
| ## Summary | ||
|
|
||
| When a line of text breaks at a soft hyphen (U+00AD), | ||
| Flutter now draws a visible hyphen at the end of the line. | ||
| A new [`Hyphens`][] enum controls this, | ||
| and [`TextStyle.getParagraphStyle`][] has a new `hyphens` parameter. | ||
| Classes that override `getParagraphStyle` must add the parameter. | ||
|
|
||
| ## Background | ||
|
|
||
| A soft hyphen marks a place where a word can be broken across lines. | ||
| Flutter already broke lines at soft hyphens, | ||
| but never drew the hyphen, so broken words looked cut off. | ||
|
|
||
| The new `hyphens` parameter on [`Text`][], [`RichText`][], [`TextPainter`][], | ||
| and `dart:ui`'s [`ParagraphStyle`][] takes a `Hyphens` value: | ||
|
|
||
| * `Hyphens.manual` (the default) draws a hyphen at the break. | ||
| * `Hyphens.hidden` doesn't draw a hyphen. | ||
| The soft hyphen is still a place where the line can break. | ||
|
|
||
| This change affects apps in two ways. | ||
|
|
||
| **Rendering.** Text now shows a hyphen | ||
| wherever a line breaks at a soft hyphen. | ||
| Lines still break in the same places, | ||
| but the hyphen makes its line wider, | ||
| so it can change `Paragraph.longestLine` and the size of text | ||
| laid out with [`TextWidthBasis.longestLine`][]. | ||
| Golden image tests that contain such text might need updating. | ||
|
|
||
| This applies to all platforms except the web, | ||
| where soft hyphens aren't rendered yet. | ||
| Widgets built on `EditableText`, such as `TextField` and `SelectableText`, | ||
| also render the hyphen but don't have a `hyphens` parameter yet, | ||
| so there's no way to opt out for them. | ||
|
|
||
| **API.** `TextStyle.getParagraphStyle` gained an optional `hyphens` parameter. | ||
| Because Dart requires an override to accept every parameter | ||
| of the method it overrides, a class that overrides `getParagraphStyle` | ||
| no longer compiles until it adds the parameter. | ||
| This mostly affects test doubles and proxies of `TextStyle`, | ||
| not typical app code. | ||
|
|
||
| ## Migration guide | ||
|
|
||
| ### Keep the old rendering {: #keep-the-old-rendering } | ||
|
|
||
| To keep soft hyphens invisible, pass `Hyphens.hidden`. | ||
|
|
||
| Code before migration: | ||
|
|
||
| ```dart | ||
| Text('inter\u00ADnational') | ||
| ``` | ||
|
|
||
| Code after migration: | ||
|
|
||
| ```dart | ||
| Text('inter\u00ADnational', hyphens: Hyphens.hidden) | ||
| ``` | ||
|
|
||
| ### Update overrides of `getParagraphStyle` {: #update-overrides } | ||
|
|
||
| If you override `TextStyle.getParagraphStyle`, add the new parameter. | ||
|
|
||
| Code before migration: | ||
|
|
||
| ```dart | ||
| @override | ||
| ui.ParagraphStyle getParagraphStyle({ | ||
| TextAlign? textAlign, | ||
| // ...other parameters... | ||
| StrutStyle? strutStyle, | ||
| }) { | ||
| // ... | ||
| } | ||
| ``` | ||
|
|
||
| Code after migration: | ||
|
|
||
| ```dart | ||
| @override | ||
| ui.ParagraphStyle getParagraphStyle({ | ||
| TextAlign? textAlign, | ||
| // ...other parameters... | ||
| StrutStyle? strutStyle, | ||
| Hyphens? hyphens, | ||
| }) { | ||
| // ... | ||
| } | ||
| ``` | ||
|
|
||
| If your override forwards to another `getParagraphStyle` | ||
| or constructs a `ParagraphStyle`, pass `hyphens` through. | ||
| Otherwise, accepting and ignoring the parameter is enough. | ||
|
|
||
| ## Timeline | ||
|
|
||
| Landed in version: 3.49.0-1.0.pre-294<br> | ||
| In stable release: Not yet | ||
|
|
||
| ## References | ||
|
|
||
| API documentation: | ||
|
|
||
| * [`Hyphens`][] | ||
| * [`ParagraphStyle`][] | ||
| * [`RichText`][] | ||
| * [`Text`][] | ||
| * [`TextPainter`][] | ||
| * [`TextStyle.getParagraphStyle`][] | ||
|
|
||
| Relevant issues: | ||
|
|
||
| * [Support soft hyphenation][issue-18443] | ||
|
|
||
| Relevant PRs: | ||
|
|
||
| * [Support soft hyphen (U+00AD) rendering with a Hyphens API][] | ||
|
|
||
| [`Hyphens`]: {{site.api}}/flutter/dart-ui/Hyphens.html | ||
| [`ParagraphStyle`]: {{site.api}}/flutter/dart-ui/ParagraphStyle-class.html | ||
| [`RichText`]: {{site.api}}/flutter/widgets/RichText-class.html | ||
| [`Text`]: {{site.api}}/flutter/widgets/Text-class.html | ||
| [`TextPainter`]: {{site.api}}/flutter/painting/TextPainter-class.html | ||
| [`TextStyle.getParagraphStyle`]: {{site.api}}/flutter/painting/TextStyle/getParagraphStyle.html | ||
| [`TextWidthBasis.longestLine`]: {{site.api}}/flutter/painting/TextWidthBasis.html | ||
| [issue-18443]: {{site.repo.flutter}}/issues/18443 | ||
| [Support soft hyphen (U+00AD) rendering with a Hyphens API]: {{site.repo.flutter}}/pull/185152 | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.