krzysztofzablocki / Inject

Hot Reloading for Swift applications!
MIT License
2.14k stars 114 forks source link

❌🫵🏽 Show reloaded result instantly without tapping the simulator #44

Closed mattigrthr closed 2 years ago

mattigrthr commented 2 years ago

First of all, thanks for open-sourcing this amazing repo. ❤️ A true time-saver!

I got it running but to be able to see the change I have to tap on the simulator. Would be neat to show the result instantly.

I'm guessing enabling the animation is meant for that.

Inject.animation = .interactiveSpring()

But I don't know where to place it. Xcode gives me an error no matter where I place it.

I'm using the @ObserveInjection var inject inside my ContentView.

My Xcode version is 13.4.1.

krzysztofzablocki commented 2 years ago

You definitely shouldn't need to touch simulator, mind recording a video and the code integration snippet you did?

mattigrthr commented 2 years ago

Sure, this is a recording where I change the color of a button. It updates once I click on it.

https://user-images.githubusercontent.com/28758040/176725939-8700d3cd-6bd3-4956-93f5-88e16bd18f9c.mov

This is where I injected the snippet:

import SwiftUI
import Inject

struct ContentView: View {
    @ObserveInjection var inject
    @StateObject var viewRouter = ViewRouter()

    @ViewBuilder
    var body: some View {
          MainContainer(viewRouter: viewRouter).enableInjection()
    }
}
mattigrthr commented 2 years ago

Also, I was following this YouTube video and it has the same behaviour: https://youtu.be/kk1DnjyLpUE

krzysztofzablocki commented 2 years ago

@mattigrthr add enableInjection and ObservedObject var in each view and you should get proper updates

mattigrthr commented 2 years ago

Jupp, that works. 👍🏽 Thanks for the swift reply @krzysztofzablocki! 🙌🏽