My fuck-around-and-find-out moments
With Texture (formerly AsyncDisplayKit)
- If the shadow inside section controller is being clipped off. Make clipsToBound/layer.maskToBound false for ASCellNode
- If you are facing animation issues with Texture, try to group the concerned nodes in a container node and just animate the container. Don't use setNeedsLayout or layoutIfNeeded for root node (imp)
- If your view's frame is important to you and applying transform in an UIView animation block making it jump, try using CABasicAnimation. One latent benefit is CABasicAnimation runs on a 'proxy' layer so your host view won't get affected.
- Sometimes when we apply gradient background to a node, gradient layer appears on top of content even if it's added to the begining of sublayer hierarchy. One hack to fix this is to set zPosition of gradient layer to
-.greatestFiniteMagnitude
- If you are using ASBackgroundLayoutSpec and the node that is supposed to be in background appears on top of other content you need to manually manage subnodes (
automaticallyManagesSubnodes = false
). Also add backgroundNode Subnode first before adding other subnodes.
With SwiftUI
- If there is a composite view and different layers are not animating in sync, use drawingGroup or geometryGroup . One of the two would surely work. Reference article.
- TabView is weirdly engineered. It doesn't hugs the content. For a dynamic content TabView, use geometry reader first to get the intrinsic height ans then assign it a fixed height. Also, in a peculiar case TabView's content was shifted a bit up. I had to wrap it in a ScrollView (with scroll disabled) to make it work.
safeAreaInset(edge: .top, alignment: .leading)
to place something like a backbutton. Can (haven't tried yet?) also be used to stick a content to bottom- TabView uses UIcollectionView beneath. On SO and multiple other places, it's written that it uses UIPageViewController which is wrong. Also, TabView with page style has the lazy loading capability but is highly constrained. For v simple paged carousels, I found it better that ScrollView + LazyHStack combo (surprise, surprise...)
- (Maybe a well-known fact but still) If you are optimising for performance look out for frame, offset, padding etc updates. These consume CPU cycles and are costly. Consider using equivalent transformations like
scaleTransform
etc as these are performed by GPU. Same theory applies to UIKit context as well.
General purpose stuff
- https://www.toptal.com/developers/gitignore/ - put in things like “swift”, “xcode”, “macOS” etc and get a complete ignore file
- https://andresalla.com/en/stop-using-branch-in-your-podfiles/ - tldr. use tag at the place of branch in Podfile
-
addArc with tangent points https://stackoverflow.com/questions/66838135/what-are-the-tangent-parameters-found-in-the-addarc-method-for-swiftui
-
addArc with angles onmyway133/blog#673
-
cool way to draw gradient over text/custom view https://www.magnuskahr.dk/posts/2022/10/blendmode-trick-swiftui-source-overlay/