Share gradient stop calculations with Kotlin Multiplatform - #58456
Share gradient stop calculations with Kotlin Multiplatform#58456kunal26das wants to merge 4 commits into
Conversation
|
Hi @kunal26das! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
6b32111 to
597c840
Compare
Summary
Native stacked review: Review this layer in the registered six-PR fork stack. This PR remains the upstream submission to
react/react-native.Share CSS gradient stop positioning and transition-hint calculations between Android and iOS using the Kotlin Multiplatform foundation in #58472. This is the first use case in a series; multipart framing #58474 and explicit scroll snap-target selection #58475 are separate proposals.
Review this layer: gradient implementation and first-consumer integration. The upstream diff includes the foundation and the independent RNTester test dependency fix in #58471 because cross-fork stacked bases are unsupported. Those dependencies can land independently; this layer changes 38 paths.
Android embeds the shared JVM code in its existing ReactAndroid AAR. iOS source builds opt in with
RCT_USE_KMP=1during CocoaPods installation. The common implementation takes stop positions and color-presence flags and returns positions, source color indices and interpolation weights. Native color interpolation, geometry, drawing and precision choices remain in the adapters. There is no Compose dependency or JavaScript API change.This first consumer also establishes packaging and integration checks: actual Maven/npm consumers, shrinking, source applications, independent Kotlin framework coexistence, and repeatable cost probes. Catalyst keeps its native fallback. Full React Native core SwiftPM and published Apple prebuilt integration remain guarded; the separate XCFramework/SwiftPM consumer is a distribution experiment.
Feasibility and alternatives
The benefit is one Kotlin implementation and common tests for calculations otherwise maintained in Kotlin and Objective-C++. Android calls it directly without a new JNI interface. C++ is a strong alternative because the Apple adapter already uses C++ data types and React Native already ships a shared C++ runtime. This proposal does not establish that KMP is the preferred implementation.
The measured gradient bridge adds cost, including its conversions:
Each platform uses matched native/KMP inputs; hint inputs differ between platforms. These are simulator/emulator measurements, not app startup, frame time, installed size or physical-device results. Footprint snapshots are not allocation or leak measurements. Broader adoption needs an accepted performance budget and representative application/device evidence. Catalyst fallback also means the experiment does not eliminate every native copy.
Changelog:
[GENERAL] [CHANGED] - Share gradient stop calculations using Kotlin Multiplatform on Android and opt-in iOS source builds.
Test Plan
Base: upstream
f109c0af8693b58e0716b77b0b7c0c2299fc0a0e. Local toolchain: JDK 17, Kotlin 2.4.20, Xcode 26.6/iOS 26.5. CI selects Xcode 26.4.1.The common algorithms, native adapters and JVM packaging retain their previously validated implementations. Hosted-test runtime ownership is now established in this first consumer: full-pod sibling tests resolve shared classes through the actual application host, including projects without optional
TestTargetIDmetadata. Standalone tests and tests hosted by a non-KMP app retain their own runtime. The application runner also rejects a second shared runtime in hosted test binaries.Previously completed gradient-layer validation on unchanged algorithm and adapter sources, from
packages/react-native/ReactShared:Fresh hosted-runtime review checks at
9e28d94bf595:Previously executed on the identical production implementation, using the checked-in runners documented in
ReactShared/README.md:Intel simulator execution remains deferred; physical-device execution and complete React Native core SwiftPM/prebuilt adoption are outstanding. Hosted CI needs upstream approval; local passes do not stand in for that approval.