<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rubydog</title>
    <description>The latest articles on DEV Community by Rubydog (@rbdog).</description>
    <link>https://dev.to/rbdog</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F664507%2Fe70f5a08-a38c-4ae9-ba67-922309cef252.png</url>
      <title>DEV Community: Rubydog</title>
      <link>https://dev.to/rbdog</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rbdog"/>
    <language>en</language>
    <item>
      <title>count increasing text</title>
      <dc:creator>Rubydog</dc:creator>
      <pubDate>Sat, 10 Jul 2021 01:52:56 +0000</pubDate>
      <link>https://dev.to/rbdog/count-increasing-text-43ao</link>
      <guid>https://dev.to/rbdog/count-increasing-text-43ao</guid>
      <description>&lt;p&gt;Hello, great hackers. I'm a Japanese dog.&lt;br&gt;&lt;br&gt;
Please use my trivial "AnimationReader" to animate text, with dinamic number.&lt;br&gt;&lt;br&gt;
such as increasing count, or to control state of somethting.&lt;/p&gt;
&lt;h2&gt;
  
  
  ContentView.swift
&lt;/h2&gt;

&lt;p&gt;Sample&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import SwiftUI
struct ContentView: View {
    @State var count: Int = 0
    var body: some View {

        // observe count
        AnimationReader(count) { value in
            // use value instead of raw count
            Text("total: \(value)")
        }

        // test
        .onAppear {
            withAnimation(.easeInOut(duration: 10)) {
                count += 99
            }
        }
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  AnimationReader.swift
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import SwiftUI

fileprivate struct AnimationReaderModifier&amp;lt;Body: View&amp;gt;: AnimatableModifier {
    let content: (CGFloat) -&amp;gt; Body
    var animatableData: CGFloat

    init(value: CGFloat, @ViewBuilder content: @escaping (CGFloat) -&amp;gt; Body) {
        self.animatableData = value
        self.content = content
    }

    func body(content: Content) -&amp;gt; Body {
        self.content(animatableData)
    }
}

struct AnimationReader&amp;lt;Content: View&amp;gt;: View {

    let value: CGFloat
    let content: (_ animatingValue: CGFloat) -&amp;gt; Content

    init(_ observedValue: Int, @ViewBuilder content: @escaping (_ animatingValue: Int) -&amp;gt; Content) {
        self.value = CGFloat(observedValue)
        self.content = { value in content(Int(value)) }
    }

    init(_ observedValue: CGFloat, @ViewBuilder content: @escaping (_ animatingValue: CGFloat) -&amp;gt; Content) {
        self.value = observedValue
        self.content = content
    }

    var body: some View {
        EmptyView()
            .modifier(AnimationReaderModifier(value: value, content: content))
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks to read&lt;/p&gt;

</description>
      <category>swiftui</category>
      <category>swift</category>
    </item>
  </channel>
</rss>
