Skip to content

Commit

Permalink
feat: Create props file
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Jan 15, 2025
1 parent edfe3c3 commit 5e9f92d
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/nitrogen/src/syntax/kotlin/KotlinHybridObject.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 7 additions & 0 deletions packages/nitrogen/src/syntax/swift/SwiftHybridObject.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions packages/nitrogen/src/views/kotlin/KotlinHybridViewManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { SourceFile } from '../../syntax/SourceFile.js'
import type { HybridObjectSpec } from '../../syntax/HybridObjectSpec.js'

export function createKotlinHybridViewManager(
_: HybridObjectSpec
): SourceFile[] {
return []
}
48 changes: 48 additions & 0 deletions packages/nitrogen/src/views/swift/SwiftHybridViewManager.ts
Original file line number Diff line number Diff line change
@@ -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 <react/renderer/core/PropsParserContext.h>
#import <react/renderer/components/view/ViewProps.h>
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: [],
},
]
}
Original file line number Diff line number Diff line change
@@ -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 <react/renderer/core/PropsParserContext.h>
#import <react/renderer/components/view/ViewProps.h>

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

0 comments on commit 5e9f92d

Please sign in to comment.