Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.

Commit 2295483

Browse files
Merge pull request #33 from square/zachklipp/fix-viewregistry-showrendering
Bug fix: Make ViewRegistry.showRendering update if ViewRegistry changes.
2 parents a23b56e + 5e620d7 commit 2295483

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2020 Square Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.squareup.workflow.ui.compose.internal
17+
18+
import androidx.compose.FrameManager
19+
import androidx.compose.mutableStateOf
20+
import androidx.test.ext.junit.runners.AndroidJUnit4
21+
import androidx.ui.foundation.Text
22+
import androidx.ui.test.assertIsDisplayed
23+
import androidx.ui.test.createComposeRule
24+
import androidx.ui.test.findByText
25+
import com.squareup.workflow.ui.ViewEnvironment
26+
import com.squareup.workflow.ui.ViewRegistry
27+
import com.squareup.workflow.ui.compose.bindCompose
28+
import org.junit.Rule
29+
import org.junit.Test
30+
import org.junit.runner.RunWith
31+
32+
@RunWith(AndroidJUnit4::class)
33+
class ViewRegistriesTest {
34+
35+
@Rule @JvmField val composeRule = createComposeRule()
36+
37+
@Test fun showRendering_recomposes_whenFactoryChanged() {
38+
val registry1 = ViewRegistry(bindCompose<String> { rendering, _ ->
39+
Text(rendering)
40+
})
41+
val registry2 = ViewRegistry(bindCompose<String> { rendering, _ ->
42+
Text(rendering.reversed())
43+
})
44+
val registry = mutableStateOf(registry1)
45+
46+
composeRule.setContent {
47+
registry.value.showRendering("hello", ViewEnvironment(registry.value))
48+
}
49+
50+
findByText("hello").assertIsDisplayed()
51+
FrameManager.framed {
52+
registry.value = registry2
53+
}
54+
findByText("olleh").assertIsDisplayed()
55+
}
56+
}

core-compose/src/main/java/com/squareup/workflow/ui/compose/internal/ViewRegistries.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ import com.squareup.workflow.ui.ViewRegistry
3737
modifier: Modifier = Modifier
3838
) {
3939
val renderingType = rendering::class
40-
val viewFactory = remember(renderingType) { getFactoryFor(renderingType) }
40+
val viewFactory = remember(this, renderingType) { getFactoryFor(renderingType) }
4141
viewFactory.showRendering(rendering, hints, modifier)
4242
}

0 commit comments

Comments
 (0)