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

Bug fix: Make ViewRegistry.showRendering update if ViewRegistry changes. #33

Merged
merged 1 commit into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2020 Square Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.workflow.ui.compose.internal

import androidx.compose.FrameManager
import androidx.compose.mutableStateOf
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.ui.foundation.Text
import androidx.ui.test.assertIsDisplayed
import androidx.ui.test.createComposeRule
import androidx.ui.test.findByText
import com.squareup.workflow.ui.ViewEnvironment
import com.squareup.workflow.ui.ViewRegistry
import com.squareup.workflow.ui.compose.bindCompose
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class ViewRegistriesTest {

@Rule @JvmField val composeRule = createComposeRule()

@Test fun showRendering_recomposes_whenFactoryChanged() {
val registry1 = ViewRegistry(bindCompose<String> { rendering, _ ->
Text(rendering)
})
val registry2 = ViewRegistry(bindCompose<String> { rendering, _ ->
Text(rendering.reversed())
})
val registry = mutableStateOf(registry1)

composeRule.setContent {
registry.value.showRendering("hello", ViewEnvironment(registry.value))
}

findByText("hello").assertIsDisplayed()
FrameManager.framed {
registry.value = registry2
}
findByText("olleh").assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ import com.squareup.workflow.ui.ViewRegistry
modifier: Modifier = Modifier
) {
val renderingType = rendering::class
val viewFactory = remember(renderingType) { getFactoryFor(renderingType) }
val viewFactory = remember(this, renderingType) { getFactoryFor(renderingType) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoa

viewFactory.showRendering(rendering, hints, modifier)
}