EmojiRow.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // EmojiRow.swift
  3. // LoopKitUI
  4. //
  5. // Created by Noah Brauner on 8/1/23.
  6. // Copyright © 2023 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. public struct EmojiRow: View {
  10. @Binding private var text: String
  11. @Binding private var isFocused: Bool
  12. private let emojiType: EmojiDataSourceType
  13. private let title: String
  14. public init(text: Binding<String>, isFocused: Binding<Bool>, emojiType: EmojiDataSourceType, title: String) {
  15. self._text = text
  16. self._isFocused = isFocused
  17. self.emojiType = emojiType
  18. self.title = title
  19. }
  20. public var body: some View {
  21. HStack {
  22. Text(title)
  23. .foregroundColor(.primary)
  24. Spacer()
  25. RowEmojiTextField(text: $text, isFocused: $isFocused, placeholder: SettingsTableViewCell.NoValueString, emojiType: emojiType)
  26. .onTapGesture {
  27. // so that row does not lose focus on cursor move
  28. if !isFocused {
  29. rowTapped()
  30. }
  31. }
  32. }
  33. .onTapGesture {
  34. rowTapped()
  35. }
  36. }
  37. private func rowTapped() {
  38. withAnimation {
  39. isFocused.toggle()
  40. }
  41. }
  42. }