From fc352c1c865fa96330f6005d9b48c1e5628d35d9 Mon Sep 17 00:00:00 2001 From: Borut Tomazin Date: Tue, 19 Sep 2023 21:25:21 +0200 Subject: [PATCH] Addressed PR comment. --- Sources/LinkedIn/LinkedInAuthenticator.swift | 2 +- Sources/LinkedIn/WebView/LinkedInSheet.swift | 59 +++++++++++--------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Sources/LinkedIn/LinkedInAuthenticator.swift b/Sources/LinkedIn/LinkedInAuthenticator.swift index 66aa6ed..cfb8ca7 100644 --- a/Sources/LinkedIn/LinkedInAuthenticator.swift +++ b/Sources/LinkedIn/LinkedInAuthenticator.swift @@ -39,7 +39,7 @@ extension LinkedInAuthenticator: Authenticator { storage.set(true, forKey: storageIsAuthenticatedKey) - let name = [profileResponse.localizedFirstName, profileResponse.localizedLastName].joined(separator: " ") + let name = "\(profileResponse.localizedFirstName) \(profileResponse.localizedLastName)" return Response( userId: profileResponse.id, token: authResponse.accessToken, diff --git a/Sources/LinkedIn/WebView/LinkedInSheet.swift b/Sources/LinkedIn/WebView/LinkedInSheet.swift index 5cb2bf1..aaf96fd 100644 --- a/Sources/LinkedIn/WebView/LinkedInSheet.swift +++ b/Sources/LinkedIn/WebView/LinkedInSheet.swift @@ -1,35 +1,40 @@ // // File.swift -// +// // // Created by Borut Tomazin on 04/09/2023. // import SwiftUI -//struct LinkedInSheet: ViewModifier { -// typealias SuccessHandler = (Bool) -> Void -// typealias ErrorHandler = (Error) -> Void -// let isPresented: Binding -// let onSuccess: SuccessHandler? -// let onError: ErrorHandler? -// -// func body(content: Content) -> some View { -// content -// .sheet(isPresented: isPresented) { -// LinkedInWebView { data in -// // Task { await viewModel.signInWithLinkedIn() } -// } onFailure: { -// // viewModel.error = .general -// } -// } -// } -//} -// -//extension View { -// func linkedInSheet(isPresented: Binding, -// onSuccess: LinkedInSheet.SuccessHandler? = nil, -// onError: LinkedInSheet.ErrorHandler? = nil) -> some View { -// modifier(LinkedInSheet(isPresented: isPresented, onSuccess: onSuccess, onError: onError)) -// } -//} +@available(iOS 15.0, *) +struct LinkedInSheet: ViewModifier { + typealias SuccessHandler = LinkedInWebView.SuccessHandler // (Bool) -> Void + typealias ErrorHandler = LinkedInWebView.ErrorHandler // (Error) -> Void + let config: LinkedInAuthenticator.Configuration + let isPresented: Binding + let onSuccess: SuccessHandler? + let onError: ErrorHandler? + + func body(content: Content) -> some View { + content + .sheet(isPresented: isPresented) { + LinkedInWebView(with: config) { data in + onSuccess?(data) + } onFailure: { + onError?() + } + } + } +} + +@available(iOS 15.0, *) +extension View { + /// ViewModifier to present `LinkedInWebView` in sheet + func linkedInSheet(with config: LinkedInAuthenticator.Configuration, + isPresented: Binding, + onSuccess: LinkedInSheet.SuccessHandler? = nil, + onError: LinkedInSheet.ErrorHandler? = nil) -> some View { + modifier(LinkedInSheet(config: config, isPresented: isPresented, onSuccess: onSuccess, onError: onError)) + } +}