Skip to content

Commit

Permalink
Add some additional logging logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kkafar committed Nov 21, 2024
1 parent 21bbf56 commit 8023b6e
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.swmansion.rnscreens

import android.util.Log
import android.view.View
import androidx.core.view.OnApplyWindowInsetsListener
import androidx.core.view.ViewCompat
Expand All @@ -17,6 +18,10 @@ object InsetsObserverProxy : OnApplyWindowInsetsListener, LifecycleEventListener
// whether this observer has been initially registered.
private var hasBeenRegistered: Boolean = false

// Mainly debug variable to log warnings in case we missed some code path regarding
// context lifetime handling.
private var isObservingContextLifetime: Boolean = false

private var shouldForwardInsetsToView = true

// Allow only when we have not been registered yet or the view we're observing has been
Expand All @@ -43,6 +48,14 @@ object InsetsObserverProxy : OnApplyWindowInsetsListener, LifecycleEventListener
// Call this method to ensure that the observer proxy is
// unregistered when apps is destroyed or we change activity.
fun registerWithContext(context: ReactApplicationContext) {
if (isObservingContextLifetime) {
Log.w(
"[RNScreens]",
"InsetObserverProxy registers on new context while it has not been invalidated on the old one. Please report this as issue at https://github.com/software-mansion/react-native-screens/issues",
)
}

isObservingContextLifetime = true
context.addLifecycleEventListener(this)
}

Expand All @@ -57,6 +70,7 @@ object InsetsObserverProxy : OnApplyWindowInsetsListener, LifecycleEventListener
hasBeenRegistered = false
eventSourceView.clear()
}
isObservingContextLifetime = false
}

fun addOnApplyWindowInsetsListener(listener: OnApplyWindowInsetsListener) {
Expand Down

0 comments on commit 8023b6e

Please sign in to comment.