react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Android] Add Kotlin collection factory functions for Maps and Arrays

Open l2hyunwoo opened this issue 4 weeks ago • 0 comments

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
스크린샷 2025-12-19 오전 10 40 31

l2hyunwoo avatar Dec 19 '25 01:12 l2hyunwoo