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

[#22] [iOS] [Integrate] As a user, I can see Survey header #94

Merged
merged 7 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions iosApp/Survey.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
0982A7E329222EFF00FC1976 /* RouteCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0982A7E229222EFF00FC1976 /* RouteCoordinator.swift */; };
0982A7E429222F2000FC1976 /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09495F6E28FFDE8C0036BDFB /* LoginView.swift */; };
0982A7E72922357C00FC1976 /* Font+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09636AF828D47A4D00A5CB97 /* Font+Extensions.swift */; };
0982A7EB29223C3A00FC1976 /* SurveyLoadingSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0982A7EA29223C3A00FC1976 /* SurveyLoadingSpec.swift */; };
0982A7F6292371F000FC1976 /* StringResource+Localized.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0982A7F5292371F000FC1976 /* StringResource+Localized.swift */; };
0982A80229278E9000FC1976 /* SurveySelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0982A7FA29278E9000FC1976 /* SurveySelectionView.swift */; };
0982A80329278E9000FC1976 /* SurveyHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0982A7FC29278E9000FC1976 /* SurveyHeaderView.swift */; };
Expand Down Expand Up @@ -90,6 +89,9 @@
09CE772728E2C44D00EAA9EE /* View+BackButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09CE772628E2C44D00EAA9EE /* View+BackButton.swift */; };
09CE773328E2ED2300EAA9EE /* KoinApplication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09CE773028E2ED2300EAA9EE /* KoinApplication.swift */; };
09CE773428E2ED2300EAA9EE /* Typealias+Koin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09CE773128E2ED2300EAA9EE /* Typealias+Koin.swift */; };
09FE26CD294B1EE3005A7F85 /* SurveySelectionView+DataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09FE26CC294B1EE3005A7F85 /* SurveySelectionView+DataSource.swift */; };
09FE26D1294B26A0005A7F85 /* SurveySelectionViewDataSourceSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09FE26CF294B264B005A7F85 /* SurveySelectionViewDataSourceSpec.swift */; };
09FE26D3294C1906005A7F85 /* ViewDidLoadModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09FE26D2294C1905005A7F85 /* ViewDidLoadModifier.swift */; };
351F5715D07BB9ED3F8B15F8 /* Pods_Survey.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 315DBBA2E56D199C3AC672B5 /* Pods_Survey.framework */; };
3D0ADA9FBBF8D55D5F00610F /* OptionalUnwrapSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1EE1175F99D55A95E0995E9 /* OptionalUnwrapSpec.swift */; };
5BBBFAF49689F25A8C1D57AB /* AutoMockable.generated.swift in Sources */ = {isa = PBXBuildFile; fileRef = A88CA60577ABA5F7885E1DE7 /* AutoMockable.generated.swift */; };
Expand Down Expand Up @@ -200,7 +202,6 @@
0982A7A32921DFE700FC1976 /* ResetPasswordSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResetPasswordSpec.swift; sourceTree = "<group>"; };
0982A7DE29222EA800FC1976 /* LoginSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginSpec.swift; sourceTree = "<group>"; };
0982A7E229222EFF00FC1976 /* RouteCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RouteCoordinator.swift; sourceTree = "<group>"; };
0982A7EA29223C3A00FC1976 /* SurveyLoadingSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SurveyLoadingSpec.swift; sourceTree = "<group>"; };
0982A7EE29223DA600FC1976 /* LoginFlow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginFlow.swift; sourceTree = "<group>"; };
0982A7F5292371F000FC1976 /* StringResource+Localized.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StringResource+Localized.swift"; sourceTree = "<group>"; };
0982A7FA29278E9000FC1976 /* SurveySelectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SurveySelectionView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -229,6 +230,9 @@
09CE772F28E2ED2300EAA9EE /* LazyKoin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LazyKoin.swift; sourceTree = "<group>"; };
09CE773028E2ED2300EAA9EE /* KoinApplication.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KoinApplication.swift; sourceTree = "<group>"; };
09CE773128E2ED2300EAA9EE /* Typealias+Koin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Typealias+Koin.swift"; sourceTree = "<group>"; };
09FE26CC294B1EE3005A7F85 /* SurveySelectionView+DataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SurveySelectionView+DataSource.swift"; sourceTree = "<group>"; };
09FE26CF294B264B005A7F85 /* SurveySelectionViewDataSourceSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurveySelectionViewDataSourceSpec.swift; sourceTree = "<group>"; };
09FE26D2294C1905005A7F85 /* ViewDidLoadModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewDidLoadModifier.swift; sourceTree = "<group>"; };
122A6B9F6217729620D91A43 /* DebugProduction.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = DebugProduction.xcconfig; sourceTree = "<group>"; };
15C39F2CB60CF0314258019E /* Pods-Survey.debug production.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Survey.debug production.xcconfig"; path = "Target Support Files/Pods-Survey/Pods-Survey.debug production.xcconfig"; sourceTree = "<group>"; };
16E10E52E1F7EAF6527F4E27 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -372,6 +376,7 @@
isa = PBXGroup;
children = (
0964B1DA2947007D00946FA1 /* SplashView */,
09FE26CE294B2639005A7F85 /* SurveySelection */,
09495FBC290B9CBD0036BDFB /* Login */,
09C2F3FA293093F600F44818 /* ResetPassword */,
);
Expand Down Expand Up @@ -441,6 +446,7 @@
09636AFF28D4860F00A5CB97 /* PrimaryTextField.swift */,
09636B0128D4876100A5CB97 /* PrimaryButton.swift */,
09636B0C28D4917200A5CB97 /* OverlayButton.swift */,
09FE26D2294C1905005A7F85 /* ViewDidLoadModifier.swift */,
);
path = ViewModifiers;
sourceTree = "<group>";
Expand Down Expand Up @@ -525,7 +531,6 @@
0982A7972921DE6700FC1976 /* SurveySelection */ = {
isa = PBXGroup;
children = (
0982A7E929223C3A00FC1976 /* SurveyLoading */,
0982A7982921DE6700FC1976 /* SurveySelectionSpec.swift */,
);
path = SurveySelection;
Expand Down Expand Up @@ -557,14 +562,6 @@
path = Login;
sourceTree = "<group>";
};
0982A7E929223C3A00FC1976 /* SurveyLoading */ = {
isa = PBXGroup;
children = (
0982A7EA29223C3A00FC1976 /* SurveyLoadingSpec.swift */,
);
path = SurveyLoading;
sourceTree = "<group>";
};
0982A7ED29223DA600FC1976 /* Flows */ = {
isa = PBXGroup;
children = (
Expand All @@ -585,6 +582,7 @@
isa = PBXGroup;
children = (
0982A7FA29278E9000FC1976 /* SurveySelectionView.swift */,
09FE26CC294B1EE3005A7F85 /* SurveySelectionView+DataSource.swift */,
0982A7FB29278E9000FC1976 /* SurveyHeader */,
0982A7FD29278E9000FC1976 /* SurveyItemView.swift */,
0982A7FE29278E9000FC1976 /* SurveyLoading */,
Expand Down Expand Up @@ -715,6 +713,14 @@
path = Koin;
sourceTree = "<group>";
};
09FE26CE294B2639005A7F85 /* SurveySelection */ = {
isa = PBXGroup;
children = (
09FE26CF294B264B005A7F85 /* SurveySelectionViewDataSourceSpec.swift */,
);
path = SurveySelection;
sourceTree = "<group>";
};
0A2BA072E9C5F7AC2C58F613 /* Views */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1489,12 +1495,14 @@
buildActionMask = 2147483647;
files = (
0982A80729278E9000FC1976 /* SurveyHeaderLoading.swift in Sources */,
09FE26D3294C1906005A7F85 /* ViewDidLoadModifier.swift in Sources */,
09CE772728E2C44D00EAA9EE /* View+BackButton.swift in Sources */,
0982A80329278E9000FC1976 /* SurveyHeaderView.swift in Sources */,
09636B0D28D4917200A5CB97 /* OverlayButton.swift in Sources */,
09495FC9291106A00036BDFB /* Constants+SystemImage.swift in Sources */,
686B2C185816765B3E124776 /* IOSApp.swift in Sources */,
09CE771328E1A94600EAA9EE /* ResetPasswordView.swift in Sources */,
09FE26CD294B1EE3005A7F85 /* SurveySelectionView+DataSource.swift in Sources */,
09636B3028D8267D00A5CB97 /* ViewId+General.swift in Sources */,
09636B0228D4876100A5CB97 /* PrimaryButton.swift in Sources */,
09CE770C28E191B400EAA9EE /* AppCoordinator.swift in Sources */,
Expand Down Expand Up @@ -1556,7 +1564,6 @@
09495F1828E4461C0036BDFB /* SurveySelectionScreen.swift in Sources */,
09636B3228D8272200A5CB97 /* ScreenProtocol.swift in Sources */,
0982A79E2921DF7E00FC1976 /* SurveySelectionSpec.swift in Sources */,
0982A7EB29223C3A00FC1976 /* SurveyLoadingSpec.swift in Sources */,
09C2F4032934588B00F44818 /* TimeInterval+Constants.swift in Sources */,
0964B1CA294051CE00946FA1 /* ArgumentedXCUIApplication.swift in Sources */,
09C2F40A29346A8800F44818 /* XCUIElement+Label.swift in Sources */,
Expand Down Expand Up @@ -1585,6 +1592,7 @@
0964B18D293F28DC00946FA1 /* TimeInterval+Constants.swift in Sources */,
09C2F3FD2930943700F44818 /* ResetPasswordViewDataSourceSpec.swift in Sources */,
09495FBF290B9D5C0036BDFB /* LoginViewDataSourceSpec.swift in Sources */,
09FE26D1294B26A0005A7F85 /* SurveySelectionViewDataSourceSpec.swift in Sources */,
3D0ADA9FBBF8D55D5F00610F /* OptionalUnwrapSpec.swift in Sources */,
09C2F416293778BE00F44818 /* Shared+AutoMockable.swift in Sources */,
09C2F415293777F800F44818 /* XCTestCase+Publisher.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ struct AppCoordinator: View {
SplashView(coordinator: coordinator)
case .surveySelection:
SurveySelectionView()
case .surveyLoading:
SurveyLoading(coordinator: coordinator)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ extension RouteCoordinator: LoginCoordinator {
routes.push(.resetPassword)
}

func showHomeLoading() {
routes = [.root(.surveyLoading)]
}
}

extension RouteCoordinator: SurveyLoadingCoordinator {

func showHome() {
routes = [.root(.surveySelection)]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ enum Screen {
case splash
case resetPassword
case surveySelection
case surveyLoading
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Shared
protocol LoginCoordinator {

func showResetPassword()
func showHomeLoading()
func showHome()
}

extension LoginView {
Expand Down Expand Up @@ -73,7 +73,7 @@ extension LoginView {
showingLoading = state.isLoading
showingErrorAlert = !state.error.string.isEmpty
if state.isSuccess {
coordinator.showHomeLoading()
coordinator.showHome()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import SwiftUI
protocol SplashCoordinator {

func showLogin()
func showHomeLoading()
func showHome()
}

extension SplashView {
Expand Down Expand Up @@ -58,7 +58,7 @@ extension SplashView {
guard !viewState.isLoading else { return }
withAnimation(.linear(duration: .fast)) {
if viewState.isLogin {
coordinator.showHomeLoading()
coordinator.showHome()
} else {
coordinator.showLogin()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@
// Copyright © 2022 Nimble. All rights reserved.
//

import Kingfisher
import Shared
import SwiftUI

struct SurveyHeaderView: View {

let surveyHeader: SurveyHeaderUiModel

var body: some View {
VStack(alignment: .leading, spacing: 4.0) {
// TODO: Use real data from ViewModel
Text("MONDAY, JUNE 15")
Text(surveyHeader.dateText)
.font(.boldSmall)
HStack {
Text("Today")
Text(surveyHeader.todayText())
.font(.boldLarge)
Spacer()
Assets.background.image
KFImage(surveyHeader.imageUrl.string.asURL)
.resizable()
.frame(width: 36.0, height: 36.0)
.cornerRadius(18.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,17 @@

import SwiftUI

protocol SurveyLoadingCoordinator {

func showHome()
}

struct SurveyLoading: View {

let coordinator: SurveyLoadingCoordinator

var body: some View {
VStack {}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.black.ignoresSafeArea())
VStack {
SurveyHeaderLoading()
SurveyItemLoading()
}
.padding(.horizontal, .smallPadding)
.onAppear {
// TODO: Use real loading
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
withAnimation {
coordinator.showHome()
}
}
}
.accessibility(.surveyLoading(.view))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// SurveySelectionView+DataSource.swift
// Survey
//
// Created by Bliss on 15/12/22.
// Copyright © 2022 Nimble. All rights reserved.
//

import Combine
import KMPNativeCoroutinesCombine
import Shared

extension SurveySelectionView {

final class DataSource: ObservableObject {

let viewModel: SurveySelectionViewModel

@Published private(set) var viewState = SurveySelectionViewState()
@Published var showingLoading = false

private var cancellables = Set<AnyCancellable>()

init(
viewModel: SurveySelectionViewModel = KoinApplication.shared.inject()
) {
self.viewModel = viewModel
createPublisher(for: viewModel.viewStateNative)
.catch { _ -> Just<SurveySelectionViewState> in
let surveySelectionViewState = SurveySelectionViewState()
return Just(surveySelectionViewState)
}
.receive(on: DispatchQueue.main)
.sink { [weak self] value in
guard let self = self else { return }
self.updateStates(value)
}
.store(in: &cancellables)
}

func fetch() {
viewModel.fetch()
}

private func updateStates(_ state: SurveySelectionViewState) {
viewState = state
showingLoading = state.isLoading
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import SwiftUI

struct SurveySelectionView: View {

@StateObject private var dataSource = DataSource()

@State private var currentPage = 0
// TODO: Replace Example data
@State private var surveys: [SurveyUiModel] = [
Expand All @@ -35,6 +37,21 @@ struct SurveySelectionView: View {
]

var body: some View {
ZStack {
if dataSource.showingLoading {
SurveyLoading()
} else {
survey
}
}
.accessibilityElement(children: .contain)
.accessibility(.surveySelection(.view))
.onLoad {
dataSource.fetch()
}
}

var survey: some View {
ZStack {
FadePaginationView(
currentPage: $currentPage,
Expand Down Expand Up @@ -63,8 +80,10 @@ struct SurveySelectionView: View {
.frame(maxWidth: .infinity, maxHeight: .infinity)

VStack {
SurveyHeaderView()
.accessibility(.surveySelection(.header))
if let surveyHeader = dataSource.viewState.surveyHeaderUiModel {
SurveyHeaderView(surveyHeader: surveyHeader)
.accessibility(.surveySelection(.header))
}
Spacer()
HStack {
Spacer()
Expand All @@ -82,7 +101,5 @@ struct SurveySelectionView: View {
}
}
}
.accessibilityElement(children: .contain)
.accessibility(.surveySelection(.view))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// ViewDidLoadModifier.swift
// Survey
//
// Created by Bliss on 16/12/22.
// Copyright © 2022 Nimble. All rights reserved.
//

import SwiftUI

struct ViewDidLoadModifier: ViewModifier {

@State private var didLoad = false

private let action: (() -> Void)?

init(perform action: (() -> Void)? = nil) {
self.action = action
}

func body(content: Content) -> some View {
content.onAppear {
if didLoad == false {
didLoad = true
action?()
}
}
}
}

extension View {

func onLoad(perform action: (() -> Void)? = nil) -> some View {
modifier(ViewDidLoadModifier(perform: action))
}
}
Loading