Skip to content

Instantly share code, notes, and snippets.

@Nomad-Go
Created November 30, 2020 02:01
Show Gist options
  • Save Nomad-Go/bf33979d79b1f5fe213bdce23d213ccb to your computer and use it in GitHub Desktop.
Save Nomad-Go/bf33979d79b1f5fe213bdce23d213ccb to your computer and use it in GitHub Desktop.
Cell for upload object.
public struct TransferableObjectCell: View {
//MARK: State and binding properties
var viewModel: S3Transferable
@State var progress: Double = 0
@State var status: AWSS3TransferUtilityTransferStatusType = AWSS3TransferUtilityTransferStatusType.unknown
//MARK: Computed Properties
//MARK: View conformance
public var body: some View {
HStack {
VStack(alignment: .leading) {
Text(self.viewModel.id.uuidString).font(.footnote)
Text(self.viewModel.objectCloudKey).font(.footnote)
Text(self.viewModel.status.value.toString())
}
Spacer()
switch self.viewModel.status.value {
case AWSS3TransferUtilityTransferStatusType.cancelled, AWSS3TransferUtilityTransferStatusType.error:
Image(systemName: "xmark.octagon.fill").resizable().frame(width: 55, height: 55).foregroundColor(Color.red)
case AWSS3TransferUtilityTransferStatusType.completed:
Image(systemName: "checkmark.circle.fill").resizable().frame(width: 55, height: 55).foregroundColor(Color.green)
case AWSS3TransferUtilityTransferStatusType.inProgress, AWSS3TransferUtilityTransferStatusType.paused, AWSS3TransferUtilityTransferStatusType.waiting:
ProgressBar(progress: self.$progress).frame(width: 55, height: 55)
case AWSS3TransferUtilityTransferStatusType.unknown:
Image(systemName: "questionmark.circle.fill").resizable().frame(width: 55, height: 55).foregroundColor(Color.gray)
@unknown default:
Image(systemName: "xmark.octagon.fill").resizable().frame(width: 55, height: 55).foregroundColor(Color.red)
}
}.padding().onReceive(self.viewModel.progress.receive(on: RunLoop.main)) { (newProgress) in
self.progress = newProgress
}.onReceive(self.viewModel.status.receive(on: RunLoop.main)) { (newStatus) in
self.status = newStatus
}
}
//MARK: Init
//MARK: Functions
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment