Skip to content

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

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
CainLuo opened this issue Jun 19, 2021 · 5 comments
Open

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

CainLuo opened this issue Jun 19, 2021 · 5 comments

Comments

@CainLuo
Copy link

CainLuo commented Jun 19, 2021

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
Copy link
Author

CainLuo commented Jun 20, 2021

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.

CainLuo pushed a commit to CainLuo/Texture that referenced this issue Jun 20, 2021
[bug] ASCellNode has no background color in iOS 13
@denkeni
Copy link

denkeni commented Jul 9, 2021

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
Copy link
Author

CainLuo commented Jul 13, 2021

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
Copy link

denkeni commented Jul 13, 2021

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
Copy link

realLam commented Apr 26, 2024

最近也发现了这个问题,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
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants