-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parent-child order of back press handling by fixing lifecycle issue
- Loading branch information
1 parent
6c38a88
commit a2effa9
Showing
9 changed files
with
331 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application> | ||
|
||
<activity | ||
android:name="com.bumble.appyx.core.plugin.BackPressHandlerTestActivity" | ||
android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | ||
|
||
</application> | ||
|
||
</manifest> |
54 changes: 54 additions & 0 deletions
54
core/src/androidTest/kotlin/com/bumble/appyx/core/plugin/AppyxTestScenario.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.bumble.appyx.core.plugin | ||
|
||
import androidx.annotation.WorkerThread | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.test.junit4.ComposeTestRule | ||
import androidx.compose.ui.test.junit4.createEmptyComposeRule | ||
import androidx.test.core.app.ActivityScenario | ||
import com.bumble.appyx.core.integration.NodeFactory | ||
import com.bumble.appyx.core.integration.NodeHost | ||
import com.bumble.appyx.core.node.Node | ||
import com.bumble.appyx.testing.ui.rules.AppyxViewActivity | ||
import java.util.concurrent.CountDownLatch | ||
import java.util.concurrent.TimeUnit | ||
|
||
/** | ||
* [com.bumble.appyx.testing.ui.rules.AppyxTestRule] based on [ActivityScenario] to support lifecycle tests. | ||
* | ||
* TODO: Consider merging with AppyxTestRule. | ||
*/ | ||
class AppyxTestScenario<T : Node>( | ||
private val composeTestRule: ComposeTestRule = createEmptyComposeRule(), | ||
/** Add decorations like custom theme or CompositionLocalProvider. Do not forget to invoke `content()`. */ | ||
private val decorator: (@Composable (content: @Composable () -> Unit) -> Unit) = { content -> content() }, | ||
private val nodeFactory: NodeFactory<T>, | ||
) : ComposeTestRule by composeTestRule { | ||
|
||
@get:WorkerThread | ||
val activityScenario: ActivityScenario<BackPressHandlerTestActivity> by lazy { | ||
val awaitNode = CountDownLatch(1) | ||
AppyxViewActivity.composableView = { activity -> | ||
decorator { | ||
NodeHost(integrationPoint = activity.integrationPoint, factory = { buildContext -> | ||
node = nodeFactory.create(buildContext) | ||
awaitNode.countDown() | ||
node | ||
}) | ||
} | ||
} | ||
val scenario = ActivityScenario.launch(BackPressHandlerTestActivity::class.java) | ||
require(awaitNode.await(10, TimeUnit.SECONDS)) { | ||
"Timeout while waiting for node initialization" | ||
} | ||
waitForIdle() | ||
scenario | ||
} | ||
|
||
lateinit var node: T | ||
private set | ||
|
||
fun start() { | ||
activityScenario | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.