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

Move confirmation prompt to a static function #21006

Closed

Conversation

crazytonyli
Copy link
Contributor

This PR is an alternative to #21003 and a follow up of #21003 (comment).


Relates to #20994.

When the user wants to change their username from ChangeUsernameViewController, the app shows a confirmation alert which has a text field to ask the user to type the new username. The confirmation button in the alert will be disabled first and turn into enabled only when the user types the new username correctly.

Current implementation adds notification observer at the time of creating the alert and unregisters the observer when alert is dismissed. There are a few issues with current implementation, I'll post an inline comments to highlight them. This PR refactors the observing notification approach to register an observer once the view controller is loaded and let iOS SDK to unregister it when the view controller is released.

Test Instructions

  1. Modify this code in "Account Settings" to always be editableUsername, so that we can enter the "change username" screen.
  2. Launch the app from Xcode.
  3. Navigate to "Avatar" -> "Account Settings" -> "Username".
  4. Select or type a new username.
  5. Tap "Save". This is where you'll see the confirmation alert.

The "Change username" alert button should be disabled. The button should become enabled when the text in the text field matches the new username, and should become disable if it doesn't.

Regression Notes

  1. Potential unintended areas of impact
    None.

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    What's described in the test instruction section.

  3. What automated tests I added (or what prevented me from doing so)
    None.

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

UI Changes testing checklist: N/A

@wpmobilebot
Copy link
Contributor

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr21006-20c8d32
Version22.7
Bundle IDcom.jetpack.alpha
Commit20c8d32
App Center Buildjetpack-installable-builds #5231
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr21006-20c8d32
Version22.7
Bundle IDorg.wordpress.alpha
Commit20c8d32
App Center BuildWPiOS - One-Offs #6205
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Comment on lines +185 to +187
// Bind the subscription with the lifetime of the alert. When the alert instance is released, `cancellable` will be
// released too which will automatically unregister the notification observer.
objc_setAssociatedObject(alertController, &UIAlertController.cancellableKey, cancellable, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crazytonyli @jkmassel I generally prefer having an extension on UIAlertController that encapsulates all the configuration logic for a customize instance.

However, in this particular instance, the approach comes with the need for this legit but unusual objc_setAssociatedObject call.

All in all, I think the original version from #21003 might be best because of it's straightforwardness.

I'll leave it up to @jkmassel to decide. Also, I think given this address an relatively unfrequent use case (changing the user name) we don't need to rush into merging either version. Or, if we really want to rest assured that the bug is fixed ASAP, we could merge either for 22.8, and then refine if necessary.

@oguzkocer oguzkocer modified the milestones: 22.8, 22.9 Jul 10, 2023
@crazytonyli crazytonyli modified the milestones: 22.9, Pending Jul 21, 2023
@jkmassel jkmassel closed this Jun 26, 2024
@mokagio mokagio deleted the fix-memory-leak-in-notification-observers-9 branch June 26, 2024 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants