This commit is contained in:
Max Goedjen 2020-09-19 16:51:00 -07:00
parent 3b093379b8
commit d1a2ae79bf
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8

View File

@ -52,17 +52,21 @@ struct CopyableView: View {
HStack { HStack {
image image
.renderingMode(.template) .renderingMode(.template)
.imageScale(.large)
.foregroundColor(primaryTextColor) .foregroundColor(primaryTextColor)
Text(title) Text(title)
.font(.headline) .font(.headline)
.foregroundColor(primaryTextColor) .foregroundColor(primaryTextColor)
Spacer() Spacer()
if interactionState != .normal {
Text(hoverText) Text(hoverText)
.bold() .bold()
.textCase(.uppercase) .textCase(.uppercase)
.foregroundColor(secondaryTextColor) .foregroundColor(secondaryTextColor)
.transition(.opacity) .transition(.opacity)
} }
}
.padding(EdgeInsets(top: 20, leading: 20, bottom: 10, trailing: 20)) .padding(EdgeInsets(top: 20, leading: 20, bottom: 10, trailing: 20))
Divider() Divider()
Text(text) Text(text)
@ -71,25 +75,30 @@ struct CopyableView: View {
.multilineTextAlignment(.leading) .multilineTextAlignment(.leading)
.font(.system(.body, design: .monospaced)) .font(.system(.body, design: .monospaced))
} }
.frame(minWidth: 150, maxWidth: .infinity)
.background(backgroundColor) .background(backgroundColor)
.frame(minWidth: 150, maxWidth: .infinity)
.cornerRadius(10) .cornerRadius(10)
.onHover { hovering in .onHover { hovering in
withAnimation {
interactionState = hovering ? .hovering : .normal interactionState = hovering ? .hovering : .normal
} }
}
.onDrag { .onDrag {
NSItemProvider(item: NSData(data: text.data(using: .utf8)!), typeIdentifier: kUTTypeUTF8PlainText as String) NSItemProvider(item: NSData(data: text.data(using: .utf8)!), typeIdentifier: kUTTypeUTF8PlainText as String)
} }
.animation(.spring())
.onTapGesture { .onTapGesture {
copy() copy()
withAnimation {
interactionState = .clicking interactionState = .clicking
} }
}
.gesture( .gesture(
TapGesture() TapGesture()
.onEnded { .onEnded {
withAnimation {
interactionState = .normal interactionState = .normal
} }
}
) )
} }
@ -100,9 +109,8 @@ struct CopyableView: View {
case .clicking: case .clicking:
return "Copied!" return "Copied!"
case .normal: case .normal:
return "" fatalError()
} }
} }
var backgroundColor: Color { var backgroundColor: Color {