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.

49 lines
1.5 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. //
  2. // AnimationKeypath.swift
  3. // lottie-swift
  4. //
  5. // Created by Brandon Withrow on 2/4/19.
  6. //
  7. import Foundation
  8. /// `AnimationKeypath` is an object that describes a keypath search for nodes in the
  9. /// animation JSON. `AnimationKeypath` matches views and properties inside of `AnimationView`
  10. /// to their backing `Animation` model by name.
  11. ///
  12. /// A keypath can be used to set properties on an existing animation, or can be validated
  13. /// with an existing `Animation`.
  14. ///
  15. /// `AnimationKeypath` can describe a specific object, or can use wildcards for fuzzy matching
  16. /// of objects. Acceptable wildcards are either "*" (star) or "**" (double star).
  17. /// Single star will search a single depth for the next object.
  18. /// Double star will search any depth.
  19. ///
  20. /// Read More at https://airbnb.io/lottie/#/ios?id=dynamic-animation-properties
  21. ///
  22. /// EG:
  23. /// @"Layer.Shape Group.Stroke 1.Color"
  24. /// Represents a specific color node on a specific stroke.
  25. ///
  26. /// @"**.Stroke 1.Color"
  27. /// Represents the color node for every Stroke named "Stroke 1" in the animation.
  28. public struct AnimationKeypath: Hashable, ExpressibleByStringLiteral {
  29. /// Creates a keypath from a dot-separated string. The string is separated by "."
  30. public init(keypath: String) {
  31. keys = keypath.components(separatedBy: ".")
  32. }
  33. /// Creates a keypath from a dot-separated string
  34. public init(stringLiteral: String) {
  35. self.init(keypath: stringLiteral)
  36. }
  37. /// Creates a keypath from a list of strings.
  38. public init(keys: [String]) {
  39. self.keys = keys
  40. }
  41. var keys: [String]
  42. }