Skip to content

Instantly share code, notes, and snippets.

@kieranb662
Last active July 23, 2024 15:19
Show Gist options
  • Select an option

  • Save kieranb662/c254ec73a6121ce1f88f60e4a1f9a082 to your computer and use it in GitHub Desktop.

Select an option

Save kieranb662/c254ec73a6121ce1f88f60e4a1f9a082 to your computer and use it in GitHub Desktop.

Revisions

  1. kieranb662 renamed this gist Jun 29, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. kieranb662 renamed this gist Jun 29, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. kieranb662 revised this gist Jun 29, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Examples.md
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    ![Circle Pulse](https://github.com/kieranb662/kieranb662.github.io/blob/master/assets/PulseSheen/CirclePulse.gif)
    ![Circle Pulse](https://raw.githubusercontent.com/kieranb662/kieranb662.github.io/master/assets/PulseSheen/SquarePulse.gif)
  4. kieranb662 revised this gist Jun 29, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Examples.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ![Circle Pulse](https://github.com/kieranb662/kieranb662.github.io/blob/master/assets/PulseSheen/CirclePulse.gif)
  5. kieranb662 revised this gist Jun 29, 2020. No changes.
  6. kieranb662 revised this gist Jun 29, 2020. No changes.
  7. kieranb662 revised this gist Apr 27, 2020. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Pulse.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    // Kieran Brown
    // Kieran's Components "Pulse and Sheen"
    // https://kieranb662.github.io/blog/2020/04/17/Pulse-and-Sheen

    struct PulseEffect<S: Shape>: ViewModifier {
    var shape: S
    @State var isOn: Bool = false
  8. kieranb662 created this gist Apr 27, 2020.
    33 changes: 33 additions & 0 deletions Pulse.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    struct PulseEffect<S: Shape>: ViewModifier {
    var shape: S
    @State var isOn: Bool = false
    var animation: Animation {
    Animation
    .easeIn(duration: 1)
    .repeatCount(8, autoreverses: false)
    }

    func body(content: Content) -> some View {
    content
    .background(
    ZStack {
    shape
    .stroke(Color.yellow, lineWidth: 1)
    .scaleEffect(self.isOn ? 2 : 1)
    .opacity(self.isOn ? 0 : 1)
    shape
    .stroke(Color.blue)
    })
    .onAppear {
    withAnimation(self.animation) {
    self.isOn = true
    }
    }
    }
    }

    public extension View {
    func pulse<S: Shape>(_ shape: S) -> some View {
    self.modifier(PulseEffect(shape: shape))
    }
    }