Skip to content

Commit

Permalink
Merge branch '334-authentication-form-ui-building' of https://github.…
Browse files Browse the repository at this point in the history
…com/GSM-MSG/SMS-iOS into 334-authentication-form-ui-building
  • Loading branch information
kimsh153 committed Jun 8, 2024
2 parents 40015e8 + 79491e2 commit 27089f1
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "file.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "xmark.svg",
"filename" : "Xmark.svg",
"idiom" : "universal"
}
],
Expand Down
64 changes: 64 additions & 0 deletions Projects/Core/DesignSystem/Sources/File/SMSFileField.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import SwiftUI
import ViewUtil
import UniformTypeIdentifiers

public struct SMSFileField: View {
private let placeholder: String?
private let fileText: String?
@State private var isShow: Bool = false
private let isError: Bool
private let errorText: String
private let allowedContentTypes: [UTType]
private let action: (Result<URL, Error>) -> Void

public init(
_ placeholder: String? = nil,
fileText: String?,
isError: Bool = false,
errorText: String = "",
allowedContentTypes: [UTType] = [.content],
action: @escaping (Result<URL, Error>) -> Void
) {
self.placeholder = placeholder
self.fileText = fileText
self.isError = isError
self.errorText = errorText
self.allowedContentTypes = allowedContentTypes
self.action = action
}

public var body: some View {
SMSTextField(
placeholder ?? "",
text: Binding(
get: { fileText ?? "" },
set: { _ in }
),
errorText: errorText,
isError: isError,
isOnClear: false
)
.disabled(true)
.overlay(alignment: .trailing) {
SMSIcon(.file)
.padding(.trailing, 12)
}
.simultaneousGesture(
TapGesture()
.onEnded {
self.isShow = true
}
)
.fileImporter(
isPresented: Binding(
get: { isShow },
set: { active in
isShow = active
}
),
allowedContentTypes: allowedContentTypes
) { result in
action(result)
}
}
}
4 changes: 4 additions & 0 deletions Projects/Core/DesignSystem/Sources/Icon/SMSIcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public struct SMSIcon: View {
case check
case checkmark
case downChevron
case file
case filter
case greenCheck
case photo
Expand Down Expand Up @@ -74,6 +75,9 @@ public struct SMSIcon: View {
case .downChevron:
return DesignSystemAsset.Icons.downChevron.swiftUIImage

case .file:
return DesignSystemAsset.Icons.file.swiftUIImage

case .filter:
return DesignSystemAsset.Icons.filter.swiftUIImage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct SMSTextEditor: View {
.onSubmit(onSubmit)
.smsFont(.body1, color: .neutral(.n50))
.focused($isFocused)

SMSIcon(.xmark)
.buttonWrapper {
text = ""
Expand All @@ -54,7 +54,7 @@ public struct SMSTextEditor: View {
.onTapGesture {
isFocused = true
}

if text.isEmpty {
Text(placeholder)
.smsFont(.body1, color: .neutral(.n30))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,17 @@ struct GSMAuthenticationFormBuilderView: View {
placeholder: String?,
fileName: String?
) -> some View {
SMSTextField(
placeholder ?? "",
text: Binding(
get: { fileName ?? "" },
set: { _ in }
)
)
.disabled(true)
.overlay(alignment: .trailing) {
SMSIcon(.downChevron)
.padding(.trailing, 12)
SMSFileField(
placeholder,
fileText: fileName
) { result in
switch result {
case let .success(url):
onFieldInteraction(.fieldChanges(key: key, fieldChanges: .file(url)))

default:
return
}
}
}

Expand Down

0 comments on commit 27089f1

Please sign in to comment.