Skip to content

Commit

Permalink
Undo breaking change for ReadableMap.entryIterator for Kotlin consume…
Browse files Browse the repository at this point in the history
…rs. (#45388)

Summary:
Pull Request resolved: #45388

This undos a breaking change we're about to ship in 0.75, where Kotlin users
where forced to update this callsite to be `.getEntryIterator`.

This re-introduces a `entryIterator` val so both Kotlin and Java compatibility are retained.

Changelog:
[Android] [Fixed] - Undo breaking change for ReadableMap.entryIterator for Kotlin consumers

Reviewed By: alanleedev

Differential Revision: D59637925

fbshipit-source-id: b674df86e056f17791d9cabe28557529886f1c93
  • Loading branch information
cortinico authored and facebook-github-bot committed Jul 11, 2024
1 parent 5e31b45 commit b24d47a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import kotlin.collections.Map
* Kotlin.
*/
public interface ReadableMap {
public val entryIterator: Iterator<Map.Entry<String, Any>>

public fun getArray(name: String): ReadableArray?

public fun getBoolean(name: String): Boolean
Expand All @@ -24,8 +26,6 @@ public interface ReadableMap {

public fun getDynamic(name: String): Dynamic

public fun getEntryIterator(): Iterator<Map.Entry<String, Any>>

public fun getInt(name: String): Int

public fun getLong(name: String): Long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,36 +110,36 @@ public open class ReadableNativeMap protected constructor(hybridData: HybridData

override fun getDynamic(name: String): Dynamic = DynamicFromMap.create(this, name)

override fun getEntryIterator(): Iterator<Map.Entry<String, Any>> {
synchronized(this) {
val iteratorKeys = keys
val iteratorValues = importValues()
jniPassCounter++
return object : Iterator<Map.Entry<String, Any>> {
var currentIndex = 0

override fun hasNext(): Boolean {
return currentIndex < iteratorKeys.size
}
override val entryIterator: Iterator<Map.Entry<String, Any>>
get() =
synchronized(this) {
val iteratorKeys = keys
val iteratorValues = importValues()
jniPassCounter++
return object : Iterator<Map.Entry<String, Any>> {
var currentIndex = 0

override fun hasNext(): Boolean {
return currentIndex < iteratorKeys.size
}

override fun next(): Map.Entry<String, Any> {
val index = currentIndex++
return object : MutableMap.MutableEntry<String, Any> {
override val key: String
get() = iteratorKeys[index]
override fun next(): Map.Entry<String, Any> {
val index = currentIndex++
return object : MutableMap.MutableEntry<String, Any> {
override val key: String
get() = iteratorKeys[index]

override val value: Any
get() = iteratorValues[index]
override val value: Any
get() = iteratorValues[index]

override fun setValue(newValue: Any): Any {
throw UnsupportedOperationException(
"Can't set a value while iterating over a ReadableNativeMap")
override fun setValue(newValue: Any): Any {
throw UnsupportedOperationException(
"Can't set a value while iterating over a ReadableNativeMap")
}
}
}
}
}
}
}
}

override fun keySetIterator(): ReadableMapKeySetIterator {
val iteratorKeys = keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal object FilterHelper {
filters ?: return null
var chainedEffects: RenderEffect? = null
for (i in 0 until filters.size()) {
val filter = filters.getMap(i).getEntryIterator().next()
val filter = filters.getMap(i).entryIterator.next()
val filterName = filter.key

chainedEffects =
Expand Down Expand Up @@ -58,7 +58,7 @@ internal object FilterHelper {
// New ColorMatrix objects represent the identity matrix
val resultColorMatrix = ColorMatrix()
for (i in 0 until filters.size()) {
val filter = filters.getMap(i).getEntryIterator().next()
val filter = filters.getMap(i).entryIterator.next()
val filterName = filter.key
val amount = (filter.value as Double).toFloat()

Expand All @@ -85,7 +85,7 @@ internal object FilterHelper {
public fun isOnlyColorMatrixFilters(filters: ReadableArray?): Boolean {
filters ?: return false
for (i in 0 until filters.size()) {
val filter = filters.getMap(i).getEntryIterator().next()
val filter = filters.getMap(i).entryIterator.next()
val filterName = filter.key
if (filterName == "blur" || filterName == "drop-shadow") {
return false
Expand Down

0 comments on commit b24d47a

Please sign in to comment.