Conversation
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||
📝 WalkthroughWalkthroughParameter types across nine ReactMethod signatures in the Usercentrics React Native module are converted from Int to Double. Implementation methods include corresponding Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
PR Summary: Update RN Usercentrics module spec to use Double for numeric params to fix React Native New Architecture (codegen/TurboModule) type mismatches. Changes:
Impact:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
Nitpicks 🔍
|
android/src/main/java/com/usercentrics/reactnative/RNUsercentricsModuleSpec.kt
Show resolved
Hide resolved
android/src/main/java/com/usercentrics/reactnative/RNUsercentricsModuleSpec.kt
Show resolved
Hide resolved
android/src/main/java/com/usercentrics/reactnative/RNUsercentricsModuleSpec.kt
Show resolved
Hide resolved
android/src/main/java/com/usercentrics/reactnative/RNUsercentricsModuleSpec.kt
Show resolved
Hide resolved
android/src/main/java/com/usercentrics/reactnative/RNUsercentricsModuleSpec.kt
Show resolved
Hide resolved
|
Reviewed up to commit:90a4c939250d3e4ddeac3d88392464511c21a8d1 Additional SuggestionOthers- Introduce a single helper utility (e.g. NumberUtils or BridgeConverters) that centralizes conversions from Double -> Int and Double -> Enum (with bounds checks). Many methods require the same conversions (consentType, fromLayer, event, cmpId). Centralizing avoids duplication and makes it easier to maintain behavior (rounding/truncation policy, error messages). Example helper signatures: - fun doubleToIntStrict(value: Double, fieldName: String): Int - fun doubleToEnumOrdinal>(value: Double, values: Array, fieldName: String): T Use these helpers in every bridge method instead of repeating conversion logic.// New file: android/src/main/java/com/usercentrics/reactnative/util/BridgeConverters.kt
package com.usercentrics.reactnative.util
import com.facebook.react.bridge.Promise
internal object BridgeConverters {
fun doubleToIntStrict(value: Double, fieldName: String, promise: Promise? = null): Int {
if (!value.isFinite()) {
val message = "Invalid $fieldName: value must be finite"
promise?.reject(IllegalArgumentException(message))
throw IllegalArgumentException(message)
}
val intValue = value.toInt()
if (intValue.toDouble() != value) {
val message = "Invalid $fieldName: $value is not an integer"
promise?.reject(IllegalArgumentException(message))
throw IllegalArgumentException(message)
}
return intValue
}
fun <T : Enum<T>> doubleToEnumOrdinal(
value: Double,
values: Array<T>,
fieldName: String,
promise: Promise? = null,
): T {
val index = doubleToIntStrict(value, fieldName, promise)
if (index !in values.indices) {
val message = "Invalid $fieldName: index $index out of bounds [0, ${values.lastIndex}]"
promise?.reject(IllegalArgumentException(message))
throw IllegalArgumentException(message)
}
return values[index]
}
}
// Usage example in RNUsercentricsModule.kt
@ReactMethod
override fun track(event: Double) {
val eventType = BridgeConverters.doubleToEnumOrdinal(
value = event,
values = UsercentricsAnalyticsEventType.values(),
fieldName = "event"
)
usercentricsProxy.track(eventType)
}
// Example validation usage in RNUsercentricsModule.kt
@ReactMethod
override fun acceptAll(consentType: Double, promise: Promise) {
try {
val type = BridgeConverters.doubleToEnumOrdinal(
value = consentType,
values = UsercentricsConsentType.values(),
fieldName = "consentType",
promise = promise,
)
handleResult(promise) {
usercentricsProxy.acceptAll(type)
}
} catch (_: IllegalArgumentException) {
// Promise already rejected in converter
}
}
@ReactMethod
override fun setCMPId(id: Double, promise: Promise) {
try {
val intId = BridgeConverters.doubleToIntStrict(id, "cmpId", promise)
usercentricsProxy.setCMPId(intId)
promise.resolve(null)
} catch (_: IllegalArgumentException) {
// Promise already rejected
}
} |
|
CodeAnt AI finished reviewing your PR. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@android/src/main/java/com/usercentrics/reactnative/RNUsercentricsModule.kt`:
- Around line 206-208: The track method currently indexes
UsercentricsAnalyticsEventType.values() with event.toInt() which can throw
ArrayIndexOutOfBounds; update RNUsercentricsModule.track to validate the index
before using it (e.g., obtain vals = UsercentricsAnalyticsEventType.values(),
check eventIndex >= 0 && eventIndex < vals.size), and if out of range handle
gracefully (log via usercentricsProxy.instance or no-op/return) instead of
indexing directly into UsercentricsAnalyticsEventType.values().
- Around line 134-140: The acceptAllForTCF method currently indexes enums
directly with TCFDecisionUILayer.values()[fromLayer.toInt()] and
UsercentricsConsentType.values()[consentType.toInt()] which can throw
ArrayIndexOutOfBoundsException for invalid Double inputs; add defensive
validation or conversion helper(s) (e.g., getTCFDecisionUILayer(fromLayer:
Double) and getConsentType(consentType: Double)) that convert toInt(), check
index is within values().indices, and throw/return a clear error; wrap the enum
access in try-catch in acceptAllForTCF and call promise.reject(...) with a
descriptive message on failure, otherwise resolve as before.
android/src/main/java/com/usercentrics/reactnative/RNUsercentricsModule.kt
Show resolved
Hide resolved
android/src/main/java/com/usercentrics/reactnative/RNUsercentricsModule.kt
Show resolved
Hide resolved
|
CodeAnt AI is running Incremental review Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
@islameldesoky95 can you please check this? 🙏 |
|
CodeAnt AI Incremental review completed. |
|
Can confirm this works for me. Thanks! |
islameldesoky95
left a comment
There was a problem hiding this comment.
Thank you for bringing this to our attention, we will take a look and surely apply the needed fix to our upcoming releases.
When is the next release planed? Android is blocked because of this issue. |
User description
User description
Codegen generates Double for number, you can check here https://reactnative.dev/docs/appendix
right now your whole TurboModule doesn't work for functions that takes number primitive type.
PR Type
Bug fix
Description
Replace Int with Double for number parameters in TurboModule methods
Align with React Native codegen specification for number primitives
Fix compatibility with Android New Architecture
Diagram Walkthrough
File Walkthrough
RNUsercentricsModuleSpec.kt
Convert Int parameters to Double in TurboModule specandroid/src/main/java/com/usercentrics/reactnative/RNUsercentricsModuleSpec.kt
InttoDoubleinsetCMPIdmethodacceptAll,acceptAllForTCF,denyAll,denyAllForTCFmethods touse
Doublefor numeric parameterssaveDecisionsandsaveDecisionsForTCFmethods to acceptDoubleinstead ofIntsaveOptOutForCCPAandtrackmethods to useDoublefor numericparameters
CodeAnt-AI Description
Fix numeric parameter handling so TurboModule methods work on Android New Architecture
What Changed
Impact
✅ Fewer native module failures on Android New Architecture✅ Calls from JS with numeric arguments succeed for consent and tracking methods✅ Consistent behavior for consent-related actions when invoked from React Native💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.