You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
6.1 KiB

6 years ago
  1. // Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
  2. //
  3. // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  4. // copy, modify, and distribute this software in source code or binary form for use
  5. // in connection with the web services and APIs provided by Facebook.
  6. //
  7. // As with any software that integrates with the Facebook platform, your use of
  8. // this software is subject to the Facebook Developer Principles and Policies
  9. // [http://developers.facebook.com/policy/]. This copyright notice shall be
  10. // included in all copies or substantial portions of the software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. import FBSDKShareKit
  19. extension LikeControl {
  20. /**
  21. Specifies the style of the auxilary view in the like control.
  22. */
  23. public enum AuxilaryStyle {
  24. /// Use the standard social share message.
  25. case standard(horizontalAlignment: HorizontalAlignment, verticalAlignment: VerticalAlignment)
  26. /// Use a more compact box count auxilary view.
  27. case boxCount(horizontalAlignment: HorizontalAlignment, verticalAlignment: VerticalAlignment)
  28. /// The horizontal alignment of this style.
  29. public var horizontalAlignment: HorizontalAlignment {
  30. get {
  31. switch self {
  32. case .standard(let alignment): return alignment.horizontalAlignment
  33. case .boxCount(let alignment): return alignment.horizontalAlignment
  34. }
  35. }
  36. set {
  37. switch self {
  38. case .standard(let alignment):
  39. self = .standard(horizontalAlignment: newValue, verticalAlignment: alignment.verticalAlignment)
  40. case .boxCount(let alignment):
  41. self = .boxCount(horizontalAlignment: newValue, verticalAlignment: alignment.verticalAlignment)
  42. }
  43. }
  44. }
  45. /// The vertical alignment of this style.
  46. public var verticalAlignment: VerticalAlignment {
  47. get {
  48. switch self {
  49. case .standard(let alignment): return alignment.verticalAlignment
  50. case .boxCount(let alignment): return alignment.verticalAlignment
  51. }
  52. }
  53. set {
  54. switch self {
  55. case .standard(let alignment):
  56. self = .standard(horizontalAlignment: alignment.horizontalAlignment, verticalAlignment: newValue)
  57. case .boxCount(let alignment):
  58. self = .boxCount(horizontalAlignment: alignment.horizontalAlignment, verticalAlignment: newValue)
  59. }
  60. }
  61. }
  62. }
  63. }
  64. extension LikeControl.AuxilaryStyle: Equatable {
  65. /**
  66. Compare two `AuxilaryStyle`'s for equality.
  67. - parameter lhs: The first style to compare.
  68. - parameter rhs: The second style to compare.
  69. - returns: Whether or not the styles are equal.
  70. */
  71. public static func == (lhs: LikeControl.AuxilaryStyle, rhs: LikeControl.AuxilaryStyle) -> Bool {
  72. switch (lhs, rhs) {
  73. case (.standard(let lhs), .standard(let rhs)): return lhs == rhs
  74. case (.boxCount(let lhs), .boxCount(let rhs)): return lhs == rhs
  75. default: return false
  76. }
  77. }
  78. }
  79. extension LikeControl.AuxilaryStyle {
  80. internal init(sdkStyle: FBSDKLikeControlStyle,
  81. sdkHorizontalAlignment: FBSDKLikeControlHorizontalAlignment,
  82. sdkAuxilaryPosition: FBSDKLikeControlAuxiliaryPosition) {
  83. let horizontalAlignment = HorizontalAlignment(sdkHorizontalAlignment: sdkHorizontalAlignment)
  84. let verticalAlignment = VerticalAlignment(sdkAuxilaryPosition: sdkAuxilaryPosition)
  85. switch sdkStyle {
  86. case .standard: self = .standard(horizontalAlignment: horizontalAlignment, verticalAlignment: verticalAlignment)
  87. case .boxCount: self = .boxCount(horizontalAlignment: horizontalAlignment, verticalAlignment: verticalAlignment)
  88. }
  89. }
  90. internal var sdkStyleRepresentation: (FBSDKLikeControlStyle, FBSDKLikeControlHorizontalAlignment, FBSDKLikeControlAuxiliaryPosition) {
  91. switch self {
  92. case .standard(let horizontal, let vertical):
  93. return (.standard, horizontal.sdkHorizontalAlignment, vertical.sdkAuxilaryPosition)
  94. case .boxCount(let horizontal, let vertical):
  95. return (.boxCount, horizontal.sdkHorizontalAlignment, vertical.sdkAuxilaryPosition)
  96. }
  97. }
  98. }
  99. extension LikeControl.AuxilaryStyle {
  100. /**
  101. Control the horizontal alignment of the auxilary view.
  102. */
  103. public enum HorizontalAlignment {
  104. /// The auxilary view should be placed to the left of the like button.
  105. case left
  106. /// The auxilary view should be placed centered to the like button.
  107. case center
  108. /// The auxilary view should be placed to the right of the like button.
  109. case right
  110. internal init(sdkHorizontalAlignment: FBSDKLikeControlHorizontalAlignment) {
  111. switch sdkHorizontalAlignment {
  112. case .left: self = .left
  113. case .center: self = .center
  114. case .right: self = .right
  115. }
  116. }
  117. internal var sdkHorizontalAlignment: FBSDKLikeControlHorizontalAlignment {
  118. switch self {
  119. case .left: return .left
  120. case .center: return .center
  121. case .right: return .right
  122. }
  123. }
  124. }
  125. /**
  126. Controls vertical alignment of the auxilary view.
  127. */
  128. public enum VerticalAlignment {
  129. /// The auxilary view should be placed above the like button.
  130. case top
  131. /// The auxilary view should be placed inline with the like button.
  132. case inline
  133. /// The auxilary view should be placed below the like button.
  134. case bottom
  135. internal init(sdkAuxilaryPosition: FBSDKLikeControlAuxiliaryPosition) {
  136. switch sdkAuxilaryPosition {
  137. case .top: self = .top
  138. case .inline: self = .inline
  139. case .bottom: self = .bottom
  140. }
  141. }
  142. internal var sdkAuxilaryPosition: FBSDKLikeControlAuxiliaryPosition {
  143. switch self {
  144. case .top: return .top
  145. case .inline: return .inline
  146. case .bottom: return .bottom
  147. }
  148. }
  149. }
  150. }