Skip to content

Commit

Permalink
(Re)introduce ViewTreeLifecycleOwner support to containers
Browse files Browse the repository at this point in the history
Introduces something called `WorkflowLifecycleOwner` that implements `LifecycleOwner` and is set as the `ViewTreeLifecycleOwner` on the child views of the navigation containers: `WorkflowViewStub`, `BackstackContainer`, and `ModalContainer`. These containers all move their lifecycle to the `DESTROYED` state when they are about to discard the current child view and replace it with a new one because the rendering type changed. Until then, their lifecycle follows that of their parent lifecycle.

This PR was created in March, then left for a few months, and finally picked back up in August. That said, very little had to be changed. The updates to AndroidX and Kotlin were merged in separate PRs (#459, #460). It was started by reverting commit 8500b06 (which reverted 74e14e9 and cdca31c).
  • Loading branch information
zach-klippenstein committed Aug 6, 2021
1 parent 70af222 commit bc24557
Show file tree
Hide file tree
Showing 39 changed files with 2,684 additions and 418 deletions.
2 changes: 2 additions & 0 deletions .buildscript/configure-android-defaults.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ android {
exclude 'META-INF/common.kotlin_module'
exclude 'META-INF/android_debug.kotlin_module'
exclude 'META-INF/android_release.kotlin_module'
exclude 'META-INF/AL2.0'
exclude 'META-INF/LGPL2.1'
}
}
7 changes: 7 additions & 0 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ object Dependencies {
const val activityKtx = "androidx.activity:activity-ktx:1.3.0"
const val appcompat = "androidx.appcompat:appcompat:1.3.1"

object Compose {
const val foundation = "androidx.compose.foundation:foundation:1.0.1"
const val ui = "androidx.compose.ui:ui:1.0.1"
}

const val constraint_layout = "androidx.constraintlayout:constraintlayout:2.1.0"
const val fragment = "androidx.fragment:fragment:1.3.6"
const val fragmentKtx = "androidx.fragment:fragment-ktx:1.3.6"
const val gridlayout = "androidx.gridlayout:gridlayout:1.0.0"

object Lifecycle {
const val ktx = "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
const val viewModel = "androidx.lifecycle:lifecycle-viewmodel:2.3.1"
const val viewModelKtx = "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
const val viewModelSavedState = "androidx.lifecycle:lifecycle-viewmodel-savedstate:1.1.0"
}
Expand Down Expand Up @@ -113,6 +119,7 @@ object Dependencies {

object Test {
object AndroidX {
const val compose = "androidx.compose.ui:ui-test-junit4:1.0.1"
const val core = "androidx.test:core:1.3.0"

object Espresso {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.squareup.sample
import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
import android.view.View
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ActivityScenario.launch
import androidx.test.espresso.IdlingRegistry
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.action.ViewActions.click
Expand All @@ -15,6 +13,7 @@ import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.squareup.sample.gameworkflow.GamePlayScreen
Expand All @@ -26,10 +25,11 @@ import com.squareup.workflow1.ui.ViewEnvironment
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
import com.squareup.workflow1.ui.environment
import com.squareup.workflow1.ui.getRendering
import com.squareup.workflow1.ui.internal.test.actuallyPressBack
import com.squareup.workflow1.ui.internal.test.inAnyView
import com.squareup.workflow1.ui.internal.test.actuallyPressBack
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.atomic.AtomicReference
Expand All @@ -38,25 +38,23 @@ import java.util.concurrent.atomic.AtomicReference
@RunWith(AndroidJUnit4::class)
class TicTacToeEspressoTest {

private lateinit var scenario: ActivityScenario<TicTacToeActivity>
@Rule @JvmField var scenarioRule = ActivityScenarioRule(TicTacToeActivity::class.java)
private val scenario get() = scenarioRule.scenario

@Before
fun setUp() {
scenario = launch(TicTacToeActivity::class.java)
.apply {
onActivity { activity ->
IdlingRegistry.getInstance()
.register(activity.idlingResource)
activity.requestedOrientation = SCREEN_ORIENTATION_PORTRAIT
}
}
scenario.onActivity { activity ->
IdlingRegistry.getInstance()
.register(activity.idlingResource)
activity.requestedOrientation = SCREEN_ORIENTATION_PORTRAIT
}
}

@After
fun tearDown() {
scenario.onActivity { activity ->
IdlingRegistry.getInstance()
.unregister(activity.idlingResource)
.unregister(activity.idlingResource)
}
}

Expand Down Expand Up @@ -93,7 +91,7 @@ class TicTacToeEspressoTest {
// lambda above and it all worked just fine. But that seems like a land mine.)

inAnyView(withId(R.id.game_play_toolbar))
.check(matches(hasDescendant(withText("O, place your ${Player.O.symbol}"))))
.check(matches(hasDescendant(withText("O, place your ${Player.O.symbol}"))))

// Now that we're confident the views have updated, back to the activity
// to mess with what should be the updated rendering.
Expand Down Expand Up @@ -134,7 +132,7 @@ class TicTacToeEspressoTest {
// email should have been restored from view state.
inAnyView(withId(R.id.login_email)).check(matches(withText("foo@bar")))
inAnyView(withId(R.id.login_error_message))
.check(matches(withText("Unknown email or invalid password")))
.check(matches(withText("Unknown email or invalid password")))
}

@Test fun dialogSurvivesConfigChange() {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ include(
":workflow-tracing",
":workflow-ui:backstack-common",
":workflow-ui:backstack-android",
":workflow-ui:compose",
":workflow-ui:core-common",
":workflow-ui:core-android",
":workflow-ui:internal-testing-android",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<activity android:name=".fixtures.BackStackTestActivity" />
<activity
android:name=".fixtures.BackStackContainerLifecycleActivity"
android:theme="@style/Theme.AppCompat.NoActionBar"/>
</application>
</manifest>

This file was deleted.

Loading

0 comments on commit bc24557

Please sign in to comment.