react-native-marquee-animation 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,7 @@ import android.view.VelocityTracker
11
11
  import android.view.View
12
12
  import android.view.ViewConfiguration
13
13
  import android.view.ViewGroup
14
+ import android.view.ViewTreeObserver
14
15
  import com.facebook.react.uimanager.PixelUtil
15
16
  import kotlin.math.abs
16
17
  import kotlin.math.hypot
@@ -39,6 +40,13 @@ class MarqueeView : ViewGroup, Choreographer.FrameCallback {
39
40
  private var pressContentX: Double? = null
40
41
  private val resumeRunnable = Runnable { reconcileMotionState() }
41
42
 
43
+ // doFrame stops the loop while the view is scrolled fully out of view, and
44
+ // scrolling an ancestor changes no prop, layout or visibility. Restart the
45
+ // loop on the next scroll that could bring it back.
46
+ private val scrollChangedListener = ViewTreeObserver.OnScrollChangedListener {
47
+ if (motion.isFrameDriven() && shouldScheduleMotion()) postFrame()
48
+ }
49
+
42
50
  init {
43
51
  setWillNotDraw(false)
44
52
  clipChildren = false
@@ -47,6 +55,8 @@ class MarqueeView : ViewGroup, Choreographer.FrameCallback {
47
55
  importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_YES
48
56
  }
49
57
 
58
+ internal val testingPhasePx: Double get() = motion.phasePx
59
+
50
60
  internal fun setEventListener(listener: MarqueeEventListener?) {
51
61
  eventListener = listener
52
62
  }
@@ -226,12 +236,14 @@ class MarqueeView : ViewGroup, Choreographer.FrameCallback {
226
236
 
227
237
  override fun onAttachedToWindow() {
228
238
  super.onAttachedToWindow()
239
+ viewTreeObserver.addOnScrollChangedListener(scrollChangedListener)
229
240
  attachedAndVisible = isShown
230
241
  reconcileMotionState()
231
242
  }
232
243
 
233
244
  override fun onDetachedFromWindow() {
234
245
  attachedAndVisible = false
246
+ viewTreeObserver.removeOnScrollChangedListener(scrollChangedListener)
235
247
  removeCallbacks(resumeRunnable)
236
248
  stopFrames()
237
249
  motion.pause()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-marquee-animation",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Production-grade generic native marquee for React Native",
5
5
  "main": "./lib/module/index.js",
6
6
  "react-native": "./src/index.ts",