Skip to content

Commit a2da81d

Browse files
committed
create stub nativescript_init() method
1 parent f02fef5 commit a2da81d

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

packages/jsi/android/src/main/java/com/nativescriptjsi/NativescriptJsiModule.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ class NativescriptJsiModule(reactContext: ReactApplicationContext) :
99
return a * b
1010
}
1111

12+
override fun nativescript_init(metadata_path: String?) {
13+
// NativeScript JSI is not currently supported on Android. For now, we just
14+
// no-op.
15+
}
16+
1217
companion object {
1318
const val NAME = NativeNativescriptJsiSpec.NAME
1419
}

packages/jsi/apple/NativescriptJsi.mm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22

33
@implementation NativescriptJsi
44
- (NSNumber *)multiply:(double)a b:(double)b {
5-
NSNumber *result = @(a * b);
5+
NSNumber *result = @(a * b);
66

7-
return result;
7+
return result;
8+
}
9+
10+
- (void)nativescript_init:(NSString *)metadata_path {
11+
// TODO
812
}
913

1014
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
1115
(const facebook::react::ObjCTurboModule::InitParams &)params
1216
{
13-
return std::make_shared<facebook::react::NativeNativescriptJsiSpecJSI>(params);
17+
return std::make_shared<facebook::react::NativeNativescriptJsiSpecJSI>(params);
1418
}
1519

1620
+ (NSString *)moduleName

packages/jsi/example/src/App.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
import { Text, View, StyleSheet } from 'react-native';
2-
import { multiply } from 'nativescript-jsi';
1+
import { Text, View, StyleSheet, Button } from 'react-native';
2+
import { multiply, nativescript_init } from 'nativescript-jsi';
33

44
const result = multiply(3, 7);
55

66
export default function App() {
77
return (
88
<View style={styles.container}>
99
<Text>Result: {result}</Text>
10+
<Button
11+
title="Init NativeScript"
12+
onPress={() => {
13+
try {
14+
nativescript_init('abc');
15+
} catch (error) {
16+
console.log('Error initialising NativeScript:', error);
17+
}
18+
}}
19+
/>
1020
</View>
1121
);
1222
}

packages/jsi/src/NativeNativescriptJsi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { TurboModuleRegistry, type TurboModule } from 'react-native';
22

33
export interface Spec extends TurboModule {
44
multiply(a: number, b: number): number;
5+
nativescript_init(metadata_path: string | null): void;
56
}
67

78
export default TurboModuleRegistry.getEnforcing<Spec>('NativescriptJsi');

packages/jsi/src/index.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,17 @@ import NativescriptJsi from './NativeNativescriptJsi';
33
export function multiply(a: number, b: number): number {
44
return NativescriptJsi.multiply(a, b);
55
}
6+
7+
/**
8+
* Initialise NativeScript JSI. This installs its bindings to the Objective-C
9+
* runtime. It will bind to whatever APIs are referenced in in the metadata
10+
* bundle.
11+
*
12+
* @platform Only currently supported on iOS and macOS. Will no-op on Android.
13+
*
14+
* @param metadata_path A path to the metadata bundle (or null, if you'd
15+
* rather use metadata_ptr).
16+
*/
17+
export function nativescript_init(metadata_path: string | null): void {
18+
return NativescriptJsi.nativescript_init(metadata_path);
19+
}

0 commit comments

Comments
 (0)