generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 89
PM-10051: Add the intro carousel with the first content page #780
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
BitwardenShared/UI/Auth/IntroCarousel/IntroCarouselAction.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // MARK: - IntroCarouselAction | ||
|
|
||
| /// Actions that can be processed by a `IntroCarouselProcessor`. | ||
| /// | ||
| enum IntroCarouselAction: Equatable { | ||
| /// The create account button was tapped. | ||
| case createAccount | ||
|
|
||
| /// The log in button was tapped. | ||
| case logIn | ||
| } |
41 changes: 41 additions & 0 deletions
41
BitwardenShared/UI/Auth/IntroCarousel/IntroCarouselProcessor.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import Combine | ||
| import SwiftUI | ||
|
|
||
| // MARK: - IntroCarouselProcessor | ||
|
|
||
| /// The processor used to manage state and handle actions for the intro carousel screen. | ||
| /// | ||
| class IntroCarouselProcessor: StateProcessor<IntroCarouselState, IntroCarouselAction, Void> { | ||
| // MARK: Private Properties | ||
|
|
||
| /// The coordinator that handles navigation. | ||
| private let coordinator: AnyCoordinator<AuthRoute, AuthEvent> | ||
|
|
||
| // MARK: Initialization | ||
|
|
||
| /// Creates a new `IntroCarouselProcessor`. | ||
| /// | ||
| /// - Parameters: | ||
| /// - coordinator: The coordinator that handles navigation. | ||
| /// - services: The services required by this processor. | ||
| /// - state: The initial state of the processor. | ||
| /// | ||
| init( | ||
| coordinator: AnyCoordinator<AuthRoute, AuthEvent>, | ||
| state: IntroCarouselState | ||
| ) { | ||
| self.coordinator = coordinator | ||
| super.init(state: state) | ||
| } | ||
|
|
||
| // MARK: Methods | ||
|
|
||
| override func receive(_ action: IntroCarouselAction) { | ||
| switch action { | ||
| case .createAccount: | ||
| coordinator.navigate(to: .createAccount) | ||
| case .logIn: | ||
| coordinator.navigate(to: .landing) | ||
| } | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
BitwardenShared/UI/Auth/IntroCarousel/IntroCarouselProcessorTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import XCTest | ||
|
|
||
| @testable import BitwardenShared | ||
|
|
||
| class IntroCarouselProcessorTests: BitwardenTestCase { | ||
| // MARK: Properties | ||
|
|
||
| var coordinator: MockCoordinator<AuthRoute, AuthEvent>! | ||
| var subject: IntroCarouselProcessor! | ||
|
|
||
| // MARK: Setup & Teardown | ||
|
|
||
| override func setUp() { | ||
| super.setUp() | ||
|
|
||
| coordinator = MockCoordinator() | ||
|
|
||
| subject = IntroCarouselProcessor( | ||
| coordinator: coordinator.asAnyCoordinator(), | ||
| state: IntroCarouselState() | ||
| ) | ||
| } | ||
|
|
||
| override func tearDown() { | ||
| super.tearDown() | ||
|
|
||
| coordinator = nil | ||
| subject = nil | ||
| } | ||
|
|
||
| // MARK: Tests | ||
|
|
||
| /// `receive(_:)` with `.createAccount` navigates to the create account view. | ||
| func test_receive_createAccount() { | ||
| subject.receive(.createAccount) | ||
| XCTAssertEqual(coordinator.routes.last, .createAccount) | ||
| } | ||
|
|
||
| /// `receive(_:)` with `.logIn` navigates to the landing view. | ||
| func test_receive_logIn() { | ||
| subject.receive(.logIn) | ||
| XCTAssertEqual(coordinator.routes.last, .landing) | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
BitwardenShared/UI/Auth/IntroCarousel/IntroCarouselState.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import SwiftUI | ||
|
|
||
| // MARK: - IntroCarouselState | ||
|
|
||
| /// An object that defines the current state of a `IntroCarouselView`. | ||
| /// | ||
| struct IntroCarouselState: Equatable { | ||
| // MARK: Types | ||
|
|
||
| /// A model representing the data to display on a single page in the carousel. | ||
| /// | ||
| struct CarouselPage: Equatable, Identifiable { | ||
| // MARK: | ||
|
|
||
| /// A unique identifier of the page. | ||
| let id: String = UUID().uuidString | ||
phil-livefront marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// An image to display. | ||
| let image: Image | ||
|
|
||
| /// A message to display on the page. | ||
| let message: String | ||
|
|
||
| /// A title to display on the page. | ||
| let title: String | ||
| } | ||
|
|
||
| // MARK: Properties | ||
|
|
||
| /// The list of scrollable pages displayed in the carousel. | ||
| let pages: [CarouselPage] = [ | ||
| CarouselPage( | ||
| image: Asset.Images.partnership.swiftUIImage, | ||
| message: Localizations.introCarouselPage1Message, | ||
| title: Localizations.introCarouselPage1Title | ||
| ), | ||
| ] | ||
| } | ||
138 changes: 138 additions & 0 deletions
138
BitwardenShared/UI/Auth/IntroCarousel/IntroCarouselView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| import SwiftUI | ||
|
|
||
| // MARK: - IntroCarouselView | ||
|
|
||
| /// A view that allows the user to swipe through the intro carousel and then proceed to creating an | ||
| /// account or logging in. | ||
| /// | ||
| struct IntroCarouselView: View { | ||
| // MARK: Properties | ||
|
|
||
| /// An environment variable for getting the vertical size class of the view. | ||
| @Environment(\.verticalSizeClass) var verticalSizeClass | ||
|
|
||
| /// The `Store` for this view. | ||
| @ObservedObject var store: Store<IntroCarouselState, IntroCarouselAction, Void> | ||
|
|
||
| /// The index of the currently visible page in the carousel. | ||
| @SwiftUI.State private var tabSelection = 0 | ||
|
|
||
| // MARK: View | ||
|
|
||
| var body: some View { | ||
| VStack(spacing: 0) { | ||
| TabView(selection: $tabSelection.animation()) { | ||
| ForEachIndexed(store.state.pages) { index, page in | ||
| pageView(page) | ||
| .tag(index) | ||
| } | ||
| } | ||
| .tabViewStyle(.page(indexDisplayMode: .never)) | ||
|
|
||
| HStack(spacing: 8) { | ||
| ForEachIndexed(store.state.pages) { index, _ in | ||
| Image(systemName: "circle.fill") | ||
| .resizable() | ||
| .frame(width: 8, height: 8) | ||
| .foregroundStyle( | ||
| tabSelection == index ? | ||
| Asset.Colors.textPrimary.swiftUIColor : | ||
| Asset.Colors.textPrimary.swiftUIColor.opacity(0.3) | ||
| ) | ||
| } | ||
| } | ||
| .padding(16) | ||
|
|
||
| VStack(spacing: 12) { | ||
| Button(Localizations.createAccount) { | ||
| store.send(.createAccount) | ||
| } | ||
| .buttonStyle(.primary()) | ||
|
|
||
| Button(Localizations.logIn) { | ||
| store.send(.logIn) | ||
| } | ||
| .buttonStyle(.transparent) | ||
| } | ||
| .dynamicTypeSize(...DynamicTypeSize.xxxLarge) | ||
| .padding(.horizontal, 16) | ||
| .padding(.vertical, 12) | ||
| } | ||
| .frame(maxWidth: .infinity, maxHeight: .infinity) | ||
| .background(Asset.Colors.backgroundSecondary.swiftUIColor.ignoresSafeArea()) | ||
| .foregroundStyle(Asset.Colors.textPrimary.swiftUIColor) | ||
| .multilineTextAlignment(.center) | ||
| } | ||
|
|
||
| /// A dynamic stack view that lays out content vertically when in a regular vertical size class | ||
| /// and horizontally for the compact vertical size class. | ||
| @ViewBuilder | ||
| private func dynamicStackView( | ||
| minHeight: CGFloat, | ||
| @ViewBuilder imageContent: () -> some View, | ||
| @ViewBuilder textContent: () -> some View | ||
| ) -> some View { | ||
| if verticalSizeClass == .regular { | ||
| VStack(spacing: 80) { | ||
| imageContent() | ||
| textContent() | ||
| } | ||
| .padding(.vertical, 16) | ||
| .frame(maxWidth: .infinity, minHeight: minHeight) | ||
| .scrollView(addVerticalPadding: false) | ||
| } else { | ||
| HStack(alignment: .top, spacing: 40) { | ||
| VStack(spacing: 0) { | ||
| Spacer(minLength: 0) | ||
| imageContent() | ||
| .padding(.leading, 36) | ||
| .padding(.vertical, 16) | ||
| Spacer(minLength: 0) | ||
| } | ||
| .frame(minHeight: minHeight) | ||
|
|
||
| textContent() | ||
| .padding(.vertical, 16) | ||
| .frame(maxWidth: .infinity, minHeight: minHeight) | ||
| .scrollView(addVerticalPadding: false) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// A view that displays a carousel page. | ||
| @ViewBuilder | ||
| private func pageView(_ page: IntroCarouselState.CarouselPage) -> some View { | ||
| GeometryReader { reader in | ||
| dynamicStackView(minHeight: reader.size.height) { | ||
| page.image | ||
| .resizable() | ||
| .frame( | ||
| width: verticalSizeClass == .regular ? 200 : 132, | ||
| height: verticalSizeClass == .regular ? 200 : 132 | ||
| ) | ||
| .accessibilityHidden(true) | ||
| } textContent: { | ||
| VStack(spacing: 16) { | ||
| Text(page.title) | ||
| .styleGuide(.title, weight: .bold) | ||
|
|
||
| Text(page.message) | ||
| .styleGuide(.title3) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Previews | ||
|
|
||
| #if DEBUG | ||
| #Preview("Carousel") { | ||
| IntroCarouselView(store: Store(processor: StateProcessor(state: IntroCarouselState()))) | ||
| } | ||
|
|
||
| @available(iOS 17, *) | ||
| #Preview("Carousel Landscape", traits: .landscapeRight) { | ||
| IntroCarouselView(store: Store(processor: StateProcessor(state: IntroCarouselState()))) | ||
| } | ||
| #endif |
55 changes: 55 additions & 0 deletions
55
BitwardenShared/UI/Auth/IntroCarousel/IntroCarouselViewTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import SnapshotTesting | ||
| import ViewInspector | ||
| import XCTest | ||
|
|
||
| @testable import BitwardenShared | ||
|
|
||
| class IntroCarouselViewTests: BitwardenTestCase { | ||
| // MARK: Properties | ||
|
|
||
| var processor: MockProcessor<IntroCarouselState, IntroCarouselAction, Void>! | ||
| var subject: IntroCarouselView! | ||
|
|
||
| // MARK: Setup & Teardown | ||
|
|
||
| override func setUp() { | ||
| super.setUp() | ||
|
|
||
| processor = MockProcessor(state: IntroCarouselState()) | ||
|
|
||
| subject = IntroCarouselView(store: Store(processor: processor)) | ||
| } | ||
|
|
||
| override func tearDown() { | ||
| super.tearDown() | ||
|
|
||
| processor = nil | ||
| subject = nil | ||
| } | ||
|
|
||
| // MARK: Tests | ||
|
|
||
| /// Tapping the create account button dispatches the create account action. | ||
| func test_createAccount_tap() throws { | ||
| let button = try subject.inspect().find(button: Localizations.createAccount) | ||
| try button.tap() | ||
| XCTAssertEqual(processor.dispatchedActions.last, .createAccount) | ||
| } | ||
|
|
||
| /// Tapping the log in button dispatches the login action. | ||
| func test_login_tap() throws { | ||
| let button = try subject.inspect().find(button: Localizations.logIn) | ||
| try button.tap() | ||
| XCTAssertEqual(processor.dispatchedActions.last, .logIn) | ||
| } | ||
|
|
||
| // MARK: Snapshots | ||
|
|
||
| /// The intro carousel renders correctly. | ||
| func test_snapshot_introCarousel() { | ||
| assertSnapshots( | ||
| of: subject.navStackWrapped, | ||
| as: [.defaultPortrait, .defaultPortraitDark, .defaultPortraitAX5, .defaultLandscape] | ||
| ) | ||
| } | ||
| } |
Binary file added
BIN
+187 KB
...Carousel/__Snapshots__/IntroCarouselViewTests/test_snapshot_introCarousel.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+186 KB
...Carousel/__Snapshots__/IntroCarouselViewTests/test_snapshot_introCarousel.2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+192 KB
...Carousel/__Snapshots__/IntroCarouselViewTests/test_snapshot_introCarousel.3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+164 KB
...Carousel/__Snapshots__/IntroCarouselViewTests/test_snapshot_introCarousel.4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 there a reason the
CarouselPageneeds to beIdentifiable? I was able to achieve the same effect with just an Equatable enum in the Authenticator app.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.
It needed to be
Identifiableto iterate over the array withForEach. An enum could work too, I just liked the ability to define the list of pages as a list within the state.