-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix ASTableNode / ASCollectionNode backgroundColor does not apply correctly. #1537
Fix ASTableNode / ASCollectionNode backgroundColor does not apply correctly. #1537
Conversation
@maicki interesting. So, there is actually a similar workaround for frame. UITableView frame does not work properly if it is set only on the layer, unlike almost all other UIViews. I think the right fix here is actually to change the property bridge, and always use -[UIView setBackgroundColor:] for a view-backed node. Otherwise, initWithViewBlock: on certain elements like perhaps a custom table (that a developer doesn't need to be async) will have the same issue. There could also be other UIKit classes that override setBackgroundColor: -- because it is difficult for UIKit to intercept the CALayer calls in the way our architecture allows. Lastly, it would reduce the code change. We would need to change the _ASPendingState to always store a UIColor as regenerating it is too costly. This is fine as the node.backgroundColor is already of this type. It would actually make some drawing operations faster as capturing it as a draw parameter would be quicker that regenerating. For layer-backed we'd call CGColor. If you'd prefer to land this as-is and file a task for the other change, that's totally fine. I'm not certain how complex the diff would be to make, but it may be simple enough to do now. @maicki just let me know and I will merge this now if you suggest. |
If the background color is applied via the pending state it's applied to the layer of the UICollectionView / UITableview. Unfortunately UITableView / UICollectionView does not consider using the layer backgroundColor property as it's background color, so it needs to be applied to the view after the ASCollectionNode / ASTableNode did load and the view is available
…e UIView - Remove duplicated code in ASCollectionNode and ASTableNode - Fix setting the pending state to the view if applying the pending state to the view
@@ -19,6 +19,7 @@ | |||
#import "ASPendingStateController.h" | |||
#import "ASThread.h" | |||
#import "ASTextNode.h" | |||
#import "ASTableNode.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this if possible
Thanks, this is a great fix because it is so generalized! We can make some tweaks in a followup. |
is layerBacked. Summary: UIColor can now be a dynamic color provider to support capabilities like Dark Mode in applications. UIKit is able to re-render views when a user enters dark mode but this dynamic capabilities is not handled at the layer level. Currently this takes the recommendation in facebookarchive/AsyncDisplayKit#1537 (comment) to set background color on the view directly or layer depending on if the node is layer backed. This change allows UIKit to track these colors and update the UI when the UITraitCollection.userInterfaceStyle changes.
* Set background color directly to view or layer depending on if the node is layerBacked. Summary: UIColor can now be a dynamic color provider to support capabilities like Dark Mode in applications. UIKit is able to re-render views when a user enters dark mode but this dynamic capabilities is not handled at the layer level. Currently this takes the recommendation in facebookarchive/AsyncDisplayKit#1537 (comment) to set background color on the view directly or layer depending on if the node is layer backed. This change allows UIKit to track these colors and update the UI when the UITraitCollection.userInterfaceStyle changes. * Updates to UIViewBridge to fix tests * Remove opaque * Test fixes * Revert change to test checker method * Fix strange issue where setting UIView backgroundColor sets the layer to opaque to false * Address Huy comments * Address last comment
) * Improve Accessibility Implementation - Fixes calculations for accessibilityFrame of ASAccessibilityCustomAction and ASAccessibilityElement - Fix crash for accessibility elements within layer backed nodes - Fix accessibility action label updating after other actions change the accessibility label of the corresponding node * Address comments
If the background color is applied via the pending state it's applied to the layer of the UICollectionView / UITableview. Unfortunately UITableView / UICollectionView does not consider using the layer backgroundColor property as it's background color, so it needs to be applied to the view after the ASCollectionNode / ASTableNode did load and the view is available