-
Notifications
You must be signed in to change notification settings - Fork 543
Text rendering improvements #107
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
scorsin-oai
wants to merge
21
commits into
Snapchat:main
Choose a base branch
from
scorsin-oai:simon/260621-text_rendering_improvements
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 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3704022
compilation fix
scorsin-oai 663d6e5
Fix baseline module tests
scorsin-oai 4bf13aa
Backport core text styling and layout support
scorsin-oai e7cf9ee
Backport SnapDrawing TextView and TextField layers
scorsin-oai f5ec57d
Backport custom text underline styles
scorsin-oai 4cf64f8
Backport TextView rendering parity
scorsin-oai b8a0697
Backport text selection support
scorsin-oai 1edbfb4
Backport text animation support
scorsin-oai ce52adf
Backport inline text children support
scorsin-oai 57d2eb4
Backport inline text child animations
scorsin-oai 11da885
Backport persistent text animations
scorsin-oai e93d7f2
Backport stale composite text fallback pruning
scorsin-oai 42ea6d9
Backport web text rendering parity
scorsin-oai 0b2ddf7
Remove web text rendering parity
scorsin-oai f09709a
Added some required changes
scorsin-oai 3df308a
Cleanups
scorsin-oai ea538f2
Merge branch 'main' into simon/260621-text_rendering_improvements
clholgat 0532196
Restore lineHeight ratio semantics
scorsin-oai 6cc34c2
Merge branch 'simon/260621-text_rendering_improvements' of github-pub…
scorsin-oai 881d0bc
Merge main into simon/260621-text_rendering_improvements
scorsin-oai fd7a17f
address comments
scorsin-oai 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
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,24 @@ | ||
| load("//bzl/valdi:valdi_application.bzl", "valdi_application") | ||
| load("//bzl/valdi:valdi_module.bzl", "valdi_module") | ||
|
|
||
| valdi_module( | ||
| name = "inline_text_children_example", | ||
| srcs = glob([ | ||
| "**/*.ts", | ||
| "**/*.tsx", | ||
| ]), | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//src/valdi_modules/src/valdi/valdi_core", | ||
| "//src/valdi_modules/src/valdi/valdi_tsx", | ||
| ], | ||
| ) | ||
|
|
||
| valdi_application( | ||
| name = "inline_text_children_example_app", | ||
| ios_bundle_id = "com.snap.valdi.inlinetextchildren", | ||
| root_component_path = "App@inline_text_children_example/InlineTextChildrenExample", | ||
| title = "Inline Text Children", | ||
| version = "1.0.0", | ||
| deps = [":inline_text_children_example"], | ||
| ) |
273 changes: 273 additions & 0 deletions
273
apps/inline_text_children_example/InlineTextChildrenExample.tsx
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,273 @@ | ||
| import { Component, StatefulComponent } from 'valdi_core/src/Component'; | ||
| import { Device } from 'valdi_core/src/Device'; | ||
| import { Style } from 'valdi_core/src/Style'; | ||
| import { systemBoldFont, systemFont } from 'valdi_core/src/SystemFont'; | ||
| import { AttributedTextBuilder } from 'valdi_core/src/utils/AttributedTextBuilder'; | ||
| import { AttributedTextInlineViewVerticalAlignment } from 'valdi_tsx/src/AttributedTextInlineViewAttachment'; | ||
| import { View } from 'valdi_tsx/src/NativeTemplateElements'; | ||
|
|
||
| const alignmentText = new AttributedTextBuilder() | ||
| .append('Top ') | ||
| .appendInlineView(0, AttributedTextInlineViewVerticalAlignment.Top) | ||
| .append(' Center ') | ||
| .appendInlineView(1, AttributedTextInlineViewVerticalAlignment.Center) | ||
| .append(' Bottom ') | ||
| .appendInlineView(2, AttributedTextInlineViewVerticalAlignment.Bottom) | ||
| .append(' Baseline ') | ||
| .appendInlineView(3, AttributedTextInlineViewVerticalAlignment.Baseline) | ||
| .append(' inside one wrapped text run.') | ||
| .build(); | ||
|
|
||
| const labelInteractiveText = new AttributedTextBuilder() | ||
| .append('A label can host a stateful inline child: ') | ||
| .appendInlineView(0, AttributedTextInlineViewVerticalAlignment.Center) | ||
| .append(' and the surrounding text is not rebuilt when it changes size.') | ||
| .build(); | ||
|
|
||
| const textViewInteractiveText = new AttributedTextBuilder() | ||
| .append('The same stateful child works in a textview: ') | ||
| .appendInlineView(0, AttributedTextInlineViewVerticalAlignment.Center) | ||
| .append(' so text layout can place a resized view again.') | ||
| .build(); | ||
|
|
||
| const ltrEndInlineText = new AttributedTextBuilder() | ||
| .append('Text before ') | ||
| .appendInlineView(0, AttributedTextInlineViewVerticalAlignment.Center) | ||
| .build(); | ||
|
|
||
| const rtlEndInlineText = new AttributedTextBuilder() | ||
| .append('אבג ') | ||
| .appendInlineView(0, AttributedTextInlineViewVerticalAlignment.Center) | ||
| .build(); | ||
|
|
||
| /** | ||
| * @ViewModel | ||
| * @ExportModel | ||
| */ | ||
| export interface ViewModel {} | ||
|
|
||
| interface MarkerViewModel { | ||
| title: string; | ||
| color: string; | ||
| height: number; | ||
| width: number; | ||
| } | ||
|
|
||
| class AlignmentMarker extends Component<MarkerViewModel> { | ||
| onRender(): void { | ||
| <view | ||
| alignItems="center" | ||
| backgroundColor={this.viewModel.color} | ||
| borderRadius={5} | ||
| height={this.viewModel.height} | ||
| justifyContent="center" | ||
| width={this.viewModel.width} | ||
| > | ||
| <label color="#FFFFFF" font={systemBoldFont(9)} textAlign="center" value={this.viewModel.title} width="100%" /> | ||
| </view>; | ||
| } | ||
| } | ||
|
|
||
| interface ExpandableInlineButtonViewModel { | ||
| compactTitle: string; | ||
| expandedTitle: string; | ||
| } | ||
|
|
||
| interface ExpandableInlineButtonState { | ||
| expanded: boolean; | ||
| } | ||
|
|
||
| class ExpandableInlineButton extends StatefulComponent<ExpandableInlineButtonViewModel, ExpandableInlineButtonState> { | ||
| state: ExpandableInlineButtonState = { | ||
| expanded: false, | ||
| }; | ||
|
|
||
| onRender(): void { | ||
| const expanded = this.state.expanded; | ||
| <view | ||
| accessibilityCategory="button" | ||
| alignItems="center" | ||
| backgroundColor={expanded ? '#0F766E' : '#2563EB'} | ||
| border="1 solid #0F172A" | ||
| borderRadius={7} | ||
| height={26} | ||
| justifyContent="center" | ||
| onTap={this.toggle} | ||
| paddingLeft={expanded ? 12 : 8} | ||
| paddingRight={expanded ? 12 : 8} | ||
| width={expanded ? 156 : 82} | ||
| > | ||
| <label | ||
| color="#FFFFFF" | ||
| font={systemBoldFont(expanded ? 13 : 12)} | ||
| textAlign="center" | ||
| value={expanded ? this.viewModel.expandedTitle : this.viewModel.compactTitle} | ||
| width="100%" | ||
| /> | ||
| </view>; | ||
| } | ||
|
|
||
| private toggle = () => { | ||
| this.setState({ expanded: !this.state.expanded }); | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * @Component | ||
| * @ExportModel | ||
| */ | ||
| export class App extends Component<ViewModel> { | ||
| onRender(): void { | ||
| <view backgroundColor="#F8FAFC" height="100%" width="100%"> | ||
| <scroll height="100%" width="100%"> | ||
| <view padding={22} paddingTop={22 + Device.getDisplayTopInset()} width="100%"> | ||
| <label color="#0F172A" font={systemBoldFont(27)} marginBottom={8} value="Inline Text Children" width="100%" /> | ||
| <label | ||
| color="#475569" | ||
| font={systemFont(15)} | ||
| lineHeight={1.25} | ||
| marginBottom={18} | ||
| numberOfLines={0} | ||
| value="Labels and textviews can embed real Valdi child views. Yoga resolves child size; native text layout places each child inline." | ||
| width="100%" | ||
| /> | ||
|
|
||
| <view style={styles.card} marginBottom={14}> | ||
| <label color="#334155" font={systemBoldFont(14)} marginBottom={10} value="Label alignment" width="100%" /> | ||
| <label | ||
| color="#0F172A" | ||
| font={systemFont(20)} | ||
| lineHeight={1.45} | ||
| numberOfLines={0} | ||
| value={alignmentText} | ||
| width="100%" | ||
| > | ||
| <AlignmentMarker color="#DC2626" height={12} title="TOP" width={48} /> | ||
| <AlignmentMarker color="#7C3AED" height={12} title="MID" width={48} /> | ||
| <AlignmentMarker color="#047857" height={12} title="BOT" width={48} /> | ||
| <AlignmentMarker color="#0F766E" height={12} title="BASE" width={48} /> | ||
| </label> | ||
| </view> | ||
|
|
||
| <view style={styles.card} marginBottom={14}> | ||
| <label color="#334155" font={systemBoldFont(14)} marginBottom={10} value="Textview alignment" width="100%" /> | ||
| <textview | ||
| backgroundColor="#FFFFFF" | ||
| color="#0F172A" | ||
| enabled={false} | ||
| font={systemFont(19)} | ||
| height={104} | ||
| lineHeight={1.45} | ||
| numberOfLines={0} | ||
| value={alignmentText} | ||
| width="100%" | ||
| > | ||
| <AlignmentMarker color="#EA580C" height={18} title="TOP" width={48} /> | ||
| <AlignmentMarker color="#2563EB" height={18} title="MID" width={48} /> | ||
| <AlignmentMarker color="#16A34A" height={18} title="BOT" width={48} /> | ||
| <AlignmentMarker color="#0F766E" height={18} title="BASE" width={48} /> | ||
| </textview> | ||
| </view> | ||
|
|
||
| <view style={styles.card} marginBottom={14}> | ||
| <label color="#334155" font={systemBoldFont(14)} marginBottom={10} value="Label LTR vs RTL append position" width="100%" /> | ||
| <label | ||
| color="#64748B" | ||
| font={systemFont(13)} | ||
| lineHeight={1.25} | ||
| marginBottom={10} | ||
| numberOfLines={0} | ||
| value="Both labels append the inline child after the text. The END pill should sit on the right in LTR and on the left in RTL." | ||
| width="100%" | ||
| /> | ||
| <view alignItems="center" flexDirection="row" marginBottom={8} width="100%"> | ||
| <label color="#475569" font={systemBoldFont(12)} marginRight={10} textAlign="center" value="LTR" width={34} /> | ||
| <view | ||
| backgroundColor="#F8FAFC" | ||
| border="1 solid #CBD5E1" | ||
| borderRadius={7} | ||
| direction="ltr" | ||
| flexGrow={1} | ||
| padding={10} | ||
| > | ||
| <label | ||
| color="#0F172A" | ||
| font={systemFont(19)} | ||
| lineHeight={1.45} | ||
| numberOfLines={0} | ||
| value={ltrEndInlineText} | ||
| width="100%" | ||
| > | ||
| <AlignmentMarker color="#2563EB" height={18} title="END" width={48} /> | ||
| </label> | ||
| </view> | ||
| </view> | ||
| <view alignItems="center" flexDirection="row" width="100%"> | ||
| <label color="#475569" font={systemBoldFont(12)} marginRight={10} textAlign="center" value="RTL" width={34} /> | ||
| <view | ||
| backgroundColor="#F8FAFC" | ||
| border="1 solid #CBD5E1" | ||
| borderRadius={7} | ||
| direction="rtl" | ||
| flexGrow={1} | ||
| padding={10} | ||
| > | ||
| <label | ||
| color="#0F172A" | ||
| font={systemFont(19)} | ||
| lineHeight={1.45} | ||
| numberOfLines={0} | ||
| value={rtlEndInlineText} | ||
| width="100%" | ||
| > | ||
| <AlignmentMarker color="#7C3AED" height={18} title="END" width={48} /> | ||
| </label> | ||
| </view> | ||
| </view> | ||
| </view> | ||
|
|
||
| <view style={styles.card} marginBottom={14}> | ||
| <label color="#334155" font={systemBoldFont(14)} marginBottom={10} value="Stateful child in a label" width="100%" /> | ||
| <label | ||
| color="#0F172A" | ||
| font={systemFont(19)} | ||
| lineHeight={1.45} | ||
| numberOfLines={0} | ||
| value={labelInteractiveText} | ||
| width="100%" | ||
| > | ||
| <ExpandableInlineButton compactTitle="Expand" expandedTitle="Contract inline" /> | ||
| </label> | ||
| </view> | ||
|
|
||
| <view style={styles.card}> | ||
| <label color="#334155" font={systemBoldFont(14)} marginBottom={10} value="Stateful child in a textview" width="100%" /> | ||
| <textview | ||
| backgroundColor="#FFFFFF" | ||
| color="#0F172A" | ||
| enabled={false} | ||
| font={systemFont(19)} | ||
| height={124} | ||
| lineHeight={1.45} | ||
| numberOfLines={0} | ||
| value={textViewInteractiveText} | ||
| width="100%" | ||
| > | ||
| <ExpandableInlineButton compactTitle="Open" expandedTitle="Close inline view" /> | ||
| </textview> | ||
| </view> | ||
| </view> | ||
| </scroll> | ||
| </view>; | ||
| } | ||
| } | ||
|
|
||
| const styles = { | ||
| card: new Style<View>({ | ||
| backgroundColor: '#FFFFFF', | ||
| border: '1 solid #CBD5E1', | ||
| borderRadius: 8, | ||
| padding: 14, | ||
| width: '100%', | ||
| }), | ||
| }; |
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,22 @@ | ||
| load("//bzl/valdi:valdi_application.bzl", "valdi_application") | ||
| load("//bzl/valdi:valdi_module.bzl", "valdi_module") | ||
|
|
||
| valdi_module( | ||
| name = "text_animation_group_example", | ||
| srcs = glob([ | ||
| "**/*.ts", | ||
| "**/*.tsx", | ||
| ]), | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//src/valdi_modules/src/valdi/valdi_core", | ||
| "//src/valdi_modules/src/valdi/valdi_tsx", | ||
| ], | ||
| ) | ||
|
|
||
| valdi_application( | ||
| name = "text_animation_group_example_app", | ||
| root_component_path = "App@text_animation_group_example/TextAnimationGroupExample", | ||
| title = "Text Animation Group", | ||
| deps = [":text_animation_group_example"], | ||
| ) |
Oops, something went wrong.
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.
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.
These new flags are a bit too broad, can you make them more specific?