Skip to content
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

Fix initialization of @State var #494

Open
wants to merge 1 commit into
base: release/3.0.0
Choose a base branch
from

Conversation

pinarol
Copy link
Contributor

@pinarol pinarol commented Oct 11, 2024

Closes #

Description

This fixes a bug i detected during the Jetpack integration. Because of the way we initialize the @State variable, the token was not being set successfully. This article does a good job explaining why: https://www.swiftcraft.io/articles/how-to-initialize-state-inside-the-views-init-

From an Apple dev:

Although that will compile, @State variables in SwiftUI should not be initialized from data you pass down through the initializer; since the model is maintained outside of the view, there is no guarantee that the value will really be used. The correct thing to do is to set your initial state values inline: @State private var viewModel = SignInViewModel(...)

So I am separating the local @State token from the one passed from outside.
Also removing the @State from scope as well, it doesn't need to be a @State. This is not directly related with the bug but it's a wrong usage as well so needs fixing.
I also rearranged the lines a bit.

Testing Steps

Go to UIKit Demo app > QE
Enter email
Enter token <-- important

Tap Logout if the button is present

Open the QE, verify it does NOT go through OAuth and goes directly to QE.

@pinarol pinarol changed the base branch from trunk to release/3.0.0 October 11, 2024 12:23
@wpmobilebot
Copy link

Gravatar SwiftUI Prototype Build📲 You can test the changes from this Pull Request in Gravatar SwiftUI Prototype Build by scanning the QR code below to install the corresponding build.
App NameGravatar SwiftUI Prototype Build Gravatar SwiftUI Prototype Build
Build Number1480
Version1.0
Bundle IDcom.automattic.gravatar-sdk-demo-swiftui.prototype-build
Commit4652388
App Center BuildGravatar SDK Demo - SwiftUI #258
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link

Gravatar UIKit Prototype Build📲 You can test the changes from this Pull Request in Gravatar UIKit Prototype Build by scanning the QR code below to install the corresponding build.
App NameGravatar UIKit Prototype Build Gravatar UIKit Prototype Build
Build Number1480
Version1.0
Bundle IDcom.automattic.gravatar-sdk-demo-uikit.prototype-build
Commit4652388
App Center BuildGravatar SDK Demo - UIKit #258
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@pinarol pinarol marked this pull request as ready for review October 11, 2024 14:45
@pinarol pinarol added this to the Milestone 4 - Quick Editor milestone Oct 11, 2024
@pinarol pinarol self-assigned this Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants