What I did yesterday
- Had a lot of conversations about cinnamon rolls and how to start a business with one. Still trying to come up with a name for it. Need all the help with naming that I can possibly get
- SwiftUI study yes! Not as much as I hoped but it’s still better than nothing
- Learnt about disabling user interactivity with
.allowsHitTesting(false)
. It’s really just as simple as that modifier because with html/react I would usually have to use a combination of properties like:
.no-hit {
pointer-events: none;
user-select: none;
}
There is also the option to use a custom Content Shape but that seems to have a rather specific use case. Eg. If you have a circle and you would like to have the hit area for the circle to be that of a rectangle you can use .contentShape(.rect)
. According to Paul Hudson, this comes in really handy when there is a Spacer
in your components and you would like to have it handle clicks as well
- ⏲️ Learnt about timers and I can’t help but have mixed feelings for it. Starting a timer that performs an action repeatedly looks like this:
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
.- The
on: .main
part of it indicates it should be running on the main thread (yet to interact with any other thread aside main) - The
in: .common
indicates the timer should run on the common run loop. According to Paul Hudson:
- The
Run loops let iOS handle running code while the user is actively doing something, such as scrolling in a list.
I’m yet to fully understand what this means in relation to running a heavy app that has timers in there.
So the timer stuff was all great until it came time to cancel the timer and that’s where the code made me raise an eyebrow. That looks like this: timer.upstream.connect().cancel()
. I had to look at this for a while to understand why it looks this way
- Steps
- First we get to the timer’s upstream publisher to find the timer then we connect to the timer publisher hence the
.upstream
. - Next we connect to the timer with
.connect()
- Then we go ahead and cancel it with
.cancel()
- First we get to the timer’s upstream publisher to find the timer then we connect to the timer publisher hence the
- Getting notified when your app moves to the background is something new I learnt along with new Environment variables.
@Environment(\.scenePhase) var scenePhase
.\.scenePhase
holds one of three enums which are.active
,.inactive
and.background
. Explanations for these are:- Active scenes are visible to the user
- Inactive scenes are running and might be visible to the user. eg. Screen could be locked while the app was active
- Background scenes are not visible to the user
- Accessing more accessibility options via environment variables.
struct ContentView: View {
@Environment(\.accessibilityDifferentiateWithoutColor) var differentiateWithoutColor
@Environment(\.accessibilityReduceMotion) var reduceMotion
@Environment(\.accessibilityReduceTransparency) var reduceTransparency
...
- With the
\.accessibilityReduceMotion
having to write the implementation for it when building out views can be a pain when you can to type out
struct ContentView: View {
@Environment(\.accessibilityReduceMotion) var reduceMotion
@State private var scale = 1.0
var body: some View {
Button("Hello, World!") {
if reduceMotion {
scale *= 1.5
} else {
withAnimation {
scale *= 1.5
}
}
}
.scaleEffect(scale)
}
}
and such, there’s a wrapper function that can be used around withAnimation()
that uses UIKit’s UIAccessibility
data directly:
func withOptionalAnimation<Result>(_ animation: Animation? = .default, _ body: () throws -> Result) rethrows -> Result {
if UIAccessibility.isReduceMotionEnabled {
return try body()
} else {
return try withAnimation(animation, body)
}
}
- Designed a card in SwiftUI and the syntax for that a bit strange for me coming from css.
var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 25)
.fill(.white)
.shadow(radius: 10) // Why is this how we get the shadow effect on the card?
VStack {
Text(card.prompt)
.font(.largeTitle)
.foregroundStyle(.black)
Text(card.answer)
.font(.title)
.foregroundStyle(.secondary)
}
.padding(20)
.multilineTextAlignment(.center)
}
.frame(width: 450, height: 250)
\\ Feels like that should exist here
}
Today
- Checked out
Sufian Rhazi
‘s work on WebRTC and it’s so interesting. I learned about Offers and ICE Candidates! There’s so much that happens behind the scenes with the technology that we use that we have no idea about and that’s just wonderful to know!
Upcoming
Two more days to finish 100 days of SwiftUI and I’m currently on day 88. Freeing up all my time within today and tomorrow to finish this with my RC batch!