├── .buckconfig
├── .eslintrc.js
├── .gitattributes
├── .gitignore
├── .prettierrc.js
├── .watchmanconfig
├── README.md
├── __tests__
└── App-test.tsx
├── android
├── app
│ ├── _BUCK
│ ├── build.gradle
│ ├── build_defs.bzl
│ ├── debug.keystore
│ ├── proguard-rules.pro
│ └── src
│ │ ├── debug
│ │ └── AndroidManifest.xml
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── turbomoduleplayground
│ │ │ ├── MainActivity.java
│ │ │ └── MainApplication.java
│ │ └── res
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── strings.xml
│ │ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── app.json
├── babel.config.js
├── index.js
├── ios
├── Podfile
├── Podfile.lock
├── TurboModulePlayground-tvOS
│ └── Info.plist
├── TurboModulePlayground-tvOSTests
│ └── Info.plist
├── TurboModulePlayground.xcodeproj
│ ├── project.pbxproj
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── TurboModulePlayground-tvOS.xcscheme
│ │ └── TurboModulePlayground.xcscheme
├── TurboModulePlayground.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
├── TurboModulePlayground
│ ├── AppDelegate.h
│ ├── AppDelegate.mm
│ ├── Base.lproj
│ │ └── LaunchScreen.xib
│ ├── Images.xcassets
│ │ ├── AppIcon.appiconset
│ │ │ └── Contents.json
│ │ └── Contents.json
│ ├── Info.plist
│ └── main.m
├── TurboModulePlaygroundTests
│ ├── Info.plist
│ └── TurboModulePlaygroundTests.m
└── turbomodule
│ ├── MyTurboModule.h
│ ├── MyTurboModule.mm
│ ├── MyTurboModuleCxx.cpp
│ ├── MyTurboModuleCxx.h
│ ├── provider
│ ├── TurboModuleProvider.h
│ └── TurboModuleProvider.mm
│ └── spec
│ ├── TurboModuleCxxSpec.cpp
│ ├── TurboModuleCxxSpec.h
│ ├── TurboModuleSpec.h
│ └── TurboModuleSpec.mm
├── metro.config.js
├── package.json
├── packages
└── react-native-codegen
│ ├── BUCK
│ ├── DEFS.bzl
│ ├── buck_tests
│ ├── emptyFile.cpp
│ ├── emptyFile.mm
│ ├── generate-tests.js
│ ├── generate-tests.sh
│ └── java
│ │ ├── ArrayPropsNativeComponentViewManager.java
│ │ ├── BooleanPropNativeComponentViewManager.java
│ │ ├── ColorPropNativeComponentViewManager.java
│ │ ├── EdgeInsetsPropNativeComponentViewManager.java
│ │ ├── EnumPropNativeComponentViewManager.java
│ │ ├── EventNestedObjectPropsNativeComponentViewManager.java
│ │ ├── EventPropsNativeComponentViewManager.java
│ │ ├── FloatPropsNativeComponentViewManager.java
│ │ ├── ImagePropNativeComponentViewManager.java
│ │ ├── IntegerPropNativeComponentViewManager.java
│ │ ├── InterfaceOnlyNativeComponentViewManager.java
│ │ ├── MultiNativePropNativeComponentViewManager.java
│ │ ├── NoPropsNoEventsNativeComponentViewManager.java
│ │ ├── ObjectPropsNativeComponentManager.java
│ │ ├── PointPropNativeComponentViewManager.java
│ │ └── StringPropNativeComponentViewManager.java
│ ├── e2e
│ └── __test_fixtures__
│ │ ├── components
│ │ ├── ArrayPropsNativeComponent.js
│ │ ├── BooleanPropNativeComponent.js
│ │ ├── ColorPropNativeComponent.js
│ │ ├── EdgeInsetsPropNativeComponent.js
│ │ ├── EnumPropNativeComponent.js
│ │ ├── EventNestedObjectPropsNativeComponent.js
│ │ ├── EventPropsNativeComponent.js
│ │ ├── FloatPropsNativeComponent.js
│ │ ├── ImagePropNativeComponent.js
│ │ ├── IntegerPropNativeComponent.js
│ │ ├── InterfaceOnlyNativeComponent.js
│ │ ├── MultiNativePropNativeComponent.js
│ │ ├── NoPropsNoEventsNativeComponent.js
│ │ ├── ObjectPropsNativeComponent.js
│ │ ├── PointPropNativeComponent.js
│ │ └── StringPropNativeComponent.js
│ │ └── modules
│ │ ├── NativeArrayTurboModule.js
│ │ ├── NativeBooleanTurboModule.js
│ │ ├── NativeCallbackTurboModule.js
│ │ ├── NativeNullableTurboModule.js
│ │ ├── NativeNumberTurboModule.js
│ │ ├── NativeObjectTurboModule.js
│ │ ├── NativeOptionalObjectTurboModule.js
│ │ ├── NativePromiseTurboModule.js
│ │ ├── NativeSampleTurboModule.js
│ │ └── NativeStringTurboModule.js
│ ├── package.json
│ ├── src
│ ├── CodegenSchema.js
│ ├── SchemaValidator.js
│ ├── __tests__
│ │ ├── SchemaValidator-test.js
│ │ └── __snapshots__
│ │ │ └── SchemaValidator-test.js.snap
│ ├── cli
│ │ ├── combine
│ │ │ ├── combine-js-to-schema-cli.js
│ │ │ ├── combine-js-to-schema.js
│ │ │ └── combine_js_to_schema.sh
│ │ ├── parser
│ │ │ ├── parser-cli.js
│ │ │ ├── parser.js
│ │ │ └── parser.sh
│ │ ├── verify_all_modules_with_old_codegen.sh
│ │ ├── verify_with_old_codegen.js
│ │ └── verify_with_old_codegen.sh
│ ├── generators
│ │ ├── RNCodegen.js
│ │ ├── components
│ │ │ ├── CppHelpers.js
│ │ │ ├── GenerateComponentDescriptorH.js
│ │ │ ├── GenerateComponentHObjCpp.js
│ │ │ ├── GenerateEventEmitterCpp.js
│ │ │ ├── GenerateEventEmitterH.js
│ │ │ ├── GeneratePropsCpp.js
│ │ │ ├── GeneratePropsH.js
│ │ │ ├── GeneratePropsJavaDelegate.js
│ │ │ ├── GeneratePropsJavaInterface.js
│ │ │ ├── GenerateShadowNodeCpp.js
│ │ │ ├── GenerateShadowNodeH.js
│ │ │ ├── GenerateTests.js
│ │ │ ├── GenerateViewConfigJs.js
│ │ │ ├── JavaHelpers.js
│ │ │ ├── __test_fixtures__
│ │ │ │ └── fixtures.js
│ │ │ └── __tests__
│ │ │ │ ├── GenerateComponentDescriptorH-test.js
│ │ │ │ ├── GenerateComponentHObjCpp-test.js
│ │ │ │ ├── GenerateEventEmitterCpp-test.js
│ │ │ │ ├── GenerateEventEmitterH-test.js
│ │ │ │ ├── GeneratePropsCpp-test.js
│ │ │ │ ├── GeneratePropsH-test.js
│ │ │ │ ├── GeneratePropsJavaDelegate-test.js
│ │ │ │ ├── GeneratePropsJavaInterface-test.js
│ │ │ │ ├── GenerateShadowNodeCpp-test.js
│ │ │ │ ├── GenerateShadowNodeH-test.js
│ │ │ │ ├── GenerateTests-test.js
│ │ │ │ ├── GenerateViewConfigJs-test.js
│ │ │ │ └── __snapshots__
│ │ │ │ ├── GenerateComponentDescriptorH-test.js.snap
│ │ │ │ ├── GenerateComponentHObjCpp-test.js.snap
│ │ │ │ ├── GenerateEventEmitterCpp-test.js.snap
│ │ │ │ ├── GenerateEventEmitterH-test.js.snap
│ │ │ │ ├── GeneratePropsCpp-test.js.snap
│ │ │ │ ├── GeneratePropsH-test.js.snap
│ │ │ │ ├── GeneratePropsJavaDelegate-test.js.snap
│ │ │ │ ├── GeneratePropsJavaInterface-test.js.snap
│ │ │ │ ├── GenerateShadowNodeCpp-test.js.snap
│ │ │ │ ├── GenerateShadowNodeH-test.js.snap
│ │ │ │ ├── GenerateTests-test.js.snap
│ │ │ │ └── GenerateViewConfigJs-test.js.snap
│ │ └── modules
│ │ │ ├── GenerateModuleCpp.js
│ │ │ ├── GenerateModuleH.js
│ │ │ ├── GenerateModuleHObjCpp.js
│ │ │ ├── GenerateModuleMm.js
│ │ │ ├── ObjCppUtils
│ │ │ ├── GenerateStructs.js
│ │ │ ├── GenerateStructsForConstants.js
│ │ │ └── Utils.js
│ │ │ ├── __test_fixtures__
│ │ │ ├── fixtures.js
│ │ │ └── structFixtures.js
│ │ │ └── __tests__
│ │ │ ├── GenerateModuleCpp-test.js
│ │ │ ├── GenerateModuleH-test.js
│ │ │ ├── GenerateModuleHObjCpp-test.js
│ │ │ ├── GenerateModuleMm-test.js
│ │ │ ├── GenerateStructs-test.js
│ │ │ └── __snapshots__
│ │ │ ├── GenerateModuleCpp-test.js.snap
│ │ │ ├── GenerateModuleH-test.js.snap
│ │ │ ├── GenerateModuleHObjCpp-test.js.snap
│ │ │ ├── GenerateModuleMm-test.js.snap
│ │ │ └── GenerateStructs-test.js.snap
│ └── parsers
│ │ ├── flow
│ │ ├── components
│ │ │ ├── __test_fixtures__
│ │ │ │ ├── failures.js
│ │ │ │ └── fixtures.js
│ │ │ ├── __tests__
│ │ │ │ ├── __snapshots__
│ │ │ │ │ └── component-parser-test.js.snap
│ │ │ │ └── component-parser-test.js
│ │ │ ├── commands.js
│ │ │ ├── events.js
│ │ │ ├── extends.js
│ │ │ ├── index.js
│ │ │ ├── options.js
│ │ │ ├── props.js
│ │ │ └── schema.js
│ │ ├── index.js
│ │ ├── modules
│ │ │ ├── __test_fixtures__
│ │ │ │ ├── failures.js
│ │ │ │ └── fixtures.js
│ │ │ ├── __tests__
│ │ │ │ ├── __snapshots__
│ │ │ │ │ └── module-parser-test.js.snap
│ │ │ │ └── module-parser-test.js
│ │ │ ├── index.js
│ │ │ ├── methods.js
│ │ │ └── schema.js
│ │ └── utils.js
│ │ └── schema
│ │ └── index.js
│ └── yarn.lock
├── scripts
└── generate-turbomodule-cli.sh
├── src
├── App.tsx
├── components
│ ├── GetArray.tsx
│ ├── GetObject.tsx
│ ├── Greeting.tsx
│ ├── NumberAndBoolean.tsx
│ ├── Page
│ │ ├── Footer.tsx
│ │ ├── Header.tsx
│ │ └── index.ts
│ ├── Section.tsx
│ ├── SimulateCallback.tsx
│ └── SimulatePromise.tsx
├── turbomodules
│ ├── NativeMyTurboModule.js
│ └── NativeMyTurboModuleCxx.js
├── types.ts
└── utils
│ └── print.ts
├── tsconfig.json
└── yarn.lock
/.buckconfig:
--------------------------------------------------------------------------------
1 |
2 | [android]
3 | target = Google Inc.:Google APIs:23
4 |
5 | [maven_repositories]
6 | central = https://repo1.maven.org/maven2
7 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | extends: '@react-native-community',
4 | parser: '@typescript-eslint/parser',
5 | plugins: ['@typescript-eslint'],
6 | };
7 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Xcode
6 | #
7 | build/
8 | *.pbxuser
9 | !default.pbxuser
10 | *.mode1v3
11 | !default.mode1v3
12 | *.mode2v3
13 | !default.mode2v3
14 | *.perspectivev3
15 | !default.perspectivev3
16 | xcuserdata
17 | *.xccheckout
18 | *.moved-aside
19 | DerivedData
20 | *.hmap
21 | *.ipa
22 | *.xcuserstate
23 | project.xcworkspace
24 |
25 | # Android/IntelliJ
26 | #
27 | build/
28 | .idea
29 | .gradle
30 | local.properties
31 | *.iml
32 |
33 | # Visual Studio Code
34 | #
35 | .vscode/
36 |
37 | # node.js
38 | #
39 | node_modules/
40 | npm-debug.log
41 | yarn-error.log
42 |
43 | # BUCK
44 | buck-out/
45 | \.buckd/
46 | *.keystore
47 | !debug.keystore
48 |
49 | # fastlane
50 | #
51 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
52 | # screenshots whenever they are needed.
53 | # For more information about the recommended setup visit:
54 | # https://docs.fastlane.tools/best-practices/source-control/
55 |
56 | */fastlane/report.xml
57 | */fastlane/Preview.html
58 | */fastlane/screenshots
59 |
60 | # Bundle artifact
61 | *.jsbundle
62 |
63 | # CocoaPods
64 | /ios/Pods/
65 |
66 | # schema from codegen
67 | schema-turbomodules.json
--------------------------------------------------------------------------------
/.prettierrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | bracketSpacing: true,
3 | jsxBracketSameLine: true,
4 | singleQuote: true,
5 | trailingComma: 'all',
6 | };
7 |
--------------------------------------------------------------------------------
/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TurboModulePlayground
2 |
3 | ## First things first
4 |
5 | - This repository is nothing, just try to simulate how TurboModule, and CodeGen work together.
6 |
7 | - TurboModule and CodeGen are not yet formally released. It may change in the future. **_Do not use this project for production._**
8 |
9 | - only iOS is supported at the moment. PRs for Android are welcome.
10 |
11 | 
12 |
13 | ## Getting started
14 |
15 | 1. Clone this repository.
16 | 2. Run `npm install` , all required components will be installed automatically.
17 |
18 | ### iOS
19 |
20 | 1. Run `pod install` from `TurboModulePlayground/ios` folder.
21 | 2. Start XCode and open generated `TurboModulePlayground.xcworkspace`.
22 |
23 | ### Android
24 |
25 | no steps required.
26 |
27 | ## Create your turbo module
28 |
29 | ### iOS
30 |
31 | 1. Create a Spec file at `src/turbomodules`. Each Spec file is named `Native*.js` for ObjC module **OR** `Native*Cxx.js` for C++ module, where `*` is the name of the NativeModule.
32 |
33 | 2. Run `npm run codegen`. Then TurboModuleSpec and TurboModuleCxxSpec will be generated at `Xcode/TurboModulePlayground/turbomodule/spec`
34 |
35 | 3. Add your native file into Xcode.
36 |
37 | 4. Add your turbo module name into `Xcode/TurboModulePlayground/turbomodule/TurboModuleProvider.mm`
38 |
39 | ### Android
40 |
41 | not yet supported.
42 |
43 | ## More about Spec file and supported types.
44 |
45 | https://github.com/facebook/react-native/issues/24875#issue-444697876
46 |
--------------------------------------------------------------------------------
/__tests__/App-test.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * @format
3 | */
4 |
5 | import 'react-native';
6 | import React from 'react';
7 | import App from '../src/App';
8 |
9 | // Note: test renderer must be required after react-native.
10 | import renderer from 'react-test-renderer';
11 |
12 | it('renders correctly', () => {
13 | renderer.create();
14 | });
15 |
--------------------------------------------------------------------------------
/android/app/_BUCK:
--------------------------------------------------------------------------------
1 | # To learn about Buck see [Docs](https://buckbuild.com/).
2 | # To run your application with Buck:
3 | # - install Buck
4 | # - `npm start` - to start the packager
5 | # - `cd android`
6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
8 | # - `buck install -r android/app` - compile, install and run application
9 | #
10 |
11 | load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")
12 |
13 | lib_deps = []
14 |
15 | create_aar_targets(glob(["libs/*.aar"]))
16 |
17 | create_jar_targets(glob(["libs/*.jar"]))
18 |
19 | android_library(
20 | name = "all-libs",
21 | exported_deps = lib_deps,
22 | )
23 |
24 | android_library(
25 | name = "app-code",
26 | srcs = glob([
27 | "src/main/java/**/*.java",
28 | ]),
29 | deps = [
30 | ":all-libs",
31 | ":build_config",
32 | ":res",
33 | ],
34 | )
35 |
36 | android_build_config(
37 | name = "build_config",
38 | package = "com.turbomoduleplayground",
39 | )
40 |
41 | android_resource(
42 | name = "res",
43 | package = "com.turbomoduleplayground",
44 | res = "src/main/res",
45 | )
46 |
47 | android_binary(
48 | name = "app",
49 | keystore = "//android/keystores:debug",
50 | manifest = "src/main/AndroidManifest.xml",
51 | package_type = "debug",
52 | deps = [
53 | ":app-code",
54 | ],
55 | )
56 |
--------------------------------------------------------------------------------
/android/app/build_defs.bzl:
--------------------------------------------------------------------------------
1 | """Helper definitions to glob .aar and .jar targets"""
2 |
3 | def create_aar_targets(aarfiles):
4 | for aarfile in aarfiles:
5 | name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")]
6 | lib_deps.append(":" + name)
7 | android_prebuilt_aar(
8 | name = name,
9 | aar = aarfile,
10 | )
11 |
12 | def create_jar_targets(jarfiles):
13 | for jarfile in jarfiles:
14 | name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")]
15 | lib_deps.append(":" + name)
16 | prebuilt_jar(
17 | name = name,
18 | binary_jar = jarfile,
19 | )
20 |
--------------------------------------------------------------------------------
/android/app/debug.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thegamenicorus/TurboModulePlayground/b82ced93f016326706cd03e4537673b7b86bcd0f/android/app/debug.keystore
--------------------------------------------------------------------------------
/android/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
--------------------------------------------------------------------------------
/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/android/app/src/main/java/com/turbomoduleplayground/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.turbomoduleplayground;
2 |
3 | import com.facebook.react.ReactActivity;
4 |
5 | public class MainActivity extends ReactActivity {
6 |
7 | /**
8 | * Returns the name of the main component registered from JavaScript. This is used to schedule
9 | * rendering of the component.
10 | */
11 | @Override
12 | protected String getMainComponentName() {
13 | return "TurboModulePlayground";
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/android/app/src/main/java/com/turbomoduleplayground/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.turbomoduleplayground;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import com.facebook.react.PackageList;
6 | import com.facebook.react.ReactApplication;
7 | import com.facebook.react.ReactNativeHost;
8 | import com.facebook.react.ReactPackage;
9 | import com.facebook.soloader.SoLoader;
10 | import java.lang.reflect.InvocationTargetException;
11 | import java.util.List;
12 |
13 | public class MainApplication extends Application implements ReactApplication {
14 |
15 | private final ReactNativeHost mReactNativeHost =
16 | new ReactNativeHost(this) {
17 | @Override
18 | public boolean getUseDeveloperSupport() {
19 | return BuildConfig.DEBUG;
20 | }
21 |
22 | @Override
23 | protected List getPackages() {
24 | @SuppressWarnings("UnnecessaryLocalVariable")
25 | List packages = new PackageList(this).getPackages();
26 | // Packages that cannot be autolinked yet can be added manually here, for example:
27 | // packages.add(new MyReactNativePackage());
28 | return packages;
29 | }
30 |
31 | @Override
32 | protected String getJSMainModuleName() {
33 | return "index";
34 | }
35 | };
36 |
37 | @Override
38 | public ReactNativeHost getReactNativeHost() {
39 | return mReactNativeHost;
40 | }
41 |
42 | @Override
43 | public void onCreate() {
44 | super.onCreate();
45 | SoLoader.init(this, /* native exopackage */ false);
46 | initializeFlipper(this); // Remove this line if you don't want Flipper enabled
47 | }
48 |
49 | /**
50 | * Loads Flipper in React Native templates.
51 | *
52 | * @param context
53 | */
54 | private static void initializeFlipper(Context context) {
55 | if (BuildConfig.DEBUG) {
56 | try {
57 | /*
58 | We use reflection here to pick up the class that initializes Flipper,
59 | since Flipper library is not available in release mode
60 | */
61 | Class> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
62 | aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
63 | } catch (ClassNotFoundException e) {
64 | e.printStackTrace();
65 | } catch (NoSuchMethodException e) {
66 | e.printStackTrace();
67 | } catch (IllegalAccessException e) {
68 | e.printStackTrace();
69 | } catch (InvocationTargetException e) {
70 | e.printStackTrace();
71 | }
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thegamenicorus/TurboModulePlayground/b82ced93f016326706cd03e4537673b7b86bcd0f/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thegamenicorus/TurboModulePlayground/b82ced93f016326706cd03e4537673b7b86bcd0f/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thegamenicorus/TurboModulePlayground/b82ced93f016326706cd03e4537673b7b86bcd0f/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thegamenicorus/TurboModulePlayground/b82ced93f016326706cd03e4537673b7b86bcd0f/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thegamenicorus/TurboModulePlayground/b82ced93f016326706cd03e4537673b7b86bcd0f/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thegamenicorus/TurboModulePlayground/b82ced93f016326706cd03e4537673b7b86bcd0f/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thegamenicorus/TurboModulePlayground/b82ced93f016326706cd03e4537673b7b86bcd0f/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thegamenicorus/TurboModulePlayground/b82ced93f016326706cd03e4537673b7b86bcd0f/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thegamenicorus/TurboModulePlayground/b82ced93f016326706cd03e4537673b7b86bcd0f/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thegamenicorus/TurboModulePlayground/b82ced93f016326706cd03e4537673b7b86bcd0f/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/android/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TurboModulePlayground
3 |
4 |
--------------------------------------------------------------------------------
/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext {
5 | buildToolsVersion = "28.0.3"
6 | minSdkVersion = 16
7 | compileSdkVersion = 28
8 | targetSdkVersion = 28
9 | }
10 | repositories {
11 | google()
12 | jcenter()
13 | }
14 | dependencies {
15 | classpath("com.android.tools.build:gradle:3.4.2")
16 |
17 | // NOTE: Do not place your application dependencies here; they belong
18 | // in the individual module build.gradle files
19 | }
20 | }
21 |
22 | allprojects {
23 | repositories {
24 | mavenLocal()
25 | maven {
26 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
27 | url("$rootDir/../node_modules/react-native/android")
28 | }
29 | maven {
30 | // Android JSC is installed from npm
31 | url("$rootDir/../node_modules/jsc-android/dist")
32 | }
33 |
34 | google()
35 | jcenter()
36 | maven { url 'https://jitpack.io' }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | android.useAndroidX=true
21 | android.enableJetifier=true
22 |
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thegamenicorus/TurboModulePlayground/b82ced93f016326706cd03e4537673b7b86bcd0f/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem http://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
34 |
35 | @rem Find java.exe
36 | if defined JAVA_HOME goto findJavaFromJavaHome
37 |
38 | set JAVA_EXE=java.exe
39 | %JAVA_EXE% -version >NUL 2>&1
40 | if "%ERRORLEVEL%" == "0" goto init
41 |
42 | echo.
43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
44 | echo.
45 | echo Please set the JAVA_HOME variable in your environment to match the
46 | echo location of your Java installation.
47 |
48 | goto fail
49 |
50 | :findJavaFromJavaHome
51 | set JAVA_HOME=%JAVA_HOME:"=%
52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
53 |
54 | if exist "%JAVA_EXE%" goto init
55 |
56 | echo.
57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
58 | echo.
59 | echo Please set the JAVA_HOME variable in your environment to match the
60 | echo location of your Java installation.
61 |
62 | goto fail
63 |
64 | :init
65 | @rem Get command-line arguments, handling Windows variants
66 |
67 | if not "%OS%" == "Windows_NT" goto win9xME_args
68 |
69 | :win9xME_args
70 | @rem Slurp the command line arguments.
71 | set CMD_LINE_ARGS=
72 | set _SKIP=2
73 |
74 | :win9xME_args_slurp
75 | if "x%~1" == "x" goto execute
76 |
77 | set CMD_LINE_ARGS=%*
78 |
79 | :execute
80 | @rem Setup the command line
81 |
82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
83 |
84 | @rem Execute Gradle
85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
86 |
87 | :end
88 | @rem End local scope for the variables with windows NT shell
89 | if "%ERRORLEVEL%"=="0" goto mainEnd
90 |
91 | :fail
92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
93 | rem the _cmd.exe /c_ return code!
94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
95 | exit /b 1
96 |
97 | :mainEnd
98 | if "%OS%"=="Windows_NT" endlocal
99 |
100 | :omega
101 |
--------------------------------------------------------------------------------
/android/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'TurboModulePlayground'
2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
3 | include ':app'
4 |
--------------------------------------------------------------------------------
/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "TurboModulePlayground",
3 | "displayName": "TurboModulePlayground"
4 | }
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: ['module:metro-react-native-babel-preset'],
3 | };
4 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @format
3 | */
4 |
5 | import {AppRegistry} from 'react-native';
6 | import App from './src/App';
7 | import {name as appName} from './app.json';
8 |
9 | AppRegistry.registerComponent(appName, () => App);
10 |
--------------------------------------------------------------------------------
/ios/Podfile:
--------------------------------------------------------------------------------
1 | platform :ios, '9.0'
2 | require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
3 |
4 | target 'TurboModulePlayground' do
5 | # Pods for TurboModulePlayground
6 | pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
7 | pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
8 | pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
9 | pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
10 | pod 'React', :path => '../node_modules/react-native/'
11 | pod 'React-Core', :path => '../node_modules/react-native/'
12 | pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
13 | pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
14 | pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
15 | pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
16 | pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
17 | pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
18 | pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
19 | pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
20 | pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
21 | pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
22 | pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
23 | pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'
24 |
25 | pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
26 | pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
27 | pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
28 | pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
29 | pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
30 | pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
31 | pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
32 |
33 | pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
34 | pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
35 | pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
36 |
37 | target 'TurboModulePlaygroundTests' do
38 | inherit! :search_paths
39 | # Pods for testing
40 | end
41 |
42 | use_native_modules!
43 | end
44 |
45 | target 'TurboModulePlayground-tvOS' do
46 | # Pods for TurboModulePlayground-tvOS
47 |
48 | target 'TurboModulePlayground-tvOSTests' do
49 | inherit! :search_paths
50 | # Pods for testing
51 | end
52 |
53 | end
54 |
--------------------------------------------------------------------------------
/ios/TurboModulePlayground-tvOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | NSAppTransportSecurity
26 |
27 | NSExceptionDomains
28 |
29 | localhost
30 |
31 | NSExceptionAllowsInsecureHTTPLoads
32 |
33 |
34 |
35 |
36 | NSLocationWhenInUseUsageDescription
37 |
38 | UILaunchStoryboardName
39 | LaunchScreen
40 | UIRequiredDeviceCapabilities
41 |
42 | armv7
43 |
44 | UISupportedInterfaceOrientations
45 |
46 | UIInterfaceOrientationPortrait
47 | UIInterfaceOrientationLandscapeLeft
48 | UIInterfaceOrientationLandscapeRight
49 |
50 | UIViewControllerBasedStatusBarAppearance
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/ios/TurboModulePlayground-tvOSTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/ios/TurboModulePlayground.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/ios/TurboModulePlayground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/TurboModulePlayground/AppDelegate.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (nonatomic, strong) UIWindow *window;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/ios/TurboModulePlayground/AppDelegate.mm:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import "AppDelegate.h"
9 |
10 | #import
11 | #import
12 |
13 | #import
14 | #import
15 | #import
16 | #import
17 | //#import
18 | //#import
19 | #import
20 | #import
21 | #import
22 | #import
23 | #import
24 | #import
25 | #import
26 | #import
27 |
28 | #import
29 | #import "TurboModuleProvider.h"
30 |
31 | @interface AppDelegate() {
32 |
33 | RCTTurboModuleManager *_turboModuleManager;
34 | }
35 | @end
36 |
37 | @implementation AppDelegate
38 |
39 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
40 | {
41 | RCTEnableTurboModule(TRUE);
42 | RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
43 | RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
44 | moduleName:@"TurboModulePlayground"
45 | initialProperties:nil];
46 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
47 |
48 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
49 | UIViewController *rootViewController = [UIViewController new];
50 | rootViewController.view = rootView;
51 | self.window.rootViewController = rootViewController;
52 | [self.window makeKeyAndVisible];
53 | return YES;
54 | }
55 |
56 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
57 | {
58 | #if DEBUG
59 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
60 | #else
61 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
62 | #endif
63 | }
64 |
65 | # pragma mark - RCTCxxBridgeDelegate
66 |
67 | - (std::unique_ptr)jsExecutorFactoryForBridge:(RCTBridge *)bridge
68 | {
69 | _turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge delegate:self];
70 | __weak __typeof(self) weakSelf = self;
71 | return std::make_unique([weakSelf, bridge](facebook::jsi::Runtime &runtime) {
72 | if (!bridge) {
73 | return;
74 | }
75 | __typeof(self) strongSelf = weakSelf;
76 | if (strongSelf) {
77 | [strongSelf->_turboModuleManager installJSBindingWithRuntime:&runtime];
78 | }
79 | });
80 | }
81 |
82 | #pragma mark RCTTurboModuleManagerDelegate
83 |
84 | - (Class)getModuleClassFromName:(const char *)name
85 | {
86 | return facebook::react::TurboModuleClassProvider(name);
87 | }
88 |
89 | - (std::shared_ptr)getTurboModule:(const std::string &)name
90 | jsInvoker:(std::shared_ptr)jsInvoker
91 | {
92 | return facebook::react::TurboModuleProvider(name, jsInvoker);
93 | }
94 |
95 | - (std::shared_ptr)getTurboModule:(const std::string &)name
96 | instance:(id)instance
97 | jsInvoker:(std::shared_ptr)jsInvoker
98 | {
99 | return facebook::react::TurboModuleProvider(name, instance, jsInvoker);
100 | }
101 |
102 | - (id)getModuleInstanceFromClass:(Class)moduleClass
103 | {
104 | if (moduleClass == RCTImageLoader.class) {
105 | return [[moduleClass alloc] initWithRedirectDelegate:nil loadersProvider:^NSArray> *{
106 | return @[[RCTLocalAssetImageLoader new]];
107 | } decodersProvider:^NSArray> *{
108 | return @[[RCTGIFImageDecoder new]];
109 | }];
110 | } else if (moduleClass == RCTNetworking.class) {
111 | return [[moduleClass alloc] initWithHandlersProvider:^NSArray> *{
112 | return @[
113 | [RCTHTTPRequestHandler new],
114 | [RCTDataRequestHandler new],
115 | [RCTFileRequestHandler new],
116 | ];
117 | }];
118 | }
119 | // No custom initializer here.
120 | return [moduleClass new];
121 | }
122 |
123 | @end
124 |
--------------------------------------------------------------------------------
/ios/TurboModulePlayground/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/ios/TurboModulePlayground/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | },
43 | {
44 | "idiom" : "ios-marketing",
45 | "size" : "1024x1024",
46 | "scale" : "1x"
47 | }
48 | ],
49 | "info" : {
50 | "version" : 1,
51 | "author" : "xcode"
52 | }
53 | }
--------------------------------------------------------------------------------
/ios/TurboModulePlayground/Images.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/ios/TurboModulePlayground/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | TurboModulePlayground
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1
25 | LSRequiresIPhoneOS
26 |
27 | NSAppTransportSecurity
28 |
29 | NSAllowsArbitraryLoads
30 |
31 | NSExceptionDomains
32 |
33 | localhost
34 |
35 | NSExceptionAllowsInsecureHTTPLoads
36 |
37 |
38 |
39 |
40 | NSLocationWhenInUseUsageDescription
41 |
42 | UILaunchStoryboardName
43 | LaunchScreen
44 | UIRequiredDeviceCapabilities
45 |
46 | armv7
47 |
48 | UISupportedInterfaceOrientations
49 |
50 | UIInterfaceOrientationPortrait
51 | UIInterfaceOrientationLandscapeLeft
52 | UIInterfaceOrientationLandscapeRight
53 |
54 | UIViewControllerBasedStatusBarAppearance
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/ios/TurboModulePlayground/main.m:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import
9 |
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/ios/TurboModulePlaygroundTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/ios/TurboModulePlaygroundTests/TurboModulePlaygroundTests.m:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import
9 | #import
10 |
11 | #import
12 | #import
13 |
14 | #define TIMEOUT_SECONDS 600
15 | #define TEXT_TO_LOOK_FOR @"Welcome to React"
16 |
17 | @interface TurboModulePlaygroundTests : XCTestCase
18 |
19 | @end
20 |
21 | @implementation TurboModulePlaygroundTests
22 |
23 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
24 | {
25 | if (test(view)) {
26 | return YES;
27 | }
28 | for (UIView *subview in [view subviews]) {
29 | if ([self findSubviewInView:subview matching:test]) {
30 | return YES;
31 | }
32 | }
33 | return NO;
34 | }
35 |
36 | - (void)testRendersWelcomeScreen
37 | {
38 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
39 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
40 | BOOL foundElement = NO;
41 |
42 | __block NSString *redboxError = nil;
43 | #ifdef DEBUG
44 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
45 | if (level >= RCTLogLevelError) {
46 | redboxError = message;
47 | }
48 | });
49 | #endif
50 |
51 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
52 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
53 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
54 |
55 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
56 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
57 | return YES;
58 | }
59 | return NO;
60 | }];
61 | }
62 |
63 | #ifdef DEBUG
64 | RCTSetLogFunction(RCTDefaultLogFunction);
65 | #endif
66 |
67 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
68 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
69 | }
70 |
71 |
72 | @end
73 |
--------------------------------------------------------------------------------
/ios/turbomodule/MyTurboModule.h:
--------------------------------------------------------------------------------
1 | //
2 | // MyTurboModule.h
3 | // TurboModulePlayground
4 | //
5 | // Created by Watcharachai Kanjaikaew on 22/12/2562 BE.
6 | // Copyright © 2562 Facebook. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #import "TurboModuleSpec.h"
12 |
13 | @interface MyTurboModule : NSObject
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/ios/turbomodule/MyTurboModule.mm:
--------------------------------------------------------------------------------
1 | //
2 | // MyTurboModule.cpp
3 | // TurboModulePlayground
4 | //
5 | // Created by Watcharachai Kanjaikaew on 22/12/2562 BE.
6 | // Copyright © 2562 Facebook. All rights reserved.
7 | //
8 |
9 | #import "MyTurboModule.h"
10 |
11 | #import
12 |
13 | using namespace facebook::react;
14 |
15 | @implementation MyTurboModule //TurboModule name
16 |
17 | - (std::shared_ptr)getTurboModuleWithJsInvoker:
18 | (std::shared_ptr)jsInvoker
19 | {
20 | return std::make_shared(self, jsInvoker);
21 | }
22 |
23 | - (NSString *)greeting{
24 | return @"Hello from Objective-C Module";
25 | }
26 |
27 | - (NSNumber *) getRandomNumber{
28 | int number = arc4random() % 100;
29 | return @(number);
30 | }
31 |
32 | RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, addItBy30:(double)num) {
33 | return @(num + 30);
34 | }
35 |
36 | RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSNumber *, isBiggerThan100:(double)num) {
37 | return @(num > 100);
38 | }
39 |
40 | RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD(NSArray> *, nativeReverse : (NSArray *)array)
41 | {
42 | NSArray *reversedArray = [[array reverseObjectEnumerator] allObjects];
43 | return reversedArray;
44 | }
45 |
46 | RCT_EXPORT_METHOD(simulateCallback:(double)waitingSeconds callback:(RCTResponseSenderBlock)callback){
47 | if(!callback){
48 | return;
49 | }
50 |
51 | dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * waitingSeconds);
52 | dispatch_after(delay, dispatch_get_main_queue(), ^(void){
53 | callback(@[ @"This is value from callback!!" ]);
54 | });
55 | }
56 |
57 | RCT_EXPORT_METHOD(simulatePromise: (BOOL)error
58 | waitingSeconds: (double)waitingSeconds
59 | resolve: (RCTPromiseResolveBlock)resolve
60 | reject: (RCTPromiseRejectBlock)reject)
61 | {
62 | if (!resolve || !reject) {
63 | return;
64 | }
65 |
66 | dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * waitingSeconds);
67 | dispatch_after(delay, dispatch_get_main_queue(), ^(void){
68 | if (error) {
69 | reject(
70 | @"code_1",
71 | @"intentional promise rejection",
72 | [NSError errorWithDomain:@"MyTurboModule" code:1 userInfo:nil]);
73 | } else {
74 | resolve(@"This is value from Promise!!");
75 | }
76 | });
77 | }
78 |
79 | - (NSDictionary *) getDeviceInfo{
80 | UIDevice *device = [UIDevice currentDevice];
81 | NSUUID *uuid = [device identifierForVendor];
82 | NSString *name = device.name;
83 | NSString *systemName = device.systemName;
84 | NSString *model = device.model;
85 | NSString *uuidString = uuid.UUIDString;
86 |
87 | return @{
88 | @"name": name,
89 | @"systemName": systemName,
90 | @"model": model,
91 | @"uuid": uuidString ?: [NSNull null],
92 | };
93 | }
94 |
95 |
96 | @end
97 |
--------------------------------------------------------------------------------
/ios/turbomodule/MyTurboModuleCxx.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // MyTurboModuleCxx.cpp
3 | // TurboModulePlayground
4 | //
5 | // Created by Watcharachai Kanjaikaew on 22/12/2562 BE.
6 | // Copyright © 2562 Facebook. All rights reserved.
7 | //
8 |
9 | #include "MyTurboModuleCxx.h"
10 | #import
11 |
12 | using namespace facebook;
13 |
14 | namespace facebook {
15 | namespace react {
16 |
17 | MyTurboModuleCxx::MyTurboModuleCxx(
18 | std::shared_ptr jsInvoker)
19 | : NativeMyTurboModuleCxxSpecJSI(jsInvoker) {}
20 |
21 | jsi::String MyTurboModuleCxx::greeting(jsi::Runtime &rt) {
22 | return jsi::String::createFromUtf8(rt, "Hello from Cpp Module");
23 | }
24 |
25 | } // namespace react
26 | } // namespace facebook
27 |
--------------------------------------------------------------------------------
/ios/turbomodule/MyTurboModuleCxx.h:
--------------------------------------------------------------------------------
1 | //
2 | // MyTurboModuleCxx.hpp
3 | // TurboModulePlayground
4 | //
5 | // Created by Watcharachai Kanjaikaew on 22/12/2562 BE.
6 | // Copyright © 2562 Facebook. All rights reserved.
7 | //
8 | #import "TurboModuleCxxSpec.h"
9 |
10 | namespace facebook {
11 | namespace react {
12 |
13 | /**
14 | * A sample implementation of the C++ spec. In practice, this class can just
15 | * extend jsi::HostObject directly, but using the spec provides build-time
16 | * type-safety.
17 | */
18 | class MyTurboModuleCxx : public NativeMyTurboModuleCxxSpecJSI {
19 | public:
20 | MyTurboModuleCxx(std::shared_ptr jsInvoker);
21 |
22 | jsi::String greeting(jsi::Runtime &rt)override;
23 | };
24 |
25 | } // namespace react
26 | } // namespace facebook
27 |
--------------------------------------------------------------------------------
/ios/turbomodule/provider/TurboModuleProvider.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import
9 |
10 | namespace facebook {
11 | namespace react {
12 |
13 | /**
14 | * Provide the TurboModule class for the given name.
15 | */
16 | Class TurboModuleClassProvider(const char *name);
17 |
18 | /**
19 | * Provide a pure C++ instance of a TurboModule, specific to this app.
20 | */
21 | std::shared_ptr TurboModuleProvider(const std::string &name, std::shared_ptr jsInvoker);
22 |
23 | /**
24 | * Provide an instance of a ObjCTurboModule, given the ObjC instance, specific to this app.
25 | */
26 | std::shared_ptr TurboModuleProvider(const std::string &name,
27 | id instance,
28 | std::shared_ptr jsInvoker);
29 |
30 | } // namespace react
31 | } // namespace facebook
32 |
--------------------------------------------------------------------------------
/ios/turbomodule/provider/TurboModuleProvider.mm:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import "TurboModuleProvider.h"
9 |
10 | #import
11 | #import "MyTurboModule.h"
12 | #import "MyTurboModuleCxx.h"
13 |
14 | // NOTE: This entire file should be codegen'ed.
15 |
16 | namespace facebook {
17 | namespace react {
18 |
19 | Class TurboModuleClassProvider(const char *name) {
20 | return RCTCoreModulesClassProvider(name);
21 | }
22 |
23 | std::shared_ptr TurboModuleProvider(const std::string &name, std::shared_ptr jsInvoker) {
24 | if (name == "MyTurboModuleCxx") {
25 | return std::make_shared(jsInvoker);
26 | }
27 | return nullptr;
28 | }
29 |
30 | std::shared_ptr TurboModuleProvider(const std::string &name,
31 | id instance,
32 | std::shared_ptr jsInvoker) {
33 | if (name == "MyTurboModule") {
34 | return std::make_shared(instance, jsInvoker);
35 | }
36 | return nullptr;
37 | }
38 |
39 | } // namespace react
40 | } // namespace facebook
41 |
--------------------------------------------------------------------------------
/ios/turbomodule/spec/TurboModuleCxxSpec.cpp:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Copyright (c) Facebook, Inc. and its affiliates.
4 | *
5 | * This source code is licensed under the MIT license found in the
6 | * LICENSE file in the root directory of this source tree.
7 | */
8 |
9 | #include "TurboModuleCxxSpec.h"
10 |
11 | namespace facebook {
12 | namespace react {
13 |
14 | static jsi::Value __hostFunction_NativeMyTurboModuleCxxSpecJSI_greeting(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
15 | return static_cast(&turboModule)->greeting(rt);
16 | }
17 |
18 | NativeMyTurboModuleCxxSpecJSI::NativeMyTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker)
19 | : TurboModule("MyTurboModuleCxx", jsInvoker) {
20 | methodMap_["greeting"] = MethodMetadata {0, __hostFunction_NativeMyTurboModuleCxxSpecJSI_greeting};
21 | }
22 |
23 |
24 | } // namespace react
25 | } // namespace facebook
26 |
--------------------------------------------------------------------------------
/ios/turbomodule/spec/TurboModuleCxxSpec.h:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Copyright (c) Facebook, Inc. and its affiliates.
4 | *
5 | * This source code is licensed under the MIT license found in the
6 | * LICENSE file in the root directory of this source tree.
7 | */
8 |
9 | #pragma once
10 |
11 | #include
12 |
13 | namespace facebook {
14 | namespace react {
15 |
16 | class JSI_EXPORT NativeMyTurboModuleCxxSpecJSI : public TurboModule {
17 | protected:
18 | NativeMyTurboModuleCxxSpecJSI(std::shared_ptr jsInvoker);
19 |
20 | public:
21 | virtual jsi::String greeting(jsi::Runtime &rt) = 0;
22 |
23 | };
24 |
25 | } // namespace react
26 | } // namespace facebook
27 |
--------------------------------------------------------------------------------
/ios/turbomodule/spec/TurboModuleSpec.h:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Copyright (c) Facebook, Inc. and its affiliates.
4 | *
5 | * This source code is licensed under the MIT license found in the
6 | * LICENSE file in the root directory of this source tree.
7 | */
8 |
9 | // NOTE: This entire file should be codegen'ed.
10 |
11 | #import
12 |
13 | #import
14 |
15 | #import
16 |
17 | #import
18 | #import
19 | #import
20 | #import
21 | #import
22 | #import
23 |
24 |
25 |
26 |
27 |
28 |
29 | @protocol NativeMyTurboModuleSpec
30 | - (NSString *) greeting;
31 | - (NSNumber *) getRandomNumber;
32 | - (NSNumber *) addItBy30:(double)num;
33 | - (NSNumber *) isBiggerThan100:(double)num;
34 | - (NSArray> *) nativeReverse:(NSArray *)array;
35 | - (void) simulateCallback:(double)waitingSeconds
36 | callback:(RCTResponseSenderBlock)callback;
37 | - (void) simulatePromise:(BOOL)error
38 | waitingSeconds:(double)waitingSeconds
39 | resolve:(RCTPromiseResolveBlock)resolve
40 | reject:(RCTPromiseRejectBlock)reject;
41 | - (NSDictionary *) getDeviceInfo;
42 | @end
43 |
44 |
45 | namespace facebook {
46 | namespace react {
47 |
48 | class JSI_EXPORT NativeMyTurboModuleSpecJSI : public ObjCTurboModule {
49 | public:
50 | NativeMyTurboModuleSpecJSI(id instance, std::shared_ptr jsInvoker);
51 | };
52 |
53 | } // namespace react
54 | } // namespace facebook
55 |
--------------------------------------------------------------------------------
/ios/turbomodule/spec/TurboModuleSpec.mm:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Copyright (c) Facebook, Inc. and its affiliates.
4 | *
5 | * This source code is licensed under the MIT license found in the
6 | * LICENSE file in the root directory of this source tree.
7 | */
8 |
9 | #include "TurboModuleSpec.h"
10 |
11 | namespace facebook {
12 | namespace react {
13 |
14 | static facebook::jsi::Value __hostFunction_NativeMyTurboModuleSpecJSI_greeting(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
15 | return static_cast(turboModule)
16 | .invokeObjCMethod(rt, StringKind, "greeting", @selector(greeting), args, count);
17 | }
18 | static facebook::jsi::Value __hostFunction_NativeMyTurboModuleSpecJSI_getRandomNumber(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
19 | return static_cast(turboModule)
20 | .invokeObjCMethod(rt, NumberKind, "getRandomNumber", @selector(getRandomNumber), args, count);
21 | }
22 | static facebook::jsi::Value __hostFunction_NativeMyTurboModuleSpecJSI_addItBy30(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
23 | return static_cast(turboModule)
24 | .invokeObjCMethod(rt, NumberKind, "addItBy30", @selector(addItBy30:), args, count);
25 | }
26 | static facebook::jsi::Value __hostFunction_NativeMyTurboModuleSpecJSI_isBiggerThan100(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
27 | return static_cast(turboModule)
28 | .invokeObjCMethod(rt, BooleanKind, "isBiggerThan100", @selector(isBiggerThan100:), args, count);
29 | }
30 | static facebook::jsi::Value __hostFunction_NativeMyTurboModuleSpecJSI_nativeReverse(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
31 | return static_cast(turboModule)
32 | .invokeObjCMethod(rt, ArrayKind, "nativeReverse", @selector(nativeReverse:), args, count);
33 | }
34 | static facebook::jsi::Value __hostFunction_NativeMyTurboModuleSpecJSI_simulateCallback(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
35 | return static_cast(turboModule)
36 | .invokeObjCMethod(rt, VoidKind, "simulateCallback", @selector(simulateCallback:callback:), args, count);
37 | }
38 | static facebook::jsi::Value __hostFunction_NativeMyTurboModuleSpecJSI_simulatePromise(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
39 | return static_cast(turboModule)
40 | .invokeObjCMethod(rt, PromiseKind, "simulatePromise", @selector(simulatePromise:waitingSeconds:resolve:reject:), args, count);
41 | }
42 | static facebook::jsi::Value __hostFunction_NativeMyTurboModuleSpecJSI_getDeviceInfo(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
43 | return static_cast(turboModule)
44 | .invokeObjCMethod(rt, ObjectKind, "getDeviceInfo", @selector(getDeviceInfo), args, count);
45 | }
46 |
47 | NativeMyTurboModuleSpecJSI::NativeMyTurboModuleSpecJSI(id instance, std::shared_ptr jsInvoker)
48 | : ObjCTurboModule("MyTurboModule", instance, jsInvoker) {
49 | methodMap_["greeting"] = MethodMetadata {0, __hostFunction_NativeMyTurboModuleSpecJSI_greeting};
50 | methodMap_["getRandomNumber"] = MethodMetadata {0, __hostFunction_NativeMyTurboModuleSpecJSI_getRandomNumber};
51 | methodMap_["addItBy30"] = MethodMetadata {1, __hostFunction_NativeMyTurboModuleSpecJSI_addItBy30};
52 | methodMap_["isBiggerThan100"] = MethodMetadata {1, __hostFunction_NativeMyTurboModuleSpecJSI_isBiggerThan100};
53 | methodMap_["nativeReverse"] = MethodMetadata {1, __hostFunction_NativeMyTurboModuleSpecJSI_nativeReverse};
54 | methodMap_["simulateCallback"] = MethodMetadata {2, __hostFunction_NativeMyTurboModuleSpecJSI_simulateCallback};
55 | methodMap_["simulatePromise"] = MethodMetadata {2, __hostFunction_NativeMyTurboModuleSpecJSI_simulatePromise};
56 | methodMap_["getDeviceInfo"] = MethodMetadata {0, __hostFunction_NativeMyTurboModuleSpecJSI_getDeviceInfo};
57 | }
58 |
59 |
60 | } // namespace react
61 | } // namespace facebook
62 |
--------------------------------------------------------------------------------
/metro.config.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Metro configuration for React Native
3 | * https://github.com/facebook/react-native
4 | *
5 | * @format
6 | */
7 |
8 | module.exports = {
9 | transformer: {
10 | getTransformOptions: async () => ({
11 | transform: {
12 | experimentalImportSupport: false,
13 | inlineRequires: false,
14 | },
15 | }),
16 | },
17 | };
18 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "TurboModulePlayground",
3 | "version": "0.0.1",
4 | "private": true,
5 | "scripts": {
6 | "android": "react-native run-android",
7 | "ios": "react-native run-ios",
8 | "start": "react-native start",
9 | "test": "jest",
10 | "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
11 | "codegen": "./scripts/generate-turbomodule-cli.sh"
12 | },
13 | "dependencies": {
14 | "@types/react-native": "^0.60.25",
15 | "react": "16.9.0",
16 | "react-native": "0.61.5"
17 | },
18 | "devDependencies": {
19 | "@babel/core": "^7.6.2",
20 | "@babel/runtime": "^7.6.2",
21 | "@react-native-community/eslint-config": "^0.0.5",
22 | "@types/jest": "^24.0.24",
23 | "@types/react-test-renderer": "16.9.1",
24 | "@typescript-eslint/eslint-plugin": "^2.12.0",
25 | "@typescript-eslint/parser": "^2.12.0",
26 | "babel-jest": "^24.9.0",
27 | "eslint": "^6.5.1",
28 | "flow-bin": "^0.110.0",
29 | "flow-remove-types": "1.2.3",
30 | "jest": "^24.9.0",
31 | "jscodeshift": "^0.6.2",
32 | "metro-react-native-babel-preset": "^0.56.0",
33 | "react-test-renderer": "16.9.0",
34 | "typescript": "^3.7.3"
35 | },
36 | "jest": {
37 | "preset": "react-native",
38 | "moduleFileExtensions": [
39 | "ts",
40 | "tsx",
41 | "js",
42 | "jsx",
43 | "json",
44 | "node"
45 | ]
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/emptyFile.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import
9 |
10 | // TODO: Import every prop and event to asset they're generated
11 |
12 | int main(){
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/emptyFile.mm:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | #import
9 | #import
10 | #import
11 | #import
12 |
13 | // TODO: Import every prop and event to asset they're generated
14 |
15 | int main(){
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/generate-tests.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | const RNCodegen = require('../src/generators/RNCodegen.js');
14 | const fs = require('fs');
15 | const mkdirp = require('mkdirp');
16 |
17 | const args = process.argv.slice(2);
18 | if (args.length !== 4) {
19 | throw new Error(
20 | `Expected to receive path to schema, library name, output directory and module spec name. Received ${args.join(
21 | ', ',
22 | )}`,
23 | );
24 | }
25 |
26 | const schemaPath = args[0];
27 | const libraryName = args[1];
28 | const outputDirectory = args[2];
29 | const moduleSpecName = args[3];
30 |
31 | const schemaText = fs.readFileSync(schemaPath, 'utf-8');
32 |
33 | if (schemaText == null) {
34 | throw new Error(`Can't find schema at ${schemaPath}`);
35 | }
36 |
37 | mkdirp.sync(outputDirectory);
38 |
39 | let schema;
40 | try {
41 | schema = JSON.parse(schemaText);
42 | } catch (err) {
43 | throw new Error(`Can't parse schema to JSON. ${schemaPath}`);
44 | }
45 |
46 | RNCodegen.generate(
47 | {libraryName, schema, outputDirectory, moduleSpecName},
48 | {
49 | generators: [
50 | 'descriptors',
51 | 'events',
52 | 'props',
53 | 'tests',
54 | 'shadow-nodes',
55 | 'modules',
56 | ],
57 | },
58 | );
59 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/generate-tests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright (c) Facebook, Inc. and its affiliates.
3 | #
4 | # This source code is licensed under the MIT license found in the
5 | # LICENSE file in the root directory of this source tree.
6 |
7 | set -e
8 | set -u
9 |
10 | THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
11 |
12 | # shellcheck source=xplat/js/env-utils/setup_env_vars.sh
13 | source "$THIS_DIR/../../../../env-utils/setup_env_vars.sh"
14 |
15 | pushd "$THIS_DIR/.." >/dev/null
16 | "$INSTALL_NODE_MODULES"
17 | popd >/dev/null
18 |
19 | exec "$FLOW_NODE_BINARY" "$THIS_DIR/generate-tests.js" "$@"
20 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/ArrayPropsNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.bridge.ReadableArray;
12 | import com.facebook.react.viewmanagers.ArrayPropsNativeComponentViewManagerDelegate;
13 | import com.facebook.react.viewmanagers.ArrayPropsNativeComponentViewManagerInterface;
14 |
15 | public class ArrayPropsNativeComponentViewManager extends SimpleViewManager
16 | implements ArrayPropsNativeComponentViewManagerInterface {
17 |
18 | public static final String REACT_CLASS = "ArrayPropsNativeComponentView";
19 |
20 | @Override
21 | public String getName() {
22 | return REACT_CLASS;
23 | }
24 |
25 | private void test() {
26 | ArrayPropsNativeComponentViewManagerDelegate
27 | delegate = new ArrayPropsNativeComponentViewManagerDelegate<>(this);
28 | }
29 |
30 | @Override
31 | public ViewGroup createViewInstance(ThemedReactContext context) {
32 | throw new IllegalStateException();
33 | }
34 |
35 | @Override
36 | public void setNames(ViewGroup view, ReadableArray value) {}
37 |
38 | @Override
39 | public void setDisableds(ViewGroup view, ReadableArray value) {}
40 |
41 | @Override
42 | public void setProgress(ViewGroup view, ReadableArray value) {}
43 |
44 | @Override
45 | public void setRadii(ViewGroup view, ReadableArray value) {}
46 |
47 | @Override
48 | public void setColors(ViewGroup view, ReadableArray value) {}
49 |
50 | @Override
51 | public void setSrcs(ViewGroup view, ReadableArray value) {}
52 |
53 | @Override
54 | public void setPoints(ViewGroup view, ReadableArray value) {}
55 |
56 | @Override
57 | public void setEdgeInsets(ViewGroup view, ReadableArray value) {}
58 |
59 | @Override
60 | public void setSizes(ViewGroup view, ReadableArray value) {}
61 |
62 | @Override
63 | public void setObject(ViewGroup view, ReadableArray value) {}
64 | }
65 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/BooleanPropNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import androidx.annotation.Nullable;
12 | import com.facebook.react.viewmanagers.BooleanPropNativeComponentViewManagerDelegate;
13 | import com.facebook.react.viewmanagers.BooleanPropNativeComponentViewManagerInterface;
14 |
15 | public class BooleanPropNativeComponentViewManager extends SimpleViewManager
16 | implements BooleanPropNativeComponentViewManagerInterface {
17 |
18 | public static final String REACT_CLASS = "BooleanPropNativeComponentView";
19 |
20 | @Override
21 | public String getName() {
22 | return REACT_CLASS;
23 | }
24 |
25 | private void test() {
26 | BooleanPropNativeComponentViewManagerDelegate
27 | delegate = new BooleanPropNativeComponentViewManagerDelegate<>(this);
28 | }
29 |
30 | @Override
31 | public ViewGroup createViewInstance(ThemedReactContext context) {
32 | throw new IllegalStateException();
33 | }
34 |
35 | @Override
36 | public void setDisabled(ViewGroup view, boolean value) {}
37 |
38 | @Override
39 | public void setDisabledNullable(ViewGroup view, @Nullable Boolean value) {}
40 | }
41 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/ColorPropNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.viewmanagers.ColorPropNativeComponentViewManagerDelegate;
12 | import com.facebook.react.viewmanagers.ColorPropNativeComponentViewManagerInterface;
13 |
14 | public class ColorPropNativeComponentViewManager extends SimpleViewManager
15 | implements ColorPropNativeComponentViewManagerInterface {
16 |
17 | public static final String REACT_CLASS = "ColorPropNativeComponentView";
18 |
19 | @Override
20 | public String getName() {
21 | return REACT_CLASS;
22 | }
23 |
24 | private void test() {
25 | ColorPropNativeComponentViewManagerDelegate
26 | delegate = new ColorPropNativeComponentViewManagerDelegate<>(this);
27 | }
28 |
29 | @Override
30 | public ViewGroup createViewInstance(ThemedReactContext context) {
31 | throw new IllegalStateException();
32 | }
33 |
34 | @Override
35 | public void setTintColor(ViewGroup view, Integer value) {}
36 | }
37 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/EdgeInsetsPropNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.bridge.ReadableMap;
12 | import com.facebook.react.viewmanagers.EdgeInsetsPropNativeComponentViewManagerDelegate;
13 | import com.facebook.react.viewmanagers.EdgeInsetsPropNativeComponentViewManagerInterface;
14 |
15 | public class EdgeInsetsPropNativeComponentViewManager extends SimpleViewManager
16 | implements EdgeInsetsPropNativeComponentViewManagerInterface {
17 |
18 | public static final String REACT_CLASS = "EdgeInsetsPropNativeComponentView";
19 |
20 | @Override
21 | public String getName() {
22 | return REACT_CLASS;
23 | }
24 |
25 | private void test() {
26 | EdgeInsetsPropNativeComponentViewManagerDelegate<
27 | ViewGroup, EdgeInsetsPropNativeComponentViewManager>
28 | delegate = new EdgeInsetsPropNativeComponentViewManagerDelegate<>(this);
29 | }
30 |
31 | @Override
32 | public ViewGroup createViewInstance(ThemedReactContext context) {
33 | throw new IllegalStateException();
34 | }
35 |
36 | @Override
37 | public void setContentInset(ViewGroup view, ReadableMap value) {}
38 | }
39 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/EnumPropNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.viewmanagers.EnumPropNativeComponentViewManagerDelegate;
12 | import com.facebook.react.viewmanagers.EnumPropNativeComponentViewManagerInterface;
13 |
14 | public class EnumPropNativeComponentViewManager extends SimpleViewManager
15 | implements EnumPropNativeComponentViewManagerInterface {
16 |
17 | public static final String REACT_CLASS = "EnumPropNativeComponentView";
18 |
19 | @Override
20 | public String getName() {
21 | return REACT_CLASS;
22 | }
23 |
24 | private void test() {
25 | EnumPropNativeComponentViewManagerDelegate
26 | delegate = new EnumPropNativeComponentViewManagerDelegate<>(this);
27 | }
28 |
29 | @Override
30 | public ViewGroup createViewInstance(ThemedReactContext context) {
31 | throw new IllegalStateException();
32 | }
33 |
34 | @Override
35 | public void setAlignment(ViewGroup view, String value) {}
36 |
37 | @Override
38 | public void setIntervals(ViewGroup view, Integer value) {}
39 | }
40 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/EventNestedObjectPropsNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.viewmanagers.EventNestedObjectPropsNativeComponentViewManagerDelegate;
12 | import com.facebook.react.viewmanagers.EventNestedObjectPropsNativeComponentViewManagerInterface;
13 |
14 | public class EventNestedObjectPropsNativeComponentViewManager extends SimpleViewManager
15 | implements EventNestedObjectPropsNativeComponentViewManagerInterface {
16 |
17 | public static final String REACT_CLASS = "EventNestedObjectPropsNativeComponentView";
18 |
19 | @Override
20 | public String getName() {
21 | return REACT_CLASS;
22 | }
23 |
24 | private void test() {
25 | EventNestedObjectPropsNativeComponentViewManagerDelegate<
26 | ViewGroup, EventNestedObjectPropsNativeComponentViewManager>
27 | delegate = new EventNestedObjectPropsNativeComponentViewManagerDelegate<>(this);
28 | }
29 |
30 | @Override
31 | public ViewGroup createViewInstance(ThemedReactContext context) {
32 | throw new IllegalStateException();
33 | }
34 |
35 | @Override
36 | public void setDisabled(ViewGroup view, boolean value) {}
37 | }
38 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/EventPropsNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.viewmanagers.EventPropsNativeComponentViewManagerDelegate;
12 | import com.facebook.react.viewmanagers.EventPropsNativeComponentViewManagerInterface;
13 |
14 | public class EventPropsNativeComponentViewManager extends SimpleViewManager
15 | implements EventPropsNativeComponentViewManagerInterface {
16 |
17 | public static final String REACT_CLASS = "EventPropsNativeComponentView";
18 |
19 | @Override
20 | public String getName() {
21 | return REACT_CLASS;
22 | }
23 |
24 | private void test() {
25 | EventPropsNativeComponentViewManagerDelegate
26 | delegate = new EventPropsNativeComponentViewManagerDelegate<>(this);
27 | }
28 |
29 | @Override
30 | public ViewGroup createViewInstance(ThemedReactContext context) {
31 | throw new IllegalStateException();
32 | }
33 |
34 | @Override
35 | public void setDisabled(ViewGroup view, boolean value) {}
36 | }
37 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/FloatPropsNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import androidx.annotation.Nullable;
12 | import com.facebook.react.viewmanagers.FloatPropsNativeComponentViewManagerDelegate;
13 | import com.facebook.react.viewmanagers.FloatPropsNativeComponentViewManagerInterface;
14 |
15 | public class FloatPropsNativeComponentViewManager extends SimpleViewManager
16 | implements FloatPropsNativeComponentViewManagerInterface {
17 |
18 | public static final String REACT_CLASS = "FloatPropsNativeComponentView";
19 |
20 | @Override
21 | public String getName() {
22 | return REACT_CLASS;
23 | }
24 |
25 | private void test() {
26 | FloatPropsNativeComponentViewManagerDelegate
27 | delegate = new FloatPropsNativeComponentViewManagerDelegate<>(this);
28 | }
29 |
30 | @Override
31 | public ViewGroup createViewInstance(ThemedReactContext context) {
32 | throw new IllegalStateException();
33 | }
34 |
35 | @Override
36 | public void setBlurRadius(ViewGroup view, float value) {}
37 |
38 | @Override
39 | public void setBlurRadius2(ViewGroup view, float value) {}
40 |
41 | @Override
42 | public void setBlurRadius3(ViewGroup view, float value) {}
43 |
44 | @Override
45 | public void setBlurRadius4(ViewGroup view, float value) {}
46 |
47 | @Override
48 | public void setBlurRadius5(ViewGroup view, float value) {}
49 |
50 | @Override
51 | public void setBlurRadius6(ViewGroup view, float value) {}
52 |
53 | @Override
54 | public void setBlurRadiusNullable(ViewGroup view, @Nullable Float value) {}
55 | }
56 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/ImagePropNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.bridge.ReadableMap;
12 | import com.facebook.react.viewmanagers.ImagePropNativeComponentViewManagerDelegate;
13 | import com.facebook.react.viewmanagers.ImagePropNativeComponentViewManagerInterface;
14 |
15 | public class ImagePropNativeComponentViewManager extends SimpleViewManager
16 | implements ImagePropNativeComponentViewManagerInterface {
17 |
18 | public static final String REACT_CLASS = "ImagePropNativeComponentView";
19 |
20 | @Override
21 | public String getName() {
22 | return REACT_CLASS;
23 | }
24 |
25 | private void test() {
26 | ImagePropNativeComponentViewManagerDelegate
27 | delegate = new ImagePropNativeComponentViewManagerDelegate<>(this);
28 | }
29 |
30 | @Override
31 | public ViewGroup createViewInstance(ThemedReactContext context) {
32 | throw new IllegalStateException();
33 | }
34 |
35 | @Override
36 | public void setThumbImage(ViewGroup view, ReadableMap value) {}
37 | }
38 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/IntegerPropNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.viewmanagers.IntegerPropNativeComponentViewManagerDelegate;
12 | import com.facebook.react.viewmanagers.IntegerPropNativeComponentViewManagerInterface;
13 |
14 | public class IntegerPropNativeComponentViewManager extends SimpleViewManager
15 | implements IntegerPropNativeComponentViewManagerInterface {
16 |
17 | public static final String REACT_CLASS = "IntegerPropNativeComponentView";
18 |
19 | @Override
20 | public String getName() {
21 | return REACT_CLASS;
22 | }
23 |
24 | private void test() {
25 | IntegerPropNativeComponentViewManagerDelegate
26 | delegate = new IntegerPropNativeComponentViewManagerDelegate<>(this);
27 | }
28 |
29 | @Override
30 | public ViewGroup createViewInstance(ThemedReactContext context) {
31 | throw new IllegalStateException();
32 | }
33 |
34 | @Override
35 | public void setProgress1(ViewGroup view, int value) {}
36 |
37 | @Override
38 | public void setProgress2(ViewGroup view, int value) {}
39 |
40 | @Override
41 | public void setProgress3(ViewGroup view, int value) {}
42 | }
43 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/InterfaceOnlyNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.viewmanagers.InterfaceOnlyNativeComponentViewManagerDelegate;
12 | import com.facebook.react.viewmanagers.InterfaceOnlyNativeComponentViewManagerInterface;
13 |
14 | public class InterfaceOnlyNativeComponentViewManager extends SimpleViewManager
15 | implements InterfaceOnlyNativeComponentViewManagerInterface {
16 |
17 | public static final String REACT_CLASS = "InterfaceOnlyNativeComponentView";
18 |
19 | @Override
20 | public String getName() {
21 | return REACT_CLASS;
22 | }
23 |
24 | private void test() {
25 | InterfaceOnlyNativeComponentViewManagerDelegate<
26 | ViewGroup, InterfaceOnlyNativeComponentViewManager>
27 | delegate = new InterfaceOnlyNativeComponentViewManagerDelegate<>(this);
28 | }
29 |
30 | @Override
31 | public ViewGroup createViewInstance(ThemedReactContext context) {
32 | throw new IllegalStateException();
33 | }
34 |
35 | @Override
36 | public void setTitle(ViewGroup view, String value) {}
37 | }
38 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/MultiNativePropNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.bridge.ReadableMap;
12 | import com.facebook.react.viewmanagers.MultiNativePropNativeComponentViewManagerDelegate;
13 | import com.facebook.react.viewmanagers.MultiNativePropNativeComponentViewManagerInterface;
14 |
15 | public class MultiNativePropNativeComponentViewManager extends SimpleViewManager
16 | implements MultiNativePropNativeComponentViewManagerInterface {
17 |
18 | public static final String REACT_CLASS = "MultiNativePropNativeComponentView";
19 |
20 | @Override
21 | public String getName() {
22 | return REACT_CLASS;
23 | }
24 |
25 | private void test() {
26 | MultiNativePropNativeComponentViewManagerDelegate<
27 | ViewGroup, MultiNativePropNativeComponentViewManager>
28 | delegate = new MultiNativePropNativeComponentViewManagerDelegate<>(this);
29 | }
30 |
31 | @Override
32 | public ViewGroup createViewInstance(ThemedReactContext context) {
33 | throw new IllegalStateException();
34 | }
35 |
36 | @Override
37 | public void setThumbImage(ViewGroup view, ReadableMap value) {}
38 |
39 | @Override
40 | public void setColor(ViewGroup view, Integer value) {}
41 |
42 | @Override
43 | public void setThumbTintColor(ViewGroup view, Integer value) {}
44 |
45 | @Override
46 | public void setPoint(ViewGroup view, ReadableMap value) {}
47 | }
48 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/NoPropsNoEventsNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.viewmanagers.NoPropsNoEventsNativeComponentViewManagerDelegate;
12 | import com.facebook.react.viewmanagers.NoPropsNoEventsNativeComponentViewManagerInterface;
13 |
14 | public class NoPropsNoEventsNativeComponentViewManager extends SimpleViewManager
15 | implements NoPropsNoEventsNativeComponentViewManagerInterface {
16 |
17 | public static final String REACT_CLASS = "NoPropsNoEventsNativeComponentView";
18 |
19 | @Override
20 | public String getName() {
21 | return REACT_CLASS;
22 | }
23 |
24 | private void test() {
25 | NoPropsNoEventsNativeComponentViewManagerDelegate<
26 | ViewGroup, NoPropsNoEventsNativeComponentViewManager>
27 | delegate = new NoPropsNoEventsNativeComponentViewManagerDelegate<>(this);
28 | }
29 |
30 | @Override
31 | public ViewGroup createViewInstance(ThemedReactContext context) {
32 | throw new IllegalStateException();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/ObjectPropsNativeComponentManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.bridge.ReadableMap;
12 | import com.facebook.react.viewmanagers.ObjectPropsNativeComponentManagerDelegate;
13 | import com.facebook.react.viewmanagers.ObjectPropsNativeComponentManagerInterface;
14 |
15 | public class ObjectPropsNativeComponentManager extends SimpleViewManager
16 | implements ObjectPropsNativeComponentManagerInterface {
17 |
18 | public static final String REACT_CLASS = "ObjectPropsNativeComponent";
19 |
20 | @Override
21 | public String getName() {
22 | return REACT_CLASS;
23 | }
24 |
25 | private void test() {
26 | ObjectPropsNativeComponentManagerDelegate
27 | delegate = new ObjectPropsNativeComponentManagerDelegate<>(this);
28 | }
29 |
30 | @Override
31 | public ViewGroup createViewInstance(ThemedReactContext context) {
32 | throw new IllegalStateException();
33 | }
34 |
35 | @Override
36 | public void setObjectProp(ViewGroup view, ReadableMap value) {}
37 |
38 | @Override
39 | public void setObjectArrayProp(ViewGroup view, ReadableMap value) {}
40 |
41 | @Override
42 | public void setObjectPrimitiveRequiredProp(ViewGroup view, ReadableMap value) {}
43 | }
44 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/PointPropNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.bridge.ReadableMap;
12 | import com.facebook.react.viewmanagers.PointPropNativeComponentViewManagerDelegate;
13 | import com.facebook.react.viewmanagers.PointPropNativeComponentViewManagerInterface;
14 |
15 | public class PointPropNativeComponentViewManager extends SimpleViewManager
16 | implements PointPropNativeComponentViewManagerInterface {
17 |
18 | public static final String REACT_CLASS = "PointPropNativeComponentView";
19 |
20 | @Override
21 | public String getName() {
22 | return REACT_CLASS;
23 | }
24 |
25 | private void test() {
26 | PointPropNativeComponentViewManagerDelegate
27 | delegate = new PointPropNativeComponentViewManagerDelegate<>(this);
28 | }
29 |
30 | @Override
31 | public ViewGroup createViewInstance(ThemedReactContext context) {
32 | throw new IllegalStateException();
33 | }
34 |
35 | @Override
36 | public void setStartPoint(ViewGroup view, ReadableMap value) {}
37 | }
38 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/buck_tests/java/StringPropNativeComponentViewManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | */
7 |
8 | package com.facebook.react.uimanager;
9 |
10 | import android.view.ViewGroup;
11 | import com.facebook.react.viewmanagers.StringPropNativeComponentViewManagerDelegate;
12 | import com.facebook.react.viewmanagers.StringPropNativeComponentViewManagerInterface;
13 |
14 | public class StringPropNativeComponentViewManager extends SimpleViewManager
15 | implements StringPropNativeComponentViewManagerInterface {
16 |
17 | public static final String REACT_CLASS = "StringPropNativeComponentView";
18 |
19 | @Override
20 | public String getName() {
21 | return REACT_CLASS;
22 | }
23 |
24 | private void test() {
25 | StringPropNativeComponentViewManagerDelegate
26 | delegate = new StringPropNativeComponentViewManagerDelegate<>(this);
27 | }
28 |
29 | @Override
30 | public ViewGroup createViewInstance(ThemedReactContext context) {
31 | throw new IllegalStateException();
32 | }
33 |
34 | @Override
35 | public void setPlaceholder(ViewGroup view, String value) {}
36 |
37 | @Override
38 | public void setDefaultValue(ViewGroup view, String value) {}
39 | }
40 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/ArrayPropsNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {
14 | PointValue,
15 | ColorValue,
16 | EdgeInsetsValue,
17 | } from '../../../../../Libraries/StyleSheet/StyleSheetTypes';
18 | import type {ImageSource} from '../../../../../Libraries/Image/ImageSource';
19 | import type {
20 | Int32,
21 | Float,
22 | WithDefault,
23 | } from '../../../../../Libraries/Types/CodegenTypes';
24 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
25 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
26 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
27 |
28 | type NativeProps = $ReadOnly<{|
29 | ...ViewProps,
30 |
31 | // Props
32 | names?: $ReadOnlyArray,
33 | disableds?: $ReadOnlyArray,
34 | progress?: $ReadOnlyArray,
35 | radii?: $ReadOnlyArray,
36 | colors?: $ReadOnlyArray,
37 | srcs?: $ReadOnlyArray,
38 | points?: $ReadOnlyArray,
39 | edgeInsets?: $ReadOnlyArray,
40 | sizes?: WithDefault<$ReadOnlyArray<'small' | 'large'>, 'small'>,
41 | object?: $ReadOnlyArray<$ReadOnly<{|prop: string|}>>,
42 | |}>;
43 |
44 | export default (codegenNativeComponent(
45 | 'ArrayPropsNativeComponentView',
46 | ): HostComponent);
47 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/BooleanPropNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {WithDefault} from '../../../../../Libraries/Types/CodegenTypes';
14 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
15 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
16 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
17 |
18 | type NativeProps = $ReadOnly<{|
19 | ...ViewProps,
20 |
21 | // Props
22 | disabled?: WithDefault,
23 | disabledNullable?: WithDefault,
24 | |}>;
25 |
26 | export default (codegenNativeComponent(
27 | 'BooleanPropNativeComponentView',
28 | ): HostComponent);
29 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/ColorPropNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {ColorValue} from '../../../../../Libraries/StyleSheet/StyleSheetTypes';
14 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
15 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
16 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
17 |
18 | type NativeProps = $ReadOnly<{|
19 | ...ViewProps,
20 |
21 | // Props
22 | tintColor?: ColorValue,
23 | |}>;
24 |
25 | export default (codegenNativeComponent(
26 | 'ColorPropNativeComponentView',
27 | ): HostComponent);
28 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/EdgeInsetsPropNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {EdgeInsetsValue} from '../../../../../Libraries/StyleSheet/StyleSheetTypes';
14 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
15 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
16 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
17 |
18 | type NativeProps = $ReadOnly<{|
19 | ...ViewProps,
20 |
21 | // Props
22 | contentInset?: EdgeInsetsValue,
23 | |}>;
24 |
25 | export default (codegenNativeComponent(
26 | 'EdgeInsetsPropNativeComponentView',
27 | ): HostComponent);
28 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/EnumPropNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {WithDefault} from '../../../../../Libraries/Types/CodegenTypes';
14 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
15 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
16 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
17 |
18 | type NativeProps = $ReadOnly<{|
19 | ...ViewProps,
20 |
21 | // Props
22 | alignment?: WithDefault<'top' | 'center' | 'bottom-right', 'center'>,
23 | intervals?: WithDefault<0 | 15 | 30 | 60, 0>,
24 | |}>;
25 |
26 | export default (codegenNativeComponent(
27 | 'EnumPropNativeComponentView',
28 | ): HostComponent);
29 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/EventNestedObjectPropsNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {
14 | Int32,
15 | BubblingEventHandler,
16 | WithDefault,
17 | } from '../../../../../Libraries/Types/CodegenTypes';
18 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
19 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
20 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
21 |
22 | type OnChangeEvent = $ReadOnly<{|
23 | location: {
24 | source: {
25 | url: string,
26 | },
27 | x: Int32,
28 | y: Int32,
29 | },
30 | |}>;
31 |
32 | type NativeProps = $ReadOnly<{|
33 | ...ViewProps,
34 |
35 | // Props
36 | disabled?: WithDefault,
37 |
38 | // Events
39 | onChange?: ?BubblingEventHandler,
40 | |}>;
41 |
42 | export default (codegenNativeComponent(
43 | 'EventNestedObjectPropsNativeComponentView',
44 | ): HostComponent);
45 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/EventPropsNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {
14 | Int32,
15 | Float,
16 | BubblingEventHandler,
17 | DirectEventHandler,
18 | WithDefault,
19 | } from '../../../../../Libraries/Types/CodegenTypes';
20 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
21 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
22 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
23 |
24 | type OnChangeEvent = $ReadOnly<{|
25 | value: boolean,
26 | source?: string,
27 | progress: ?Int32,
28 | scale?: ?Float,
29 | |}>;
30 |
31 | type OnEventDirect = $ReadOnly<{|
32 | value: boolean,
33 | |}>;
34 |
35 | type OnOrientationChangeEvent = $ReadOnly<{|
36 | orientation: 'landscape' | 'portrait',
37 | |}>;
38 |
39 | type NativeProps = $ReadOnly<{|
40 | ...ViewProps,
41 |
42 | // Props
43 | disabled?: WithDefault,
44 |
45 | // Events
46 | onChange?: ?BubblingEventHandler,
47 | onEventDirect?: ?DirectEventHandler,
48 | onEventDirectWithPaperName?: ?DirectEventHandler<
49 | OnEventDirect,
50 | 'paperDirectName',
51 | >,
52 | onOrientationChange?: ?DirectEventHandler<
53 | OnOrientationChangeEvent,
54 | 'paperBubblingName',
55 | >,
56 | onEnd?: ?BubblingEventHandler,
57 | onEventBubblingWithPaperName?: ?BubblingEventHandler<
58 | null,
59 | 'paperBubblingName',
60 | >,
61 | |}>;
62 |
63 | export default (codegenNativeComponent(
64 | 'EventPropsNativeComponentView',
65 | ): HostComponent);
66 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/FloatPropsNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {
14 | WithDefault,
15 | Float,
16 | } from '../../../../../Libraries/Types/CodegenTypes';
17 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
18 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
19 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
20 |
21 | type NativeProps = $ReadOnly<{|
22 | ...ViewProps,
23 |
24 | // Props
25 | blurRadius: Float,
26 | blurRadius2?: WithDefault,
27 | blurRadius3?: WithDefault,
28 | blurRadius4?: WithDefault,
29 | blurRadius5?: WithDefault,
30 | blurRadius6?: WithDefault,
31 | blurRadiusNullable?: WithDefault,
32 | |}>;
33 |
34 | export default (codegenNativeComponent(
35 | 'FloatPropsNativeComponentView',
36 | ): HostComponent);
37 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/ImagePropNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {ImageSource} from '../../../../../Libraries/Image/ImageSource';
14 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
15 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
16 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
17 |
18 | type NativeProps = $ReadOnly<{|
19 | ...ViewProps,
20 |
21 | // Props
22 | thumbImage?: ImageSource,
23 | |}>;
24 |
25 | export default (codegenNativeComponent(
26 | 'ImagePropNativeComponentView',
27 | ): HostComponent);
28 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/IntegerPropNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {
14 | WithDefault,
15 | Int32,
16 | } from '../../../../../Libraries/Types/CodegenTypes';
17 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
18 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
19 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
20 |
21 | type NativeProps = $ReadOnly<{|
22 | ...ViewProps,
23 |
24 | // Props
25 | progress1?: WithDefault,
26 | progress2?: WithDefault,
27 | progress3?: WithDefault,
28 | |}>;
29 |
30 | export default (codegenNativeComponent(
31 | 'IntegerPropNativeComponentView',
32 | ): HostComponent);
33 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/InterfaceOnlyNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {
14 | BubblingEventHandler,
15 | WithDefault,
16 | } from '../../../../../Libraries/Types/CodegenTypes';
17 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
18 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
19 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
20 |
21 | type NativeProps = $ReadOnly<{|
22 | ...ViewProps,
23 |
24 | // Props
25 | title?: WithDefault,
26 |
27 | // Events
28 | onChange?: ?BubblingEventHandler<$ReadOnly<{|value: boolean|}>>,
29 | |}>;
30 |
31 | export default (codegenNativeComponent(
32 | 'InterfaceOnlyNativeComponentView',
33 | {
34 | interfaceOnly: true,
35 | paperComponentName: 'RCTInterfaceOnlyComponent',
36 | },
37 | ): HostComponent);
38 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/MultiNativePropNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {
14 | PointValue,
15 | ColorValue,
16 | } from '../../../../../Libraries/StyleSheet/StyleSheetTypes';
17 | import type {ImageSource} from '../../../../../Libraries/Image/ImageSource';
18 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
19 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
20 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
21 |
22 | type NativeProps = $ReadOnly<{|
23 | ...ViewProps,
24 |
25 | // Props
26 | thumbImage?: ImageSource,
27 | color?: ColorValue,
28 | thumbTintColor?: ColorValue,
29 | point?: PointValue,
30 | |}>;
31 |
32 | export default (codegenNativeComponent(
33 | 'MultiNativePropNativeComponentView',
34 | ): HostComponent);
35 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/NoPropsNoEventsNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
14 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
15 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
16 |
17 | type NativeProps = $ReadOnly<{|
18 | ...ViewProps,
19 |
20 | // No Props or events
21 | |}>;
22 |
23 | export default (codegenNativeComponent(
24 | 'NoPropsNoEventsNativeComponentView',
25 | ): HostComponent);
26 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/ObjectPropsNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
14 | import type {ImageSource} from '../../../../../Libraries/Image/ImageSource';
15 | import type {
16 | PointValue,
17 | ColorValue,
18 | } from '../../../../../Libraries/StyleSheet/StyleSheetTypes';
19 | import type {
20 | Int32,
21 | Float,
22 | WithDefault,
23 | } from '../../../../../Libraries/Types/CodegenTypes';
24 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
25 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
26 |
27 | type ObjectArrayPropType = $ReadOnly<{|
28 | array: $ReadOnlyArray,
29 | |}>;
30 |
31 | type NativeProps = $ReadOnly<{|
32 | ...ViewProps,
33 |
34 | // Props
35 | objectProp?: $ReadOnly<{|
36 | stringProp?: WithDefault,
37 | booleanProp: boolean,
38 | floatProp: Float,
39 | intProp: Int32,
40 | stringEnumProp?: WithDefault<'small' | 'large', 'small'>,
41 | intEnumProp?: WithDefault<0 | 1, 0>,
42 | |}>,
43 | objectArrayProp: ObjectArrayPropType,
44 | objectPrimitiveRequiredProp: $ReadOnly<{|
45 | image: ImageSource,
46 | color?: ColorValue,
47 | point: ?PointValue,
48 | |}>,
49 | |}>;
50 |
51 | export default (codegenNativeComponent(
52 | 'ObjectPropsNativeComponent',
53 | ): HostComponent);
54 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/PointPropNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {PointValue} from '../../../../../Libraries/StyleSheet/StyleSheetTypes';
14 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
15 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
16 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
17 |
18 | type NativeProps = $ReadOnly<{|
19 | ...ViewProps,
20 |
21 | // Props
22 | startPoint?: PointValue,
23 | |}>;
24 |
25 | export default (codegenNativeComponent(
26 | 'PointPropNativeComponentView',
27 | ): HostComponent);
28 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/components/StringPropNativeComponent.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @format
8 | * @flow
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {WithDefault} from '../../../../../Libraries/Types/CodegenTypes';
14 | import type {ViewProps} from '../../../../../Libraries/Components/View/ViewPropTypes';
15 | import codegenNativeComponent from '../../../../../Libraries/Utilities/codegenNativeComponent';
16 | import type {HostComponent} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
17 |
18 | type NativeProps = $ReadOnly<{|
19 | ...ViewProps,
20 |
21 | // Props
22 | placeholder?: WithDefault,
23 | defaultValue?: string,
24 | |}>;
25 |
26 | export default (codegenNativeComponent(
27 | 'StringPropNativeComponentView',
28 | ): HostComponent);
29 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeArrayTurboModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
14 | import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
15 |
16 | export type ArrayType = string;
17 | type AnotherArray = Array;
18 |
19 | export interface Spec extends TurboModule {
20 | +getArray: (a: Array) => Array;
21 | +getReadOnlyArray: (a: Array) => $ReadOnlyArray;
22 | +getArrayWithAlias: (a: AnotherArray, b: Array) => AnotherArray;
23 | }
24 |
25 | export default (TurboModuleRegistry.getEnforcing(
26 | 'SampleTurboModule',
27 | ): Spec);
28 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeBooleanTurboModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
14 | import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
15 |
16 | export type Boolean = boolean;
17 | type AnotherBoolean = Boolean;
18 |
19 | export interface Spec extends TurboModule {
20 | +getBoolean: (arg: boolean) => boolean;
21 | +getBooleanWithAlias: (arg: Boolean) => AnotherBoolean;
22 | }
23 |
24 | export default (TurboModuleRegistry.getEnforcing(
25 | 'SampleTurboModule',
26 | ): Spec);
27 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeCallbackTurboModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
14 | import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
15 |
16 | export type String = string;
17 | type CB = (value: String) => void;
18 |
19 | export interface Spec extends TurboModule {
20 | +getValueWithCallback: (callback: (value: string) => void) => void;
21 | +getValueWithCallbackWithAlias: (c: CB) => void;
22 | }
23 |
24 | export default (TurboModuleRegistry.getEnforcing(
25 | 'SampleTurboModule',
26 | ): Spec);
27 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeNullableTurboModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
14 | import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
15 |
16 | export interface Spec extends TurboModule {
17 | +getBool: (a: ?boolean) => ?boolean;
18 | +getNumber: (a: ?number) => ?number;
19 | +getString: (a: ?number) => ?string;
20 | +getArray: (a: ?Array) => ?Array;
21 | +getObject: (a: ?Object) => ?Object;
22 | +getValueWithPromise: () => ?Promise;
23 | }
24 |
25 | export default (TurboModuleRegistry.getEnforcing(
26 | 'SampleTurboModule',
27 | ): Spec);
28 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeNumberTurboModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
14 | import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
15 |
16 | export type Number = number;
17 | type AnotherNumber = Number;
18 |
19 | export interface Spec extends TurboModule {
20 | +getNumber: (arg: number) => number;
21 | +getNumberWithAlias: (arg: Number) => AnotherNumber;
22 | }
23 |
24 | export default (TurboModuleRegistry.getEnforcing(
25 | 'SampleTurboModule',
26 | ): Spec);
27 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeObjectTurboModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
14 | import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
15 |
16 | export type GenericObject = Object;
17 | type AnotherGenericObject = GenericObject;
18 |
19 | export interface Spec extends TurboModule {
20 | +getGenericObject: (arg: Object) => Object;
21 | +getGenericObjectReadOnly: (arg: Object) => $ReadOnly<{|a: string|}>;
22 | +getGenericObjectWithAlias: (arg: GenericObject) => AnotherGenericObject;
23 | +difficultObject: (A: {|
24 | D: boolean,
25 | E: {|
26 | D: boolean,
27 | E: number,
28 | F: string,
29 | |},
30 | F: string,
31 | |}) => {|
32 | D: boolean,
33 | E: {|
34 | D: boolean,
35 | E: {|
36 | D: boolean,
37 | E: number,
38 | F: string,
39 | |},
40 | F: string,
41 | |},
42 | F: string,
43 | |};
44 | +getConstants: () => {|
45 | D: boolean,
46 | E: {|
47 | D: boolean,
48 | E: {|
49 | D: boolean,
50 | E: {|
51 | D: boolean,
52 | E: number,
53 | F: string,
54 | |},
55 | F: string,
56 | |},
57 | F: string,
58 | |},
59 | F: string,
60 | |};
61 | }
62 |
63 | export default (TurboModuleRegistry.getEnforcing(
64 | 'SampleTurboModule',
65 | ): Spec);
66 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeOptionalObjectTurboModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
14 | import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
15 |
16 | export interface Spec extends TurboModule {
17 | +getConstants: () => {|
18 | D?: ?boolean,
19 | A?: Array,
20 | G?: any,
21 | E?: ?{|
22 | D?: ?boolean,
23 | E?: ?{|
24 | D?: ?boolean,
25 | E?: ?{|
26 | D?: boolean,
27 | E?: number,
28 | F?: string,
29 | |},
30 | F?: string,
31 | |},
32 | F?: string,
33 | |},
34 | F?: string,
35 | |};
36 | }
37 |
38 | export default (TurboModuleRegistry.getEnforcing(
39 | 'SampleTurboModule',
40 | ): Spec);
41 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativePromiseTurboModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
14 | import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
15 |
16 | export type String = string;
17 | type AnotherPromise = Promise;
18 |
19 | export interface Spec extends TurboModule {
20 | +getValueWithPromise: (error: boolean) => Promise;
21 | +getValueWithPromiseWithAlias: (arg: String) => AnotherPromise;
22 | }
23 |
24 | export default (TurboModuleRegistry.getEnforcing(
25 | 'SampleTurboModule',
26 | ): Spec);
27 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeSampleTurboModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
14 | import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
15 |
16 | export interface Spec extends TurboModule {
17 | // Exported methods.
18 | +getConstants: () => {|
19 | const1: boolean,
20 | const2: number,
21 | const3: string,
22 | |};
23 | +voidFunc: () => void;
24 | +getBool: (arg: boolean) => boolean;
25 | +getNumber: (arg: number) => number;
26 | +getString: (arg: string) => string;
27 | +getArray: (arg: Array) => Array;
28 | +getObject: (arg: Object) => Object;
29 | +getValue: (x: number, y: string, z: Object) => Object;
30 | +getValueWithCallback: (callback: (value: string) => void) => void;
31 | +getValueWithPromise: (error: boolean) => Promise;
32 | }
33 |
34 | export default (TurboModuleRegistry.getEnforcing(
35 | 'SampleTurboModule',
36 | ): Spec);
37 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/e2e/__test_fixtures__/modules/NativeStringTurboModule.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
14 | import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
15 |
16 | export type String = string;
17 | type AnotherString = String;
18 |
19 | export interface Spec extends TurboModule {
20 | +getString: (arg: string) => string;
21 | +getStringWithAlias: (arg: String) => AnotherString;
22 | }
23 |
24 | export default (TurboModuleRegistry.getEnforcing(
25 | 'SampleTurboModule',
26 | ): Spec);
27 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.0.1",
3 | "name": "react-native-codegen",
4 | "description": "⚛️ Code generation tools for React Native",
5 | "repository": {
6 | "type": "git",
7 | "url": "git@github.com:facebook/react-native.git"
8 | },
9 | "dependencies": {
10 | "flow-parser": "^0.102.0",
11 | "jscodeshift": "^0.6.2",
12 | "nullthrows": "^1.1.1"
13 | },
14 | "license": "MIT"
15 | }
16 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/SchemaValidator.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow strict-local
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | const nullthrows = require('nullthrows');
14 |
15 | import type {SchemaType} from './CodegenSchema';
16 |
17 | function getErrors(schema: SchemaType): $ReadOnlyArray {
18 | const errors = new Set();
19 |
20 | // Map of component name -> Array of module names
21 | const componentModules: Map> = new Map();
22 |
23 | Object.keys(schema.modules).forEach(moduleName => {
24 | const module = schema.modules[moduleName];
25 |
26 | if (module.components == null) {
27 | return;
28 | }
29 |
30 | Object.keys(module.components).forEach(componentName => {
31 | if (module.components == null) {
32 | return;
33 | }
34 |
35 | if (!componentModules.has(componentName)) {
36 | componentModules.set(componentName, []);
37 | }
38 |
39 | nullthrows(componentModules.get(componentName)).push(moduleName);
40 | });
41 | });
42 |
43 | componentModules.forEach((modules, componentName) => {
44 | if (modules.length > 1) {
45 | errors.add(
46 | `Duplicate components found with name ${componentName}. Found in modules ${modules.join(
47 | ', ',
48 | )}`,
49 | );
50 | }
51 | });
52 |
53 | return Array.from(errors).sort();
54 | }
55 |
56 | function validate(schema: SchemaType) {
57 | const errors = getErrors(schema);
58 |
59 | if (errors.length !== 0) {
60 | throw new Error('Errors found validating schema:\n' + errors.join('\n'));
61 | }
62 | }
63 |
64 | module.exports = {
65 | getErrors,
66 | validate,
67 | };
68 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/__tests__/SchemaValidator-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../generators/components/__test_fixtures__/fixtures.js');
15 | const schemaValidator = require('../SchemaValidator.js');
16 |
17 | import type {SchemaType} from '../CodegenSchema.js';
18 |
19 | const simpleProp = {
20 | name: 'disabled',
21 | optional: true,
22 | typeAnnotation: {
23 | type: 'BooleanTypeAnnotation',
24 | default: false,
25 | },
26 | };
27 |
28 | describe('SchemaValidator', () => {
29 | it('fails on components across modules with same name', () => {
30 | const fixture: SchemaType = {
31 | modules: {
32 | Module1: {
33 | components: {
34 | Component1: {
35 | extendsProps: [
36 | {
37 | type: 'ReactNativeBuiltInType',
38 | knownTypeName: 'ReactNativeCoreViewProps',
39 | },
40 | ],
41 | events: [],
42 | props: [simpleProp],
43 | commands: [],
44 | },
45 | },
46 | },
47 | Module2: {
48 | components: {
49 | Component1: {
50 | extendsProps: [
51 | {
52 | type: 'ReactNativeBuiltInType',
53 | knownTypeName: 'ReactNativeCoreViewProps',
54 | },
55 | ],
56 | events: [],
57 | props: [simpleProp],
58 | commands: [],
59 | },
60 | },
61 | },
62 | },
63 | };
64 |
65 | expect(schemaValidator.getErrors(fixture)).toMatchSnapshot();
66 | });
67 |
68 | describe('fixture', () => {
69 | Object.keys(fixtures)
70 | .sort()
71 | .forEach(fixtureName => {
72 | const fixture = fixtures[fixtureName];
73 |
74 | it(`${fixtureName} has no errors`, () => {
75 | expect(schemaValidator.getErrors(fixture)).toHaveLength(0);
76 | });
77 | });
78 | });
79 | });
80 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/__tests__/__snapshots__/SchemaValidator-test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`SchemaValidator fails on components across modules with same name 1`] = `
4 | Array [
5 | "Duplicate components found with name Component1. Found in modules Module1, Module2",
6 | ]
7 | `;
8 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/cli/combine/combine-js-to-schema-cli.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const combine = require('./combine-js-to-schema');
15 | const fs = require('fs');
16 |
17 | const [outfile, ...fileList] = process.argv.slice(2);
18 |
19 | const formattedSchema = JSON.stringify(combine(fileList), null, 2);
20 | if (outfile != null) {
21 | fs.writeFileSync(outfile, formattedSchema);
22 | } else {
23 | console.log(formattedSchema);
24 | }
25 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 | import type {SchemaType} from '../../CodegenSchema.js';
13 |
14 | const FlowParser = require('../../parsers/flow');
15 | const fs = require('fs');
16 |
17 | function combineSchemas(files: Array): SchemaType {
18 | return files.reduce(
19 | (merged, filename) => {
20 | const contents = fs.readFileSync(filename, 'utf8');
21 | if (
22 | contents &&
23 | (/export\s+default\s+\(?codegenNativeComponent/dev/null
16 | "$INSTALL_NODE_MODULES"
17 | popd >/dev/null
18 |
19 | exec "$FLOW_NODE_BINARY" "$THIS_DIR/combine-js-to-schema-cli.js" "$@"
20 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/cli/parser/parser-cli.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const parseFiles = require('./parser.js');
15 |
16 | const [...fileList] = process.argv.slice(2);
17 |
18 | parseFiles(fileList);
19 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/cli/parser/parser.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | const FlowParser = require('../../parsers/flow');
14 |
15 | function parseFiles(files: Array) {
16 | files.forEach(filename => {
17 | console.log(
18 | filename,
19 | JSON.stringify(FlowParser.parseFile(filename), null, 2),
20 | );
21 | });
22 | }
23 |
24 | module.exports = parseFiles;
25 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/cli/parser/parser.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright (c) Facebook, Inc. and its affiliates.
3 | #
4 | # This source code is licensed under the MIT license found in the
5 | # LICENSE file in the root directory of this source tree.
6 |
7 | set -e
8 | set -u
9 |
10 | THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
11 |
12 | # shellcheck source=xplat/js/env-utils/setup_env_vars.sh
13 | source "$THIS_DIR/../../../../../../env-utils/setup_env_vars.sh"
14 |
15 | exec "$FLOW_NODE_BINARY" "$THIS_DIR/parser.js" "$@"
16 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/cli/verify_all_modules_with_old_codegen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright (c) Facebook, Inc. and its affiliates.
3 | #
4 | # This source code is licensed under the MIT license found in the
5 | # LICENSE file in the root directory of this source tree.
6 |
7 | set -e
8 | set -u
9 |
10 | exec buck query "filter('generated_objcpp_modules_tests_', '//xplat/js/...')" | xargs buck build
11 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/cli/verify_with_old_codegen.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | const fs = require('fs');
14 | const [first, second] = process.argv.slice(2);
15 |
16 | const contents1 = fs.readFileSync(first, 'utf8');
17 | const contents2 = fs.readFileSync(second, 'utf8');
18 |
19 | function traverse(t) {
20 | return t
21 | .replace(/\).invoke/g, ')\n.invoke') // in old codegen it was in one line
22 | .split('\n')
23 | .map(l => l.trim()) // no whitespaces
24 | .filter(Boolean) // no empty lines
25 | .filter(
26 | l =>
27 | !l.startsWith('namespace') && // no namespaces
28 | !l.startsWith('}') && // after removing openign namespaces we need to remove all closings
29 | !l.startsWith('/**') && // all comments
30 | !l.startsWith('#') && // imports
31 | !l.startsWith('//') && // comments
32 | !l.startsWith('importing it, you must change') && // comment in old codegen
33 | !l.startsWith('*'), //comments
34 | )
35 | .map(l => l.replace(/ /g, '')) // remove rest whitespaces
36 | .sort(); // sort alphabetically lines
37 | }
38 |
39 | const t1 = traverse(contents1);
40 | const t2 = traverse(contents2);
41 |
42 | if (t1.length !== t2.length) {
43 | throw new Error('Old and new codegen produces output of different size');
44 | } else {
45 | for (let i = 0; i < t1.length; i++) {
46 | if (t1[i] !== t2[i]) {
47 | throw new Error(
48 | `Old and new codegen does not produce similar output! ${i} ${
49 | t1[i]
50 | } | ${t2[i]}`,
51 | );
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/cli/verify_with_old_codegen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright (c) Facebook, Inc. and its affiliates.
3 | #
4 | # This source code is licensed under the MIT license found in the
5 | # LICENSE file in the root directory of this source tree.
6 |
7 | set -e
8 | set -u
9 |
10 | THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
11 |
12 | # shellcheck source=xplat/js/env-utils/setup_env_vars.sh
13 | source "$THIS_DIR/../../../../../env-utils/setup_env_vars.sh"
14 |
15 | pushd "$THIS_DIR/../.." >/dev/null
16 | "$INSTALL_NODE_MODULES"
17 | popd >/dev/null
18 |
19 | exec "$FLOW_NODE_BINARY" "$THIS_DIR/verify_with_old_codegen.js" "$@"
20 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/GenerateComponentDescriptorH.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow strict
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {SchemaType} from '../../CodegenSchema';
14 |
15 | // File path -> contents
16 | type FilesOutput = Map;
17 |
18 | const template = `
19 | /**
20 | * Copyright (c) Facebook, Inc. and its affiliates.
21 | *
22 | * This source code is licensed under the MIT license found in the
23 | * LICENSE file in the root directory of this source tree.
24 | */
25 |
26 | #pragma once
27 |
28 | #include
29 | #include
30 |
31 | namespace facebook {
32 | namespace react {
33 |
34 | ::_COMPONENT_DESCRIPTORS_::
35 |
36 | } // namespace react
37 | } // namespace facebook
38 | `;
39 |
40 | const componentTemplate = `
41 | using ::_CLASSNAME_::ComponentDescriptor = ConcreteComponentDescriptor<::_CLASSNAME_::ShadowNode>;
42 | `.trim();
43 |
44 | module.exports = {
45 | generate(
46 | libraryName: string,
47 | schema: SchemaType,
48 | moduleSpecName: string,
49 | ): FilesOutput {
50 | const fileName = 'ComponentDescriptors.h';
51 |
52 | const componentDescriptors = Object.keys(schema.modules)
53 | .map(moduleName => {
54 | const components = schema.modules[moduleName].components;
55 | // No components in this module
56 | if (components == null) {
57 | return null;
58 | }
59 |
60 | return Object.keys(components)
61 | .map(componentName => {
62 | if (components[componentName].interfaceOnly === true) {
63 | return;
64 | }
65 | return componentTemplate.replace(/::_CLASSNAME_::/g, componentName);
66 | })
67 | .join('\n');
68 | })
69 | .filter(Boolean)
70 | .join('\n');
71 |
72 | const replacedTemplate = template
73 | .replace(/::_COMPONENT_DESCRIPTORS_::/g, componentDescriptors)
74 | .replace('::_LIBRARY_::', libraryName);
75 |
76 | return new Map([[fileName, replacedTemplate]]);
77 | },
78 | };
79 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow strict
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {ComponentShape, SchemaType} from '../../CodegenSchema';
14 | const {convertDefaultTypeToString, getImports} = require('./CppHelpers');
15 |
16 | // File path -> contents
17 | type FilesOutput = Map;
18 |
19 | const template = `
20 | /**
21 | * Copyright (c) Facebook, Inc. and its affiliates.
22 | *
23 | * This source code is licensed under the MIT license found in the
24 | * LICENSE file in the root directory of this source tree.
25 | */
26 |
27 | #include
28 | ::_IMPORTS_::
29 |
30 | namespace facebook {
31 | namespace react {
32 |
33 | ::_COMPONENT_CLASSES_::
34 |
35 | } // namespace react
36 | } // namespace facebook
37 | `;
38 |
39 | const componentTemplate = `
40 | ::_CLASSNAME_::::::_CLASSNAME_::(
41 | const ::_CLASSNAME_:: &sourceProps,
42 | const RawProps &rawProps):::_EXTEND_CLASSES_::
43 |
44 | ::_PROPS_::
45 | {}
46 | `.trim();
47 |
48 | function generatePropsString(componentName: string, component: ComponentShape) {
49 | return component.props
50 | .map(prop => {
51 | const defaultValue = convertDefaultTypeToString(componentName, prop);
52 | return `${prop.name}(convertRawProp(rawProps, "${
53 | prop.name
54 | }", sourceProps.${prop.name}, {${defaultValue}}))`;
55 | })
56 | .join(',\n' + ' ');
57 | }
58 |
59 | function getClassExtendString(component): string {
60 | const extendString =
61 | ' ' +
62 | component.extendsProps
63 | .map(extendProps => {
64 | switch (extendProps.type) {
65 | case 'ReactNativeBuiltInType':
66 | switch (extendProps.knownTypeName) {
67 | case 'ReactNativeCoreViewProps':
68 | return 'ViewProps(sourceProps, rawProps)';
69 | default:
70 | (extendProps.knownTypeName: empty);
71 | throw new Error('Invalid knownTypeName');
72 | }
73 | default:
74 | (extendProps.type: empty);
75 | throw new Error('Invalid extended type');
76 | }
77 | })
78 | .join(', ') +
79 | `${component.props.length > 0 ? ',' : ''}`;
80 |
81 | return extendString;
82 | }
83 |
84 | module.exports = {
85 | generate(
86 | libraryName: string,
87 | schema: SchemaType,
88 | moduleSpecName: string,
89 | ): FilesOutput {
90 | const fileName = 'Props.cpp';
91 | const allImports: Set = new Set([
92 | '#include ',
93 | ]);
94 |
95 | const componentProps = Object.keys(schema.modules)
96 | .map(moduleName => {
97 | const components = schema.modules[moduleName].components;
98 | // No components in this module
99 | if (components == null) {
100 | return null;
101 | }
102 |
103 | return Object.keys(components)
104 | .map(componentName => {
105 | const component = components[componentName];
106 | const newName = `${componentName}Props`;
107 |
108 | const propsString = generatePropsString(componentName, component);
109 | const extendString = getClassExtendString(component);
110 |
111 | const imports = getImports(component.props);
112 | imports.forEach(allImports.add, allImports);
113 |
114 | const replacedTemplate = componentTemplate
115 | .replace(/::_CLASSNAME_::/g, newName)
116 | .replace('::_EXTEND_CLASSES_::', extendString)
117 | .replace('::_PROPS_::', propsString);
118 |
119 | return replacedTemplate;
120 | })
121 | .join('\n');
122 | })
123 | .filter(Boolean)
124 | .join('\n');
125 |
126 | const replacedTemplate = template
127 | .replace(/::_COMPONENT_CLASSES_::/g, componentProps)
128 | .replace('::_LIBRARY_::', libraryName)
129 | .replace(
130 | '::_IMPORTS_::',
131 |
132 | Array.from(allImports)
133 | .sort()
134 | .join('\n')
135 | .trim(),
136 | );
137 |
138 | return new Map([[fileName, replacedTemplate]]);
139 | },
140 | };
141 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/GenerateShadowNodeCpp.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow strict
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {SchemaType} from '../../CodegenSchema';
14 |
15 | // File path -> contents
16 | type FilesOutput = Map;
17 |
18 | const template = `
19 | /**
20 | * Copyright (c) Facebook, Inc. and its affiliates.
21 | *
22 | * This source code is licensed under the MIT license found in the
23 | * LICENSE file in the root directory of this source tree.
24 | */
25 |
26 | #include
27 |
28 | namespace facebook {
29 | namespace react {
30 |
31 | ::_COMPONENT_NAMES_::
32 |
33 | } // namespace react
34 | } // namespace facebook
35 | `;
36 |
37 | const componentTemplate = `
38 | extern const char ::_CLASSNAME_::ComponentName[] = "::_CLASSNAME_::";
39 | `.trim();
40 |
41 | module.exports = {
42 | generate(
43 | libraryName: string,
44 | schema: SchemaType,
45 | moduleSpecName: string,
46 | ): FilesOutput {
47 | const fileName = 'ShadowNodes.cpp';
48 |
49 | const componentNames = Object.keys(schema.modules)
50 | .map(moduleName => {
51 | const components = schema.modules[moduleName].components;
52 | // No components in this module
53 | if (components == null) {
54 | return null;
55 | }
56 |
57 | return Object.keys(components)
58 | .map(componentName => {
59 | if (components[componentName].interfaceOnly === true) {
60 | return;
61 | }
62 | const replacedTemplate = componentTemplate.replace(
63 | /::_CLASSNAME_::/g,
64 | componentName,
65 | );
66 |
67 | return replacedTemplate;
68 | })
69 | .join('\n');
70 | })
71 | .filter(Boolean)
72 | .join('\n');
73 |
74 | const replacedTemplate = template
75 | .replace(/::_COMPONENT_NAMES_::/g, componentNames)
76 | .replace('::_LIBRARY_::', libraryName);
77 |
78 | return new Map([[fileName, replacedTemplate]]);
79 | },
80 | };
81 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow strict
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {SchemaType} from '../../CodegenSchema';
14 |
15 | // File path -> contents
16 | type FilesOutput = Map;
17 |
18 | const template = `
19 | /**
20 | * Copyright (c) Facebook, Inc. and its affiliates.
21 | *
22 | * This source code is licensed under the MIT license found in the
23 | * LICENSE file in the root directory of this source tree.
24 | */
25 |
26 | #pragma once
27 |
28 | ::_IMPORTS_::#include
29 | #include
30 |
31 | namespace facebook {
32 | namespace react {
33 |
34 | ::_COMPONENT_CLASSES_::
35 |
36 | } // namespace react
37 | } // namespace facebook
38 | `;
39 |
40 | const componentTemplate = `
41 | extern const char ::_CLASSNAME_::ComponentName[];
42 |
43 | /*
44 | * \`ShadowNode\` for <::_CLASSNAME_::> component.
45 | */
46 | using ::_CLASSNAME_::ShadowNode = ConcreteViewShadowNode<
47 | ::_CLASSNAME_::ComponentName,
48 | ::_CLASSNAME_::Props::_EVENT_EMITTER_::>;
49 | `.trim();
50 |
51 | module.exports = {
52 | generate(
53 | libraryName: string,
54 | schema: SchemaType,
55 | moduleSpecName: string,
56 | ): FilesOutput {
57 | const fileName = 'ShadowNodes.h';
58 |
59 | let hasAnyEvents = false;
60 |
61 | const moduleResults = Object.keys(schema.modules)
62 | .map(moduleName => {
63 | const components = schema.modules[moduleName].components;
64 | // No components in this module
65 | if (components == null) {
66 | return null;
67 | }
68 |
69 | return Object.keys(components)
70 | .map(componentName => {
71 | const component = components[componentName];
72 | if (component.interfaceOnly === true) {
73 | return;
74 | }
75 |
76 | const hasEvents = component.events.length > 0;
77 |
78 | if (hasEvents) {
79 | hasAnyEvents = true;
80 | }
81 |
82 | const eventEmitter = hasEvents
83 | ? `,\n${componentName}EventEmitter`
84 | : '';
85 |
86 | const replacedTemplate = componentTemplate
87 | .replace(/::_CLASSNAME_::/g, componentName)
88 | .replace('::_EVENT_EMITTER_::', eventEmitter);
89 |
90 | return replacedTemplate;
91 | })
92 | .join('\n\n');
93 | })
94 | .filter(Boolean)
95 | .join('\n\n');
96 |
97 | const eventEmitterImport = `#include \n`;
98 |
99 | const replacedTemplate = template
100 | .replace(/::_COMPONENT_CLASSES_::/g, moduleResults)
101 | .replace('::_LIBRARY_::', libraryName)
102 | .replace('::_IMPORTS_::', hasAnyEvents ? eventEmitterImport : '');
103 |
104 | return new Map([[fileName, replacedTemplate]]);
105 | },
106 | };
107 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/JavaHelpers.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow strict
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {ComponentShape} from '../../CodegenSchema';
14 |
15 | function upperCaseFirst(inString: string): string {
16 | return inString[0].toUpperCase() + inString.slice(1);
17 | }
18 |
19 | function getInterfaceJavaClassName(componentName: string): string {
20 | return `${componentName.replace(/^RCT/, '')}ManagerInterface`;
21 | }
22 |
23 | function getDelegateJavaClassName(componentName: string): string {
24 | return `${componentName.replace(/^RCT/, '')}ManagerDelegate`;
25 | }
26 |
27 | function toSafeJavaString(
28 | input: string,
29 | shouldUpperCaseFirst?: boolean,
30 | ): string {
31 | const parts = input.split('-');
32 |
33 | if (shouldUpperCaseFirst === false) {
34 | return parts.join('');
35 | }
36 |
37 | return parts.map(upperCaseFirst).join('');
38 | }
39 |
40 | function getImports(component: ComponentShape): Set {
41 | const imports: Set = new Set();
42 |
43 | component.extendsProps.forEach(extendProps => {
44 | switch (extendProps.type) {
45 | case 'ReactNativeBuiltInType':
46 | switch (extendProps.knownTypeName) {
47 | case 'ReactNativeCoreViewProps':
48 | imports.add('import android.view.View;');
49 | return;
50 | default:
51 | (extendProps.knownTypeName: empty);
52 | throw new Error('Invalid knownTypeName');
53 | }
54 | default:
55 | (extendProps.type: empty);
56 | throw new Error('Invalid extended type');
57 | }
58 | });
59 |
60 | function addImportsForNativeName(name) {
61 | switch (name) {
62 | case 'ColorPrimitive':
63 | return;
64 | case 'ImageSourcePrimitive':
65 | imports.add('import com.facebook.react.bridge.ReadableMap;');
66 | return;
67 | case 'PointPrimitive':
68 | imports.add('import com.facebook.react.bridge.ReadableMap;');
69 | return;
70 | case 'EdgeInsetsPrimitive':
71 | imports.add('import com.facebook.react.bridge.ReadableMap;');
72 | return;
73 | default:
74 | (name: empty);
75 | throw new Error(
76 | `Invalid NativePrimitiveTypeAnnotation name, got ${name}`,
77 | );
78 | }
79 | }
80 |
81 | component.props.forEach(prop => {
82 | const typeAnnotation = prop.typeAnnotation;
83 |
84 | if (typeAnnotation.type === 'NativePrimitiveTypeAnnotation') {
85 | addImportsForNativeName(typeAnnotation.name);
86 | }
87 |
88 | if (typeAnnotation.type === 'ArrayTypeAnnotation') {
89 | imports.add('import com.facebook.react.bridge.ReadableArray;');
90 | }
91 |
92 | if (typeAnnotation.type === 'ObjectTypeAnnotation') {
93 | imports.add('import com.facebook.react.bridge.ReadableMap;');
94 | }
95 | });
96 |
97 | return imports;
98 | }
99 |
100 | module.exports = {
101 | getInterfaceJavaClassName,
102 | getDelegateJavaClassName,
103 | toSafeJavaString,
104 | getImports,
105 | };
106 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentDescriptorH-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GenerateComponentDescriptorH.js');
16 |
17 | describe('GenerateComponentDescriptorH', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/__tests__/GenerateComponentHObjCpp-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GenerateComponentHObjCpp.js');
16 |
17 | describe('GenerateComponentHObjCpp', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/__tests__/GenerateEventEmitterCpp-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GenerateEventEmitterCpp.js');
16 |
17 | describe('GenerateEventEmitterCpp', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/__tests__/GenerateEventEmitterH-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GenerateEventEmitterH.js');
16 |
17 | describe('GenerateEventEmitterH', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsCpp-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GeneratePropsCpp.js');
16 |
17 | describe('GeneratePropsCpp', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsH-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GeneratePropsH.js');
16 |
17 | describe('GeneratePropsH', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsJavaDelegate-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GeneratePropsJavaDelegate.js');
16 |
17 | describe('GeneratePropsJavaDelegate', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/__tests__/GeneratePropsJavaInterface-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GeneratePropsJavaInterface.js');
16 |
17 | describe('GeneratePropsJavaInterface', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/__tests__/GenerateShadowNodeCpp-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GenerateShadowNodeCpp.js');
16 |
17 | describe('GenerateShadowNodeCpp', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/__tests__/GenerateShadowNodeH-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GenerateShadowNodeH.js');
16 |
17 | describe('GenerateShadowNodeH', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/__tests__/GenerateTests-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GenerateTests.js');
16 |
17 | describe('GenerateTests', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/components/__tests__/GenerateViewConfigJs-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GenerateViewConfigJs.js');
16 |
17 | describe('GenerateViewConfigJs', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
25 | });
26 | });
27 |
28 | it('can generate fixture with a deprecated view config name', () => {
29 | expect(
30 | generator.generate('DEPRECATED_VIEW_CONFIG_NAME', {
31 | modules: {
32 | Component: {
33 | components: {
34 | NativeComponentName: {
35 | paperComponentNameDeprecated: 'DeprecatedNativeComponentName',
36 | extendsProps: [
37 | {
38 | type: 'ReactNativeBuiltInType',
39 | knownTypeName: 'ReactNativeCoreViewProps',
40 | },
41 | ],
42 | events: [],
43 | props: [],
44 | commands: [],
45 | },
46 | },
47 | },
48 | },
49 | }),
50 | ).toMatchSnapshot();
51 | });
52 | });
53 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow strict
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {
14 | SchemaType,
15 | FunctionTypeAnnotationParamTypeAnnotation,
16 | FunctionTypeAnnotationReturn,
17 | } from '../../CodegenSchema';
18 |
19 | type FilesOutput = Map;
20 |
21 | const moduleTemplate = `
22 | class JSI_EXPORT Native::_MODULE_NAME_::SpecJSI : public TurboModule {
23 | protected:
24 | Native::_MODULE_NAME_::SpecJSI(std::shared_ptr jsInvoker);
25 |
26 | public:
27 | ::_MODULE_PROPERTIES_::
28 |
29 | };`;
30 |
31 | const template = `
32 | /**
33 | * Copyright (c) Facebook, Inc. and its affiliates.
34 | *
35 | * This source code is licensed under the MIT license found in the
36 | * LICENSE file in the root directory of this source tree.
37 | */
38 |
39 | #pragma once
40 |
41 | #include
42 |
43 | namespace facebook {
44 | namespace react {
45 | ::_MODULES_::
46 |
47 | } // namespace react
48 | } // namespace facebook
49 | `;
50 |
51 | function translatePrimitiveJSTypeToCpp(
52 | type:
53 | | FunctionTypeAnnotationParamTypeAnnotation
54 | | FunctionTypeAnnotationReturn,
55 | error: string,
56 | ) {
57 | switch (type.type) {
58 | case 'VoidTypeAnnotation':
59 | return 'void';
60 | case 'StringTypeAnnotation':
61 | return 'jsi::String';
62 | case 'NumberTypeAnnotation':
63 | case 'FloatTypeAnnotation':
64 | return 'double';
65 | case 'Int32TypeAnnotation':
66 | return 'int';
67 | case 'BooleanTypeAnnotation':
68 | return 'bool';
69 | case 'GenericObjectTypeAnnotation':
70 | case 'ObjectTypeAnnotation':
71 | return 'jsi::Object';
72 | case 'ArrayTypeAnnotation':
73 | return 'jsi::Array';
74 | case 'FunctionTypeAnnotation':
75 | return 'jsi::Function';
76 | case 'GenericPromiseTypeAnnotation':
77 | return 'jsi::Value';
78 |
79 | default:
80 | throw new Error(error);
81 | }
82 | }
83 | const propertyTemplate =
84 | 'virtual ::_RETURN_VALUE_:: ::_PROPERTY_NAME_::(jsi::Runtime &rt::_ARGS_::) = 0;';
85 |
86 | module.exports = {
87 | generate(
88 | libraryName: string,
89 | schema: SchemaType,
90 | moduleSpecName: string,
91 | ): FilesOutput {
92 | const nativeModules = Object.keys(schema.modules)
93 | .filter(moduleName => moduleName.substr(-3) === 'Cxx')
94 | .map(moduleName => {
95 | const modules = schema.modules[moduleName].nativeModules;
96 | if (modules == null) {
97 | return null;
98 | }
99 |
100 | return modules;
101 | })
102 | .filter(Boolean)
103 | .reduce((acc, components) => Object.assign(acc, components), {});
104 |
105 | const modules = Object.keys(nativeModules)
106 | .map(name => {
107 | const {properties} = nativeModules[name];
108 | const traversedProperties = properties
109 | .map(prop => {
110 | const traversedArgs = prop.typeAnnotation.params
111 | .map(param => {
112 | const translatedParam = translatePrimitiveJSTypeToCpp(
113 | param.typeAnnotation,
114 | `Unspopported type for param "${param.name}" in ${
115 | prop.name
116 | }. Found: ${param.typeAnnotation.type}`,
117 | );
118 | const isObject = translatedParam.startsWith('jsi::');
119 | return (
120 | (isObject
121 | ? 'const ' + translatedParam + ' &'
122 | : translatedParam + ' ') + param.name
123 | );
124 | })
125 | .join(', ');
126 | return propertyTemplate
127 | .replace('::_PROPERTY_NAME_::', prop.name)
128 | .replace(
129 | '::_RETURN_VALUE_::',
130 | translatePrimitiveJSTypeToCpp(
131 | prop.typeAnnotation.returnTypeAnnotation,
132 | `Unspopported return type for ${prop.name}. Found: ${
133 | prop.typeAnnotation.returnTypeAnnotation.type
134 | }`,
135 | ),
136 | )
137 | .replace(
138 | '::_ARGS_::',
139 | traversedArgs === '' ? '' : ', ' + traversedArgs,
140 | );
141 | })
142 | .join('\n');
143 | return moduleTemplate
144 | .replace(/::_MODULE_PROPERTIES_::/g, traversedProperties)
145 | .replace(/::_MODULE_NAME_::/g, name)
146 | .replace('::_PROPERTIES_MAP_::', '');
147 | })
148 | .join('\n');
149 |
150 | const fileName = `${moduleSpecName.replace(/Spec/g, 'CxxSpec')}.h`;
151 | const replacedTemplate = template.replace(/::_MODULES_::/g, modules);
152 |
153 | return new Map([[fileName, replacedTemplate]]);
154 | },
155 | };
156 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/modules/ObjCppUtils/Utils.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow strict
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {ObjectParamTypeAnnotation} from '../../../CodegenSchema';
14 |
15 | function capitalizeFirstLetter(string: string): string {
16 | return string.charAt(0).toUpperCase() + string.slice(1);
17 | }
18 |
19 | function flatObjects(
20 | annotations: $ReadOnlyArray<
21 | $ReadOnly<{|
22 | name: string,
23 | object: $ReadOnly<{|
24 | type: 'ObjectTypeAnnotation',
25 | properties: $ReadOnlyArray,
26 | |}>,
27 | |}>,
28 | >,
29 | forConstants: boolean = false,
30 | ): $ReadOnlyArray<
31 | $ReadOnly<{|
32 | name: string,
33 | properties: $ReadOnlyArray,
34 | |}>,
35 | > {
36 | let objectTypesToFlatten: Array<{|
37 | properties: $ReadOnlyArray,
38 | name: string,
39 | |}> = annotations
40 | .map(annotation => ({
41 | name: annotation.name,
42 | properties: annotation.object.properties,
43 | }))
44 | .filter(
45 | annotation =>
46 | (annotation.name === 'GetConstantsReturnType') === forConstants,
47 | )
48 | .filter(
49 | annotation =>
50 | annotation.name !== 'GetConstantsReturnType' ||
51 | annotation.properties.length > 0,
52 | );
53 |
54 | let flattenObjects: Array<{|
55 | properties: $ReadOnlyArray,
56 | name: string,
57 | |}> = [];
58 |
59 | while (objectTypesToFlatten.length !== 0) {
60 | const oldObjectTypesToFlatten = objectTypesToFlatten;
61 | objectTypesToFlatten = [];
62 | flattenObjects = flattenObjects.concat(
63 | oldObjectTypesToFlatten.map(object => {
64 | const {properties} = object;
65 | if (properties !== undefined) {
66 | objectTypesToFlatten = objectTypesToFlatten.concat(
67 | properties.reduce((acc, curr) => {
68 | if (
69 | curr.typeAnnotation.type === 'ObjectTypeAnnotation' &&
70 | curr.typeAnnotation.properties
71 | ) {
72 | return acc.concat({
73 | properties: curr.typeAnnotation.properties,
74 | name: object.name + capitalizeFirstLetter(curr.name),
75 | });
76 | }
77 | return acc;
78 | }, []),
79 | );
80 | }
81 | return object;
82 | }),
83 | );
84 | }
85 |
86 | return flattenObjects;
87 | }
88 | module.exports = {
89 | flatObjects,
90 | capitalizeFirstLetter,
91 | };
92 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleCpp-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GenerateModuleCpp.js');
16 |
17 | describe('GenerateModuleCpp', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleH-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GenerateModuleH.js');
16 |
17 | describe('GenerateModuleCpp', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleHObjCpp-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GenerateModuleHObjCpp.js');
16 |
17 | describe('GenerateModuleHObjCpp', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/modules/__tests__/GenerateModuleMm-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/fixtures.js');
15 | const generator = require('../GenerateModuleMm.js');
16 |
17 | describe('GenerateModuleHObjCpp', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator.generate(fixtureName, fixture, 'SampleSpec'),
26 | ).toMatchSnapshot();
27 | });
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/generators/modules/__tests__/GenerateStructs-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow strict-local
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const fixtures = require('../__test_fixtures__/structFixtures.js');
15 | const generator = require('../ObjCppUtils/GenerateStructs.js');
16 |
17 | describe('GenerateStructs', () => {
18 | Object.keys(fixtures)
19 | .sort()
20 | .forEach(fixtureName => {
21 | const fixture = fixtures[fixtureName];
22 |
23 | it(`can generate fixture ${fixtureName}`, () => {
24 | expect(
25 | generator
26 | .translateObjectsForStructs(fixture)
27 | .replace(/::_MODULE_NAME_::/g, 'SampleTurboModule'),
28 | ).toMatchSnapshot();
29 | });
30 | });
31 | });
32 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/parsers/flow/components/__tests__/component-parser-test.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @emails oncall+react_native
8 | * @flow
9 | * @format
10 | */
11 |
12 | 'use strict';
13 |
14 | const FlowParser = require('../../index.js');
15 | const fixtures = require('../__test_fixtures__/fixtures.js');
16 | const failureFixtures = require('../__test_fixtures__/failures.js');
17 | jest.mock('fs', () => ({
18 | readFileSync: filename => fixtures[filename] || failureFixtures[filename],
19 | }));
20 |
21 | describe('RN Codegen Flow Parser', () => {
22 | Object.keys(fixtures)
23 | .sort()
24 | .forEach(fixtureName => {
25 | it(`can generate fixture ${fixtureName}`, () => {
26 | expect(FlowParser.parseFile(fixtureName)).toMatchSnapshot();
27 | });
28 | });
29 |
30 | Object.keys(failureFixtures)
31 | .sort()
32 | .forEach(fixtureName => {
33 | it(`Fails with error message ${fixtureName}`, () => {
34 | expect(() => {
35 | FlowParser.parseFile(fixtureName);
36 | }).toThrowErrorMatchingSnapshot();
37 | });
38 | });
39 | });
40 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/parsers/flow/components/commands.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {CommandTypeShape} from '../../../CodegenSchema.js';
14 | import type {TypeMap} from '../utils.js';
15 |
16 | const {getValueFromTypes} = require('../utils.js');
17 |
18 | type EventTypeAST = Object;
19 |
20 | function buildCommandSchema(property, types: TypeMap) {
21 | const name = property.key.name;
22 | const optional = property.optional;
23 | const value = getValueFromTypes(property.value, types);
24 |
25 | const firstParam = value.params[0].typeAnnotation;
26 |
27 | if (
28 | !(
29 | firstParam.id != null &&
30 | firstParam.id.type === 'QualifiedTypeIdentifier' &&
31 | firstParam.id.qualification.name === 'React' &&
32 | firstParam.id.id.name === 'ElementRef'
33 | )
34 | ) {
35 | throw new Error(
36 | `The first argument of method ${name} must be of type React.ElementRef<>`,
37 | );
38 | }
39 |
40 | const params = value.params.slice(1).map(param => {
41 | const paramName = param.name.name;
42 | const paramValue = getValueFromTypes(param.typeAnnotation, types);
43 | const type =
44 | paramValue.type === 'GenericTypeAnnotation'
45 | ? paramValue.id.name
46 | : paramValue.type;
47 | let returnType;
48 |
49 | switch (type) {
50 | case 'BooleanTypeAnnotation':
51 | returnType = {
52 | type: 'BooleanTypeAnnotation',
53 | };
54 | break;
55 | case 'Int32':
56 | returnType = {
57 | type: 'Int32TypeAnnotation',
58 | };
59 | break;
60 | case 'Double':
61 | returnType = {
62 | type: 'DoubleTypeAnnotation',
63 | };
64 | break;
65 | case 'Float':
66 | returnType = {
67 | type: 'FloatTypeAnnotation',
68 | };
69 | break;
70 | default:
71 | (type: empty);
72 | throw new Error(
73 | `Unsupported param type for method "${name}", param "${paramName}". Found ${type}`,
74 | );
75 | }
76 |
77 | return {
78 | name: paramName,
79 | typeAnnotation: returnType,
80 | };
81 | });
82 |
83 | return {
84 | name,
85 | optional,
86 | typeAnnotation: {
87 | type: 'FunctionTypeAnnotation',
88 | params,
89 | },
90 | };
91 | }
92 |
93 | function getCommands(
94 | commandTypeAST: $ReadOnlyArray,
95 | types: TypeMap,
96 | ): $ReadOnlyArray {
97 | return commandTypeAST
98 | .filter(property => property.type === 'ObjectTypeProperty')
99 | .map(property => buildCommandSchema(property, types))
100 | .filter(Boolean);
101 | }
102 |
103 | module.exports = {
104 | getCommands,
105 | };
106 |
--------------------------------------------------------------------------------
/packages/react-native-codegen/src/parsers/flow/components/extends.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Facebook, Inc. and its affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the
5 | * LICENSE file in the root directory of this source tree.
6 | *
7 | * @flow strict-local
8 | * @format
9 | */
10 |
11 | 'use strict';
12 |
13 | import type {ExtendsPropsShape} from '../../../CodegenSchema.js';
14 | import type {TypeMap} from '../utils.js';
15 |
16 | function extendsForProp(prop: PropsAST, types: TypeMap) {
17 | if (!prop.argument) {
18 | console.log('null', prop);
19 | }
20 | const name = prop.argument.id.name;
21 |
22 | if (types[name] != null) {
23 | // This type is locally defined in the file
24 | return null;
25 | }
26 |
27 | switch (name) {
28 | case 'ViewProps':
29 | return {
30 | type: 'ReactNativeBuiltInType',
31 | knownTypeName: 'ReactNativeCoreViewProps',
32 | };
33 | default: {
34 | throw new Error(`Unable to handle prop spread: ${name}`);
35 | }
36 | }
37 | }
38 |
39 | function removeKnownExtends(
40 | typeDefinition: $ReadOnlyArray,
41 | types: TypeMap,
42 | ): $ReadOnlyArray