Skip to content
Open
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 @@ -27,10 +27,10 @@ internal class BorderInsets {
* Sets the border width for a specific logical edge.
*
* @param edge The logical edge to set
* @param width The border width in pixels, or null to clear
* @param width The border width in pixels, or null or NaN to clear
*/
fun setBorderWidth(edge: LogicalEdge, width: Float?) {
edgeInsets[edge.ordinal] = width
edgeInsets[edge.ordinal] = width?.takeUnless { it.isNaN() }
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.uimanager.style

import android.content.Context
import android.util.LayoutDirection
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.mockito.kotlin.mock

class BorderInsetsTest {
@Test
fun nanBorderWidthsAreTreatedAsUnset() {
val borderInsets = BorderInsets()
borderInsets.setBorderWidth(LogicalEdge.ALL, 4f)
borderInsets.setBorderWidth(LogicalEdge.LEFT, Float.NaN)

val resolved = borderInsets.resolve(LayoutDirection.LTR, mock<Context>())

assertThat(resolved.left).isEqualTo(4f)
assertThat(resolved.top).isEqualTo(4f)
assertThat(resolved.right).isEqualTo(4f)
assertThat(resolved.bottom).isEqualTo(4f)
}
}
Loading