generated from GSM-MSG/MSG-Repository-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #331 from GSM-MSG/330-design-system-file-field
🔀 :: [#330] DesignSystem / FileField
- Loading branch information
Showing
5 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
Projects/Core/DesignSystem/Resources/Icon/Icons.xcassets/File.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Projects/Core/DesignSystem/Resources/Icon/Icons.xcassets/File.imageset/file.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import SwiftUI | ||
import ViewUtil | ||
import UniformTypeIdentifiers | ||
|
||
public struct FileField: View { | ||
@State var fileText: String | ||
@State var isShow: Bool | ||
@State var isError: Bool | ||
let errorText: String | ||
let allowedContentTypes: [UTType] | ||
let action: (URL) -> Void | ||
|
||
public init( | ||
fileText: String, | ||
isShow: Bool, | ||
isError: Bool = false, | ||
errorText: String = "", | ||
allowedContentTypes: [UTType] = [.content], | ||
action: @escaping (URL) -> Void | ||
) { | ||
self.fileText = fileText | ||
self.isShow = isShow | ||
self.isError = isError | ||
self.errorText = errorText | ||
self.allowedContentTypes = allowedContentTypes | ||
self.action = action | ||
} | ||
|
||
public var body: some View { | ||
SMSTextField( | ||
"", | ||
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 | ||
switch result { | ||
case .success(let url): | ||
fileText = url.lastPathComponent | ||
action(url) | ||
|
||
case .failure: | ||
self.isError = true | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters