TextureGroup / Texture

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

[bug] ASCellNode has no background color in iOS 13 #2009

Open CainLuo opened 3 years ago

CainLuo commented 3 years ago

ASCellNode has no background color in iOS 13 version, but it is normal in iOS 12 or iOS 14, how can I fix it? @garrettmoon

class AboutCell: ASCellNode {
    private let titleNode = ASTextNode()
    private let lineNode = ASImageNode()

    init(_ model: AboutModel) {
        super.init()
        automaticallyManagesSubnodes = true
        accessoryType = .disclosureIndicator
        lineNode.isHidden = model.type == .privacy
        lineNode.style.flexGrow = 1.0
        lineNode.backgroundColor = UIColor(0xE9E9E9)
        titleNode.attributedText = NSAttributedString.attributed(model.title ?? "")
    }

    override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
        LayoutSpec {
            VStackLayout {
                CenterLayout(centeringOptions: .Y) {
                    InsetLayout(insets: .zero) {
                        titleNode
                    }
                }
                .minHeight(frame.maxY - 1)
                lineNode
            }
            .padding(UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15))
        }
    }
}

iOS 13

image

iOS 14

image
CainLuo commented 3 years ago

Regarding the above issue, I found the specific problem, in the - (void)setElement:(ASCollectionElement *)element method of the ASTableView.mm file, the backgroundColor of node is used to set the _ ASTableViewCell's backgroundColor, I think this is incorrect, because node's backgroundColor should not be used to set as _ASTableViewCell's backgroundColor, but to open a separate property value of color to set separately. The temporary solution is to comment out self.backgroundColor = node.backgroundColor; and hope that it can be solved in subsequent versions of Texture.

denkeni commented 3 years ago

It is actually a new behavior introduced since iOS 14 UIKit. When cell.backgroundColor is not set, it puts _UISystemBackgroundView to make your backgroundColor white, rather than transparent as before. Not really related to Texture here.

In this case, I suggest just specifying cellNode.backgroundColor to whatever you'd like.

CainLuo commented 3 years ago

It's not, it's also normal in iOS 12, only iOS 13 has problems, you can download an iOS 13 emulator to check it. @denkeni

denkeni commented 3 years ago

Would you mind providing a sample project to replicate the issue? I’ve created a sample project based on my understanding of this issue, which happens on iOS 14 or later:

Texture_issue_2009

realLam commented 7 months ago

最近也发现了这个问题,TableViewCell背景颜色默认是白色,无论我怎么设置Node的颜色,结果都一样是白色。解决问题的过程中也试过改源码,虽然能解决问题,但是如果改源码,每次pod install 后都要重新修改。最后通过下面的代码解决。

func tableNode(_ tableNode: ASTableNode, willDisplayRowWith node: ASCellNode) {
        /** 遍历superView,找到UITableViewCell,设置背景色为clear。
         解决iOS 14后系统默认 UITableViewCell 背景为白色的问题 */
        var view: UIView = node.view // 假设这是你要开始遍历的视图
        while let superview = view.superview {
            view = superview
            if let tmp = view.superview, let cell = tmp as? UITableViewCell {
                cell.backgroundColor = .clear
                break
            } else {
                break
            }
        }
    }