TimelineTableViewCell icon indicating copy to clipboard operation
TimelineTableViewCell copied to clipboard

maxNumSubviews == -1

Open peterkos opened this issue 5 years ago • 4 comments

Not sure how to reproduce this, but for some reason maxNumSubviews ends up being -1, which causes a crash in TimelineTableViewCell on this line:

let views = viewsInStackView.count <= maxNumSubviews ? viewsInStackView : Array(viewsInStackView[0..<maxNumSubviews])

Just curious if anyone else has had this problem? I'm working on a fork on my end, so it may be caused by that. However refactoring this line to be a bit cleaner couldn't hurt

peterkos avatar Feb 01 '20 21:02 peterkos

Yeah, I think it's fork specific, as in the definition

Int(floor(stackView.frame.size.width / (stackView.frame.size.height + stackView.spacing))) - 1

the ratio is evaluated to 0, which is then turned to -1.

Thoughts on submitting a fix?

peterkos avatar Feb 01 '20 21:02 peterkos

@peterkos thank your for reporting this issue. It should be checked whether maxNumSubviews and divisor are valid or not. I will try to fix it when I am available. BTW, I would appreciate it if you can help fix it or provide reproduce test cases.

kf99916 avatar Feb 03 '20 16:02 kf99916

I'm busy through the weekend, so I wont' be able to investigate further until then. But here's my temporary fix:

+ var views = viewsInStackView
+ // Overwrite if too many views
+ if (viewsInStackView.count > maxNumSubviews && maxNumSubviews >= 0) {
+    views = Array(viewsInStackView[0..<maxNumSubviews])
+ }

peterkos avatar Feb 03 '20 18:02 peterkos

Same here

thachonline avatar Aug 16 '20 16:08 thachonline