diff --git a/packages/nitrogen/src/views/ViewComponentShadowNode.ts b/packages/nitrogen/src/views/ViewComponentShadowNode.ts index 292978a90..5bdbb973d 100644 --- a/packages/nitrogen/src/views/ViewComponentShadowNode.ts +++ b/packages/nitrogen/src/views/ViewComponentShadowNode.ts @@ -12,6 +12,7 @@ interface ViewComponentNames { shadowNodeClassName: `${string}ShadowNode` descriptorClassName: `${string}ComponentDescriptor` component: `${string}Component` + manager: `${string}Manager` } export function getViewComponentNames( @@ -25,6 +26,7 @@ export function getViewComponentNames( shadowNodeClassName: `${name.HybridT}ShadowNode`, descriptorClassName: `${name.HybridT}ComponentDescriptor`, component: `${spec.name}Component`, + manager: `${spec.name}Manager`, } } diff --git a/packages/nitrogen/src/views/kotlin/KotlinHybridViewManager.ts b/packages/nitrogen/src/views/kotlin/KotlinHybridViewManager.ts index 62a6a6aba..f279f714b 100644 --- a/packages/nitrogen/src/views/kotlin/KotlinHybridViewManager.ts +++ b/packages/nitrogen/src/views/kotlin/KotlinHybridViewManager.ts @@ -1,8 +1,57 @@ import type { SourceFile } from '../../syntax/SourceFile.js' import type { HybridObjectSpec } from '../../syntax/HybridObjectSpec.js' +import { + createViewComponentShadowNodeFiles, + getViewComponentNames, +} from '../ViewComponentShadowNode.js' +import { createFileMetadataString } from '../../syntax/helpers.js' +import { NitroConfig } from '../../config/NitroConfig.js' export function createKotlinHybridViewManager( - _: HybridObjectSpec + spec: HybridObjectSpec ): SourceFile[] { - return [] + const cppFiles = createViewComponentShadowNodeFiles(spec) + const javaNamespace = NitroConfig.getAndroidPackage('java/kotlin', 'views') + const { manager } = getViewComponentNames(spec) + + const mmFile = ` +${createFileMetadataString(`${manager}.kt`)} + +package ${javaNamespace} + +import android.view.View +import com.facebook.react.fabric.StateWrapperImpl +import com.facebook.react.uimanager.ReactStylesDiffMap +import com.facebook.react.uimanager.SimpleViewManager +import com.facebook.react.uimanager.StateWrapper +import com.facebook.react.uimanager.ThemedReactContext + +class ${manager} extends SimpleViewManager { + override fun getName(): String { + return "${spec.name}" + } + + override fun createViewInstance(reactContext: ThemedReactContext): View { + throw Error("Not yet implemented!") + } + + override fun updateState(view: View, props: ReactStylesDiffMap, stateWrapper: StateWrapper): Any { + val stateWrapperImpl = stateWrapper as? StateWrapperImpl ?: throw Error("StateWrapper uses a different implementation!") + // TODO: Get props from stateWrapperImpl and update them in HybridView + + return super.updateState(view, props, stateWrapper) + } +} + ` + + return [ + ...cppFiles, + { + content: mmFile, + language: 'kotlin', + name: `${manager}.kt`, + platform: 'android', + subdirectory: [...javaNamespace.split('.')], + }, + ] } diff --git a/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/views/TestViewManager.kt b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/views/TestViewManager.kt new file mode 100644 index 000000000..270353b58 --- /dev/null +++ b/packages/react-native-nitro-image/nitrogen/generated/android/kotlin/com/margelo/nitro/image/views/TestViewManager.kt @@ -0,0 +1,32 @@ +/// +/// TestViewManager.kt +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2025 Marc Rousavy @ Margelo +/// + +package com.margelo.nitro.image.views + +import android.view.View +import com.facebook.react.fabric.StateWrapperImpl +import com.facebook.react.uimanager.ReactStylesDiffMap +import com.facebook.react.uimanager.SimpleViewManager +import com.facebook.react.uimanager.StateWrapper +import com.facebook.react.uimanager.ThemedReactContext + +class TestViewManager extends SimpleViewManager { + override fun getName(): String { + return "TestView" + } + + override fun createViewInstance(reactContext: ThemedReactContext): View { + throw Error("Not yet implemented!") + } + + override fun updateState(view: View, props: ReactStylesDiffMap, stateWrapper: StateWrapper): Any { + val stateWrapperImpl = stateWrapper as? StateWrapperImpl ?: throw Error("StateWrapper uses a different implementation!") + // TODO: Get props from stateWrapperImpl and update them in HybridView + + return super.updateState(view, props, stateWrapper) + } +}