Skip to content

Commit c00e349

Browse files
committed
fix: Generate now
1 parent e86c1db commit c00e349

File tree

4 files changed

+35
-59
lines changed

4 files changed

+35
-59
lines changed

packages/nitrogen/src/getPlatformSpecs.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,10 @@ export function getHybridObjectPlatforms(
166166
}
167167

168168
const genericArguments = base.getTypeArguments()
169-
if (genericArguments.length === 0) {
170-
// it uses `HybridObject` without generic arguments. This defaults to C++
171-
return { android: 'c++', ios: 'c++' }
172-
}
173169
const platformSpecsArgument = genericArguments[0]
174170
if (platformSpecsArgument == null) {
175-
throw new Error(
176-
`${declaration.getName()} does not properly extend HybridObject<T>! ${base.getText()} does not have a single generic type argument for platform spec languages!`
177-
)
171+
// it uses `HybridObject` without generic arguments. This defaults to C++
172+
return { android: 'c++', ios: 'c++' }
178173
}
179174

180175
return getPlatformSpec(declaration.getName(), platformSpecsArgument)
@@ -184,13 +179,9 @@ export function getHybridViewPlatforms(
184179
view: InterfaceDeclaration | TypeAliasDeclaration
185180
): PlatformSpec | undefined {
186181
const genericArguments = view.getType().getTypeArguments()
187-
if (genericArguments.length === 0) {
188-
throw new Error(
189-
`${view.getName()} does not properly extend HybridView<Props, Methods, Platforms?>!`
190-
)
191-
}
192-
const platformSpecsArgument = genericArguments[2]
182+
const platformSpecsArgument = genericArguments[0]
193183
if (platformSpecsArgument == null) {
184+
// it uses `HybridObject` without generic arguments. This defaults to platform native languages
194185
return { ios: 'swift', android: 'kotlin' }
195186
}
196187

packages/nitrogen/src/nitrogen.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,22 @@ export async function runNitrogen({
101101
...sourceFile.getTypeAliases(),
102102
]
103103
for (const type of types) {
104-
console.log('---->', type.getName())
105104
// Get name of interface (= our module name)
106105
const typeName = type.getName()
107106
try {
108107
let allFiles: SourceFile[]
109108
let platformSpec: PlatformSpec
110-
if (extendsHybridObject(type.getType(), true)) {
109+
if (extendsHybridView(type.getType(), true)) {
110+
// Hybrid View Props
111+
const targetPlatforms = getHybridViewPlatforms(type)
112+
if (targetPlatforms == null) {
113+
// It does not extend HybridView, continue..
114+
continue
115+
}
116+
platformSpec = targetPlatforms
117+
targetSpecs++
118+
allFiles = []
119+
} else if (extendsHybridObject(type.getType(), true)) {
111120
// Hybrid View
112121
const targetPlatforms = getHybridObjectPlatforms(type)
113122
if (targetPlatforms == null) {
@@ -139,16 +148,6 @@ export async function runNitrogen({
139148
return generatePlatformFiles(type.getType(), language)
140149
})
141150
.filter(filterDuplicateFiles)
142-
} else if (extendsHybridView(type.getType(), true)) {
143-
// Hybrid View Props
144-
const targetPlatforms = getHybridViewPlatforms(type)
145-
if (targetPlatforms == null) {
146-
// It does not extend HybridView, continue..
147-
continue
148-
}
149-
platformSpec = targetPlatforms
150-
targetSpecs++
151-
allFiles = []
152151
} else {
153152
continue
154153
}
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
import type {
2-
HybridView,
3-
HybridViewMethods,
4-
HybridViewProps,
5-
} from 'react-native-nitro-modules'
1+
import type { HybridView } from 'react-native-nitro-modules'
62

7-
export interface TestViewProps extends HybridViewProps {
8-
someString: string
3+
export interface TestView extends HybridView {
4+
someProp: string
5+
someCallback: (value: number) => void
6+
someRefMethod(): number
97
}
10-
11-
export interface TestViewMethods extends HybridViewMethods {
12-
doSomething(): void
13-
}
14-
15-
export type TestView = HybridView<TestViewProps, TestViewMethods>
Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
interface ViewPlatformSpec {
2-
ios?: 'swift'
3-
android?: 'kotlin'
4-
}
5-
6-
/**
7-
* Represents the React props of a Nitro {@linkcode HybridView}.
8-
*/
9-
export interface HybridViewProps {}
1+
import type { HybridObject } from './HybridObject'
102

113
/**
12-
* Represents the methods of the React `ref` to a Nitro {@linkcode HybridView}.
4+
* Describes the languages this view will be implemented in.
135
*/
14-
export interface HybridViewMethods {}
6+
export interface ViewPlatformSpec {
7+
ios?: 'swift'
8+
android?: 'kotlin'
9+
}
1510

1611
/**
1712
* Represents a Nitro `HybridView` which is implemented in a native language
@@ -21,23 +16,22 @@ export interface HybridViewMethods {}
2116
*
2217
* All `HybridViews`s have a C++ Fabric View base with a backing Shadow Node.
2318
*
19+
* - TypeScript Properties (`name: Type`) will be React Props
20+
* - TypeScript Methods (`name(): Type`) will be Ref Methods
21+
*
2422
* @example
2523
* ```tsx
26-
* export interface ImageProps extends HybridViewProps {
27-
* source: string
28-
* }
29-
* export interface ImageMethods extends HybridViewMethods {
30-
* takeScreenshot(): void
24+
* export interface Camera extends HybridView {
25+
* zoom: number
26+
* flash: boolean
27+
* takePhoto(): Image
3128
* }
32-
* export type ImageView = HybridView<ImageProps, ImageMethods>
3329
* ```
3430
*/
3531
export interface HybridView<
36-
Props extends HybridViewProps,
37-
Methods extends HybridViewMethods = {},
3832
Platforms extends ViewPlatformSpec = { ios: 'swift'; android: 'kotlin' },
39-
> {
40-
readonly __tag?: HybridView<Props, Methods, Platforms> & never
33+
> extends HybridObject<Platforms> {
34+
/* empty interface for now */
4135
}
4236

4337
export * from './views/getHostComponent'

0 commit comments

Comments
 (0)