-
Notifications
You must be signed in to change notification settings - Fork 32
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
Toast Message Issue #15
Comments
@muhammadfarooq012012 Could you please provide more information or a short code snippet? I can't reproduce your problem. It's even possible to change the message while the toast is visible, although such things are not recommended. |
@State private var toastMessage: String = "xxxx" .simpleToast(isPresented: $isShowToast, options: SimpleToastOptions(hideAfter: 2)) {
|
@muhammadfarooq012012 For me it looks more as if your view is not being updated correctly. The toast itself is not modifying the content to display, so it basically only shows what it gets. How do you set the value of your state variable? I made a recording of my example: Simulator.Screen.Recording.-.iPhone.13.-.2022-03-20.at.12.10.22.mp4Here's the code: import SwiftUI
import SimpleToast
struct ContentView: View {
@State private var toastMessage = "Some message"
@State private var showToast = false
var body: some View {
VStack {
TextField("", text: $toastMessage)
.textFieldStyle(RoundedBorderTextFieldStyle())
Button("Toast") { showToast.toggle() }
}
.padding()
.simpleToast(isPresented: $showToast, options: SimpleToastOptions()) {
let _ = print(self.toastMessage)
HStack {
Image(systemName: "exclamationmark.triangle")
Text(toastMessage)
}
.padding(EdgeInsets(top: 8, leading: 12, bottom: 8, trailing: 12))
.background(Color.black)
.foregroundColor(Color.white)
}
}
} |
first click change button,then click show button |
@Monkey-X-Byte @muhammadfarooq012012 I can confirm the behavior with your code, although I suspect some SwiftUI / Combine publisher quirks to be the problem. If you simply add a Text to your code, the state variable updates perfectly, also inside the toast: ZStack {
VStack {
Text(self.toastMessage)
Button {
self.toastMessage = "Hello world!"
let _ = print(self.toastMessage)
... I will do some more investigation, as this is neither a solution, nor a workaround. |
.onChange(of: toastMessage) { newValue in This can solve the problem, but I don't know why. |
Yeah, it really has to do with publishing and weird pre caching of views. I will investigate deeper this weekend. If you call the show before changing the value it works, also removing the if-clause for showing the toast or a simple Text() with the value. Very weird. Hope I can provide a fix, soon. |
@muhammadfarooq012012 @Monkey-X-Byte Release 0.6.2 should fix your issue. |
The message in the toast does not change if we set the global variable for the toast message.
The text was updated successfully, but these errors were encountered: