LiTranslate-iOS/LiTranslate/Presentation/Component/Languages/InputTranslationView.swift

53 lines
1.7 KiB
Swift
Raw Permalink Normal View History

2022-09-10 19:46:05 +02:00
//
// InputTranslationView.swift
// LiTranslate
//
// Created by Viktor Kalyniuk on 13.08.2022.
//
import SwiftUI
struct InputTranslationView: View, KeyboardReadable {
@EnvironmentObject private var selection: LanguagesSelection
@EnvironmentObject private var textData: TextData
@State private var isKeyboardVisible: Bool = false
var body: some View {
VStack(alignment: .leading) {
ChooseLanguagesView()
.padding()
.background(Colors.Background.chooseLanguageView.ignoresSafeArea())
HStack(alignment: .top) {
TextEditor(text: $textData.input)
.modifier(ScrollContentBackgroundModifier())
2022-09-10 19:46:05 +02:00
.padding([.leading, .trailing])
.onReceive(keyboardPublisher) { isVisible in
isKeyboardVisible = isVisible
}
Button {
textData.input = ""
textData.output = ""
} label: {
Image(systemName: SystemNames.closeCircleFill)
}
.opacity(
Double(textData.input.isEmpty ?
Numbers.zero : Numbers.one))
.padding([.top, .trailing])
}
InputBottomButtons(isKeyboardVisible: $isKeyboardVisible)
}
.background(Colors.Background.primaryView)
.cornerRadius(CGFloat(Numbers.twentyFive))
}
}
struct InputTranslationView_Previews: PreviewProvider {
static var previews: some View {
InputTranslationView()
.environmentObject(LanguagesSelection())
.environmentObject(TextData())
}
}