Method arguments
Boolean argument
- JS Spec
- iOS Spec
- Android Spec
src/NativeMyAwesomeModule.ts
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
// ...
export interface Spec extends TurboModule {
myMethod(enabled: boolean, checked?: boolean): void
}
export default TurboModuleRegistry.getEnforcing<Spec>('MyAwesomeModule');
ios/NativeMyAwesomeModule.mm
RCT_EXPORT_METHOD(myMethod:(BOOL) enabled
checked:(NSNumber *) checked)
{
// ...
}
- Kotlin
- Java
android/src/main/newarch/com/myawesomeapp/NativeMyAwesomeModule.kt
override fun myMethod(enabled: Boolean, checked: Boolean?) {
// ...
}
android/src/main/newarch/com/myawesomeapp/NativeMyAwesomeModule.java
import androidx.annotation.Nullable;
// ...
@Override
public void myMethod(boolean enabled, @Nullable Boolean checked) {
// ...
}
Number argument
- JS Spec
- iOS Spec
- Android Spec
src/NativeMyAwesomeModule.ts
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
// ...
export interface Spec extends TurboModule {
myMethod(count: number, optionalCount?: number): void
}
export default TurboModuleRegistry.getEnforcing<Spec>('MyAwesomeModule');
ios/NativeMyAwesomeModule.mm
RCT_EXPORT_METHOD(myMethod:(double) count
optionalCount:(NSNumber *) optionalCount)
{
// ...
}
- Kotlin
- Java
android/src/main/newarch/com/myawesomeapp/NativeMyAwesomeModule.kt
override fun myMethod(count: Double, optionalCount: Double?) {
// ...
}
android/src/main/newarch/com/myawesomeapp/NativeMyAwesomeModule.java
import androidx.annotation.Nullable;
// ...
@Override
public void myMethod(double count, @Nullable Double optionalCount) {
// ...
}
String argument
- JS Spec
- iOS Spec
- Android Spec
src/NativeMyAwesomeModule.ts
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
// ...
export interface Spec extends TurboModule {
myMethod(name: string, label?: number): void
}
export default TurboModuleRegistry.getEnforcing<Spec>('MyAwesomeModule');
ios/NativeMyAwesomeModule.mm
RCT_EXPORT_METHOD(myMethod:(NSString *) name
label:(NSString * _Nullable) label)
{
// ...
}
- Kotlin
- Java
android/src/main/newarch/com/myawesomeapp/NativeMyAwesomeModule.kt
override fun myMethod(name: String, label: String?) {
// ...
}
android/src/main/newarch/com/myawesomeapp/NativeMyAwesomeModule.java
import androidx.annotation.Nullable;
// ...
@Override
public void myMethod(String name, @Nullable String label) {
// ...
}
Array argument
- JS Spec
- iOS Spec
- Android Spec
src/NativeMyAwesomeModule.ts
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
// ...
export interface Spec extends TurboModule {
myMethod(data: number[], optionalData?: string[]): void
}
export default TurboModuleRegistry.getEnforcing<Spec>('MyAwesomeModule');
ios/NativeMyAwesomeModule.mm
RCT_EXPORT_METHOD(myMethod:(NSArray *) data
optionalData:(NSArray * _Nullable) optionalData)
{
// ...
}
- Kotlin
- Java
android/src/main/newarch/com/myawesomeapp/NativeMyAwesomeModule.kt
import com.facebook.react.bridge.ReadableArray
// ...
override fun myMethod(data: ReadableArray, optionalData: ReadableArray?) {
// ...
}
android/src/main/newarch/com/myawesomeapp/NativeMyAwesomeModule.java
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableArray;
// ...
@Override
public void myMethod(ReadableArray data, @Nullable ReadableArray optionalData) {
// ...
}
Object argument
- JS Spec
- iOS Spec
- Android Spec
src/NativeMyAwesomeModule.ts
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
// ...
export interface Spec extends TurboModule {
myMethod(config: { flag: boolean, option: string }, optionalConfig?: { count: number }): void
}
export default TurboModuleRegistry.getEnforcing<Spec>('MyAwesomeModule');
ios/NativeMyAwesomeModule.mm
RCT_EXPORT_METHOD(myMethod:(JS::NativeMyAwesomeModule::SpecMyMethodConfig &) config
optionalConfig:(JS::NativeMyAwesomeModule::SpecMyMethodOptionalConfig &) optionalConfig)
{
// ...
}
- Kotlin
- Java
android/src/main/newarch/com/myawesomeapp/NativeMyAwesomeModule.kt
import com.facebook.react.bridge.ReadableMap
// ...
override fun myMethod(config: ReadableMap, optionalConfig: ReadableMap?) {
// ...
}
android/src/main/newarch/com/myawesomeapp/NativeMyAwesomeModule.java
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableMap;
// ...
@Override
public void myMethod(ReadableMap config, @Nullable ReadableMap optionalConfig) {
// ...
}