Skip to content

Conversation

@l2hyunwoo
Copy link
Contributor

Summary:

This PR is based on the proposal: react-native-community/discussions-and-proposals#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

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.
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 19, 2025
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants