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
Use fallback value when source == .static #11095
base: main
Are you sure you want to change the base?
Conversation
The @RemoteConfigProperty property wrapper should use the `fallback` value when the user selects “Use in-app default” in the Firebase console. Signed-off-by: Peter Friese <[email protected]>
Generated by 🚫 Danger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Also, reminder to add a CHANGELOG entry if applicable. I'll defer approval to @charlotteliang!
self.configValue = try remoteConfig[key].decoded() | ||
} else { | ||
self.configValue = fallbackValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the codepath for when source == .static
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for source == .static
, yes. Would you rather I make this more explicit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partially it was just me being unfamiliar with the API. I think more explicit would be a little clearer (maybe a switch statement?) and would guard against any unintended behavior if we were to add a case to that enum (probably unlikely though). Up to you, really.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be a good idea to make it more explicit (and thus, easier to understand).
Coverage Report 1Affected Products
Test Logs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think fallback value is equivalent to "in app default" value.
The fallback value is a pure swift language default value that is not the "in app default" value that's the default config value.
} | ||
} catch { | ||
// Suppresses a hard failure if decoding failed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is right, we should only get remote value since this method is only triggered when config has remote value needs to be activated.
@@ -61,13 +55,19 @@ internal class RemoteConfigValueObservable<T: Decodable>: ObservableObject { | |||
if FirebaseApp.app()?.name != appName { | |||
return | |||
} | |||
applyConfigValue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from the way you refactor the logic, I'm not sure it aligns with the description because for the applyConfigValue() fundamentally didn't change any logic.
If the The way it currently works is:
And this - at least to me - doesn't sound right either. Unless I am missing something.
Not sure I follow. To specify a language-level default value, wouldn't you rather want to assign a value to the underlying variable at initialisation time? I.e., |
The way it currently works is: In the console, you select Use in-app default value Can you elaborate the "nothing happens" part? The fallback value is used when a config key is never set by developers and because sometimes SwiftUI requires developers to do a null check, so it's easier to pass in a fallback value to avoid that. Here's the API definition: https://github.com/firebase/firebase-ios-sdk/blob/master/FirebaseRemoteConfigSwift/Sources/PropertyWrapper/RemoteConfigProperty.swift#L36 |
Sure. Take a look at the following code, which uses the RC property wrapper to connect the @RemoteConfigProperty(key: "cardColor", fallback: "#ff2d55") var cardColor
var body: some View {
VStack {
Text("What's your favourite number?")
.font(.title)
.multilineTextAlignment(.center)
Spacer()
Stepper(value: $viewModel.favouriteNumber, in: minValue...maxValue) {
Text("\(viewModel.favouriteNumber)")
}
}
.foregroundColor(.white)
.background(Color(hex: cardColor))
} When defining the RC variable and setting it to Expected behaviour: toggling to Use in-app default value uses the value defined by the PW. |
Expected behaviour: toggling to Use in-app default value uses the value defined by the PW. No that's not how we designed the API, the "in-app default" value should be defined by developers, not the fall back in PW as described in the API definition. https://github.com/firebase/firebase-ios-sdk/blob/master/FirebaseRemoteConfigSwift/Sources/PropertyWrapper/RemoteConfigProperty.swift#L36 |
This is also how I understood it. In RC the 3 value sources work as follows:
Going back to this PR, the PW should use both remote and default values as-is, and only use the fallback if there happens to be a decoding issue with the value, or there was no (user-defined) RC value found (static). Hope this clarifies things, if not, happy to discuss more! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change makes sense to me, it follows the remote > default > fallback ordering we discussed today
sorry for the confusion!
do { | ||
let configValue: RemoteConfigValue = remoteConfig[key] | ||
if configValue.source == .remote { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh i see, so previously the PW value would only change if there was a remote value, and does nothing otherwise
Please close, merge, or comment. We plan to close stale PRs on November 28, 2023. |
The @RemoteConfigProperty property wrapper should use the
fallback
value when the user selects “Use in-app default” in the Firebase console.