LineSDKFlexBubbleContainer.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // LineSDKFlexBubbleContainer.swift
  3. //
  4. // Copyright (c) 2016-present, LY Corporation. All rights reserved.
  5. //
  6. // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  7. // copy and distribute this software in source code or binary form for use
  8. // in connection with the web services and APIs provided by LY Corporation.
  9. //
  10. // As with any software that integrates with the LY Corporation platform, your use of this software
  11. // is subject to the LINE Developers Agreement [http://terms2.line.me/LINE_Developers_Agreement].
  12. // This copyright notice shall be included in all copies or substantial portions of the software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  15. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. @objcMembers
  22. public class LineSDKFlexBubbleContainer: LineSDKFlexMessageContainer {
  23. public var header: LineSDKFlexBoxComponent?
  24. public var hero: LineSDKFlexImageComponent?
  25. public var body: LineSDKFlexBoxComponent?
  26. public var footer: LineSDKFlexBoxComponent?
  27. public var style: LineSDKFlexBubbleContainerStyle?
  28. public var direction: LineSDKFlexBubbleContainerDirection = .none
  29. public override init() { }
  30. convenience init(_ value: FlexBubbleContainer) {
  31. self.init()
  32. header = value.header.map { .init($0) }
  33. hero = value.hero.map { .init($0) }
  34. body = value.body.map { .init($0) }
  35. footer = value.footer.map { .init($0) }
  36. style = value.styles.map { .init($0) }
  37. direction = .init(value.direction)
  38. }
  39. override var unwrapped: FlexMessageContainer {
  40. var container = FlexBubbleContainer(
  41. header: header?.component,
  42. hero: hero?.component,
  43. body: body?.component,
  44. footer: footer?.component,
  45. styles: style?.unwrapped)
  46. container.direction = direction.unwrapped
  47. return .bubble(container)
  48. }
  49. var bubble: FlexBubbleContainer {
  50. return FlexBubbleContainer(header: nil, hero: nil, body: nil, footer: nil, styles: nil)
  51. }
  52. }
  53. @objcMembers
  54. public class LineSDKFlexBubbleContainerStyle: NSObject {
  55. public var header: LineSDKFlexBlockStyle?
  56. public var hero: LineSDKFlexBlockStyle?
  57. public var body: LineSDKFlexBlockStyle?
  58. public var footer: LineSDKFlexBlockStyle?
  59. public override init() {}
  60. public convenience init(_ value: FlexBubbleContainer.Style) {
  61. self.init()
  62. self.header = value.header.map { .init($0) }
  63. self.hero = value.hero.map { .init($0) }
  64. self.body = value.body.map { .init($0) }
  65. self.footer = value.footer.map { .init($0) }
  66. }
  67. var unwrapped: FlexBubbleContainer.Style {
  68. var style = FlexBubbleContainer.Style()
  69. style.header = header?.unwrapped
  70. style.hero = hero?.unwrapped
  71. style.body = body?.unwrapped
  72. style.footer = footer?.unwrapped
  73. return style
  74. }
  75. }
  76. @objc
  77. public enum LineSDKFlexBubbleContainerDirection: Int {
  78. case none
  79. case leftToRight
  80. case rightToLeft
  81. var unwrapped: FlexBubbleContainer.Direction? {
  82. switch self {
  83. case .none: return nil
  84. case .leftToRight: return .leftToRight
  85. case .rightToLeft: return .rightToLeft
  86. }
  87. }
  88. init(_ value: FlexBubbleContainer.Direction?) {
  89. switch value {
  90. case .leftToRight?: self = .leftToRight
  91. case .rightToLeft?: self = .rightToLeft
  92. case nil: self = .none
  93. }
  94. }
  95. }
  96. @objcMembers
  97. public class LineSDKFlexBlockStyle: NSObject {
  98. public var backgroundColor: LineSDKHexColor?
  99. public var separator: Bool
  100. public var separatorColor: LineSDKHexColor?
  101. public init(backgroundColor: LineSDKHexColor?, separator: Bool, separatorColor: LineSDKHexColor?) {
  102. self.backgroundColor = backgroundColor
  103. self.separator = separator
  104. self.separatorColor = separatorColor
  105. }
  106. public convenience init(_ value: FlexBlockStyle) {
  107. self.init(
  108. backgroundColor: value.backgroundColor.map { .init($0) },
  109. separator: value.separator ?? false,
  110. separatorColor: value.separatorColor.map { .init($0) })
  111. }
  112. var unwrapped: FlexBlockStyle {
  113. return FlexBlockStyle(
  114. backgroundColor: backgroundColor?.unwrapped,
  115. separator: separator,
  116. separatorColor: separatorColor?.unwrapped)
  117. }
  118. }