From 5e9f92d1ad3dccbd4488aec56f6bbe988317b72b Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Wed, 15 Jan 2025 15:17:21 +0100 Subject: [PATCH] feat: Create props file --- .../src/syntax/kotlin/KotlinHybridObject.ts | 7 +++ .../src/syntax/swift/SwiftHybridObject.ts | 7 +++ .../views/kotlin/KotlinHybridViewManager.ts | 8 ++++ .../src/views/swift/SwiftHybridViewManager.ts | 48 +++++++++++++++++++ .../generated/ios/c++/HybridTestViewProps.hpp | 27 +++++++++++ 5 files changed, 97 insertions(+) create mode 100644 packages/nitrogen/src/views/kotlin/KotlinHybridViewManager.ts create mode 100644 packages/nitrogen/src/views/swift/SwiftHybridViewManager.ts create mode 100644 packages/react-native-nitro-image/nitrogen/generated/ios/c++/HybridTestViewProps.hpp diff --git a/packages/nitrogen/src/syntax/kotlin/KotlinHybridObject.ts b/packages/nitrogen/src/syntax/kotlin/KotlinHybridObject.ts index 7abccf3e6..c6df0bd6c 100644 --- a/packages/nitrogen/src/syntax/kotlin/KotlinHybridObject.ts +++ b/packages/nitrogen/src/syntax/kotlin/KotlinHybridObject.ts @@ -1,5 +1,6 @@ import { NitroConfig } from '../../config/NitroConfig.js' import { indent } from '../../utils.js' +import { createKotlinHybridViewManager } from '../../views/kotlin/KotlinHybridViewManager.js' import { getAllTypes } from '../getAllTypes.js' import { getHybridObjectName } from '../getHybridObjectName.js' import { createFileMetadataString } from '../helpers.js' @@ -123,6 +124,12 @@ abstract class ${name.HybridTSpec}: ${kotlinBase}() { }) files.push(...cppFiles) files.push(...extraFiles) + + if (spec.isHybridView) { + const viewFiles = createKotlinHybridViewManager(spec) + files.push(...viewFiles) + } + return files } diff --git a/packages/nitrogen/src/syntax/swift/SwiftHybridObject.ts b/packages/nitrogen/src/syntax/swift/SwiftHybridObject.ts index 5fc77befc..71f10cd75 100644 --- a/packages/nitrogen/src/syntax/swift/SwiftHybridObject.ts +++ b/packages/nitrogen/src/syntax/swift/SwiftHybridObject.ts @@ -1,4 +1,5 @@ import { indent } from '../../utils.js' +import { createSwiftHybridViewManager } from '../../views/swift/SwiftHybridViewManager.js' import { getHybridObjectName } from '../getHybridObjectName.js' import { createFileMetadataString } from '../helpers.js' import type { HybridObjectSpec } from '../HybridObjectSpec.js' @@ -86,5 +87,11 @@ public typealias ${protocolName} = ${protocolName}_protocol & ${protocolName}_ba platform: 'ios', }) files.push(...swiftBridge) + + if (spec.isHybridView) { + const viewFiles = createSwiftHybridViewManager(spec) + files.push(...viewFiles) + } + return files } diff --git a/packages/nitrogen/src/views/kotlin/KotlinHybridViewManager.ts b/packages/nitrogen/src/views/kotlin/KotlinHybridViewManager.ts new file mode 100644 index 000000000..62a6a6aba --- /dev/null +++ b/packages/nitrogen/src/views/kotlin/KotlinHybridViewManager.ts @@ -0,0 +1,8 @@ +import type { SourceFile } from '../../syntax/SourceFile.js' +import type { HybridObjectSpec } from '../../syntax/HybridObjectSpec.js' + +export function createKotlinHybridViewManager( + _: HybridObjectSpec +): SourceFile[] { + return [] +} diff --git a/packages/nitrogen/src/views/swift/SwiftHybridViewManager.ts b/packages/nitrogen/src/views/swift/SwiftHybridViewManager.ts new file mode 100644 index 000000000..c4c781e75 --- /dev/null +++ b/packages/nitrogen/src/views/swift/SwiftHybridViewManager.ts @@ -0,0 +1,48 @@ +import type { SourceFile } from '../../syntax/SourceFile.js' +import type { HybridObjectSpec } from '../../syntax/HybridObjectSpec.js' +import { getHybridObjectName } from '../../syntax/getHybridObjectName.js' +import { createFileMetadataString } from '../../syntax/helpers.js' +import { NitroConfig } from '../../config/NitroConfig.js' + +export function createSwiftHybridViewManager( + spec: HybridObjectSpec +): SourceFile[] { + const name = getHybridObjectName(spec.name) + const propsClassName = `${name.HybridT}Props` + const namespace = NitroConfig.getCxxNamespace('c++') + + const propsCode = ` +${createFileMetadataString(`${name.HybridT}ViewProps.hpp`)} + +#pragma once + +#import +#import + +namespace ${namespace} { + + using namespace facebook; + + class ${propsClassName}: public react::ViewProps { + public: + explicit ${propsClassName}() = default; + ${propsClassName}(const react::PropsParserContext& context, + const ${propsClassName}& sourceProps, + const react::RawProps& rawProps) { + throw std::runtime_error("not yet implemented!"); + } + }; + +} // namespace ${namespace} + `.trim() + + return [ + { + name: `${propsClassName}.hpp`, + content: propsCode, + language: 'c++', + platform: 'ios', + subdirectory: [], + }, + ] +} diff --git a/packages/react-native-nitro-image/nitrogen/generated/ios/c++/HybridTestViewProps.hpp b/packages/react-native-nitro-image/nitrogen/generated/ios/c++/HybridTestViewProps.hpp new file mode 100644 index 000000000..ca896b583 --- /dev/null +++ b/packages/react-native-nitro-image/nitrogen/generated/ios/c++/HybridTestViewProps.hpp @@ -0,0 +1,27 @@ +/// +/// HybridTestViewViewProps.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/nitro +/// Copyright © 2025 Marc Rousavy @ Margelo +/// + +#pragma once + +#import +#import + +namespace margelo::nitro::image { + + using namespace facebook; + + class HybridTestViewProps: public react::ViewProps { + public: + explicit HybridTestViewProps() = default; + HybridTestViewProps(const react::PropsParserContext& context, + const HybridTestViewProps& sourceProps, + const react::RawProps& rawProps) { + throw std::runtime_error("not yet implemented!"); + } + }; + +} // namespace margelo::nitro::image