ContainerRelativeShape Modifier in SwiftUI (iOS 14+)
ContainerRelativeShape was introduced to the world of SwiftUI in iOS 14. ContainerRelativeShape is a shape that is replaced by an inset version of the current container shape. If no container shape was defined, is replaced by a rectangle.
This shape was introduced to match the corner radius for rounded rectangles. This feature was demoed in Widget development videos but its useful in other use cases as well.
Notice that we have to have same RoundedRectangle corners to make sure that corners are concentric. In this case it’s easy because we know we are choosing the value but imagine the case where rounded corner is the system container, we can either apply brute force to find out the exact value or we can use this new shape. This is the case with Widgets as they have rounded corners but we don’t need to know exact value of corner radius.
We will look at a Widget view later but for now, let’s make use of this shape in our app’s view.
With that we have reached the end of this article. Thank you once again for reading. Don’t forget to subscribe our newsletter at https://www.devtechie.com