Repository navigation
Conversation
TextStyle baked the scaled point size into the returned Font via UIFontMetrics.scaledValue(for:), which reads UITraitCollection.current at call time. SwiftUI therefore saw a fixed-size font with no dependency on \.dynamicTypeSize and never invalidated the view when the user changed their text size - the new size only appeared once the body happened to be re-evaluated for some other reason. Resolve font, uiFont, lineSpacing and kerning against an explicit DynamicTypeSize, and turn textStyle(_:) into a ViewModifier that reads it from the environment. The existing computed properties keep their signature and behaviour by resolving against the current trait collection.
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.
TextStylebakes the scaled point size into theFontit returns, so text styled with.textStyle(_:)does not resize when the user changes their text size. It catches up only the next time the view's body is re-evaluated for some other reason — on a static screen, possibly never.UIFontMetrics.scaledValue(for:)readsUITraitCollection.currentat call time and returns a plain number, so theFontis fixed-size and SwiftUI records no dependency on\.dynamicTypeSize. Same forlineSpacingandkerning..customfont types are unaffected —Font.customis resolved by SwiftUI at render time.Change
font,uiFont,lineSpacingandkerninggain…(for: DynamicTypeSize?)counterparts.nilresolves against the current trait collection, which is what the existing computed properties now call, so their behaviour is unchanged.textStyle(_:)becomes aViewModifierthat reads\.dynamicTypeSizeand passes it in.textStyleText(_:dynamicTypeSize:), sinceTextcannot read the environment and had no way to react at all.For adopters
.dynamicTypeSize(…)clamps now actually apply toTextStyle, so screens that clamp will change appearance.