@goliapkg/sentori-react-native 1.0.0-rc.6 → 1.0.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ import android.app.Activity
4
4
  import android.graphics.drawable.ColorDrawable
5
5
  import android.graphics.drawable.Drawable
6
6
  import android.graphics.drawable.GradientDrawable
7
- import android.graphics.drawable.RippleDrawable
7
+ import android.graphics.drawable.LayerDrawable
8
8
  import android.view.View
9
9
  import android.view.ViewGroup
10
10
  import android.widget.EditText
@@ -256,31 +256,34 @@ object SentoriReplayCapture {
256
256
  return String.format("#%02X%02X%02X%02X", r, g, b, a)
257
257
  }
258
258
 
259
- /** rc.5 — best-effort fill-colour extraction for the View's
260
- * background Drawable. RN's `backgroundColor: '#...'` style
261
- * lands as a ColorDrawable in flat cases and a GradientDrawable
262
- * whenever the View also carries `borderRadius` or
263
- * `borderWidth`; Pressables wrap the painted child in a
264
- * RippleDrawable layer list. We cover all three. Returns
265
- * the packed ARGB int or null when nothing usable is exposed
266
- * (StateListDrawable with no current state, opaque image
267
- * drawables, etc.). */
259
+ /** rc.5 / rc.7 — best-effort fill-colour extraction for the View's
260
+ * background Drawable. We hit:
261
+ *
262
+ * - `ColorDrawable` — flat `<View style={{ backgroundColor }}>`.
263
+ * - `GradientDrawable` RN 0.73's path for backgroundColor +
264
+ * borderRadius / borderWidth.
265
+ * - Any `LayerDrawable` subclass RippleDrawable (Pressable),
266
+ * `com.facebook.react.uimanager.drawable.CompositeBackgroundDrawable`
267
+ * (RN 0.74+ Fabric path, wraps the real
268
+ * `BackgroundDrawable` layer alongside borders / shadows), and
269
+ * any other future composite. Iterate layers, recurse.
270
+ * - **rc.7 reflective fallback** — for the BackgroundDrawable
271
+ * itself (RN 0.74+, Kotlin `internal class` so we can't
272
+ * import it from this module) and any other custom Drawable
273
+ * that follows the convention of exposing `getBackgroundColor()`
274
+ * or `getColor()`. Without this, Insight's app — which uses
275
+ * Pressables and rounded Views and so renders nearly every
276
+ * coloured surface via CompositeBackgroundDrawable —
277
+ * surfaced zero `node.color` fields on rc.5. */
268
278
  private fun extractDrawableColor(drawable: Drawable?): Int? {
269
279
  return when (drawable) {
270
280
  null -> null
271
281
  is ColorDrawable -> drawable.color
272
282
  is GradientDrawable -> {
273
- // API 24+ exposes the ColorStateList for the
274
- // `setColor()` value. RN's typical solid-colour
275
- // GradientDrawable returns a single default colour
276
- // here; gradients with multiple stops still surface
277
- // a reasonable representative colour.
278
283
  val csl = drawable.color
279
284
  csl?.defaultColor
280
285
  }
281
- is RippleDrawable -> {
282
- // Iterate the layer list; the inner painted layer
283
- // is what carries the brand colour.
286
+ is LayerDrawable -> {
284
287
  for (i in 0 until drawable.numberOfLayers) {
285
288
  val inner = drawable.getDrawable(i)
286
289
  val c = extractDrawableColor(inner)
@@ -288,7 +291,31 @@ object SentoriReplayCapture {
288
291
  }
289
292
  null
290
293
  }
291
- else -> null
294
+ else -> extractByReflection(drawable)
295
+ }
296
+ }
297
+
298
+ /** rc.7 — read `getBackgroundColor()` / `getColor()` via Java
299
+ * reflection. Kotlin synthesizes the former from any `var
300
+ * backgroundColor: Int` declaration, so RN's internal
301
+ * `BackgroundDrawable` (which holds the actual paint colour
302
+ * behind any RN View with backgroundColor) exposes it
303
+ * automatically. Any throw / non-Int return falls through to
304
+ * null — fully best-effort. */
305
+ private fun extractByReflection(drawable: Drawable): Int? {
306
+ val cls = drawable.javaClass
307
+ for (name in arrayOf("getBackgroundColor", "getColor")) {
308
+ try {
309
+ val method = cls.getMethod(name)
310
+ val result = method.invoke(drawable)
311
+ if (result is Int) return result
312
+ } catch (_: NoSuchMethodException) {
313
+ // try next
314
+ } catch (_: Throwable) {
315
+ // some custom drawables throw on reflective access; bail
316
+ return null
317
+ }
292
318
  }
319
+ return null
293
320
  }
294
321
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goliapkg/sentori-react-native",
3
- "version": "1.0.0-rc.6",
3
+ "version": "1.0.0-rc.7",
4
4
  "description": "Sentori SDK for React Native \u2014 JS-layer error capture, native crash handlers (iOS / Android), batched transport, fetch + react-navigation tracing.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://sentori.golia.jp",