-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] When editing the TextField, a Popup error occurs: "Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value" #158
Comments
Thanks for the report. The branch Have a great day, |
Thank you for the update. I will keep an eye on the patch-4.0.0 branch, and I’ll proceed with testing once it’s ready on Saturday. Have a great day, too, T.K.! |
Hey @snow-xf, The problem should be fixed in the Have a great day, |
Hey Tomasz, |
Hey, Sorry, my fault, I didn't look at your code properly. Let's start by identifying the problem: @main
struct TestApp: App {
@StateObject var viewModel:TestViewModel = TestViewModel()
var body: some Scene {
WindowGroup {
ContentView()
.registerPopups()
.environmentObject(viewModel)
}
}
} The crash is caused by the ViewModel that you declared in the The solution I recommend is to move import SwiftUI
import MijickPopups
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.registerPopups()
}
}
}
class TestViewModel:ObservableObject{
@Published var text: String = ""
}
struct ContentView: View {
@StateObject var viewModel:TestViewModel = TestViewModel()
var body: some View {
NavigationStack{
List{
NavigationLink {
NextView().environmentObject(viewModel)
} label: {
Text("Next")
}
}
}
}
}
struct NextView:View {
@EnvironmentObject var viewModel:TestViewModel
@FocusState private var isInputFocused:Bool
var body: some View{
List{
/// When editing the TextField, a Popup error occurs: "Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value"
TextField("Edit Text", text: $viewModel.text,onCommit: {
isInputFocused = false
})
.focused($isInputFocused)
Button {
isInputFocused = false
Task { await TestBottomPopup().present() }
} label: {
Text("Test Popup")
}
}
}
}
struct TestBottomPopup: BottomPopup {
var body: some View{
Text("Test")
.padding()
.onTapGesture {
Task { await dismissLastPopup() }
}
}
func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig {
config.tapOutsideToDismissPopup(true)
}
} And here is confirmation that it now works as expected: Let me know if you have any further questions and have a nice day, |
I am having the same issue and honestly this solution is not gonna work for me. I should not have to change how my app (albeit incorrect) works fundamentally to use a library. For this reason only, I will skip using this otherwise awesome library. |
Ok, there is another solution, which I strongly discourage as I haven't tested its impact on performance, BUT: There are four attributes in the Change from:To: |
Hi Tomasz, the issue has been resolved. Thank you! |
@snow-xf what worked for you? |
|
The text was updated successfully, but these errors were encountered: