State 2.swift 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import UIKit
  2. // MARK: - State
  3. /// Barcode scanner state.
  4. enum State {
  5. case scanning
  6. case processing
  7. case unauthorized
  8. case notFound
  9. }
  10. /// State message provider.
  11. public struct StateMessageProvider {
  12. public var scanningText = localizedString("INFO_DESCRIPTION_TEXT")
  13. public var processingText = localizedString("INFO_LOADING_TITLE")
  14. public var unathorizedText = localizedString("ASK_FOR_PERMISSION_TEXT")
  15. public var notFoundText = localizedString("NO_PRODUCT_ERROR_TITLE")
  16. func makeText(for state: State) -> String {
  17. switch state {
  18. case .scanning:
  19. return scanningText
  20. case .processing:
  21. return processingText
  22. case .unauthorized:
  23. return unathorizedText
  24. case .notFound:
  25. return notFoundText
  26. }
  27. }
  28. }
  29. // MARK: - Status
  30. /// Status is a holder of the current state with a few additional configuration properties.
  31. struct Status {
  32. /// The current state.
  33. let state: State
  34. /// Flag to enable/disable animation.
  35. let animated: Bool
  36. /// Text that overrides a text from the state.
  37. let text: String?
  38. /**
  39. Creates a new instance of `Status`.
  40. - Parameter state: State value.
  41. - Parameter animated: Flag to enable/disable animation.
  42. - Parameter text: Text that overrides a text from the state.
  43. */
  44. init(state: State, animated: Bool = true, text: String? = nil) {
  45. self.state = state
  46. self.animated = animated
  47. self.text = text
  48. }
  49. }