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.

129 lines
3.9 KiB

  1. // The MIT License (MIT)
  2. //
  3. // Copyright (c) 2016 Luke Zhao <me@lkzhao.com>
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. import UIKit
  23. public enum HeroSnapshotType {
  24. /// Will optimize for different type of views
  25. /// For custom views or views with masking, .optimizedDefault might create snapshots
  26. /// that appear differently than the actual view.
  27. /// In that case, use .normal or .slowRender to disable the optimization
  28. case optimized
  29. /// snapshotView(afterScreenUpdates:)
  30. case normal
  31. /// layer.render(in: currentContext)
  32. case layerRender
  33. /// will not create snapshot. animate the view directly.
  34. /// This will mess up the view hierarchy, therefore, view controllers have to rebuild
  35. /// its view structure after the transition finishes
  36. case noSnapshot
  37. }
  38. public enum HeroCoordinateSpace {
  39. case global
  40. case local
  41. }
  42. public struct HeroTargetState {
  43. public var beginState: [HeroModifier]?
  44. public var conditionalModifiers: [((HeroConditionalContext) -> Bool, [HeroModifier])]?
  45. public var position: CGPoint?
  46. public var size: CGSize?
  47. public var transform: CATransform3D?
  48. public var opacity: Float?
  49. public var cornerRadius: CGFloat?
  50. public var backgroundColor: CGColor?
  51. public var zPosition: CGFloat?
  52. public var contentsRect: CGRect?
  53. public var contentsScale: CGFloat?
  54. public var borderWidth: CGFloat?
  55. public var borderColor: CGColor?
  56. public var shadowColor: CGColor?
  57. public var shadowOpacity: Float?
  58. public var shadowOffset: CGSize?
  59. public var shadowRadius: CGFloat?
  60. public var shadowPath: CGPath?
  61. public var masksToBounds: Bool?
  62. public var displayShadow: Bool = true
  63. public var overlay: (color: CGColor, opacity: CGFloat)?
  64. public var spring: (CGFloat, CGFloat)?
  65. public var delay: TimeInterval = 0
  66. public var duration: TimeInterval?
  67. public var timingFunction: CAMediaTimingFunction?
  68. public var arc: CGFloat?
  69. public var source: String?
  70. public var cascade: (TimeInterval, CascadeDirection, Bool)?
  71. public var ignoreSubviewModifiers: Bool?
  72. public var coordinateSpace: HeroCoordinateSpace?
  73. public var useScaleBasedSizeChange: Bool?
  74. public var snapshotType: HeroSnapshotType?
  75. public var nonFade: Bool = false
  76. public var forceAnimate: Bool = false
  77. public var custom: [String: Any]?
  78. init(modifiers: [HeroModifier]) {
  79. append(contentsOf: modifiers)
  80. }
  81. public mutating func append(_ modifier: HeroModifier) {
  82. modifier.apply(&self)
  83. }
  84. public mutating func append(contentsOf modifiers: [HeroModifier]) {
  85. for modifier in modifiers {
  86. modifier.apply(&self)
  87. }
  88. }
  89. /**
  90. - Returns: custom item for a specific key
  91. */
  92. public subscript(key: String) -> Any? {
  93. get {
  94. return custom?[key]
  95. }
  96. set {
  97. if custom == nil {
  98. custom = [:]
  99. }
  100. custom![key] = newValue
  101. }
  102. }
  103. }
  104. extension HeroTargetState: ExpressibleByArrayLiteral {
  105. public init(arrayLiteral elements: HeroModifier...) {
  106. append(contentsOf: elements)
  107. }
  108. }