Skip to content
Closed
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
80 changes: 0 additions & 80 deletions java/com/facebook/yoga/YogaValue.java

This file was deleted.

62 changes: 62 additions & 0 deletions java/com/facebook/yoga/YogaValue.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.yoga

public class YogaValue
public constructor(@JvmField public val value: Float, @JvmField public val unit: YogaUnit) {
internal constructor(value: Float, unit: Int) : this(value, YogaUnit.fromInt(unit))

override fun equals(other: Any?): Boolean {
if (other is YogaValue) {
val otherValue = other
if (unit == otherValue.unit) {
return unit == YogaUnit.UNDEFINED ||
unit == YogaUnit.AUTO ||
value.compareTo(otherValue.value) == 0
}
}
return false
}

override fun hashCode(): Int = java.lang.Float.floatToIntBits(value) + unit.intValue()

override fun toString(): String =
when (unit) {
YogaUnit.UNDEFINED -> "undefined"
YogaUnit.POINT -> value.toString()
YogaUnit.PERCENT -> "$value%"
YogaUnit.AUTO -> "auto"
else -> throw IllegalStateException()
}

public companion object {
public val UNDEFINED: YogaValue = YogaValue(YogaConstants.UNDEFINED, YogaUnit.UNDEFINED)
public val ZERO: YogaValue = YogaValue(0f, YogaUnit.POINT)
public val AUTO: YogaValue = YogaValue(YogaConstants.UNDEFINED, YogaUnit.AUTO)

public fun parse(s: String?): YogaValue? {
if (s == null) {
return null
}

if ("undefined" == s) {
return UNDEFINED
}

if ("auto" == s) {
return AUTO
}

if (s.endsWith("%")) {
return YogaValue(s.substring(0, s.length - 1).toFloat(), YogaUnit.PERCENT)
}

return YogaValue(s.toFloat(), YogaUnit.POINT)
}
}
}
Loading