diff --git a/ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift b/ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift index 6aec74cd..326c9ebb 100644 --- a/ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift +++ b/ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift @@ -7,6 +7,7 @@ struct ContentView: View { @AppStorage("loggedUser") private var loggedUser: String? @State var isLoggingOut: Bool = false @State var loggedOut: Bool = false + @State var textColor: Color = .red private let confidence: Confidence @@ -19,21 +20,25 @@ struct ContentView: View { if (status.state == .loading && !isLoggingOut) { VStack { Spacer() - Text("Welcome \(loggedUser ?? "?")") + Text("Login successful: \(loggedUser ?? "?")") Text("We are preparing your experience...") ProgressView() - Spacer() } } else { - VStack { - Text("Hello World!") - .font(.largeTitle) - .foregroundStyle(ContentView.getColor(color: confidence.getValue(key: "swift-demoapp.color", defaultValue: "Gray"))) + if (status.state == .ready) { + VStack { + Spacer() + if (loggedUser != nil) { + Text("Hello World!") + .font(.largeTitle) + // This dynamically changes with the cache of flags, but it's wrapped into a conditional that makes sure flagStatus is "ready" + .foregroundStyle(ContentView.getColor(color: confidence.getValue(key: "swift-demoapp.color", defaultValue: "Gray"))) + .padding() + } + } } - .padding() Button("Logout") { isLoggingOut = true - loggedUser = nil status.state = .loading Task { @@ -46,6 +51,26 @@ struct ContentView: View { .navigationDestination(isPresented: $loggedOut) { LoginView(confidence: confidence) } + Spacer() + } + ZStack { + VStack { + Spacer() + Text("This text doesn't wait flags to be loaded") + .font(.caption) + .foregroundStyle(textColor) + Text("This text dynamically change on flag re-load") + .font(.caption) + .foregroundStyle(ContentView.getColor(color: confidence.getValue(key: "swift-demoapp.color", defaultValue: "Gray"))) + } + }.onAppear { + let eval = confidence.getEvaluation(key: "swift-demoapp.color", defaultValue: "Gray") + /* + Due to syntetic delay, the new context hasn't entered the SDK yet se we are operating with + the same empty context activated at logout, which leads to noSegmentMatch + */ + print(">> Evaluation reason: \(eval)") + textColor = ContentView.getColor(color: eval.value) } } } diff --git a/ConfidenceDemoApp/ConfidenceDemoApp/LoginView.swift b/ConfidenceDemoApp/ConfidenceDemoApp/LoginView.swift index f0469dd5..9d6f066c 100644 --- a/ConfidenceDemoApp/ConfidenceDemoApp/LoginView.swift +++ b/ConfidenceDemoApp/ConfidenceDemoApp/LoginView.swift @@ -45,10 +45,4 @@ struct LoginView: View { } } } - private var combinedBinding: Binding { - Binding( - get: { loginCompleted && flagsLoaded }, - set: { _ in } // No-op; navigation state is derived from other properties - ) - } } diff --git a/Sources/Confidence/Confidence.swift b/Sources/Confidence/Confidence.swift index 4b4f0127..d60b762c 100644 --- a/Sources/Confidence/Confidence.swift +++ b/Sources/Confidence/Confidence.swift @@ -64,10 +64,6 @@ public class Confidence: ConfidenceEventSender { } let savedFlags = try storage.load(defaultValue: FlagResolution.EMPTY) cache = savedFlags - debugLogger?.logMessage( - message: "[Activating stored cache]", - isWarning: false - ) } }