Skip to content

Commit

Permalink
[#21] Fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
blyscuit committed Nov 11, 2022
1 parent d623900 commit 9729cd0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 19 deletions.
4 changes: 4 additions & 0 deletions iosApp/Survey.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
09495FA0290A82290036BDFB /* LoginFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09495F9F290A82290036BDFB /* LoginFlow.swift */; };
09495FA3290A823C0036BDFB /* SurveySelectionScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09495FA2290A823C0036BDFB /* SurveySelectionScreen.swift */; };
09495FA6290A82590036BDFB /* SurveySelectionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09495FA5290A82590036BDFB /* SurveySelectionSpec.swift */; };
09495FCF29110E820036BDFB /* String+URL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09495FCE29110E820036BDFB /* String+URL.swift */; };
09636AF228D4779400A5CB97 /* NeuzeitSLTStd-Book.otf in Resources */ = {isa = PBXBuildFile; fileRef = 09636AF028D4779400A5CB97 /* NeuzeitSLTStd-Book.otf */; };
09636AF328D4779400A5CB97 /* NeuzeitSLTStd-BookHeavy.otf in Resources */ = {isa = PBXBuildFile; fileRef = 09636AF128D4779400A5CB97 /* NeuzeitSLTStd-BookHeavy.otf */; };
09636AF628D47A1500A5CB97 /* R.generated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09636AF528D47A1400A5CB97 /* R.generated.swift */; };
Expand Down Expand Up @@ -125,6 +126,7 @@
09495F9F290A82290036BDFB /* LoginFlow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginFlow.swift; sourceTree = "<group>"; };
09495FA2290A823C0036BDFB /* SurveySelectionScreen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SurveySelectionScreen.swift; sourceTree = "<group>"; };
09495FA5290A82590036BDFB /* SurveySelectionSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SurveySelectionSpec.swift; sourceTree = "<group>"; };
09495FCE29110E820036BDFB /* String+URL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+URL.swift"; sourceTree = "<group>"; };
09636AF028D4779400A5CB97 /* NeuzeitSLTStd-Book.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "NeuzeitSLTStd-Book.otf"; sourceTree = "<group>"; };
09636AF128D4779400A5CB97 /* NeuzeitSLTStd-BookHeavy.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "NeuzeitSLTStd-BookHeavy.otf"; sourceTree = "<group>"; };
09636AF528D47A1400A5CB97 /* R.generated.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = R.generated.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -468,6 +470,7 @@
isa = PBXGroup;
children = (
64ED519E814E897776076800 /* Optional+Unwrap.swift */,
09495FCE29110E820036BDFB /* String+URL.swift */,
);
path = Foundation;
sourceTree = "<group>";
Expand Down Expand Up @@ -1189,6 +1192,7 @@
09636B3028D8267D00A5CB97 /* ViewId+General.swift in Sources */,
09636B0228D4876100A5CB97 /* PrimaryButton.swift in Sources */,
09CE770C28E191B400EAA9EE /* AppCoordinator.swift in Sources */,
09495FCF29110E820036BDFB /* String+URL.swift in Sources */,
09636AFD28D484CA00A5CB97 /* R+SwiftUI.swift in Sources */,
09636B0F28D80B8500A5CB97 /* View+KeyboardDismiss.swift in Sources */,
09CE773428E2ED2300EAA9EE /* Typealias+Koin.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension RouteCoordinator: SplashCoordinator {

extension RouteCoordinator: LoginCoordinator {

func showSurvey() {
func showHome() {
routes = [.root(.surveySelection)]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI

protocol LoginCoordinator {

func showSurvey()
func showHome()
}

struct LoginView: View {
Expand Down Expand Up @@ -95,7 +95,7 @@ struct LoginView: View {
Button {
// TODO: Add action when press `login`
withAnimation {
coordinator.showSurvey()
coordinator.showHome()
}
} label: {
Text(Localize.loginButtonLogin())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct SurveyItemView: View {
var body: some View {
ZStack {
GeometryReader { geo in
KFImage(URL(string: survey.largeImageUrl) ?? URL(fileURLWithPath: ""))
KFImage(survey.largeImageUrl.asURL)
.resizable()
.scaledToFill()
.frame(maxWidth: geo.size.width, maxHeight: geo.size.height)
Expand Down Expand Up @@ -54,7 +54,6 @@ struct SurveyItemView: View {
.id(survey.id)
.padding(.leading, 20.0)
.padding(.trailing, 76.0)
.accessibilityElement(children: .contain)
}
.accessibilityElement(children: .contain)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct SurveySelectionView: View {
items: surveys
)
.onChange(of: currentPage) { newValue in
// TODO: Update viewModel to new index
print(newValue)
}
VStack(alignment: .leading) {
Expand Down
39 changes: 25 additions & 14 deletions iosApp/Survey/Sources/Presentation/Views/FadePaginationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ import SwiftUI
struct FadePaginationView<T>: View {

@Binding private var currentPage: Int
@State private var currentVisible: Double = 1.0

@State private var currentVisibility: Double = 1.0
@State private var nextPage = 0
private var turnLength: Double = 160.0
private var turnSpeed: Double = 700.0

@GestureVelocity private var velocity: CGVector

private var turningLength: Double = 160.0
private var turningSpeed: Double = 700.0
private var minimumTurnDistance: Double = 6.0
private var turningVisibilityMultiplier: Double = 1.17

var currentView: (T) -> AnyView
var nextView: (T) -> AnyView
var items: [T]
Expand All @@ -25,35 +30,41 @@ struct FadePaginationView<T>: View {
ZStack {
nextView(items[nextPage])
currentView(items[currentPage])
.opacity(currentVisible)
.opacity(currentVisibility)
.gesture(
DragGesture(minimumDistance: 6.0, coordinateSpace: .local)
DragGesture(minimumDistance: minimumTurnDistance, coordinateSpace: .local)
.onChanged { value in
switch value.translation.width {
case ...0: nextPage = min(items.count - 1, currentPage + 1)
case 0...: nextPage = max(0, currentPage - 1)
default: return
}
let percentage = turnLength * 1.17 / abs(value.translation.width)
currentVisible = 1.0 * max(0.0, percentage)
let turningVisibilityPercentage =
turningLength * turningVisibilityMultiplier / abs(value.translation.width)
currentVisibility = 1.0 * max(0.0, turningVisibilityPercentage)
}
.onEnded { value in
withAnimation(.easeInOut(duration: 0.3)) {
let velocity = self.velocity
if velocity.dx < -turnSpeed {
if velocity.dx < -turningSpeed {
// Swipe back fast
previousPage()
} else if velocity.dx > turnSpeed {
} else if velocity.dx > turningSpeed {
// Swipe forward fast
forwardPage()
} else {
// Slow swipe
switch value.translation.width {
case ...(-turnLength):
case ...(-turningLength):
// Swipe back reaching threshold
previousPage()
case turnLength...:
case turningLength...:
// Swipe forward reaching threshold
forwardPage()
default: break
}
}
currentVisible = 1.0
currentVisibility = 1.0
}
}
.updatingVelocity($velocity)
Expand All @@ -73,11 +84,11 @@ struct FadePaginationView<T>: View {
self.items = items
}

func forwardPage() {
private func forwardPage() {
currentPage = max(0, currentPage - 1)
}

func previousPage() {
private func previousPage() {
currentPage = min(items.count - 1, currentPage + 1)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// String+URL.swift
// Survey
//
// Created by Bliss on 1/11/22.
// Copyright © 2022 Nimble. All rights reserved.
//

import Foundation

extension String {

var asURL: URL {
URL(string: self) ?? URL(fileURLWithPath: "")
}
}

0 comments on commit 9729cd0

Please sign in to comment.