TextureGroup / Texture

Smooth asynchronous user interfaces for iOS apps.
https://texturegroup.org/
Other
8.02k stars 1.29k forks source link

In iOS 13, using Apple .systemFont will use the incorrect font if a paragraph style is set. #1701

Open Sethmr opened 5 years ago

Sethmr commented 5 years ago

After using the XCode 11 compiler, the .systemFont started having incorrect cases of font app wide for us. After looking deeper into the problem, I found that every time you use the .paragraphStyle in any way shape or form (even with an empty initializer) on your NSAttributedString it will cause Times New Roman to be displayed instead of SF Fonts.

My team uses this extensively in our app and would highly appreciate a fix. I will attempt to find a work around in the mean time that is acceptable. Thanks for a great framework to build upon :).

Example below:


import AsyncDisplayKit

class ViewController: ASViewController<ASDisplayNode> {

    init() {
        super.init(node: ASDisplayNode())
        node.layoutSpecBlock = { [unowned self] _, _ in
            return ASStackLayoutSpec(
                direction: .vertical,
                spacing: 20,
                justifyContent: .center,
                alignItems: .center,
                children: [self.sfTextNode, self.timesNewRomanTextNode]
            )
        }
        node.automaticallyManagesSubnodes = true
        modalPresentationStyle = .fullScreen
        node.backgroundColor = .white
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    lazy var sfTextNode: ASTextNode = {
        let textNode = ASTextNode()
        textNode.attributedText = NSAttributedString(
            string: "Example Text",
            attributes: [.font: UIFont.systemFont(ofSize: 20)]
        )
        return textNode
    }()

    lazy var timesNewRomanTextNode: ASTextNode = {
        let textNode = ASTextNode()
        textNode.attributedText = NSAttributedString(
            string: "Example Text",
            attributes: [.font: UIFont.systemFont(ofSize: 20), .paragraphStyle: NSParagraphStyle()]
        )
        return textNode
    }()

}

Simulator Screen Shot - iPhone 11 Pro Max - 2019-10-07 at 09 48 47

atkalikov commented 5 years ago

You can use ASTextNode2 instead of ASTextNode. But in my case it didn’t help me completely. The second version of ASTextNode sometimes behave itself completely different compared to the first version.

bolsinga commented 5 years ago

Is this #1579 ?

Sethmr commented 5 years ago

@atkalikov I would be willing to try this, but I literally have hundreds of cases I am working with here. Is there any documentation on the differences between ASTextNode2 and ASTextNode?

Sethmr commented 5 years ago

Also, I don't know if this is any help, but .SF UI Text and .SF UI Display are no longer found in UIFont.familyNames or UIFont.fontNames(forFamilyName: anyFamily). I think this has something to do with the SF Symbols in iOS 13.

dirtmelon commented 5 years ago

I had test in #1579 , it fixes this issue. @bolsinga @Sethmr

bolsinga commented 5 years ago

@dirtmelon Would you be able to create a PR that has a test for this? It would be terrific to back fill these tests. Thanks. @Sethmr Please try with master.

Sethmr commented 5 years ago

@bolsinga I will attempt tomorrow.

ay8s commented 5 years ago

Ran into this myself yesterday. Couldn't get it working with latest from master either. Font displayed fine without paragraph style.

Wonder if you found the same @Sethmr?

Sethmr commented 5 years ago

@ay8s If you look at my post, that is directly what it is saying ;)

@bolsinga It is working great in master. I'll be looking forward to the next release. I came up with a patch job that mostly is working in the mean time.

ay8s commented 5 years ago

Sorry, I meant in your attempt today. Will have to dig into why it wasn't working for me with master.

nikmun commented 5 years ago

I am facing the same issue. When will you guys release the new version with the fix of this issue?

manzick commented 4 years ago

Hello. Today is December 4th. Can you release at least a little hotfix for this problem?

0xTomTom commented 4 years ago

Would love a fix. Nevertheless, great project guys! Texture makes creating iOS projects a lot of fun.