From 2da5e8fe79c0c3a3965c5aa6ab3034feb1dc47ce Mon Sep 17 00:00:00 2001 From: esiayo <41133734+blackxfiied@users.noreply.github.com> Date: Sun, 3 Nov 2024 21:34:41 +0800 Subject: [PATCH] fix: workaround for swiftui `.onChange` value only firing if value doesn't change state to 0 (fixes #162) --- .../Views/Unified/Sheets/GameSettingsView.swift | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Mythic/Views/Unified/Sheets/GameSettingsView.swift b/Mythic/Views/Unified/Sheets/GameSettingsView.swift index e0cf0ba2..ced0622e 100644 --- a/Mythic/Views/Unified/Sheets/GameSettingsView.swift +++ b/Mythic/Views/Unified/Sheets/GameSettingsView.swift @@ -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 } } @@ -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() } }