Skip to content
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
Expand Up @@ -56,6 +56,7 @@ open class UiTextNode(

const val DEFAULT_TEXT_SIZE = 0.025 // in meters
const val DEFAULT_ALIGNMENT = "bottom-left" // view alignment (pivot)
const val DEFAULT_WRAP = true
}

init {
Expand All @@ -74,8 +75,9 @@ open class UiTextNode(

override fun setupView() {
super.setupView()
val bounds = readBoundsSize()
if (bounds.x == WRAP_CONTENT_DIMENSION) {

val wrap = readWrapProperty(properties)
if (!wrap) {
(view as TextView).setSingleLine(true)
}

Expand All @@ -99,7 +101,6 @@ open class UiTextNode(
setTextColor(props)
setCharactersSpacing(props)
setLineSpacing(props)
setWrap(props)
setFontParams(props)
}

Expand All @@ -115,6 +116,14 @@ open class UiTextNode(
}
}

private fun readWrapProperty(props: Bundle): Boolean {
if (props.containsKey(PROP_BOUNDS_SIZE)) {
val boundsData = props.get(PROP_BOUNDS_SIZE) as Bundle
return boundsData.getBoolean(PROP_WRAP, DEFAULT_WRAP)
}
return DEFAULT_WRAP
}

private fun canResizeOnContentChange(): Boolean {
val bounds = readBoundsSize()
return bounds.x == WRAP_CONTENT_DIMENSION || bounds.y == WRAP_CONTENT_DIMENSION
Expand Down Expand Up @@ -193,17 +202,6 @@ open class UiTextNode(
}
}

private fun setWrap(props: Bundle) {
if (readBoundsSize().x == WRAP_CONTENT_DIMENSION) {
return
}
if (props.containsKey(PROP_BOUNDS_SIZE)) {
val boundsData = props.get(PROP_BOUNDS_SIZE) as Bundle
val wrap = boundsData.getBoolean(PROP_WRAP)
(view as TextView).setSingleLine(!wrap)
}
}

private fun setFontParams(props: Bundle) {
val fontParams = FontParams.fromBundle(props)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ import com.magicleap.magicscript.reactMapOf
import com.magicleap.magicscript.scene.nodes.base.TransformNode
import com.magicleap.magicscript.shouldEqualInexact
import com.magicleap.magicscript.utils.Utils
import com.nhaarman.mockitokotlin2.atLeastOnce
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.spy
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.*
import org.amshove.kluent.shouldBe
import org.amshove.kluent.shouldEqual
import org.junit.Assert.assertEquals
Expand Down Expand Up @@ -135,17 +132,14 @@ class UiTextNodeTest {
}

@Test
fun `should apply single line when width is dynamic`() {
val boundsData = reactMapOf(
UiTextNode.PROP_BOUNDS_SIZE, reactArrayOf(0.0, 0.2),
UiTextNode.PROP_WRAP, true // wrap has no effect when size is 0 (dynamic)
)
val props = reactMapOf(UiTextNode.PROP_BOUNDS_SIZE, boundsData)
fun `should not set single line when bounds size not specified`() {
val props = reactMapOf(UiTextNode.PROP_TEXT, "abc")
val node = createNodeWithViewSpy(props)

node.build()

verify(viewSpy).setSingleLine(true)
verify(viewSpy, never()).setSingleLine()
verify(viewSpy, never()).setSingleLine(true)
}

@Test
Expand Down