[Android] Add Kotlin collection factory functions for Maps and Arrays
Summary:
This PR is based on the proposal: https://github.com/react-native-community/discussions-and-proposals/issues/966
Add Kotlin collection factory functions for maps (WritableMap, ReadableMap) and arrays (WritableArray, ReadableArray)
Introduce idiomatic Kotlin factory functions for creating React Native bridge collection types:
-
writableMapOf(): Creates WritableMap with vararg key-value pairs -
writableArrayOf(): Creates WritableArray with vararg elements -
readableMapOf(): Returns ReadableMap -
readableArrayOf(): Returns ReadableArray
These functions mirror Kotlin's standard library conventions (mapOf/mutableMapOf) and provide a more concise alternative to the builder DSL pattern when constructing small, static collections.
Supported types: null, Boolean, Int, Long, Float, Double, String, ReadableMap, ReadableArray.
Long and Float are converted to Double for JavaScript compatibility.
Changelog:
[ANDROID] [ADDED] - Add Kotlin collection factory functions: writableMapOf, writableArrayOf, readableMapOf, readableArrayOf
Test Plan:
Unit tests added in CollectionFactoryTest.kt covering:
- Empty collections
- Primitive values (String, Int, Boolean, Double)
- Null handling
- Long/Float to Double conversion
- Nested maps and arrays
- Error handling for unsupported types