Skip to content

Strange Behavior with Dynamic Type Updates #402

Open

Description

@nevillco

Hey Zev/Rightpointers! Hope you're doing well. I'm seeing some weird behavior with Dynamic Type and application.enableAdaptiveContentSizeMonitor() I'm wondering if anyone has context on.

I have two StringStyles: one just uses the system body font (UIFont.preferredFont(for: .body)). The other uses a font in the bundle (Lato), and I create a scaled font like this:

let descriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body)
let size = descriptor.pointSize
// swiftlint:disable:next force_unwrapping
return UIFont(name: customFont.name, size: size)!

In the demo video attached, I have 4 labels: applying both .adapt(body) and .adapt(control) to each of these styles. I'm also calling application.enableAdaptiveContentSizeMonitor(), so I'm hoping to see the labels responding to changes to Dynamic Type when I return to the app. Weirdly, what I'm seeing is that all 4 labels do adjust their size somewhat in the right direction (larger or smaller), but I still need to leave and recreate the view to get the correct dynamic size. In the video attached, the labels are initially the correct (small) size, and when I move the Dynamic Type slider to the large end, the labels get bigger, but not as big as expected. Once I leave the view and push to a new view, they're the correct size again. I see the same behavior regardless of whichever 2 points on the Dynamic Type slider I use. Any idea what might be causing this weird behavior?

dynamic-type-bug.mov

Activity

  1. ZevEisenberg commented on Jan 18, 2021

    @ZevEisenberg
    Collaborator

    Weird. Nothing immediately jumps out. Keep in mind that BonMot's dynamic type stuff was created before the more recent UIKit APIs for dynamic type metrics, so in addition to debugging this, it's possible that there's a more modern rethink that we could do.

    In terms of debugging, you can't go wrong subclassing UILabel and observing its font and attributedText properties to see if anything interesting pops up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions