Files
react-native/packages/react-native-test-library/ios/RCTNativeSampleModule.mm
T
Dmitry Rykun 1cb0a3342a Add react-native-test-library package (#43068)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43068

This diff adds `react-native-test-library` package.
It contains native module and native component example, and targets both the new and the old architecture. It has structure similar to many OSS React Native libraries, and is supposed to be used to test the integration with third-party libraries.

It is integrated with RNTester as the **OSS Library Example** screen.

{F1457510909}

**Change Background** tests native commands.
**Set Opacity** tests native props.
**Get Random Number** tests native module.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D50793835

fbshipit-source-id: ff6daefab10e6e9f13049e3013f8f63cfa8a929e
2024-04-09 11:35:43 -07:00

48 lines
1.1 KiB
Plaintext

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifdef RCT_NEW_ARCH_ENABLED
#import "OSSLibraryExampleSpec/OSSLibraryExampleSpec.h"
#else
#import <React/RCTBridge.h>
#endif
#import <Foundation/Foundation.h>
#include <react/debug/react_native_assert.h>
#include <stdlib.h>
#ifdef RCT_NEW_ARCH_ENABLED
@interface RCTNativeSampleModule : NSObject <NativeSampleModuleSpec>
#else
@interface RCTNativeSampleModule : NSObject <RCTBridgeModule>
#endif
@end
@implementation RCTNativeSampleModule
RCT_EXPORT_MODULE();
#ifdef RCT_NEW_ARCH_ENABLED
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::NativeSampleModuleSpecJSI>(params);
}
#endif
#ifdef RCT_NEW_ARCH_ENABLED
- (NSNumber *)getRandomNumber
#else
RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, getRandomNumber)
#endif
{
return @(arc4random_uniform(99));
}
@end