Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #12725: Replace removed static "set", "get" methods of ViewTreeSa…
Browse files Browse the repository at this point in the history
…vedStateRegistryOwner.

ViewTreeSavedStateRegistryOwner is retrieved/set with new extension methods.
  • Loading branch information
mcarare authored and mergify[bot] committed Sep 6, 2022
1 parent bcfd0eb commit bd35438
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewTreeLifecycleOwner
import androidx.recyclerview.widget.RecyclerView
import androidx.savedstate.SavedStateRegistryOwner
import androidx.savedstate.ViewTreeSavedStateRegistryOwner
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
import org.mozilla.fenix.theme.FirefoxTheme
import org.mozilla.fenix.theme.Theme

Expand Down Expand Up @@ -48,8 +48,7 @@ abstract class ComposeViewHolder(
}

ViewTreeLifecycleOwner.set(composeView, viewLifecycleOwner)
ViewTreeSavedStateRegistryOwner.set(
composeView,
composeView.setViewTreeSavedStateRegistryOwner(
viewLifecycleOwner as SavedStateRegistryOwner
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.marginStart
import androidx.lifecycle.ViewTreeLifecycleOwner
import androidx.savedstate.ViewTreeSavedStateRegistryOwner
import androidx.savedstate.findViewTreeSavedStateRegistryOwner
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
import mozilla.components.support.ktx.android.util.dpToPx
import org.mozilla.fenix.compose.cfr.CFRPopup.IndicatorDirection.DOWN
import org.mozilla.fenix.compose.cfr.CFRPopup.IndicatorDirection.UP
Expand Down Expand Up @@ -106,7 +107,7 @@ internal class CFRPopupFullScreenLayout(

init {
ViewTreeLifecycleOwner.set(this, ViewTreeLifecycleOwner.get(anchor))
ViewTreeSavedStateRegistryOwner.set(this, ViewTreeSavedStateRegistryOwner.get(anchor))
this.setViewTreeSavedStateRegistryOwner(anchor.findViewTreeSavedStateRegistryOwner())
GeckoScreenOrientation.getInstance().addListener(orientationChangeListener)
anchor.addOnAttachStateChangeListener(anchorDetachedListener)
}
Expand Down Expand Up @@ -337,7 +338,7 @@ internal class CFRPopupFullScreenLayout(
GeckoScreenOrientation.getInstance().removeListener(orientationChangeListener)
disposeComposition()
ViewTreeLifecycleOwner.set(this, null)
ViewTreeSavedStateRegistryOwner.set(this, null)
this.setViewTreeSavedStateRegistryOwner(null)
windowManager.removeViewImmediate(this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewTreeLifecycleOwner
import androidx.recyclerview.widget.RecyclerView
import androidx.savedstate.SavedStateRegistryOwner
import androidx.savedstate.ViewTreeSavedStateRegistryOwner
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.tabstray.SelectableTabViewHolder
import org.mozilla.fenix.compose.ComposeViewHolder
Expand Down Expand Up @@ -45,8 +45,7 @@ abstract class ComposeAbstractTabViewHolder(
}

ViewTreeLifecycleOwner.set(composeView, viewLifecycleOwner)
ViewTreeSavedStateRegistryOwner.set(
composeView,
composeView.setViewTreeSavedStateRegistryOwner(
viewLifecycleOwner as SavedStateRegistryOwner
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import android.view.WindowManager
import android.view.WindowManager.LayoutParams
import androidx.lifecycle.ViewTreeLifecycleOwner
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.savedstate.ViewTreeSavedStateRegistryOwner
import androidx.savedstate.findViewTreeSavedStateRegistryOwner
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
import io.mockk.every
import io.mockk.mockk
import io.mockk.slot
Expand All @@ -33,7 +33,7 @@ class CFRPopupFullScreenLayoutTest {
fun `WHEN the popup is constructed THEN setup lifecycle owners`() {
val anchor = View(testContext).apply {
ViewTreeLifecycleOwner.set(this, mockk())
ViewTreeSavedStateRegistryOwner.set(this, mockk())
this.setViewTreeSavedStateRegistryOwner(mockk())
}

val popupView = spyk(CFRPopupFullScreenLayout("", anchor, mockk(), mockk()) {})
Expand All @@ -55,7 +55,7 @@ class CFRPopupFullScreenLayoutTest {
val context = spyk(testContext)
val anchor = View(context).apply {
ViewTreeLifecycleOwner.set(this, mockk())
ViewTreeSavedStateRegistryOwner.set(this, mockk())
this.setViewTreeSavedStateRegistryOwner(mockk())
}
val windowManager = spyk(context.getSystemService(Context.WINDOW_SERVICE) as WindowManager)
every { context.getSystemService(Context.WINDOW_SERVICE) } returns windowManager
Expand Down

0 comments on commit bd35438

Please sign in to comment.