Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 809521c

Browse files
committed
Fix
1 parent 1aa53ae commit 809521c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/posts/2022-10-03-swiftui-path-svg-scale.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ As you may already know, at [lastminute.com group](https://lmgroup.lastminute.co
1717
[Friyay instead of Friday](https://technology.lastminute.com/tech-learning-and-development-friyay/ "lastminute.com
1818
learning"). In the Friyay everyone can learn and improve his/her skill on any subject. In particular, as you seen
1919
from one of my [previous post](/2022/06/06/microfrontend-module-federation-dynamic-configuration/ "module
20-
federation"), I spent some Friday mornings putting in place the first microfrontend architecture for the customer
21-
area of lastminute.com websites (while also trying to master/study in deep some other topics).
20+
federation"), I spent some Friyay putting in place the first microfrontend architecture for the customer
21+
area of lastminute.com websites (while also trying to study in deep some other topics).
2222
In the last weeks I started a new Friyay "secret" project with my colleague
2323
[Marco De Lucchi](https://www.linkedin.com/in/marcodelucchi/). As you may already remember [I already worked with
24-
Marco](/2020/01/18/react-native-activate-hermes/) in the past when I was part of the mobile app team. In this secret
25-
project we are developing something new for our mobile app
24+
Marco](/2020/01/18/react-native-activate-hermes/ "react native hermes") in the past when I was part of the mobile app
25+
team.
26+
For this new secret project, we are developing something new for our mobile app
2627
using [SwiftUI](https://developer.apple.com/xcode/swiftui/ "swiftui"). We had various challenges to overcome.
2728
One of this has been to be able to display a cool inspirational title like the following one.
2829

@@ -32,14 +33,14 @@ The easiest way to go could be to simply include in the target bundle the locali
3233
represent the title above. This is easily achievable using
3334
[Xcode localized assets](https://developer.apple.com/documentation/xcode/localizing-assets-in-a-catalog "xcode
3435
localized assets"). But given that we were already having fun with SwiftUI (remember, it is a Friyay project
35-
:laughing:) and that we want to save bytes on the bundle size (that is always important), we decided to be bold and
36+
:laughing: ) and that we want to save bytes on the bundle size (that is always important), we decided to be bold and
3637
try to implement the title in the screenshot above using only code (no assets).
3738
So in this post we will show you our own personal journey into the world of SwiftUI `Path` and `Shape` and how we
3839
have been able to create the inspirational title in the screenshot above using only code. Let's go!! :rocket:
3940

4041
#### Implementation
4142

42-
Let's start from the most challenging part: the background. As you can see from the image above they are
43+
Let's start from the most challenging part: the background. As you can see from the image above it is
4344
basically the same shape drawn twice, one above each other, with different color and a slightly different position
4445
in space. In the original Figma we received from UX we were able to extract the svg path coordinates for these shapes.
4546
So how can we draw them in SwiftUI? We can use [Path](https://developer.apple.com/documentation/swiftui/path
@@ -121,6 +122,7 @@ y \\
121122
x \cdot S_{x}\\
122123
y \cdot S_{y} \\
123124
1 \\
125+
1 \\
124126
\end{bmatrix}
125127
$$
126128

@@ -131,7 +133,7 @@ In our case we will use `CGAffineTransform(scaleX: <value>, y: <value>)`. Which
131133
For our goal we need to calculate the ratio between the `rect` parameter of the `func path(in rect: CGRect) -> Path`
132134
function (that as we said before it is the `CGRect` in which we are drawing our shape) and the bounding rect of the
133135
path itself. Luckily, SwiftUI exposes a beautiful `boundingRect` property on the `Path` that is exactly what we need.
134-
so in the end the final implementation of our `TitleBackgroundShape` is the following one.
136+
So in the end the final implementation of our `TitleBackgroundShape` is the following one.
135137

136138
```swift
137139
private struct TitleBackgroundShape: Shape {
@@ -201,7 +203,7 @@ spacing for each side.
201203
We are finally ready to add the custom background component `TitleBackground` we created before. We need to put it
202204
behind the text, but we want also to see it grows proportionally to the text dimension. This is why we included the
203205
`Text` component in a `ZStack`, and we added with the `.background` modifier the `TitleBackground`. Below you can find
204-
the complete implementation.
206+
the implementation.
205207

206208
```swift
207209
struct InspirationaTitle: View {
@@ -226,5 +228,5 @@ struct InspirationaTitle: View {
226228
#### Conclusion
227229

228230
In this [github repository](https://github.com/chicio/Path-Example "swiftui path example") you can find the
229-
implementation fo the example described above. I really excited to share with you the entire project where we used
230-
the implementation above. Stay tuned! :ear: :rocket:
231+
implementation fo the example described above. I'm really excited to share with you in the next weeks the entire
232+
project where we used the implementation above. Stay tuned! :ear: :rocket:

0 commit comments

Comments
 (0)