Skip to content

Commit

Permalink
fix: workaround for swiftui .onChange value only firing if value do…
Browse files Browse the repository at this point in the history
…esn't change state to 0 (fixes #162)
  • Loading branch information
vapidinfinity committed Nov 3, 2024
1 parent 781c7e7 commit 2da5e8f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Mythic/Views/Unified/Sheets/GameSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ private extension GameSettingsView {
TextField("", text: Binding(
get: { typingArgument },
set: { newValue in
withAnimation{
if (0...1).contains(typingArgument.count) {
withAnimation {
typingArgument = newValue
}
} else {
typingArgument = newValue
}
}
Expand All @@ -254,7 +258,14 @@ private extension GameSettingsView {
func submitLaunchArgument() {
if !typingArgument.trimmingCharacters(in: .illegalCharacters).trimmingCharacters(in: .whitespacesAndNewlines)
.isEmpty, !launchArguments.contains(typingArgument) {
launchArguments.append(typingArgument)
if launchArguments.isEmpty {
game.launchArguments = [typingArgument]
launchArguments = [typingArgument]

} else {
launchArguments.append(typingArgument)
}

typingArgument = .init()
}
}
Expand Down

0 comments on commit 2da5e8f

Please sign in to comment.