@@ -50,11 +50,13 @@ private fun rectsOverlap(rect1: Rect, rect2: Rect): Boolean {
5050internal  class  VirtualViewContainerState  {
5151
5252  private  val  prerenderRatio:  Double  =  ReactNativeFeatureFlags .virtualViewPrerenderRatio()
53+   private  val  hysteresisRatio:  Double  =  ReactNativeFeatureFlags .virtualViewHysteresisRatio()
5354
5455  private  val  virtualViews:  MutableSet <VirtualView > =  mutableSetOf ()
5556  private  val  emptyRect:  Rect  =  Rect ()
5657  private  val  visibleRect:  Rect  =  Rect ()
5758  private  val  prerenderRect:  Rect  =  Rect ()
59+   private  val  hysteresisRect:  Rect  =  Rect ()
5860  private  val  onWindowFocusChangeListener = 
5961      if  (ReactNativeFeatureFlags .enableVirtualViewWindowFocusDetection()) {
6062        ViewTreeObserver .OnWindowFocusChangeListener  {
@@ -124,7 +126,7 @@ internal class VirtualViewContainerState {
124126    virtualViewsIt.forEach { vv -> 
125127      val  rect =  vv.containerRelativeRect
126128
127-       var  mode =  VirtualViewMode .Hidden 
129+       var  mode:   VirtualViewMode ?  =  VirtualViewMode .Hidden 
128130      var  thresholdRect =  emptyRect
129131      when  {
130132        rectsOverlap(rect, visibleRect) ->  {
@@ -143,14 +145,29 @@ internal class VirtualViewContainerState {
143145          mode =  VirtualViewMode .Prerender 
144146          thresholdRect =  prerenderRect
145147        }
146-         else  ->  {}
148+         else  ->  {
149+           if  (hysteresisRatio >  0.0 ) {
150+             hysteresisRect.set(prerenderRect)
151+             hysteresisRect.inset(
152+                 (- visibleRect.width() *  hysteresisRatio).toInt(),
153+                 (- visibleRect.height() *  hysteresisRatio).toInt(),
154+             )
155+             if  (rectsOverlap(rect, hysteresisRect)) {
156+               mode =  null 
157+             }
158+           }
159+         }
147160      }
148161
149-       debugLog(
150-           " updateModes" 
151-           { " virtualView=${vv.virtualViewID}  mode=$mode   rect=$rect  thresholdRect=$thresholdRect " 
152-       )
153-       vv.onModeChange(mode, thresholdRect)
162+       if  (mode !=  null ) {
163+         vv.onModeChange(mode, thresholdRect)
164+         debugLog(
165+             " updateModes" 
166+             {
167+               " virtualView=${vv.virtualViewID}  mode=$mode   rect=$rect  thresholdRect=$thresholdRect " 
168+             },
169+         )
170+       }
154171    }
155172  }
156173}
0 commit comments