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

Add Authentication Service and first 2 screens for new flow. #6048

Merged
merged 6 commits into from
May 4, 2022

Conversation

pixlwave
Copy link
Member

@pixlwave pixlwave commented Apr 20, 2022

This PR adds an AuthenticationService and RegistrationWizard based on the Android implementations. It additionally adds the Registration screen and Server Selection screen. It also

  • Renames AuthenticationCoordinator to LegacyAuthenticationCoordinator.
  • Adds extensions to MXRestClient and MXHTTPClient with async variants of the used methods to help the implementation more closely align with Kotlin's suspending functions.
  • Adds global colours of ems and white to the themes.

Closes #5161. Closes #5648. Requires matrix-org/matrix-ios-sdk#1443

Registration Screen Dark Mode Server Selection Screen Dark Mode
Simulator Screen Shot - iPhone 13 Pro - 2022-04-21 at 12 51 51 Simulator Screen Shot - iPhone 13 Pro - 2022-04-21 at 12 52 01 Simulator Screen Shot - iPhone 13 Pro - 2022-04-21 at 12 52 20 Simulator Screen Shot - iPhone 13 Pro - 2022-04-21 at 12 52 10
Registration Errors Server Selection Errors
Simulator Screen Shot - iPhone 13 Pro - 2022-04-21 at 12 53 52 Simulator Screen Shot - iPhone 13 Pro - 2022-04-21 at 12 52 53
4" Device
Simulator Screen Recording - iPod touch (7th generation) - 2022-04-21 at 13 02 01
iPad iPad
Simulator Screen Shot - iPad Pro (11-inch) (3rd generation) - 2022-04-21 at 13 14 29 Simulator Screen Shot - iPad Pro (11-inch) (3rd generation) - 2022-04-21 at 13 14 39

Comment on lines 67 to 69
/// Global color: The color white.
var white: ColorType { get }

/// Global color: The EMS brand's purple colour.
var ems: ColorType { get }

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm semi wondering if these should be grouped in a theme.globalColors.ems property or perhaps theme.colors.global.ems.

@pixlwave pixlwave force-pushed the doug/authentication branch 2 times, most recently from e6d4809 to 4774cf7 Compare April 21, 2022 12:18
@github-actions
Copy link

github-actions bot commented Apr 21, 2022

📱 Scan the QR code below to install the build for this PR.
🔒 This build is for internal testing purpose. Only devices listed in the ad-hoc provisioning profile can install Element Alpha.

QR code

If you can't scan the QR code you can install the build via this link: https://i.diawi.com/VwEmm3

@pixlwave pixlwave marked this pull request as ready for review April 21, 2022 14:10
@pixlwave pixlwave requested review from a team and Anderas and removed request for a team April 21, 2022 15:23
@pixlwave
Copy link
Member Author

Updated screenshot of the server selection screen with Cancel and Confirm buttons.

Simulator Screen Shot - iPhone 13 Pro - 2022-04-28 at 09 47 53

Copy link
Contributor

@Anderas Anderas left a comment

Choose a reason for hiding this comment

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

There is quite a lot of code in this PR, which makes it harder to review and see how all the bits fit together. Additionally some of the classes (e.g. the coordinators) are quite large, which makes them harder to understand and maintain in the long run. I wrote some suggestions below of how some of the code could be extracted out and tested.

@pixlwave pixlwave requested a review from Anderas May 3, 2022 10:09
Copy link
Contributor

@Anderas Anderas left a comment

Choose a reason for hiding this comment

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

Looking good, just have a few more questions

DesignKit/Source/ColorValues.swift Show resolved Hide resolved
// MARK: - Public

override func process(viewAction: AuthenticationRegistrationViewAction) {
Task {
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't Task and await MainActor.run right after equal to just not using any concurrency? Or is the process method simetimes called from non-main thread? I wonder if that should be allowed if it is mean to accept view actions, i.e. actions triggered from the main thread.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a side effect of marking completion as @MainActor where you get a compile error unless Swift can see that the call is also coming from the main thread. The right answer here is that process should also be @MainActor but that breaks the protocol conformance, and so without updating the protocol and all of the SwiftUI view models this is the best "on-ramp" onto the MainActor I could come up with.

In reality the View Model (and Coordinator and View) should be annotated @MainActor and then none of the methods/properties would need annotating individually. Would be nice to get this right early on in EIX to avoid async calls like this.

Copy link
Member Author

@pixlwave pixlwave May 4, 2022

Choose a reason for hiding this comment

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

A couple of options that I could do to make this cleaner:

  • Add a @MainActor private func processOnMain(viewAction: AuthenticationRegistrationViewAction) and call it from here.
  • Add a MainActorTask/TaskOnMain that hides away the await MainActor.run the removes one level of closure.
    Happy to consider either of these (or other ideas) if you think they make sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

@MainActor private func seems clean enough, though happy to go along the current code for this PR

Copy link
Member Author

Choose a reason for hiding this comment

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

Perfect, will do that alongside renaming the completions.

VStack(spacing: 0) {
header
.padding(.top, OnboardingMetrics.topPaddingToNavigationBar)
.padding(.bottom, 36)
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional for future PR: might be good to extract these hardcoded padding constants into some internal struct / enum for more control and consistency.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm slowing pulling out common constants into OnboardingMetrics, but I have wondered about local constants too. So far my conclusion was that unless some of these constants are shared, then the benefit is small and is no different to entering constraint values into a xib/storyboard. But definitely something I'd like to talk about more.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is true. The main issue with constants is that it is not whether different values are different deliberately or we just have not considered unifiying them (same goes for font sizes etc). But we can improve this later.

@pixlwave pixlwave requested a review from Anderas May 4, 2022 12:26
Copy link
Contributor

@Anderas Anderas left a comment

Choose a reason for hiding this comment

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

Thanks for addressing all the feedback

- Add Registration Screen.
- Add Server Selection Screen.
- Rename AuthenticationCoordinator to LegacyAuthenticationCoordinator.
- Add AuthenticationService and RegistrationWizard.
- Async extensions.
- Add global white and EMS colors to the themes.
- Add tests for server selection and registration screens.
- Accessibility and iPad layout tweaks.
- Remove MainActor from Auth Coordinators/VMs/Views.
(It broke the protocol conformances so now the methods and properties are marked individually.)
Stop using the homeserver from user defaults.
Log errors before throwing.
Remove white colour.
Remove AuthenticationCoordinatorState added during rebase.
@pixlwave pixlwave merged commit 757244a into develop May 4, 2022
@pixlwave pixlwave deleted the doug/authentication branch May 4, 2022 18:26
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.

Mobile FTUE: Create Account Screen (iOS) Mobile FTUE: Choose Server screen (iOS)
2 participants