Skip to content

Kotlin 2.4: generated *ViewManager.kt fails with "Check for instance is always 'false'" when the HybridView doesn't implement RecyclableView #2010

Closed

Description

@hrastnik

Disclaimer: An AI agent (Claude Code) found this issue while helping us upgrade our app to React Native 0.88, and it also wrote this report. A person reviewed the report before posting it.

Versions: react-native-nitro-modules / nitrogen 0.37.1, Kotlin 2.4.0, react-native 0.88.0

What happens

With Kotlin 2.4.0 (required e.g. by @react-native-firebase v27), the Android build fails in nitrogen-generated view managers whose view implementation class is final and doesn't implement RecyclableView. For example, react-native-vision-camera 5.2.3 fails like this:

e: .../react-native-vision-camera/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/views/HybridPreviewViewManager.kt:82:9 Check for instance is always 'false'.
e: .../react-native-vision-camera/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/views/HybridFrameRendererViewManager.kt:82:9 Check for instance is always 'false'.

A Nitro view in our own project, freshly generated with nitrogen 0.37.1, fails the same way.

Cause

HybridViewHolder.hybridView is typed as the concrete view class. So in prepareToRecycleView, the check hybridView is RecyclableView is provably false. Kotlin 2.4 reports this as an error, and the existing @Suppress("USELESS_IS_CHECK") doesn't suppress it.

The template on main (packages/nitrogen/src/views/kotlin/KotlinHybridViewManager.ts) still generates this.

Workaround we use

We patched the generated code like this:

val recyclableView: Any = hybridView
if (recyclableView is RecyclableView) {
  recyclableView.prepareForRecycle()
  return hybridView.view
}

Two possible fixes in the template:

  • Store the view in HybridViewHolder typed as its spec or Any.
  • Only emit the recycling branch when the implementation implements RecyclableView.

Activity

  1. mrousavy commented on Oct 27, 2026

    @mrousavy
    Member

    Fixed by #2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions