From 6c2628473b5b03755ddb4ccd0947c8d997616da9 Mon Sep 17 00:00:00 2001 From: omofolarin Date: Sat, 11 Jan 2025 00:30:07 +0100 Subject: [PATCH] fixed: Exception in HostFunction: android.content.res.TypedArray cannot be cast to java.lang.AutoCloseable @colors.ts --- .../src/main/java/com/material3/reactnative/ColorsModule.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/material3/reactnative/ColorsModule.kt b/android/src/main/java/com/material3/reactnative/ColorsModule.kt index 23a7281..adb285a 100644 --- a/android/src/main/java/com/material3/reactnative/ColorsModule.kt +++ b/android/src/main/java/com/material3/reactnative/ColorsModule.kt @@ -189,8 +189,10 @@ class ColorsModule(reactContext: ReactApplicationContext) : NativeColorsSpec(rea private fun getColorFromAttr(@AttrRes attr: Int): String { val typedArray = themedContext!!.theme.obtainStyledAttributes(intArrayOf(attr)) - val color = typedArray.use { - it.getColor(0, 0) + val color = try { + typedArray.getColor(0, 0) + } finally { + typedArray.recycle() } val alpha = (color shr 24) and 0xFF