Skip to content

Commit

Permalink
Merge pull request #27 from vespinola/10-refactor-ripplespinnerview-t…
Browse files Browse the repository at this point in the history
…o-modifier

created modifier for ripple spinner view
  • Loading branch information
vespinola authored Jun 26, 2024
2 parents 2c6db43 + 39b9165 commit 7d6b701
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 53 deletions.
8 changes: 6 additions & 2 deletions mobile-courier-app.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
1B6D75192C23BFB30067BB56 /* RoundedIndicatorViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B6D75182C23BFB30067BB56 /* RoundedIndicatorViewModifier.swift */; };
1B6D751C2C23DF910067BB56 /* ShipmentDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B6D751B2C23DF910067BB56 /* ShipmentDetailView.swift */; };
1B6F7C312C2BA621005F0476 /* Data+Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B6F7C302C2BA621005F0476 /* Data+Data.swift */; };
1B6F7C332C2BA9D6005F0476 /* RippleSpinnerModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B6F7C322C2BA9D6005F0476 /* RippleSpinnerModifier.swift */; };
1B821F192C1AA50600ED1795 /* CustomSessionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B821F182C1AA50600ED1795 /* CustomSessionDelegate.swift */; };
1B85000E2C10033D006E96A0 /* ToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B85000D2C10033D006E96A0 /* ToastView.swift */; };
1B8500102C1004D0006E96A0 /* ToastModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B85000F2C1004D0006E96A0 /* ToastModifier.swift */; };
Expand Down Expand Up @@ -156,6 +157,7 @@
1B6D75182C23BFB30067BB56 /* RoundedIndicatorViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundedIndicatorViewModifier.swift; sourceTree = "<group>"; };
1B6D751B2C23DF910067BB56 /* ShipmentDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShipmentDetailView.swift; sourceTree = "<group>"; };
1B6F7C302C2BA621005F0476 /* Data+Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Data.swift"; sourceTree = "<group>"; };
1B6F7C322C2BA9D6005F0476 /* RippleSpinnerModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RippleSpinnerModifier.swift; sourceTree = "<group>"; };
1B821F182C1AA50600ED1795 /* CustomSessionDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSessionDelegate.swift; sourceTree = "<group>"; };
1B85000D2C10033D006E96A0 /* ToastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastView.swift; sourceTree = "<group>"; };
1B85000F2C1004D0006E96A0 /* ToastModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToastModifier.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -346,6 +348,7 @@
1B85000F2C1004D0006E96A0 /* ToastModifier.swift */,
1B6D75182C23BFB30067BB56 /* RoundedIndicatorViewModifier.swift */,
1B40471C2C27C3CB00101DF4 /* GroupedPackageStyleModifier.swift */,
1B6F7C322C2BA9D6005F0476 /* RippleSpinnerModifier.swift */,
);
path = Modifiers;
sourceTree = "<group>";
Expand Down Expand Up @@ -490,10 +493,10 @@
1B6D75152C23BDA40067BB56 /* PackagesForWithdrawal */,
1B2DDEF02C1E652A003EC97C /* WithdrawnPackages */,
1B8500132C100DE2006E96A0 /* Profile */,
1BD17E612C0EB42B009B6C67 /* Navigation */,
1BE58CB12C0585B400C7DF63 /* Home */,
1B07BC8B2BFD676100D8B149 /* Helpers */,
1B58EFA12BE6BF870066F447 /* Login */,
1BD17E612C0EB42B009B6C67 /* Navigation */,
1B07BC8B2BFD676100D8B149 /* Helpers */,
1BE58CA42C05725500C7DF63 /* Previews */,
);
path = Presentation;
Expand Down Expand Up @@ -814,6 +817,7 @@
1BFD1EB32C2A7927002E4232 /* ShipmentStatus.swift in Sources */,
1B40471B2C27854200101DF4 /* AddressEntityMock.swift in Sources */,
1B8500152C100DF1006E96A0 /* ProfileView.swift in Sources */,
1B6F7C332C2BA9D6005F0476 /* RippleSpinnerModifier.swift in Sources */,
1B6D751C2C23DF910067BB56 /* ShipmentDetailView.swift in Sources */,
1B85E8EA2BFC4E85003040CC /* AuthRepository.swift in Sources */,
1B9274CD2C1158E0008F4FA3 /* AddressEndpoints.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// RippleSpinnerModifier.swift
// mobile-courier-app
//
// Created by Vladimir Espinola on 2024-06-25.
//

import SwiftUI

struct RippleSpinnerModifier: ViewModifier {
@Binding var isLoading: Bool

func body(content: Content) -> some View {
if isLoading {
ZStack {
content

if isLoading {
RippleSpinnerView()
}
}
} else {
content
}
}
}

extension View {
func showRippleSpinner(isLoading: Binding<Bool>) -> some View {
self.modifier(RippleSpinnerModifier(isLoading: isLoading))
}
}
81 changes: 38 additions & 43 deletions mobile-courier-app/Presentation/Login/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,52 @@ struct LoginView: View {
@EnvironmentObject var coordinator: Coordinator

public var body: some View {
ZStack {
VStack(spacing: 16) {
Spacer()
Image("logo")
.resizable()
.renderingMode(.template)
.foregroundStyle(.accent)
.aspectRatio(contentMode: .fit)
.padding(.bottom, 16)
VStack(spacing: 16) {
Spacer()
Image("logo")
.resizable()
.renderingMode(.template)
.foregroundStyle(.accent)
.aspectRatio(contentMode: .fit)
.padding(.bottom, 16)

TextField("Email", text: $viewModel.email)
.focused($focusField, equals: .email)
.textFieldStyle(CourierTextFieldStyle())
.keyboardType(.emailAddress)
.autocorrectionDisabled()
.autocapitalization(.none)
.submitLabel(.next)
.onSubmit {
focusField = .password
}

SecureField("Password", text: $viewModel.password)
.focused($focusField, equals: .password)
.textFieldStyle(CourierTextFieldStyle())
.submitLabel(.done)
.textContentType(.password)
.onSubmit {
navigateToLogin()
}
TextField("Email", text: $viewModel.email)
.focused($focusField, equals: .email)
.textFieldStyle(CourierTextFieldStyle())
.keyboardType(.emailAddress)
.autocorrectionDisabled()
.autocapitalization(.none)
.submitLabel(.next)
.onSubmit {
focusField = .password
}

Button("Log In") {
SecureField("Password", text: $viewModel.password)
.focused($focusField, equals: .password)
.textFieldStyle(CourierTextFieldStyle())
.submitLabel(.done)
.textContentType(.password)
.onSubmit {
navigateToLogin()
}
.frame(maxWidth: .infinity, minHeight: 44)
.background(
viewModel.buttonIsEnabled
? .accent
: .accent.opacity(0.6)
)
.foregroundStyle(.white)
.cornerRadius(16)
.disabled(!viewModel.buttonIsEnabled)

Spacer()
Button("Log In") {
navigateToLogin()
}
.padding(20)
.frame(maxWidth: .infinity, minHeight: 44)
.background(
viewModel.buttonIsEnabled
? .accent
: .accent.opacity(0.6)
)
.foregroundStyle(.white)
.cornerRadius(16)
.disabled(!viewModel.buttonIsEnabled)

if viewModel.isLoading {
RippleSpinnerView()
}
Spacer()
}
.padding(20)
.showRippleSpinner(isLoading: $viewModel.isLoading)
.toast(message: $viewModel.toastMessage)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ struct PackagesForWithdrawalView: View {
if let groupedPackagesEntity = viewModel.groupedPackagesEntity {
content(for: groupedPackagesEntity)
}

if viewModel.isLoading {
RippleSpinnerView()
}
}
.onAppear {
Task {
await viewModel.getPackages()
}
}
.showRippleSpinner(isLoading: $viewModel.isLoading)
.toast(message: $viewModel.toastMessage)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ struct WithdrawnPackagesView: View {
if let groupedPackagesEntity = viewModel.groupedPackagesEntity {
content(for: groupedPackagesEntity)
}

if viewModel.isLoading {
RippleSpinnerView()
}
}
.onAppear {
Task {
await viewModel.getPackages()
}
}
.showRippleSpinner(isLoading: $viewModel.isLoading)
.toast(message: $viewModel.toastMessage)
}

Expand Down

0 comments on commit 7d6b701

Please sign in to comment.