getTurboModule(
27 | const std::string &name,
28 | const JavaTurboModule::InitParams ¶ms) override;
29 |
30 | /**
31 | * Test-only method. Allows user to verify whether a TurboModule can be
32 | * created by instances of this class.
33 | */
34 | bool canCreateTurboModule(const std::string &name);
35 | };
36 |
37 | } // namespace react
38 | } // namespace facebook
39 |
--------------------------------------------------------------------------------
/example/src/StatefulItem.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 |
3 | import { Button, Text, View } from 'react-native';
4 | import { getRandomColor } from './getRandomColor';
5 | import { styles } from './styles';
6 |
7 | export default function StatefulItem() {
8 | const [text, setText] = React.useState('');
9 | const backgroundColor = React.useMemo(() => getRandomColor(), []);
10 | return (
11 |
15 | {text}
16 |
36 | );
37 | }
38 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/example/reactnativeunicorn/newarchitecture/components/MainComponentsRegistry.java:
--------------------------------------------------------------------------------
1 | package com.example.reactnativeunicorn.newarchitecture.components;
2 |
3 | import com.facebook.jni.HybridData;
4 | import com.facebook.proguard.annotations.DoNotStrip;
5 | import com.facebook.react.fabric.ComponentFactory;
6 | import com.facebook.soloader.SoLoader;
7 |
8 | /**
9 | * Class responsible to load the custom Fabric Components. This class has native methods and needs a
10 | * corresponding C++ implementation/header file to work correctly (already placed inside the jni/
11 | * folder for you).
12 | *
13 | * Please note that this class is used ONLY if you opt-in for the New Architecture (see the
14 | * `newArchEnabled` property). Is ignored otherwise.
15 | */
16 | @DoNotStrip
17 | public class MainComponentsRegistry {
18 | static {
19 | SoLoader.loadLibrary("fabricjni");
20 | }
21 |
22 | @DoNotStrip private final HybridData mHybridData;
23 |
24 | @DoNotStrip
25 | private native HybridData initHybrid(ComponentFactory componentFactory);
26 |
27 | @DoNotStrip
28 | private MainComponentsRegistry(ComponentFactory componentFactory) {
29 | mHybridData = initHybrid(componentFactory);
30 | }
31 |
32 | @DoNotStrip
33 | public static MainComponentsRegistry register(ComponentFactory componentFactory) {
34 | return new MainComponentsRegistry(componentFactory);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/ios/UnicornViewManager.mm:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 | #import "RCTBridge.h"
4 |
5 | @interface UnicornViewManager : RCTViewManager
6 | @end
7 |
8 | @implementation UnicornViewManager
9 |
10 | RCT_EXPORT_MODULE(UnicornView)
11 |
12 | - (UIView *)view
13 | {
14 | return [[UIView alloc] init];
15 | }
16 |
17 |
18 | RCT_EXPORT_METHOD(changeBackgroundColor
19 | : (nonnull NSNumber *) reactTag color
20 | : (nonnull NSString *) color) {
21 | [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry) {
22 | UIView *view = viewRegistry[reactTag];
23 | [view setBackgroundColor:[self hexStringToColor:color]];
24 | }];
25 | }
26 |
27 | RCT_CUSTOM_VIEW_PROPERTY(color, NSString, UIView)
28 | {
29 | [view setBackgroundColor:[self hexStringToColor:json]];
30 | }
31 |
32 | - hexStringToColor:(NSString *)stringToConvert
33 | {
34 | NSString *noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""];
35 | NSScanner *stringScanner = [NSScanner scannerWithString:noHashString];
36 |
37 | unsigned hex;
38 | if (![stringScanner scanHexInt:&hex]) return nil;
39 | int r = (hex >> 16) & 0xFF;
40 | int g = (hex >> 8) & 0xFF;
41 | int b = (hex) & 0xFF;
42 |
43 | return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f];
44 | }
45 |
46 | @end
--------------------------------------------------------------------------------
/cpp/react/renderer/components/unicorn/RCTComponentViewHelpers.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3 | *
4 | * Do not edit this file as changes may cause incorrect behavior and will be lost
5 | * once the code is regenerated.
6 | *
7 | * @generated by codegen project: GenerateComponentHObjCpp.js
8 | */
9 |
10 | #import
11 | #import
12 | #import
13 |
14 | NS_ASSUME_NONNULL_BEGIN
15 |
16 | @protocol RCTUnicornViewViewProtocol
17 | - (void)changeBackgroundColor:(NSString *)color;
18 | @end
19 |
20 | RCT_EXTERN inline void RCTUnicornViewHandleCommand(
21 | id componentView,
22 | NSString const *commandName,
23 | NSArray const *args)
24 | {
25 | if ([commandName isEqualToString:@"changeBackgroundColor"]) {
26 | #if RCT_DEBUG
27 | if ([args count] != 1) {
28 | RCTLogError(@"%@ command %@ received %d arguments, expected %d.", @"UnicornView", commandName, (int)[args count], 1);
29 | return;
30 | }
31 | #endif
32 |
33 | NSObject *arg0 = args[0];
34 | #if RCT_DEBUG
35 | if (!RCTValidateTypeOfViewCommandArgument(arg0, [NSString class], @"string", @"UnicornView", commandName, @"1st")) {
36 | return;
37 | }
38 | #endif
39 | NSString * color = (NSString *)arg0;
40 |
41 | [componentView changeBackgroundColor:color];
42 | return;
43 | }
44 |
45 | #if RCT_DEBUG
46 | RCTLogError(@"%@ received command %@, which is not a supported command.", @"UnicornView", commandName);
47 | #endif
48 | }
49 |
50 | NS_ASSUME_NONNULL_END
--------------------------------------------------------------------------------
/react-native-unicorn.podspec:
--------------------------------------------------------------------------------
1 | require "json"
2 |
3 | package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4 | folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5 |
6 | Pod::Spec.new do |s|
7 | s.name = "react-native-unicorn"
8 | s.version = package["version"]
9 | s.summary = package["description"]
10 | s.description = package["description"]
11 | s.homepage = package["homepage"]
12 | s.license = package["license"]
13 | s.authors = package["author"]
14 |
15 | s.platforms = { :ios => "11.0" }
16 | s.source = { :git => "https://github.com/MateWW/react-native-unicorn.git", :tag => "#{s.version}" }
17 |
18 | s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{h,cpp}"
19 | s.exclude_files = "cpp/unicorn.cpp", "cpp/unicorn.h"
20 | s.dependency "React-Core"
21 |
22 | # Don't install the dependencies when we run `pod install` in the old architecture.
23 | if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
24 | s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
25 | s.pod_target_xcconfig = {
26 | "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
27 | "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
28 | "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
29 | }
30 |
31 | s.dependency "React-RCTFabric"
32 | s.dependency "React-Codegen"
33 | s.dependency "RCT-Folly"
34 | s.dependency "RCTRequired"
35 | s.dependency "RCTTypeSafety"
36 | s.dependency "ReactCommon/turbomodule/core"
37 | end
38 | end
39 |
--------------------------------------------------------------------------------
/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp:
--------------------------------------------------------------------------------
1 | #include "MainApplicationTurboModuleManagerDelegate.h"
2 | #include "MainApplicationModuleProvider.h"
3 |
4 | namespace facebook {
5 | namespace react {
6 |
7 | jni::local_ref
8 | MainApplicationTurboModuleManagerDelegate::initHybrid(
9 | jni::alias_ref) {
10 | return makeCxxInstance();
11 | }
12 |
13 | void MainApplicationTurboModuleManagerDelegate::registerNatives() {
14 | registerHybrid({
15 | makeNativeMethod(
16 | "initHybrid", MainApplicationTurboModuleManagerDelegate::initHybrid),
17 | makeNativeMethod(
18 | "canCreateTurboModule",
19 | MainApplicationTurboModuleManagerDelegate::canCreateTurboModule),
20 | });
21 | }
22 |
23 | std::shared_ptr
24 | MainApplicationTurboModuleManagerDelegate::getTurboModule(
25 | const std::string &name,
26 | const std::shared_ptr &jsInvoker) {
27 | // Not implemented yet: provide pure-C++ NativeModules here.
28 | return nullptr;
29 | }
30 |
31 | std::shared_ptr
32 | MainApplicationTurboModuleManagerDelegate::getTurboModule(
33 | const std::string &name,
34 | const JavaTurboModule::InitParams ¶ms) {
35 | return MainApplicationModuleProvider(name, params);
36 | }
37 |
38 | bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule(
39 | const std::string &name) {
40 | return getTurboModule(name, nullptr) != nullptr ||
41 | getTurboModule(name, {.moduleName = name}) != nullptr;
42 | }
43 |
44 | } // namespace react
45 | } // namespace facebook
46 |
--------------------------------------------------------------------------------
/cpp/react/renderer/components/unicorn/UnicornViewState.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) Meta Platforms, Inc. and 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 | #pragma once
9 |
10 | #include
11 |
12 | #ifdef ANDROID
13 | #include
14 | #include
15 | #include
16 | #endif
17 |
18 | namespace facebook {
19 | namespace react {
20 |
21 | /*
22 | * State for component.
23 | */
24 | class UnicornViewState final {
25 | public:
26 | Point contentOffset;
27 | Rect contentBoundingRect;
28 | int scrollAwayPaddingTop;
29 |
30 | /*
31 | * Returns size of scrollable area.
32 | */
33 | Size getContentSize() const;
34 |
35 | #ifdef ANDROID
36 | UnicornViewState() = default;
37 | UnicornViewState(UnicornViewState const &previousState, folly::dynamic data)
38 | : contentOffset(
39 | {(Float)data["contentOffsetLeft"].getDouble(),
40 | (Float)data["contentOffsetTop"].getDouble()}),
41 | contentBoundingRect({}),
42 | scrollAwayPaddingTop((Float)data["scrollAwayPaddingTop"].getDouble()){};
43 |
44 | folly::dynamic getDynamic() const {
45 | return folly::dynamic::object("contentOffsetLeft", contentOffset.x)(
46 | "contentOffsetTop", contentOffset.y)(
47 | "scrollAwayPaddingTop", scrollAwayPaddingTop);
48 | };
49 | MapBuffer getMapBuffer() const {
50 | return MapBufferBuilder::EMPTY();
51 | };
52 | #endif
53 | };
54 |
55 | } // namespace react
56 | } // namespace facebook
57 |
--------------------------------------------------------------------------------
/example/ios/UnicornExample/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | example
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 | NSExceptionDomains
30 |
31 | localhost
32 |
33 | NSExceptionAllowsInsecureHTTPLoads
34 |
35 |
36 |
37 |
38 | NSLocationWhenInUseUsageDescription
39 |
40 | UILaunchStoryboardName
41 | LaunchScreen
42 | UIRequiredDeviceCapabilities
43 |
44 | armv7
45 |
46 | UISupportedInterfaceOrientations
47 |
48 | UIInterfaceOrientationPortrait
49 | UIInterfaceOrientationLandscapeLeft
50 | UIInterfaceOrientationLandscapeRight
51 |
52 | UIViewControllerBasedStatusBarAppearance
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/example/reactnativeunicorn/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.reactnativeunicorn;
2 | import com.facebook.react.ReactActivity;
3 | import com.facebook.react.ReactActivityDelegate;
4 | import com.facebook.react.ReactRootView;
5 |
6 |
7 | public class MainActivity extends ReactActivity {
8 |
9 | /**
10 | * Returns the name of the main component registered from JavaScript. This is used to schedule
11 | * rendering of the component.
12 | */
13 | @Override
14 | protected String getMainComponentName() {
15 | return "main";
16 | }
17 |
18 | /**
19 | * Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and
20 | * you can specify the rendered you wish to use (Fabric or the older renderer).
21 | */
22 | @Override
23 | protected ReactActivityDelegate createReactActivityDelegate() {
24 | return new MainActivityDelegate(this, getMainComponentName());
25 | }
26 |
27 | public static class MainActivityDelegate extends ReactActivityDelegate {
28 | public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
29 | super(activity, mainComponentName);
30 | }
31 |
32 | @Override
33 | protected ReactRootView createRootView() {
34 | ReactRootView reactRootView = new ReactRootView(getContext());
35 | // If you opted-in for the New Architecture, we enable the Fabric Renderer.
36 | reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
37 | return reactRootView;
38 | }
39 | @Override
40 | protected boolean isConcurrentRootEnabled() {
41 | // If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18).
42 | // More on this on https://reactjs.org/blog/2022/03/29/react-v18.html
43 | return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/example/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: -Xmx512m -XX:MaxMetaspaceSize=256m
13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
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 | # AndroidX package structure to make it clearer which packages are bundled with the
21 | # Android operating system, and which are packaged with your app's APK
22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
23 | android.useAndroidX=true
24 | # Automatically convert third-party libraries to use AndroidX
25 | android.enableJetifier=true
26 |
27 | # Version of flipper SDK to use with React Native
28 | FLIPPER_VERSION=0.125.0
29 |
30 | # Use this property to specify which architecture you want to build.
31 | # You can also override it from the CLI using
32 | # ./gradlew -PreactNativeArchitectures=x86_64
33 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
34 |
35 | # Use this property to enable support to the new architecture.
36 | # This will allow you to use TurboModules and the Fabric render in
37 | # your application. You should enable this flag either if you want
38 | # to write custom TurboModules/Fabric components OR use libraries that
39 | # are providing them.
40 | newArchEnabled=true
41 |
--------------------------------------------------------------------------------
/example/android/build.gradle:
--------------------------------------------------------------------------------
1 | import org.apache.tools.ant.taskdefs.condition.Os
2 |
3 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
4 |
5 | buildscript {
6 | ext {
7 | buildToolsVersion = "31.0.0"
8 | minSdkVersion = 21
9 | compileSdkVersion = 31
10 | targetSdkVersion = 31
11 |
12 | if (System.properties['os.arch'] == "aarch64") {
13 | // For M1 Users we need to use the NDK 24 which added support for aarch64
14 | ndkVersion = "24.0.8215888"
15 | } else {
16 | // Otherwise we default to the side-by-side NDK version from AGP.
17 | ndkVersion = "21.4.7075529"
18 | }
19 | }
20 | repositories {
21 | google()
22 | mavenCentral()
23 | }
24 | dependencies {
25 | classpath("com.android.tools.build:gradle:7.2.1")
26 | classpath("com.facebook.react:react-native-gradle-plugin")
27 | classpath("de.undercouch:gradle-download-task:5.0.1")
28 | // NOTE: Do not place your application dependencies here; they belong
29 | // in the individual module build.gradle files
30 | }
31 | }
32 |
33 | allprojects {
34 | repositories {
35 | maven {
36 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
37 | url("$rootDir/../node_modules/react-native/android")
38 | }
39 | maven {
40 | // Android JSC is installed from npm
41 | url("$rootDir/../node_modules/jsc-android/dist")
42 | }
43 | mavenCentral {
44 | // We don't want to fetch react-native from Maven Central as there are
45 | // older versions over there.
46 | content {
47 | excludeGroup "com.facebook.react"
48 | }
49 | }
50 | google()
51 | maven { url 'https://www.jitpack.io' }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable/rn_edit_text_material.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
21 |
22 |
23 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/example/reactnativeunicorn/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java:
--------------------------------------------------------------------------------
1 | package com.example.reactnativeunicorn.newarchitecture.modules;
2 |
3 | import com.facebook.jni.HybridData;
4 | import com.facebook.react.ReactPackage;
5 | import com.facebook.react.ReactPackageTurboModuleManagerDelegate;
6 | import com.facebook.react.bridge.ReactApplicationContext;
7 | import com.facebook.soloader.SoLoader;
8 | import java.util.List;
9 |
10 | /**
11 | * Class responsible to load the TurboModules. This class has native methods and needs a
12 | * corresponding C++ implementation/header file to work correctly (already placed inside the jni/
13 | * folder for you).
14 | *
15 | * Please note that this class is used ONLY if you opt-in for the New Architecture (see the
16 | * `newArchEnabled` property). Is ignored otherwise.
17 | */
18 | public class MainApplicationTurboModuleManagerDelegate
19 | extends ReactPackageTurboModuleManagerDelegate {
20 |
21 | private static volatile boolean sIsSoLibraryLoaded;
22 |
23 | protected MainApplicationTurboModuleManagerDelegate(
24 | ReactApplicationContext reactApplicationContext, List packages) {
25 | super(reactApplicationContext, packages);
26 | }
27 |
28 | protected native HybridData initHybrid();
29 |
30 | native boolean canCreateTurboModule(String moduleName);
31 |
32 | public static class Builder extends ReactPackageTurboModuleManagerDelegate.Builder {
33 | protected MainApplicationTurboModuleManagerDelegate build(
34 | ReactApplicationContext context, List packages) {
35 | return new MainApplicationTurboModuleManagerDelegate(context, packages);
36 | }
37 | }
38 |
39 | @Override
40 | protected synchronized void maybeLoadOtherSoLibraries() {
41 | if (!sIsSoLibraryLoaded) {
42 | // If you change the name of your application .so file in the Android.mk file,
43 | // make sure you update the name here as well.
44 | SoLoader.loadLibrary("example_appmodules");
45 | sIsSoLibraryLoaded = true;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/cpp/react/renderer/components/unicorn/ShadowNodes.cpp:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4 | *
5 | * Do not edit this file as changes may cause incorrect behavior and will be lost
6 | * once the code is regenerated.
7 | *
8 | * @generated by codegen project: GenerateShadowNodeCpp.js
9 | */
10 |
11 | #include "ShadowNodes.h"
12 |
13 | namespace facebook {
14 | namespace react {
15 |
16 | extern const char UnicornViewComponentName[] = "UnicornView";
17 |
18 | void UnicornViewShadowNode::updateStateIfNeeded() {
19 | ensureUnsealed();
20 |
21 | auto contentBoundingRect = Rect{};
22 | for (const auto &childNode : getLayoutableChildNodes()) {
23 | contentBoundingRect.unionInPlace(childNode->getLayoutMetrics().frame);
24 | }
25 |
26 | auto state = getStateData();
27 |
28 | if (state.contentBoundingRect != contentBoundingRect) {
29 | state.contentBoundingRect = contentBoundingRect;
30 | setStateData(std::move(state));
31 | }
32 | }
33 |
34 | void UnicornViewShadowNode::updateScrollContentOffsetIfNeeded() {
35 | #ifndef ANDROID
36 | if (getLayoutMetrics().layoutDirection == LayoutDirection::RightToLeft) {
37 | // Yoga places `contentView` on the right side of `scrollView` when RTL
38 | // layout is enforced. To correct for this, in RTL setting, correct the
39 | // frame's origin. React Native Classic does this as well in
40 | // `RCTScrollContentShadowView.m`.
41 | for (auto layoutableNode : getLayoutableChildNodes()) {
42 | auto layoutMetrics = layoutableNode->getLayoutMetrics();
43 | if (layoutMetrics.frame.origin.x != 0) {
44 | layoutMetrics.frame.origin.x = 0;
45 | layoutableNode->setLayoutMetrics(layoutMetrics);
46 | }
47 | }
48 | }
49 | #endif
50 | }
51 |
52 | #pragma mark - LayoutableShadowNode
53 |
54 | void UnicornViewShadowNode::layout(LayoutContext layoutContext) {
55 | ConcreteViewShadowNode::layout(layoutContext);
56 | updateScrollContentOffsetIfNeeded();
57 | updateStateIfNeeded();
58 | }
59 |
60 | Point UnicornViewShadowNode::getContentOriginOffset() const {
61 | auto stateData = getStateData();
62 | auto contentOffset = stateData.contentOffset;
63 | return {-contentOffset.x, -contentOffset.y + stateData.scrollAwayPaddingTop};
64 | }
65 |
66 | } // namespace react
67 | } // namespace facebook
68 |
69 |
70 |
--------------------------------------------------------------------------------
/UnicornView.m:
--------------------------------------------------------------------------------
1 | // This guard prevent the code from being compiled in the old architecture
2 | #ifdef RCT_NEW_ARCH_ENABLED
3 | #import "UnicornView.h"
4 |
5 | #import
6 | #import
7 | #import
8 | #import
9 |
10 | #import "RCTFabricComponentsPlugins.h"
11 |
12 | using namespace facebook::react;
13 |
14 | @interface UnicornView ()
15 |
16 | @end
17 |
18 | @implementation UnicornView {
19 | UIView * _view;
20 | }
21 |
22 | + (ComponentDescriptorProvider)componentDescriptorProvider
23 | {
24 | return concreteComponentDescriptorProvider();
25 | }
26 |
27 | - (instancetype)initWithFrame:(CGRect)frame
28 | {
29 | if (self = [super initWithFrame:frame]) {
30 | static const auto defaultProps = std::make_shared();
31 | _props = defaultProps;
32 |
33 | _view = [[UIView alloc] init];
34 |
35 | self.contentView = _view;
36 | }
37 |
38 | return self;
39 | }
40 |
41 | - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
42 | {
43 | const auto &oldViewProps = *std::static_pointer_cast(_props);
44 | const auto &newViewProps = *std::static_pointer_cast(props);
45 |
46 | if (oldViewProps.color != newViewProps.color) {
47 | NSString * colorToConvert = [[NSString alloc] initWithUTF8String: newViewProps.color.c_str()];
48 | [_view setBackgroundColor:[self hexStringToColor:colorToConvert]];
49 | }
50 |
51 | [super updateProps:props oldProps:oldProps];
52 | }
53 |
54 | Class ColoredViewCls(void)
55 | {
56 | return RNColoredView.class;
57 | }
58 |
59 | - hexStringToColor:(NSString *)stringToConvert
60 | {
61 | NSString *noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""];
62 | NSScanner *stringScanner = [NSScanner scannerWithString:noHashString];
63 |
64 | unsigned hex;
65 | if (![stringScanner scanHexInt:&hex]) return nil;
66 | int r = (hex >> 16) & 0xFF;
67 | int g = (hex >> 8) & 0xFF;
68 | int b = (hex) & 0xFF;
69 |
70 | return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f];
71 | }
72 |
73 | @end
74 | #endif
75 |
--------------------------------------------------------------------------------
/example/android/app/src/main/jni/MainComponentsRegistry.cpp:
--------------------------------------------------------------------------------
1 | #include "MainComponentsRegistry.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | namespace facebook {
10 | namespace react {
11 |
12 | MainComponentsRegistry::MainComponentsRegistry(ComponentFactory *delegate) {}
13 |
14 | std::shared_ptr
15 | MainComponentsRegistry::sharedProviderRegistry() {
16 | auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry();
17 |
18 | // Autolinked providers registered by RN CLI
19 | rncli_registerProviders(providerRegistry);
20 |
21 | // Custom Fabric Components go here. You can register custom
22 | // components coming from your App or from 3rd party libraries here.
23 | //
24 | // providerRegistry->add(concreteComponentDescriptorProvider<
25 | // AocViewerComponentDescriptor>());
26 | return providerRegistry;
27 | }
28 |
29 | jni::local_ref
30 | MainComponentsRegistry::initHybrid(
31 | jni::alias_ref,
32 | ComponentFactory *delegate) {
33 | auto instance = makeCxxInstance(delegate);
34 |
35 | auto buildRegistryFunction =
36 | [](EventDispatcher::Weak const &eventDispatcher,
37 | ContextContainer::Shared const &contextContainer)
38 | -> ComponentDescriptorRegistry::Shared {
39 | auto registry = MainComponentsRegistry::sharedProviderRegistry()
40 | ->createComponentDescriptorRegistry(
41 | {eventDispatcher, contextContainer});
42 |
43 | auto mutableRegistry =
44 | std::const_pointer_cast(registry);
45 |
46 | mutableRegistry->setFallbackComponentDescriptor(
47 | std::make_shared(
48 | ComponentDescriptorParameters{
49 | eventDispatcher, contextContainer, nullptr}));
50 |
51 | return registry;
52 | };
53 |
54 | delegate->buildRegistryFunction = buildRegistryFunction;
55 | return instance;
56 | }
57 |
58 | void MainComponentsRegistry::registerNatives() {
59 | registerHybrid({
60 | makeNativeMethod("initHybrid", MainComponentsRegistry::initHybrid),
61 | });
62 | }
63 |
64 | } // namespace react
65 | } // namespace facebook
66 |
--------------------------------------------------------------------------------
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2.1
2 |
3 | executors:
4 | default:
5 | docker:
6 | - image: circleci/node:16
7 | working_directory: ~/project
8 |
9 | commands:
10 | attach_project:
11 | steps:
12 | - attach_workspace:
13 | at: ~/project
14 |
15 | jobs:
16 | install-dependencies:
17 | executor: default
18 | steps:
19 | - checkout
20 | - attach_project
21 | - restore_cache:
22 | keys:
23 | - dependencies-{{ checksum "package.json" }}
24 | - dependencies-
25 | - restore_cache:
26 | keys:
27 | - dependencies-example-{{ checksum "example/package.json" }}
28 | - dependencies-example-
29 | - run:
30 | name: Install dependencies
31 | command: |
32 | yarn install --cwd example --frozen-lockfile
33 | yarn install --frozen-lockfile
34 | - save_cache:
35 | key: dependencies-{{ checksum "package.json" }}
36 | paths: node_modules
37 | - save_cache:
38 | key: dependencies-example-{{ checksum "example/package.json" }}
39 | paths: example/node_modules
40 | - persist_to_workspace:
41 | root: .
42 | paths: .
43 |
44 | lint:
45 | executor: default
46 | steps:
47 | - attach_project
48 | - run:
49 | name: Lint files
50 | command: |
51 | yarn lint
52 |
53 | typescript:
54 | executor: default
55 | steps:
56 | - attach_project
57 | - run:
58 | name: Typecheck files
59 | command: |
60 | yarn typescript
61 |
62 | unit-tests:
63 | executor: default
64 | steps:
65 | - attach_project
66 | - run:
67 | name: Run unit tests
68 | command: |
69 | yarn test --coverage
70 | - store_artifacts:
71 | path: coverage
72 | destination: coverage
73 |
74 | build-package:
75 | executor: default
76 | steps:
77 | - attach_project
78 | - run:
79 | name: Build package
80 | command: |
81 | yarn prepare
82 |
83 | workflows:
84 | build-and-test:
85 | jobs:
86 | - install-dependencies
87 | - lint:
88 | requires:
89 | - install-dependencies
90 | - typescript:
91 | requires:
92 | - install-dependencies
93 | - unit-tests:
94 | requires:
95 | - install-dependencies
96 | - build-package:
97 | requires:
98 | - install-dependencies
99 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Example fabric library with custom cpp state implementation
2 |
3 | ## ⚠️⚠️⚠️ UPDATE ⚠️⚠️⚠️
4 |
5 | This repository has been archived in favour of official [solution](https://github.com/react-native-community/RNNewArchitectureLibraries/tree/feat/component-with-state#fabric-component-implement-cxx-state). Thanks to great efforts from the core team this temporary repository is no longer necessary.
6 |
7 | ## Description
8 |
9 | Probably you will not need this template, since fabric is responsible for whole synchronous measurements under the hood. But in some cases, your native component would like to update its frames in synchronous [way](https://reactnative.dev/architecture/render-pipeline). Right now, codegen does not support generating a new state based on typescript implementation, hence custom state implementation must be added manually. Linking custom cpp can be tricky, so together with [@cortinico](https://github.com/cortinico) we prepared a showcase, so you can reuse this approach in your library. This example has been built on top of [bob-builder](https://github.com/callstack/react-native-builder-bob)
10 |
11 | More context you can find [here](https://github.com/reactwg/react-native-new-architecture/discussions/71#discussioncomment-3606598)
12 |
13 | ## How to generate shared cpp code
14 |
15 | - run [codegen](https://reactnative.dev/docs/new-architecture-library-android#1-extend-or-implement-the-code-generated-native-interfaces) `./gradlew generateCodegenArtifactsFromSchema` in android folder
16 | - copy everything under `build/generated/source/codegen/jni/react/renderer/components/yourlib` into [cpp](https://github.com/callstack/fabric-library-with-custom-cpp/tree/main/cpp) folder
17 | - pass `interfaceOnly` [flag](https://github.com/callstack/fabric-library-with-custom-cpp/blob/main/src/UnicornViewNativeComponent.ts#L23)
18 | - run codegen once again
19 | - implement cpp state
20 |
21 | ## How to link custom cpp state in RN 70?
22 |
23 | ### Android
24 |
25 | Here you can see how to make it:
26 | [link](https://github.com/callstack/fabric-library-with-custom-cpp/commit/5e1b0f2171490a435b540271588b34ca98287801). Instead of `AndroidMkPath` , please add `CMakePath` to [react-native.config.js](https://github.com/callstack/fabric-library-with-custom-cpp-example/blob/main/react-native.config.js#L6)
27 |
28 | ### iOS
29 |
30 | Replace `s.source_files = "ios/**/*.{h,m,mm}"` with `s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{h,cpp}"` inside `yourLib.podspec` file and change imports inside `.mm` [file](https://github.com/callstack/fabric-library-with-custom-cpp/commit/12561736b58837cd4783f55c3af20e67b40219c3#diff-9d18bbaec12252e635b26e515dd1616123b8b02def6291bfefceb645f4e5264fL4)
31 |
--------------------------------------------------------------------------------
/android/src/main/java/com/reactnativeunicorn/UnicornViewManager.java:
--------------------------------------------------------------------------------
1 | package com.reactnativeunicorn;
2 |
3 | import android.util.Log;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | import com.facebook.react.bridge.ReadableArray;
8 | import com.facebook.react.module.annotations.ReactModule;
9 | import com.facebook.react.uimanager.ReactStylesDiffMap;
10 | import com.facebook.react.uimanager.SimpleViewManager;
11 | import com.facebook.react.uimanager.StateWrapper;
12 | import com.facebook.react.uimanager.ThemedReactContext;
13 | import com.facebook.react.uimanager.ViewGroupManager;
14 | import com.facebook.react.uimanager.ViewManagerDelegate;
15 | import com.facebook.react.uimanager.annotations.ReactProp;
16 | import com.facebook.react.bridge.ReactApplicationContext;
17 | import com.facebook.react.viewmanagers.UnicornViewManagerDelegate;
18 | import com.facebook.react.viewmanagers.UnicornViewManagerInterface;
19 |
20 | import androidx.annotation.NonNull;
21 | import androidx.annotation.Nullable;
22 |
23 | import java.util.ArrayList;
24 | import java.util.List;
25 |
26 | @ReactModule(name = UnicornViewManagerImpl.NAME)
27 | public class UnicornViewManager extends ViewGroupManager implements UnicornViewManagerInterface {
28 | private final ViewManagerDelegate mDelegate;
29 |
30 | public UnicornViewManager(ReactApplicationContext context) {
31 | mDelegate = new UnicornViewManagerDelegate(this);
32 | }
33 |
34 | @Nullable
35 | @Override
36 | public Object updateState(@NonNull UnicornView view, ReactStylesDiffMap props, StateWrapper stateWrapper) {
37 | view.getFabricViewStateManager().setStateWrapper(stateWrapper);
38 | return super.updateState(view, props, stateWrapper);
39 | }
40 |
41 | @Nullable
42 | @Override
43 | protected ViewManagerDelegate getDelegate() {
44 | return mDelegate;
45 | }
46 |
47 | @Override
48 | public String getName() {
49 | return UnicornViewManagerImpl.NAME;
50 | }
51 |
52 | @Override
53 | public UnicornView createViewInstance(ThemedReactContext context) {
54 | UnicornView view = UnicornViewManagerImpl.createViewInstance(context);
55 | return view;
56 | }
57 |
58 | @ReactProp(name = "color")
59 | public void setColor(UnicornView view, String color) {
60 | UnicornViewManagerImpl.setColor(view, color);
61 | }
62 |
63 | @Override
64 | public void changeBackgroundColor(UnicornView view, String color) {
65 | UnicornViewManagerImpl.setColor(view, color);
66 | }
67 |
68 | @Override
69 | public void receiveCommand(UnicornView root, String commandId, ReadableArray args) {
70 | mDelegate.receiveCommand(root, commandId, args);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/ios/UnicornView.mm:
--------------------------------------------------------------------------------
1 | #ifdef RCT_NEW_ARCH_ENABLED
2 | #import "UnicornView.h"
3 |
4 | #import "../cpp/react/renderer/components/unicorn/ComponentDescriptors.h"
5 | #import "../cpp/react/renderer/components/unicorn/EventEmitters.h"
6 | #import "../cpp/react/renderer/components/unicorn/Props.h"
7 | #import "../cpp/react/renderer/components/unicorn/RCTComponentViewHelpers.h"
8 |
9 | #import "RCTFabricComponentsPlugins.h"
10 |
11 | using namespace facebook::react;
12 |
13 | @interface UnicornView ()
14 |
15 | @end
16 |
17 | @implementation UnicornView {
18 | UIView * _view;
19 | }
20 |
21 | + (ComponentDescriptorProvider)componentDescriptorProvider
22 | {
23 | return concreteComponentDescriptorProvider();
24 | }
25 |
26 | - (instancetype)initWithFrame:(CGRect)frame
27 | {
28 | if (self = [super initWithFrame:frame]) {
29 | static const auto defaultProps = std::make_shared();
30 | _props = defaultProps;
31 |
32 | _view = [[UIView alloc] init];
33 |
34 | self.contentView = _view;
35 | }
36 |
37 | return self;
38 | }
39 |
40 | - (void)updateState:(const facebook::react::State::Shared &)state oldState:(const facebook::react::State::Shared &)oldState {
41 | NSLog(@"Update State");
42 | }
43 |
44 | - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
45 | {
46 | const auto &oldViewProps = *std::static_pointer_cast(_props);
47 | const auto &newViewProps = *std::static_pointer_cast(props);
48 |
49 | if (oldViewProps.color != newViewProps.color) {
50 | NSString * colorToConvert = [[NSString alloc] initWithUTF8String: newViewProps.color.c_str()];
51 | [_view setBackgroundColor:[self hexStringToColor:colorToConvert]];
52 | }
53 |
54 | [super updateProps:props oldProps:oldProps];
55 | }
56 |
57 | Class UnicornViewCls(void)
58 | {
59 | return UnicornView.class;
60 | }
61 |
62 | - hexStringToColor:(NSString *)stringToConvert
63 | {
64 | NSString *noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""];
65 | NSScanner *stringScanner = [NSScanner scannerWithString:noHashString];
66 |
67 | unsigned hex;
68 | if (![stringScanner scanHexInt:&hex]) return nil;
69 | int r = (hex >> 16) & 0xFF;
70 | int g = (hex >> 8) & 0xFF;
71 | int b = (hex) & 0xFF;
72 |
73 | return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f];
74 | }
75 |
76 | - (void)changeBackgroundColor:(nonnull NSString *)color {
77 | [_view setBackgroundColor:[self hexStringToColor:color]];
78 | }
79 |
80 |
81 | - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
82 | {
83 | RCTUnicornViewHandleCommand(self, commandName, args);
84 | }
85 |
86 |
87 | @end
88 | #endif
89 |
--------------------------------------------------------------------------------
/example/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | CFPropertyList (3.0.5)
5 | rexml
6 | activesupport (6.1.5.1)
7 | concurrent-ruby (~> 1.0, >= 1.0.2)
8 | i18n (>= 1.6, < 2)
9 | minitest (>= 5.1)
10 | tzinfo (~> 2.0)
11 | zeitwerk (~> 2.3)
12 | addressable (2.8.0)
13 | public_suffix (>= 2.0.2, < 5.0)
14 | algoliasearch (1.27.5)
15 | httpclient (~> 2.8, >= 2.8.3)
16 | json (>= 1.5.1)
17 | atomos (0.1.3)
18 | claide (1.1.0)
19 | cocoapods (1.11.3)
20 | addressable (~> 2.8)
21 | claide (>= 1.0.2, < 2.0)
22 | cocoapods-core (= 1.11.3)
23 | cocoapods-deintegrate (>= 1.0.3, < 2.0)
24 | cocoapods-downloader (>= 1.4.0, < 2.0)
25 | cocoapods-plugins (>= 1.0.0, < 2.0)
26 | cocoapods-search (>= 1.0.0, < 2.0)
27 | cocoapods-trunk (>= 1.4.0, < 2.0)
28 | cocoapods-try (>= 1.1.0, < 2.0)
29 | colored2 (~> 3.1)
30 | escape (~> 0.0.4)
31 | fourflusher (>= 2.3.0, < 3.0)
32 | gh_inspector (~> 1.0)
33 | molinillo (~> 0.8.0)
34 | nap (~> 1.0)
35 | ruby-macho (>= 1.0, < 3.0)
36 | xcodeproj (>= 1.21.0, < 2.0)
37 | cocoapods-core (1.11.3)
38 | activesupport (>= 5.0, < 7)
39 | addressable (~> 2.8)
40 | algoliasearch (~> 1.0)
41 | concurrent-ruby (~> 1.1)
42 | fuzzy_match (~> 2.0.4)
43 | nap (~> 1.0)
44 | netrc (~> 0.11)
45 | public_suffix (~> 4.0)
46 | typhoeus (~> 1.0)
47 | cocoapods-deintegrate (1.0.5)
48 | cocoapods-downloader (1.6.3)
49 | cocoapods-plugins (1.0.0)
50 | nap
51 | cocoapods-search (1.0.1)
52 | cocoapods-trunk (1.6.0)
53 | nap (>= 0.8, < 2.0)
54 | netrc (~> 0.11)
55 | cocoapods-try (1.2.0)
56 | colored2 (3.1.2)
57 | concurrent-ruby (1.1.10)
58 | escape (0.0.4)
59 | ethon (0.15.0)
60 | ffi (>= 1.15.0)
61 | ffi (1.15.5)
62 | fourflusher (2.3.1)
63 | fuzzy_match (2.0.4)
64 | gh_inspector (1.1.3)
65 | httpclient (2.8.3)
66 | i18n (1.10.0)
67 | concurrent-ruby (~> 1.0)
68 | json (2.6.1)
69 | minitest (5.15.0)
70 | molinillo (0.8.0)
71 | nanaimo (0.3.0)
72 | nap (1.1.0)
73 | netrc (0.11.0)
74 | public_suffix (4.0.7)
75 | rexml (3.2.5)
76 | ruby-macho (2.5.1)
77 | typhoeus (1.4.0)
78 | ethon (>= 0.9.0)
79 | tzinfo (2.0.4)
80 | concurrent-ruby (~> 1.0)
81 | xcodeproj (1.21.0)
82 | CFPropertyList (>= 2.3.3, < 4.0)
83 | atomos (~> 0.1.3)
84 | claide (>= 1.0.2, < 2.0)
85 | colored2 (~> 3.1)
86 | nanaimo (~> 0.3.0)
87 | rexml (~> 3.2.4)
88 | zeitwerk (2.5.4)
89 |
90 | PLATFORMS
91 | ruby
92 |
93 | DEPENDENCIES
94 | cocoapods (~> 1.11, >= 1.11.2)
95 |
96 | RUBY VERSION
97 | ruby 2.7.5p203
98 |
99 | BUNDLED WITH
100 | 2.2.27
101 |
--------------------------------------------------------------------------------
/example/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 https://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 Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/example/ios/UnicornExample.xcodeproj/xcshareddata/xcschemes/UnicornExample.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
43 |
45 |
51 |
52 |
53 |
54 |
60 |
62 |
68 |
69 |
70 |
71 |
73 |
74 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/example/reactnativeunicorn/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.reactnativeunicorn;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | import com.facebook.react.PackageList;
7 | import com.facebook.react.ReactApplication;
8 | import com.facebook.react.ReactInstanceManager;
9 | import com.facebook.react.ReactNativeHost;
10 | import com.facebook.react.ReactPackage;
11 | import com.facebook.react.config.ReactFeatureFlags;
12 | import com.facebook.soloader.SoLoader;
13 | import com.example.reactnativeunicorn.newarchitecture.MainApplicationReactNativeHost;
14 | import java.lang.reflect.InvocationTargetException;
15 | import java.util.List;
16 |
17 | public class MainApplication extends Application implements ReactApplication {
18 |
19 | private final ReactNativeHost mReactNativeHost =
20 | new ReactNativeHost(this) {
21 | @Override
22 | public boolean getUseDeveloperSupport() {
23 | return BuildConfig.DEBUG;
24 | }
25 |
26 | @Override
27 | protected List getPackages() {
28 | @SuppressWarnings("UnnecessaryLocalVariable")
29 | List packages = new PackageList(this).getPackages();
30 | // Packages that cannot be autolinked yet can be added manually here, for example:
31 | // packages.add(new MyReactNativePackage());
32 | return packages;
33 | }
34 |
35 | @Override
36 | protected String getJSMainModuleName() {
37 | return "index";
38 | }
39 | };
40 |
41 | private final ReactNativeHost mNewArchitectureNativeHost =
42 | new MainApplicationReactNativeHost(this);
43 |
44 | @Override
45 | public ReactNativeHost getReactNativeHost() {
46 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
47 | return mNewArchitectureNativeHost;
48 | } else {
49 | return mReactNativeHost;
50 | }
51 | }
52 |
53 | @Override
54 | public void onCreate() {
55 | super.onCreate();
56 | // If you opted-in for the New Architecture, we enable the TurboModule system
57 | ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
58 | SoLoader.init(this, /* native exopackage */ false);
59 | initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
60 | }
61 |
62 | /**
63 | * Loads Flipper in React Native templates. Call this in the onCreate method with something like
64 | * initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
65 | *
66 | * @param context
67 | * @param reactInstanceManager
68 | */
69 | private static void initializeFlipper(
70 | Context context, ReactInstanceManager reactInstanceManager) {
71 | if (BuildConfig.DEBUG) {
72 | try {
73 | /*
74 | We use reflection here to pick up the class that initializes Flipper,
75 | since Flipper library is not available in release mode
76 | */
77 | Class> aClass = Class.forName("com.example.reactnativeunicorn.ReactNativeFlipper");
78 | aClass
79 | .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
80 | .invoke(null, context, reactInstanceManager);
81 | } catch (ClassNotFoundException e) {
82 | e.printStackTrace();
83 | } catch (NoSuchMethodException e) {
84 | e.printStackTrace();
85 | } catch (IllegalAccessException e) {
86 | e.printStackTrace();
87 | } catch (InvocationTargetException e) {
88 | e.printStackTrace();
89 | }
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/example/android/app/src/debug/java/com/example/reactnativeunicorn/ReactNativeFlipper.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Meta Platforms, Inc. and affiliates.
3 | *
4 | * This source code is licensed under the MIT license found in the LICENSE file in the root
5 | * directory of this source tree.
6 | */
7 | package com.example.reactnativeunicorn;
8 |
9 | import android.content.Context;
10 | import com.facebook.flipper.android.AndroidFlipperClient;
11 | import com.facebook.flipper.android.utils.FlipperUtils;
12 | import com.facebook.flipper.core.FlipperClient;
13 | import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin;
14 | import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin;
15 | import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin;
16 | import com.facebook.flipper.plugins.inspector.DescriptorMapping;
17 | import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
18 | import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
19 | import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
20 | import com.facebook.flipper.plugins.react.ReactFlipperPlugin;
21 | import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
22 | import com.facebook.react.ReactInstanceEventListener;
23 | import com.facebook.react.ReactInstanceManager;
24 | import com.facebook.react.bridge.ReactContext;
25 | import com.facebook.react.modules.network.NetworkingModule;
26 | import okhttp3.OkHttpClient;
27 |
28 | public class ReactNativeFlipper {
29 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
30 | if (FlipperUtils.shouldEnableFlipper(context)) {
31 | final FlipperClient client = AndroidFlipperClient.getInstance(context);
32 |
33 | client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
34 | client.addPlugin(new ReactFlipperPlugin());
35 | client.addPlugin(new DatabasesFlipperPlugin(context));
36 | client.addPlugin(new SharedPreferencesFlipperPlugin(context));
37 | client.addPlugin(CrashReporterPlugin.getInstance());
38 |
39 | NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
40 | NetworkingModule.setCustomClientBuilder(
41 | new NetworkingModule.CustomClientBuilder() {
42 | @Override
43 | public void apply(OkHttpClient.Builder builder) {
44 | builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
45 | }
46 | });
47 | client.addPlugin(networkFlipperPlugin);
48 | client.start();
49 |
50 | // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
51 | // Hence we run if after all native modules have been initialized
52 | ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
53 | if (reactContext == null) {
54 | reactInstanceManager.addReactInstanceEventListener(
55 | new ReactInstanceEventListener() {
56 | @Override
57 | public void onReactContextInitialized(ReactContext reactContext) {
58 | reactInstanceManager.removeReactInstanceEventListener(this);
59 | reactContext.runOnNativeModulesQueueThread(
60 | new Runnable() {
61 | @Override
62 | public void run() {
63 | client.addPlugin(new FrescoFlipperPlugin());
64 | }
65 | });
66 | }
67 | });
68 | } else {
69 | client.addPlugin(new FrescoFlipperPlugin());
70 | }
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | }
6 |
7 | dependencies {
8 | classpath("com.android.tools.build:gradle:7.2.1")
9 | }
10 | }
11 |
12 | def isNewArchitectureEnabled() {
13 | return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
14 | }
15 |
16 | apply plugin: 'com.android.library'
17 |
18 | if (isNewArchitectureEnabled()) {
19 | apply plugin: 'com.facebook.react'
20 | }
21 |
22 | def getExtOrDefault(name) {
23 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Unicorn_' + name]
24 | }
25 |
26 | def getExtOrIntegerDefault(name) {
27 | return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['Unicorn_' + name]).toInteger()
28 | }
29 |
30 | android {
31 | compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
32 |
33 | defaultConfig {
34 | minSdkVersion getExtOrIntegerDefault('minSdkVersion')
35 | targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
36 | buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
37 | }
38 |
39 | sourceSets {
40 | main {
41 | if (isNewArchitectureEnabled()) {
42 | java.srcDirs += ['src/newarchitecture/java']
43 | } else {
44 | java.srcDirs += ['src/oldarchitecture/java']
45 | }
46 | }
47 | }
48 |
49 | buildTypes {
50 | release {
51 | minifyEnabled false
52 | }
53 | }
54 |
55 | lintOptions {
56 | disable 'GradleCompatible'
57 | }
58 |
59 | compileOptions {
60 | sourceCompatibility JavaVersion.VERSION_1_8
61 | targetCompatibility JavaVersion.VERSION_1_8
62 | }
63 | }
64 |
65 | repositories {
66 | mavenCentral()
67 | google()
68 |
69 | def found = false
70 | def defaultDir = null
71 | def androidSourcesName = 'React Native sources'
72 |
73 | if (rootProject.ext.has('reactNativeAndroidRoot')) {
74 | defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
75 | } else {
76 | defaultDir = new File(
77 | projectDir,
78 | '/../../../node_modules/react-native/android'
79 | )
80 | }
81 |
82 | if (defaultDir.exists()) {
83 | maven {
84 | url defaultDir.toString()
85 | name androidSourcesName
86 | }
87 |
88 | logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
89 | found = true
90 | } else {
91 | def parentDir = rootProject.projectDir
92 |
93 | 1.upto(5, {
94 | if (found) return true
95 | parentDir = parentDir.parentFile
96 |
97 | def androidSourcesDir = new File(
98 | parentDir,
99 | 'node_modules/react-native'
100 | )
101 |
102 | def androidPrebuiltBinaryDir = new File(
103 | parentDir,
104 | 'node_modules/react-native/android'
105 | )
106 |
107 | if (androidPrebuiltBinaryDir.exists()) {
108 | maven {
109 | url androidPrebuiltBinaryDir.toString()
110 | name androidSourcesName
111 | }
112 |
113 | logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
114 | found = true
115 | } else if (androidSourcesDir.exists()) {
116 | maven {
117 | url androidSourcesDir.toString()
118 | name androidSourcesName
119 | }
120 |
121 | logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
122 | found = true
123 | }
124 | })
125 | }
126 |
127 | if (!found) {
128 | throw new GradleException(
129 | "${project.name}: unable to locate React Native android sources. " +
130 | "Ensure you have you installed React Native as a dependency in your project and try again."
131 | )
132 | }
133 | }
134 |
135 |
136 | dependencies {
137 | //noinspection GradleDynamicVersion
138 | implementation "com.facebook.react:react-native:+"
139 | // From node_modules
140 | implementation 'androidx.recyclerview:recyclerview:1.2.1'
141 | }
142 |
--------------------------------------------------------------------------------
/example/ios/UnicornExample/AppDelegate.mm:
--------------------------------------------------------------------------------
1 | #import "AppDelegate.h"
2 |
3 | #import
4 | #import
5 | #import
6 |
7 | #import
8 |
9 | #if RCT_NEW_ARCH_ENABLED
10 | #import
11 | #import
12 | #import
13 | #import
14 | #import
15 | #import
16 |
17 | #import
18 |
19 | @interface AppDelegate () {
20 | RCTTurboModuleManager *_turboModuleManager;
21 | RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
22 | std::shared_ptr _reactNativeConfig;
23 | facebook::react::ContextContainer::Shared _contextContainer;
24 | }
25 | @end
26 | #endif
27 |
28 | @implementation AppDelegate
29 |
30 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
31 | {
32 | RCTAppSetupPrepareApp(application);
33 |
34 | RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
35 |
36 | #if RCT_NEW_ARCH_ENABLED
37 | _contextContainer = std::make_shared();
38 | _reactNativeConfig = std::make_shared();
39 | _contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
40 | _bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
41 | bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
42 | #endif
43 |
44 | UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"main", nil);
45 |
46 | if (@available(iOS 13.0, *)) {
47 | rootView.backgroundColor = [UIColor systemBackgroundColor];
48 | } else {
49 | rootView.backgroundColor = [UIColor whiteColor];
50 | }
51 |
52 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
53 | UIViewController *rootViewController = [UIViewController new];
54 | rootViewController.view = rootView;
55 | self.window.rootViewController = rootViewController;
56 | [self.window makeKeyAndVisible];
57 | return YES;
58 | }
59 |
60 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
61 | {
62 | #if DEBUG
63 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
64 | #else
65 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
66 | #endif
67 | }
68 |
69 | #if RCT_NEW_ARCH_ENABLED
70 |
71 | #pragma mark - RCTCxxBridgeDelegate
72 |
73 | - (std::unique_ptr)jsExecutorFactoryForBridge:(RCTBridge *)bridge
74 | {
75 | _turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
76 | delegate:self
77 | jsInvoker:bridge.jsCallInvoker];
78 | return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager);
79 | }
80 |
81 | #pragma mark RCTTurboModuleManagerDelegate
82 |
83 | - (Class)getModuleClassFromName:(const char *)name
84 | {
85 | return RCTCoreModulesClassProvider(name);
86 | }
87 |
88 | - (std::shared_ptr)getTurboModule:(const std::string &)name
89 | jsInvoker:(std::shared_ptr)jsInvoker
90 | {
91 | return nullptr;
92 | }
93 |
94 | - (std::shared_ptr)getTurboModule:(const std::string &)name
95 | initParams:
96 | (const facebook::react::ObjCTurboModule::InitParams &)params
97 | {
98 | return nullptr;
99 | }
100 |
101 | - (id)getModuleInstanceFromClass:(Class)moduleClass
102 | {
103 | return RCTAppSetupDefaultModuleFromClass(moduleClass);
104 | }
105 |
106 | #endif
107 |
108 | @end
109 |
--------------------------------------------------------------------------------
/example/ios/UnicornExample/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
24 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-unicorn",
3 | "version": "0.1.0",
4 | "description": "test",
5 | "main": "lib/commonjs/index",
6 | "module": "lib/module/index",
7 | "types": "lib/typescript/index.d.ts",
8 | "react-native": "src/index",
9 | "source": "src/index",
10 | "files": [
11 | "src",
12 | "lib",
13 | "android",
14 | "ios",
15 | "cpp",
16 | "react-native-unicorn.podspec",
17 | "!lib/typescript/example",
18 | "!android/build",
19 | "!ios/build",
20 | "!**/__tests__",
21 | "!**/__fixtures__",
22 | "!**/__mocks__"
23 | ],
24 | "scripts": {
25 | "test": "jest",
26 | "typescript": "tsc --noEmit",
27 | "lint": "eslint \"**/*.{js,ts,tsx}\"",
28 | "prepare": "bob build",
29 | "release": "release-it",
30 | "example": "yarn --cwd example",
31 | "pods": "cd example && RCT_NEW_ARCH_ENABLED=1 pod-install --quiet",
32 | "bootstrap": "yarn example && yarn && yarn pods"
33 | },
34 | "keywords": [
35 | "react-native",
36 | "ios",
37 | "android"
38 | ],
39 | "repository": "https://github.com/MateWW/react-native-unicorn",
40 | "author": "Mateusz Wit (https://github.com/MateWW)",
41 | "license": "MIT",
42 | "bugs": {
43 | "url": "https://github.com/MateWW/react-native-unicorn/issues"
44 | },
45 | "homepage": "https://github.com/MateWW/react-native-unicorn#readme",
46 | "publishConfig": {
47 | "registry": "https://registry.npmjs.org/"
48 | },
49 | "devDependencies": {
50 | "@arkweid/lefthook": "^0.7.7",
51 | "@babel/eslint-parser": "^7.18.2",
52 | "@commitlint/config-conventional": "^17.0.2",
53 | "@react-native-community/eslint-config": "^3.0.2",
54 | "@release-it/conventional-changelog": "^5.0.0",
55 | "@types/jest": "^28.1.2",
56 | "@types/react": "~17.0.21",
57 | "@types/react-native": "0.69.4",
58 | "commitlint": "^17.0.2",
59 | "eslint": "^8.4.1",
60 | "eslint-config-prettier": "^8.5.0",
61 | "eslint-plugin-prettier": "^4.0.0",
62 | "jest": "^28.1.1",
63 | "pod-install": "^0.1.0",
64 | "prettier": "^2.0.5",
65 | "react": "18.1.0",
66 | "react-native": "0.70.0-rc.2",
67 | "react-native-builder-bob": "^0.18.2",
68 | "release-it": "^15.0.0",
69 | "typescript": "^4.5.2"
70 | },
71 | "resolutions": {
72 | "@types/react": "17.0.21"
73 | },
74 | "peerDependencies": {
75 | "react": "*",
76 | "react-native": "*"
77 | },
78 | "jest": {
79 | "preset": "react-native",
80 | "modulePathIgnorePatterns": [
81 | "/example/node_modules",
82 | "/lib/"
83 | ]
84 | },
85 | "commitlint": {
86 | "extends": [
87 | "@commitlint/config-conventional"
88 | ]
89 | },
90 | "release-it": {
91 | "git": {
92 | "commitMessage": "chore: release ${version}",
93 | "tagName": "v${version}"
94 | },
95 | "npm": {
96 | "publish": true
97 | },
98 | "github": {
99 | "release": true
100 | },
101 | "plugins": {
102 | "@release-it/conventional-changelog": {
103 | "preset": "angular"
104 | }
105 | }
106 | },
107 | "eslintConfig": {
108 | "root": true,
109 | "parser": "@babel/eslint-parser",
110 | "extends": [
111 | "@react-native-community",
112 | "prettier"
113 | ],
114 | "rules": {
115 | "prettier/prettier": [
116 | "error",
117 | {
118 | "quoteProps": "consistent",
119 | "singleQuote": true,
120 | "tabWidth": 2,
121 | "trailingComma": "es5",
122 | "useTabs": false
123 | }
124 | ]
125 | }
126 | },
127 | "eslintIgnore": [
128 | "node_modules/",
129 | "lib/"
130 | ],
131 | "prettier": {
132 | "quoteProps": "consistent",
133 | "singleQuote": true,
134 | "tabWidth": 2,
135 | "trailingComma": "es5",
136 | "useTabs": false
137 | },
138 | "react-native-builder-bob": {
139 | "source": "src",
140 | "output": "lib",
141 | "targets": [
142 | "commonjs",
143 | "module",
144 | [
145 | "typescript",
146 | {
147 | "project": "tsconfig.build.json"
148 | }
149 | ]
150 | ]
151 | },
152 | "codegenConfig": {
153 | "name": "unicorn",
154 | "type": "components",
155 | "jsSrcsDir": "./src",
156 | "android": {
157 | "javaPackageName": "com.reactnativeunicorn"
158 | }
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/example/android/app/src/main/java/com/example/reactnativeunicorn/newarchitecture/MainApplicationReactNativeHost.java:
--------------------------------------------------------------------------------
1 | package com.example.reactnativeunicorn.newarchitecture;
2 |
3 | import android.app.Application;
4 | import androidx.annotation.NonNull;
5 | import com.facebook.react.PackageList;
6 | import com.facebook.react.ReactInstanceManager;
7 | import com.facebook.react.ReactNativeHost;
8 | import com.facebook.react.ReactPackage;
9 | import com.facebook.react.ReactPackageTurboModuleManagerDelegate;
10 | import com.facebook.react.bridge.JSIModulePackage;
11 | import com.facebook.react.bridge.JSIModuleProvider;
12 | import com.facebook.react.bridge.JSIModuleSpec;
13 | import com.facebook.react.bridge.JSIModuleType;
14 | import com.facebook.react.bridge.JavaScriptContextHolder;
15 | import com.facebook.react.bridge.ReactApplicationContext;
16 | import com.facebook.react.bridge.UIManager;
17 | import com.facebook.react.fabric.ComponentFactory;
18 | import com.facebook.react.fabric.CoreComponentsRegistry;
19 | import com.facebook.react.fabric.EmptyReactNativeConfig;
20 | import com.facebook.react.fabric.FabricJSIModuleProvider;
21 | import com.facebook.react.uimanager.ViewManagerRegistry;
22 | import com.example.reactnativeunicorn.BuildConfig;
23 | import com.example.reactnativeunicorn.newarchitecture.components.MainComponentsRegistry;
24 | import com.example.reactnativeunicorn.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate;
25 | import java.util.ArrayList;
26 | import java.util.List;
27 | import com.facebook.react.fabric.ReactNativeConfig;
28 |
29 | /**
30 | * A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both
31 | * TurboModule delegates and the Fabric Renderer.
32 | *
33 | * Please note that this class is used ONLY if you opt-in for the New Architecture (see the
34 | * `newArchEnabled` property). Is ignored otherwise.
35 | */
36 | public class MainApplicationReactNativeHost extends ReactNativeHost {
37 | public MainApplicationReactNativeHost(Application application) {
38 | super(application);
39 | }
40 |
41 | @Override
42 | public boolean getUseDeveloperSupport() {
43 | return BuildConfig.DEBUG;
44 | }
45 |
46 | @Override
47 | protected List getPackages() {
48 | List packages = new PackageList(this).getPackages();
49 | // Packages that cannot be autolinked yet can be added manually here, for example:
50 | // packages.add(new MyReactNativePackage());
51 | // TurboModules must also be loaded here providing a valid TurboReactPackage implementation:
52 | // packages.add(new TurboReactPackage() { ... });
53 | // If you have custom Fabric Components, their ViewManagers should also be loaded here
54 | // inside a ReactPackage.
55 | return packages;
56 | }
57 |
58 | @Override
59 | protected String getJSMainModuleName() {
60 | return "index";
61 | }
62 |
63 | @NonNull
64 | @Override
65 | protected ReactPackageTurboModuleManagerDelegate.Builder
66 | getReactPackageTurboModuleManagerDelegateBuilder() {
67 | // Here we provide the ReactPackageTurboModuleManagerDelegate Builder. This is necessary
68 | // for the new architecture and to use TurboModules correctly.
69 | return new MainApplicationTurboModuleManagerDelegate.Builder();
70 | }
71 |
72 | @Override
73 | protected JSIModulePackage getJSIModulePackage() {
74 | return new JSIModulePackage() {
75 | @Override
76 | public List getJSIModules(
77 | final ReactApplicationContext reactApplicationContext,
78 | final JavaScriptContextHolder jsContext) {
79 | final List specs = new ArrayList<>();
80 |
81 | // Here we provide a new JSIModuleSpec that will be responsible of providing the
82 | // custom Fabric Components.
83 | specs.add(
84 | new JSIModuleSpec() {
85 | @Override
86 | public JSIModuleType getJSIModuleType() {
87 | return JSIModuleType.UIManager;
88 | }
89 |
90 | @Override
91 | public JSIModuleProvider getJSIModuleProvider() {
92 | final ComponentFactory componentFactory = new ComponentFactory();
93 | CoreComponentsRegistry.register(componentFactory);
94 |
95 | // Here we register a Components Registry.
96 | // The one that is generated with the template contains no components
97 | // and just provides you the one from React Native core.
98 | MainComponentsRegistry.register(componentFactory);
99 |
100 | final ReactInstanceManager reactInstanceManager = getReactInstanceManager();
101 |
102 | ViewManagerRegistry viewManagerRegistry =
103 | new ViewManagerRegistry(
104 | reactInstanceManager.getOrCreateViewManagers(reactApplicationContext));
105 |
106 | return new FabricJSIModuleProvider(
107 | reactApplicationContext,
108 | componentFactory,
109 | ReactNativeConfig.DEFAULT_CONFIG,
110 | viewManagerRegistry);
111 | }
112 | });
113 | return specs;
114 | }
115 | };
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/patch.diff:
--------------------------------------------------------------------------------
1 | From 9176ae6e7f691e1154c7cfac9a9db09db82e7cbd Mon Sep 17 00:00:00 2001
2 | From: Piotr Trocki
3 | Date: Mon, 5 Sep 2022 13:15:34 +0200
4 | Subject: [PATCH] wip
5 |
6 | ---
7 | android/CMakeLists.txt | 10 ++++++++++
8 | android/build.gradle | 11 +++++++++++
9 | .../reactnativeunicorn/UnicornViewPackage.java | 1 +
10 | cpp/CMakeLists.txt | 15 +++++++++++++++
11 | .../ComponentDescriptors.h | 0
12 | .../UnicornViewSpec => unicorn}/EventEmitters.cpp | 0
13 | .../UnicornViewSpec => unicorn}/EventEmitters.h | 0
14 | .../UnicornViewSpec => unicorn}/Props.cpp | 0
15 | .../UnicornViewSpec => unicorn}/Props.h | 0
16 | .../RCTComponentViewHelpers.h | 0
17 | .../UnicornViewSpec => unicorn}/ShadowNodes.cpp | 0
18 | .../UnicornViewSpec => unicorn}/ShadowNodes.h | 0
19 | .../UnicornViewState.cpp | 0
20 | .../UnicornViewState.h | 0
21 | 14 files changed, 37 insertions(+)
22 | create mode 100644 android/CMakeLists.txt
23 | create mode 100644 cpp/CMakeLists.txt
24 | rename cpp/{react/renderer/components/UnicornViewSpec => unicorn}/ComponentDescriptors.h (100%)
25 | rename cpp/{react/renderer/components/UnicornViewSpec => unicorn}/EventEmitters.cpp (100%)
26 | rename cpp/{react/renderer/components/UnicornViewSpec => unicorn}/EventEmitters.h (100%)
27 | rename cpp/{react/renderer/components/UnicornViewSpec => unicorn}/Props.cpp (100%)
28 | rename cpp/{react/renderer/components/UnicornViewSpec => unicorn}/Props.h (100%)
29 | rename cpp/{react/renderer/components/UnicornViewSpec => unicorn}/RCTComponentViewHelpers.h (100%)
30 | rename cpp/{react/renderer/components/UnicornViewSpec => unicorn}/ShadowNodes.cpp (100%)
31 | rename cpp/{react/renderer/components/UnicornViewSpec => unicorn}/ShadowNodes.h (100%)
32 | rename cpp/{react/renderer/components/UnicornViewSpec => unicorn}/UnicornViewState.cpp (100%)
33 | rename cpp/{react/renderer/components/UnicornViewSpec => unicorn}/UnicornViewState.h (100%)
34 |
35 | diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt
36 | new file mode 100644
37 | index 0000000..b8810de
38 | --- /dev/null
39 | +++ b/android/CMakeLists.txt
40 | @@ -0,0 +1,10 @@
41 | +cmake_minimum_required(VERSION 3.13)
42 | +
43 | +set (CMAKE_VERBOSE_MAKEFILE ON)
44 | +set (CMAKE_CXX_STANDARD 11)
45 | +
46 | +file(GLOB unicorn_SRC CONFIGURE_DEPENDS ../cpp/unicorn/*.cpp)
47 | +add_library(unicorn STATIC ${unicorn_SRC})
48 | +
49 | +# Specifies a path to native header files.
50 | +include_directories(${unicorn_SRC})
51 | diff --git a/android/build.gradle b/android/build.gradle
52 | index 32c8a67..cb4ce9c 100644
53 | --- a/android/build.gradle
54 | +++ b/android/build.gradle
55 | @@ -34,6 +34,17 @@ android {
56 | minSdkVersion getExtOrIntegerDefault('minSdkVersion')
57 | targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
58 | buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
59 | + externalNativeBuild {
60 | + cmake {
61 | + cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
62 | + abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
63 | + }
64 | + }
65 | + }
66 | + externalNativeBuild {
67 | + cmake {
68 | + path "CMakeLists.txt"
69 | + }
70 | }
71 |
72 | sourceSets {
73 | diff --git a/android/src/main/java/com/reactnativeunicorn/UnicornViewPackage.java b/android/src/main/java/com/reactnativeunicorn/UnicornViewPackage.java
74 | index 919e75b..5fd8223 100644
75 | --- a/android/src/main/java/com/reactnativeunicorn/UnicornViewPackage.java
76 | +++ b/android/src/main/java/com/reactnativeunicorn/UnicornViewPackage.java
77 | @@ -13,6 +13,7 @@ public class UnicornViewPackage implements ReactPackage {
78 | @Override
79 | public List createViewManagers(ReactApplicationContext reactContext) {
80 | List viewManagers = new ArrayList<>();
81 | + System.loadLibrary("unicorn");
82 | viewManagers.add(new UnicornViewManager(reactContext));
83 | return viewManagers;
84 | }
85 | diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
86 | new file mode 100644
87 | index 0000000..547c2b8
88 | --- /dev/null
89 | +++ b/cpp/CMakeLists.txt
90 | @@ -0,0 +1,15 @@
91 | +cmake_minimum_required(VERSION 3.13)
92 | +set(CMAKE_VERBOSE_MAKEFILE on)
93 | +
94 | +add_compile_options(
95 | + -fexceptions
96 | + -frtti
97 | + -std=c++17
98 | + -Wall
99 | + -Wpedantic
100 | + -Wno-gnu-zero-variadic-macro-arguments)
101 | +
102 | +file(GLOB unicorn_SRC CONFIGURE_DEPENDS unicorn/*.cpp)
103 | +add_library(unicorn STATIC ${unicorn_SRC})
104 | +
105 | +target_include_directories(unicorn PUBLIC .)
106 | \ No newline at end of file
107 | diff --git a/cpp/react/renderer/components/UnicornViewSpec/ComponentDescriptors.h b/cpp/unicorn/ComponentDescriptors.h
108 | similarity index 100%
109 | rename from cpp/react/renderer/components/UnicornViewSpec/ComponentDescriptors.h
110 | rename to cpp/unicorn/ComponentDescriptors.h
111 | diff --git a/cpp/react/renderer/components/UnicornViewSpec/EventEmitters.cpp b/cpp/unicorn/EventEmitters.cpp
112 | similarity index 100%
113 | rename from cpp/react/renderer/components/UnicornViewSpec/EventEmitters.cpp
114 | rename to cpp/unicorn/EventEmitters.cpp
115 | diff --git a/cpp/react/renderer/components/UnicornViewSpec/EventEmitters.h b/cpp/unicorn/EventEmitters.h
116 | similarity index 100%
117 | rename from cpp/react/renderer/components/UnicornViewSpec/EventEmitters.h
118 | rename to cpp/unicorn/EventEmitters.h
119 | diff --git a/cpp/react/renderer/components/UnicornViewSpec/Props.cpp b/cpp/unicorn/Props.cpp
120 | similarity index 100%
121 | rename from cpp/react/renderer/components/UnicornViewSpec/Props.cpp
122 | rename to cpp/unicorn/Props.cpp
123 | diff --git a/cpp/react/renderer/components/UnicornViewSpec/Props.h b/cpp/unicorn/Props.h
124 | similarity index 100%
125 | rename from cpp/react/renderer/components/UnicornViewSpec/Props.h
126 | rename to cpp/unicorn/Props.h
127 | diff --git a/cpp/react/renderer/components/UnicornViewSpec/RCTComponentViewHelpers.h b/cpp/unicorn/RCTComponentViewHelpers.h
128 | similarity index 100%
129 | rename from cpp/react/renderer/components/UnicornViewSpec/RCTComponentViewHelpers.h
130 | rename to cpp/unicorn/RCTComponentViewHelpers.h
131 | diff --git a/cpp/react/renderer/components/UnicornViewSpec/ShadowNodes.cpp b/cpp/unicorn/ShadowNodes.cpp
132 | similarity index 100%
133 | rename from cpp/react/renderer/components/UnicornViewSpec/ShadowNodes.cpp
134 | rename to cpp/unicorn/ShadowNodes.cpp
135 | diff --git a/cpp/react/renderer/components/UnicornViewSpec/ShadowNodes.h b/cpp/unicorn/ShadowNodes.h
136 | similarity index 100%
137 | rename from cpp/react/renderer/components/UnicornViewSpec/ShadowNodes.h
138 | rename to cpp/unicorn/ShadowNodes.h
139 | diff --git a/cpp/react/renderer/components/UnicornViewSpec/UnicornViewState.cpp b/cpp/unicorn/UnicornViewState.cpp
140 | similarity index 100%
141 | rename from cpp/react/renderer/components/UnicornViewSpec/UnicornViewState.cpp
142 | rename to cpp/unicorn/UnicornViewState.cpp
143 | diff --git a/cpp/react/renderer/components/UnicornViewSpec/UnicornViewState.h b/cpp/unicorn/UnicornViewState.h
144 | similarity index 100%
145 | rename from cpp/react/renderer/components/UnicornViewSpec/UnicornViewState.h
146 | rename to cpp/unicorn/UnicornViewState.h
147 | --
148 | 2.31.0
149 |
150 |
--------------------------------------------------------------------------------
/example/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | #
21 | # Gradle start up script for POSIX generated by Gradle.
22 | #
23 | # Important for running:
24 | #
25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26 | # noncompliant, but you have some other compliant shell such as ksh or
27 | # bash, then to run this script, type that shell name before the whole
28 | # command line, like:
29 | #
30 | # ksh Gradle
31 | #
32 | # Busybox and similar reduced shells will NOT work, because this script
33 | # requires all of these POSIX shell features:
34 | # * functions;
35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37 | # * compound commands having a testable exit status, especially «case»;
38 | # * various built-in commands including «command», «set», and «ulimit».
39 | #
40 | # Important for patching:
41 | #
42 | # (2) This script targets any POSIX shell, so it avoids extensions provided
43 | # by Bash, Ksh, etc; in particular arrays are avoided.
44 | #
45 | # The "traditional" practice of packing multiple parameters into a
46 | # space-separated string is a well documented source of bugs and security
47 | # problems, so this is (mostly) avoided, by progressively accumulating
48 | # options in "$@", and eventually passing that to Java.
49 | #
50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52 | # see the in-line comments for details.
53 | #
54 | # There are tweaks for specific operating systems such as AIX, CygWin,
55 | # Darwin, MinGW, and NonStop.
56 | #
57 | # (3) This script is generated from the Groovy template
58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59 | # within the Gradle project.
60 | #
61 | # You can find Gradle at https://github.com/gradle/gradle/.
62 | #
63 | ##############################################################################
64 |
65 | # Attempt to set APP_HOME
66 |
67 | # Resolve links: $0 may be a link
68 | app_path=$0
69 |
70 | # Need this for daisy-chained symlinks.
71 | while
72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73 | [ -h "$app_path" ]
74 | do
75 | ls=$( ls -ld "$app_path" )
76 | link=${ls#*' -> '}
77 | case $link in #(
78 | /*) app_path=$link ;; #(
79 | *) app_path=$APP_HOME$link ;;
80 | esac
81 | done
82 |
83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
84 |
85 | APP_NAME="Gradle"
86 | APP_BASE_NAME=${0##*/}
87 |
88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137 |
138 | Please set the JAVA_HOME variable in your environment to match the
139 | location of your Java installation."
140 | fi
141 |
142 | # Increase the maximum file descriptors if we can.
143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
144 | case $MAX_FD in #(
145 | max*)
146 | MAX_FD=$( ulimit -H -n ) ||
147 | warn "Could not query maximum file descriptor limit"
148 | esac
149 | case $MAX_FD in #(
150 | '' | soft) :;; #(
151 | *)
152 | ulimit -n "$MAX_FD" ||
153 | warn "Could not set maximum file descriptor limit to $MAX_FD"
154 | esac
155 | fi
156 |
157 | # Collect all arguments for the java command, stacking in reverse order:
158 | # * args from the command line
159 | # * the main class name
160 | # * -classpath
161 | # * -D...appname settings
162 | # * --module-path (only if needed)
163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
164 |
165 | # For Cygwin or MSYS, switch paths to Windows format before running java
166 | if "$cygwin" || "$msys" ; then
167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
169 |
170 | JAVACMD=$( cygpath --unix "$JAVACMD" )
171 |
172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
173 | for arg do
174 | if
175 | case $arg in #(
176 | -*) false ;; # don't mess with options #(
177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
178 | [ -e "$t" ] ;; #(
179 | *) false ;;
180 | esac
181 | then
182 | arg=$( cygpath --path --ignore --mixed "$arg" )
183 | fi
184 | # Roll the args list around exactly as many times as the number of
185 | # args, so each arg winds up back in the position where it started, but
186 | # possibly modified.
187 | #
188 | # NB: a `for` loop captures its iteration list before it begins, so
189 | # changing the positional parameters here affects neither the number of
190 | # iterations, nor the values presented in `arg`.
191 | shift # remove old arg
192 | set -- "$@" "$arg" # push replacement arg
193 | done
194 | fi
195 |
196 | # Collect all arguments for the java command;
197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
198 | # shell script including quotes and variable substitutions, so put them in
199 | # double quotes to make sure that they get re-expanded; and
200 | # * put everything else in single quotes, so that it's not re-expanded.
201 |
202 | set -- \
203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
204 | -classpath "$CLASSPATH" \
205 | org.gradle.wrapper.GradleWrapperMain \
206 | "$@"
207 |
208 | # Use "xargs" to parse quoted args.
209 | #
210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
211 | #
212 | # In Bash we could simply go:
213 | #
214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
215 | # set -- "${ARGS[@]}" "$@"
216 | #
217 | # but POSIX shell has neither arrays nor command substitution, so instead we
218 | # post-process each arg (as a line of input to sed) to backslash-escape any
219 | # character that might be a shell metacharacter, then use eval to reverse
220 | # that process (while maintaining the separation between arguments), and wrap
221 | # the whole thing up as a single "set" statement.
222 | #
223 | # This will of course break if any of these variables contains a newline or
224 | # an unmatched quote.
225 | #
226 |
227 | eval "set -- $(
228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
229 | xargs -n1 |
230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
231 | tr '\n' ' '
232 | )" '"$@"'
233 |
234 | exec "$JAVACMD" "$@"
235 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project.
4 |
5 | ## Development workflow
6 |
7 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:
8 |
9 | ```sh
10 | yarn
11 | ```
12 |
13 | > While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development.
14 |
15 | While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app.
16 |
17 | To start the packager:
18 |
19 | ```sh
20 | yarn example start
21 | ```
22 |
23 | To run the example app on Android:
24 |
25 | ```sh
26 | yarn example android
27 | ```
28 |
29 | To run the example app on iOS:
30 |
31 | ```sh
32 | yarn example ios
33 | ```
34 | Make sure your code passes TypeScript and ESLint. Run the following to verify:
35 |
36 | ```sh
37 | yarn typescript
38 | yarn lint
39 | ```
40 |
41 | To fix formatting errors, run the following:
42 |
43 | ```sh
44 | yarn lint --fix
45 | ```
46 |
47 | Remember to add tests for your change if possible. Run the unit tests by:
48 |
49 | ```sh
50 | yarn test
51 | ```
52 | To edit the Objective-C files, open `example/ios/UnicornExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-unicorn`.
53 |
54 | To edit the Kotlin files, open `example/android` in Android studio and find the source files at `reactnativeunicorn` under `Android`.
55 | ### Commit message convention
56 |
57 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
58 |
59 | - `fix`: bug fixes, e.g. fix crash due to deprecated method.
60 | - `feat`: new features, e.g. add new method to the module.
61 | - `refactor`: code refactor, e.g. migrate from class components to hooks.
62 | - `docs`: changes into documentation, e.g. add usage example for the module..
63 | - `test`: adding or updating tests, e.g. add integration tests using detox.
64 | - `chore`: tooling changes, e.g. change CI config.
65 |
66 | Our pre-commit hooks verify that your commit message matches this format when committing.
67 |
68 | ### Linting and tests
69 |
70 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/)
71 |
72 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing.
73 |
74 | Our pre-commit hooks verify that the linter and tests pass when committing.
75 |
76 | ### Publishing to npm
77 |
78 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc.
79 |
80 | To publish new versions, run the following:
81 |
82 | ```sh
83 | yarn release
84 | ```
85 |
86 | ### Scripts
87 |
88 | The `package.json` file contains various scripts for common tasks:
89 |
90 | - `yarn bootstrap`: setup project by installing all dependencies and pods.
91 | - `yarn typescript`: type-check files with TypeScript.
92 | - `yarn lint`: lint files with ESLint.
93 | - `yarn test`: run unit tests with Jest.
94 | - `yarn example start`: start the Metro server for the example app.
95 | - `yarn example android`: run the example app on Android.
96 | - `yarn example ios`: run the example app on iOS.
97 |
98 | ### Sending a pull request
99 |
100 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github).
101 |
102 | When you're sending a pull request:
103 |
104 | - Prefer small pull requests focused on one change.
105 | - Verify that linters and tests are passing.
106 | - Review the documentation to make sure it looks good.
107 | - Follow the pull request template when opening a pull request.
108 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.
109 |
110 | ## Code of Conduct
111 |
112 | ### Our Pledge
113 |
114 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
115 |
116 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
117 |
118 | ### Our Standards
119 |
120 | Examples of behavior that contributes to a positive environment for our community include:
121 |
122 | - Demonstrating empathy and kindness toward other people
123 | - Being respectful of differing opinions, viewpoints, and experiences
124 | - Giving and gracefully accepting constructive feedback
125 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
126 | - Focusing on what is best not just for us as individuals, but for the overall community
127 |
128 | Examples of unacceptable behavior include:
129 |
130 | - The use of sexualized language or imagery, and sexual attention or
131 | advances of any kind
132 | - Trolling, insulting or derogatory comments, and personal or political attacks
133 | - Public or private harassment
134 | - Publishing others' private information, such as a physical or email
135 | address, without their explicit permission
136 | - Other conduct which could reasonably be considered inappropriate in a
137 | professional setting
138 |
139 | ### Enforcement Responsibilities
140 |
141 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
142 |
143 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
144 |
145 | ### Scope
146 |
147 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
148 |
149 | ### Enforcement
150 |
151 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly.
152 |
153 | All community leaders are obligated to respect the privacy and security of the reporter of any incident.
154 |
155 | ### Enforcement Guidelines
156 |
157 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
158 |
159 | #### 1. Correction
160 |
161 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
162 |
163 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
164 |
165 | #### 2. Warning
166 |
167 | **Community Impact**: A violation through a single incident or series of actions.
168 |
169 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
170 |
171 | #### 3. Temporary Ban
172 |
173 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
174 |
175 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
176 |
177 | #### 4. Permanent Ban
178 |
179 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
180 |
181 | **Consequence**: A permanent ban from any sort of public interaction within the community.
182 |
183 | ### Attribution
184 |
185 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
186 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
187 |
188 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
189 |
190 | [homepage]: https://www.contributor-covenant.org
191 |
192 | For answers to common questions about this code of conduct, see the FAQ at
193 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
194 |
--------------------------------------------------------------------------------
/ios/Unicorn.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | CD3D833428CB4A8900D1D14B /* UnicornViewManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD3D833228CB4A8900D1D14B /* UnicornViewManager.mm */; };
11 | CD3D833528CB4A8900D1D14B /* UnicornView.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD3D833328CB4A8900D1D14B /* UnicornView.mm */; };
12 | /* End PBXBuildFile section */
13 |
14 | /* Begin PBXCopyFilesBuildPhase section */
15 | 58B511D91A9E6C8500147676 /* CopyFiles */ = {
16 | isa = PBXCopyFilesBuildPhase;
17 | buildActionMask = 2147483647;
18 | dstPath = "include/$(PRODUCT_NAME)";
19 | dstSubfolderSpec = 16;
20 | files = (
21 | );
22 | runOnlyForDeploymentPostprocessing = 0;
23 | };
24 | /* End PBXCopyFilesBuildPhase section */
25 |
26 | /* Begin PBXFileReference section */
27 | 134814201AA4EA6300B7C361 /* libUnicorn.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libUnicorn.a; sourceTree = BUILT_PRODUCTS_DIR; };
28 | CD3D833128CB4A8900D1D14B /* UnicornView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnicornView.h; sourceTree = ""; };
29 | CD3D833228CB4A8900D1D14B /* UnicornViewManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UnicornViewManager.mm; sourceTree = ""; };
30 | CD3D833328CB4A8900D1D14B /* UnicornView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UnicornView.mm; sourceTree = ""; };
31 | /* End PBXFileReference section */
32 |
33 | /* Begin PBXFrameworksBuildPhase section */
34 | 58B511D81A9E6C8500147676 /* Frameworks */ = {
35 | isa = PBXFrameworksBuildPhase;
36 | buildActionMask = 2147483647;
37 | files = (
38 | );
39 | runOnlyForDeploymentPostprocessing = 0;
40 | };
41 | /* End PBXFrameworksBuildPhase section */
42 |
43 | /* Begin PBXGroup section */
44 | 134814211AA4EA7D00B7C361 /* Products */ = {
45 | isa = PBXGroup;
46 | children = (
47 | 134814201AA4EA6300B7C361 /* libUnicorn.a */,
48 | );
49 | name = Products;
50 | sourceTree = "";
51 | };
52 | 58B511D21A9E6C8500147676 = {
53 | isa = PBXGroup;
54 | children = (
55 | CD3D833128CB4A8900D1D14B /* UnicornView.h */,
56 | CD3D833328CB4A8900D1D14B /* UnicornView.mm */,
57 | CD3D833228CB4A8900D1D14B /* UnicornViewManager.mm */,
58 | 134814211AA4EA7D00B7C361 /* Products */,
59 | );
60 | sourceTree = "";
61 | };
62 | /* End PBXGroup section */
63 |
64 | /* Begin PBXNativeTarget section */
65 | 58B511DA1A9E6C8500147676 /* Unicorn */ = {
66 | isa = PBXNativeTarget;
67 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Unicorn" */;
68 | buildPhases = (
69 | 58B511D71A9E6C8500147676 /* Sources */,
70 | 58B511D81A9E6C8500147676 /* Frameworks */,
71 | 58B511D91A9E6C8500147676 /* CopyFiles */,
72 | );
73 | buildRules = (
74 | );
75 | dependencies = (
76 | );
77 | name = Unicorn;
78 | productName = RCTDataManager;
79 | productReference = 134814201AA4EA6300B7C361 /* libUnicorn.a */;
80 | productType = "com.apple.product-type.library.static";
81 | };
82 | /* End PBXNativeTarget section */
83 |
84 | /* Begin PBXProject section */
85 | 58B511D31A9E6C8500147676 /* Project object */ = {
86 | isa = PBXProject;
87 | attributes = {
88 | LastUpgradeCheck = 0920;
89 | ORGANIZATIONNAME = Facebook;
90 | TargetAttributes = {
91 | 58B511DA1A9E6C8500147676 = {
92 | CreatedOnToolsVersion = 6.1.1;
93 | };
94 | };
95 | };
96 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Unicorn" */;
97 | compatibilityVersion = "Xcode 3.2";
98 | developmentRegion = English;
99 | hasScannedForEncodings = 0;
100 | knownRegions = (
101 | English,
102 | en,
103 | );
104 | mainGroup = 58B511D21A9E6C8500147676;
105 | productRefGroup = 58B511D21A9E6C8500147676;
106 | projectDirPath = "";
107 | projectRoot = "";
108 | targets = (
109 | 58B511DA1A9E6C8500147676 /* Unicorn */,
110 | );
111 | };
112 | /* End PBXProject section */
113 |
114 | /* Begin PBXSourcesBuildPhase section */
115 | 58B511D71A9E6C8500147676 /* Sources */ = {
116 | isa = PBXSourcesBuildPhase;
117 | buildActionMask = 2147483647;
118 | files = (
119 | CD3D833428CB4A8900D1D14B /* UnicornViewManager.mm in Sources */,
120 | CD3D833528CB4A8900D1D14B /* UnicornView.mm in Sources */,
121 | );
122 | runOnlyForDeploymentPostprocessing = 0;
123 | };
124 | /* End PBXSourcesBuildPhase section */
125 |
126 | /* Begin XCBuildConfiguration section */
127 | 58B511ED1A9E6C8500147676 /* Debug */ = {
128 | isa = XCBuildConfiguration;
129 | buildSettings = {
130 | ALWAYS_SEARCH_USER_PATHS = NO;
131 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
132 | CLANG_CXX_LIBRARY = "libc++";
133 | CLANG_ENABLE_MODULES = YES;
134 | CLANG_ENABLE_OBJC_ARC = YES;
135 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
136 | CLANG_WARN_BOOL_CONVERSION = YES;
137 | CLANG_WARN_COMMA = YES;
138 | CLANG_WARN_CONSTANT_CONVERSION = YES;
139 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
140 | CLANG_WARN_EMPTY_BODY = YES;
141 | CLANG_WARN_ENUM_CONVERSION = YES;
142 | CLANG_WARN_INFINITE_RECURSION = YES;
143 | CLANG_WARN_INT_CONVERSION = YES;
144 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
145 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
146 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
147 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
148 | CLANG_WARN_STRICT_PROTOTYPES = YES;
149 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
150 | CLANG_WARN_UNREACHABLE_CODE = YES;
151 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
152 | COPY_PHASE_STRIP = NO;
153 | ENABLE_STRICT_OBJC_MSGSEND = YES;
154 | ENABLE_TESTABILITY = YES;
155 | "EXCLUDED_ARCHS[sdk=*]" = arm64;
156 | GCC_C_LANGUAGE_STANDARD = gnu99;
157 | GCC_DYNAMIC_NO_PIC = NO;
158 | GCC_NO_COMMON_BLOCKS = YES;
159 | GCC_OPTIMIZATION_LEVEL = 0;
160 | GCC_PREPROCESSOR_DEFINITIONS = (
161 | "DEBUG=1",
162 | "$(inherited)",
163 | );
164 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
165 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
166 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
167 | GCC_WARN_UNDECLARED_SELECTOR = YES;
168 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
169 | GCC_WARN_UNUSED_FUNCTION = YES;
170 | GCC_WARN_UNUSED_VARIABLE = YES;
171 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
172 | MTL_ENABLE_DEBUG_INFO = YES;
173 | ONLY_ACTIVE_ARCH = YES;
174 | SDKROOT = iphoneos;
175 | };
176 | name = Debug;
177 | };
178 | 58B511EE1A9E6C8500147676 /* Release */ = {
179 | isa = XCBuildConfiguration;
180 | buildSettings = {
181 | ALWAYS_SEARCH_USER_PATHS = NO;
182 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
183 | CLANG_CXX_LIBRARY = "libc++";
184 | CLANG_ENABLE_MODULES = YES;
185 | CLANG_ENABLE_OBJC_ARC = YES;
186 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
187 | CLANG_WARN_BOOL_CONVERSION = YES;
188 | CLANG_WARN_COMMA = YES;
189 | CLANG_WARN_CONSTANT_CONVERSION = YES;
190 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
191 | CLANG_WARN_EMPTY_BODY = YES;
192 | CLANG_WARN_ENUM_CONVERSION = YES;
193 | CLANG_WARN_INFINITE_RECURSION = YES;
194 | CLANG_WARN_INT_CONVERSION = YES;
195 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
196 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
197 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
198 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
199 | CLANG_WARN_STRICT_PROTOTYPES = YES;
200 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
201 | CLANG_WARN_UNREACHABLE_CODE = YES;
202 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
203 | COPY_PHASE_STRIP = YES;
204 | ENABLE_NS_ASSERTIONS = NO;
205 | ENABLE_STRICT_OBJC_MSGSEND = YES;
206 | "EXCLUDED_ARCHS[sdk=*]" = arm64;
207 | GCC_C_LANGUAGE_STANDARD = gnu99;
208 | GCC_NO_COMMON_BLOCKS = YES;
209 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
210 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
211 | GCC_WARN_UNDECLARED_SELECTOR = YES;
212 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
213 | GCC_WARN_UNUSED_FUNCTION = YES;
214 | GCC_WARN_UNUSED_VARIABLE = YES;
215 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
216 | MTL_ENABLE_DEBUG_INFO = NO;
217 | SDKROOT = iphoneos;
218 | VALIDATE_PRODUCT = YES;
219 | };
220 | name = Release;
221 | };
222 | 58B511F01A9E6C8500147676 /* Debug */ = {
223 | isa = XCBuildConfiguration;
224 | buildSettings = {
225 | HEADER_SEARCH_PATHS = (
226 | "$(inherited)",
227 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
228 | "$(SRCROOT)/../../../React/**",
229 | "$(SRCROOT)/../../react-native/React/**",
230 | );
231 | LIBRARY_SEARCH_PATHS = "$(inherited)";
232 | OTHER_LDFLAGS = "-ObjC";
233 | PRODUCT_NAME = Unicorn;
234 | SKIP_INSTALL = YES;
235 | };
236 | name = Debug;
237 | };
238 | 58B511F11A9E6C8500147676 /* Release */ = {
239 | isa = XCBuildConfiguration;
240 | buildSettings = {
241 | HEADER_SEARCH_PATHS = (
242 | "$(inherited)",
243 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
244 | "$(SRCROOT)/../../../React/**",
245 | "$(SRCROOT)/../../react-native/React/**",
246 | );
247 | LIBRARY_SEARCH_PATHS = "$(inherited)";
248 | OTHER_LDFLAGS = "-ObjC";
249 | PRODUCT_NAME = Unicorn;
250 | SKIP_INSTALL = YES;
251 | };
252 | name = Release;
253 | };
254 | /* End XCBuildConfiguration section */
255 |
256 | /* Begin XCConfigurationList section */
257 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Unicorn" */ = {
258 | isa = XCConfigurationList;
259 | buildConfigurations = (
260 | 58B511ED1A9E6C8500147676 /* Debug */,
261 | 58B511EE1A9E6C8500147676 /* Release */,
262 | );
263 | defaultConfigurationIsVisible = 0;
264 | defaultConfigurationName = Release;
265 | };
266 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Unicorn" */ = {
267 | isa = XCConfigurationList;
268 | buildConfigurations = (
269 | 58B511F01A9E6C8500147676 /* Debug */,
270 | 58B511F11A9E6C8500147676 /* Release */,
271 | );
272 | defaultConfigurationIsVisible = 0;
273 | defaultConfigurationName = Release;
274 | };
275 | /* End XCConfigurationList section */
276 | };
277 | rootObject = 58B511D31A9E6C8500147676 /* Project object */;
278 | }
279 |
--------------------------------------------------------------------------------
/example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.android.application"
2 |
3 | import com.android.build.OutputFile
4 | import org.apache.tools.ant.taskdefs.condition.Os
5 |
6 | /**
7 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
8 | * and bundleReleaseJsAndAssets).
9 | * These basically call `react-native bundle` with the correct arguments during the Android build
10 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
11 | * bundle directly from the development server. Below you can see all the possible configurations
12 | * and their defaults. If you decide to add a configuration block, make sure to add it before the
13 | * `apply from: "../../node_modules/react-native/react.gradle"` line.
14 | *
15 | * project.ext.react = [
16 | * // the name of the generated asset file containing your JS bundle
17 | * bundleAssetName: "index.android.bundle",
18 | *
19 | * // the entry file for bundle generation. If none specified and
20 | * // "index.android.js" exists, it will be used. Otherwise "index.js" is
21 | * // default. Can be overridden with ENTRY_FILE environment variable.
22 | * entryFile: "index.android.js",
23 | *
24 | * // https://reactnative.dev/docs/performance#enable-the-ram-format
25 | * bundleCommand: "ram-bundle",
26 | *
27 | * // whether to bundle JS and assets in debug mode
28 | * bundleInDebug: false,
29 | *
30 | * // whether to bundle JS and assets in release mode
31 | * bundleInRelease: true,
32 | *
33 | * // whether to bundle JS and assets in another build variant (if configured).
34 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
35 | * // The configuration property can be in the following formats
36 | * // 'bundleIn${productFlavor}${buildType}'
37 | * // 'bundleIn${buildType}'
38 | * // bundleInFreeDebug: true,
39 | * // bundleInPaidRelease: true,
40 | * // bundleInBeta: true,
41 | *
42 | * // whether to disable dev mode in custom build variants (by default only disabled in release)
43 | * // for example: to disable dev mode in the staging build type (if configured)
44 | * devDisabledInStaging: true,
45 | * // The configuration property can be in the following formats
46 | * // 'devDisabledIn${productFlavor}${buildType}'
47 | * // 'devDisabledIn${buildType}'
48 | *
49 | * // the root of your project, i.e. where "package.json" lives
50 | * root: "../../",
51 | *
52 | * // where to put the JS bundle asset in debug mode
53 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
54 | *
55 | * // where to put the JS bundle asset in release mode
56 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
57 | *
58 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
59 | * // require('./image.png')), in debug mode
60 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
61 | *
62 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
63 | * // require('./image.png')), in release mode
64 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
65 | *
66 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
67 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
68 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle
69 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
70 | * // for example, you might want to remove it from here.
71 | * inputExcludes: ["android/**", "ios/**"],
72 | *
73 | * // override which node gets called and with what additional arguments
74 | * nodeExecutableAndArgs: ["node"],
75 | *
76 | * // supply additional arguments to the packager
77 | * extraPackagerArgs: []
78 | * ]
79 | */
80 |
81 | project.ext.react = [
82 | enableHermes: true, // clean and rebuild if changing
83 | ]
84 |
85 | apply from: "../../node_modules/react-native/react.gradle"
86 |
87 | /**
88 | * Set this to true to create two separate APKs instead of one:
89 | * - An APK that only works on ARM devices
90 | * - An APK that only works on x86 devices
91 | * The advantage is the size of the APK is reduced by about 4MB.
92 | * Upload all the APKs to the Play Store and people will download
93 | * the correct one based on the CPU architecture of their device.
94 | */
95 | def enableSeparateBuildPerCPUArchitecture = false
96 |
97 | /**
98 | * Run Proguard to shrink the Java bytecode in release builds.
99 | */
100 | def enableProguardInReleaseBuilds = false
101 |
102 | /**
103 | * The preferred build flavor of JavaScriptCore.
104 | *
105 | * For example, to use the international variant, you can use:
106 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
107 | *
108 | * The international variant includes ICU i18n library and necessary data
109 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
110 | * give correct results when using with locales other than en-US. Note that
111 | * this variant is about 6MiB larger per architecture than default.
112 | */
113 | def jscFlavor = 'org.webkit:android-jsc:+'
114 |
115 | /**
116 | * Whether to enable the Hermes VM.
117 | *
118 | * This should be set on project.ext.react and that value will be read here. If it is not set
119 | * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
120 | * and the benefits of using Hermes will therefore be sharply reduced.
121 | */
122 | def enableHermes = project.ext.react.get("enableHermes", false);
123 |
124 | /**
125 | * Architectures to build native code for.
126 | */
127 | def reactNativeArchitectures() {
128 | def value = project.getProperties().get("reactNativeArchitectures")
129 | return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
130 | }
131 |
132 | android {
133 | ndkVersion rootProject.ext.ndkVersion
134 |
135 | compileSdkVersion rootProject.ext.compileSdkVersion
136 |
137 | defaultConfig {
138 | applicationId "com.example.reactnativeunicorn"
139 | minSdkVersion rootProject.ext.minSdkVersion
140 | targetSdkVersion rootProject.ext.targetSdkVersion
141 | versionCode 1
142 | versionName "1.0"
143 | buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
144 |
145 | if (isNewArchitectureEnabled()) {
146 | // We configure the NDK build only if you decide to opt-in for the New Architecture.
147 | externalNativeBuild {
148 | cmake {
149 | arguments "-DPROJECT_BUILD_DIR=$buildDir",
150 | "-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
151 | "-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
152 | "-DNODE_MODULES_DIR=$rootDir/../node_modules",
153 | "-DANDROID_STL=c++_shared"
154 | }
155 | }
156 | if (!enableSeparateBuildPerCPUArchitecture) {
157 | ndk {
158 | abiFilters (*reactNativeArchitectures())
159 | }
160 | }
161 | }
162 | }
163 |
164 | if (isNewArchitectureEnabled()) {
165 | // We configure the NDK build only if you decide to opt-in for the New Architecture.
166 | externalNativeBuild {
167 | cmake {
168 | path "$projectDir/src/main/jni/CMakeLists.txt"
169 | }
170 | }
171 | def reactAndroidProjectDir = project(':ReactAndroid').projectDir
172 | def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
173 | dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
174 | from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
175 | into("$buildDir/react-ndk/exported")
176 | }
177 | def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
178 | dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
179 | from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
180 | into("$buildDir/react-ndk/exported")
181 | }
182 | afterEvaluate {
183 | // If you wish to add a custom TurboModule or component locally,
184 | // you should uncomment this line.
185 | // preBuild.dependsOn("generateCodegenArtifactsFromSchema")
186 | preDebugBuild.dependsOn(packageReactNdkDebugLibs)
187 | preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
188 |
189 | // Due to a bug inside AGP, we have to explicitly set a dependency
190 | // between configureNdkBuild* tasks and the preBuild tasks.
191 | // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
192 | configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
193 | configureCMakeDebug.dependsOn(preDebugBuild)
194 | reactNativeArchitectures().each { architecture ->
195 | tasks.findByName("configureCMakeDebug[${architecture}]")?.configure {
196 | dependsOn("preDebugBuild")
197 | }
198 | tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure {
199 | dependsOn("preReleaseBuild")
200 | }
201 | }
202 | }
203 | }
204 |
205 | splits {
206 | abi {
207 | reset()
208 | enable enableSeparateBuildPerCPUArchitecture
209 | universalApk false // If true, also generate a universal APK
210 | include (*reactNativeArchitectures())
211 | }
212 | }
213 | signingConfigs {
214 | debug {
215 | storeFile file('debug.keystore')
216 | storePassword 'android'
217 | keyAlias 'androiddebugkey'
218 | keyPassword 'android'
219 | }
220 | }
221 | buildTypes {
222 | debug {
223 | signingConfig signingConfigs.debug
224 | }
225 | release {
226 | // Caution! In production, you need to generate your own keystore file.
227 | // see https://reactnative.dev/docs/signed-apk-android.
228 | signingConfig signingConfigs.debug
229 | minifyEnabled enableProguardInReleaseBuilds
230 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
231 | }
232 | }
233 |
234 | // applicationVariants are e.g. debug, release
235 | applicationVariants.all { variant ->
236 | variant.outputs.each { output ->
237 | // For each separate APK per architecture, set a unique version code as described here:
238 | // https://developer.android.com/studio/build/configure-apk-splits.html
239 | // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
240 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
241 | def abi = output.getFilter(OutputFile.ABI)
242 | if (abi != null) { // null for the universal-debug, universal-release variants
243 | output.versionCodeOverride =
244 | defaultConfig.versionCode * 1000 + versionCodes.get(abi)
245 | }
246 |
247 | }
248 | }
249 | }
250 |
251 | dependencies {
252 | implementation fileTree(dir: "libs", include: ["*.jar"])
253 |
254 | //noinspection GradleDynamicVersion
255 | implementation "com.facebook.react:react-native:+" // From node_modules
256 |
257 | implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
258 |
259 | debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
260 | exclude group:'com.facebook.fbjni'
261 | }
262 |
263 | debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
264 | exclude group:'com.facebook.flipper'
265 | exclude group:'com.squareup.okhttp3', module:'okhttp'
266 | }
267 |
268 | debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
269 | exclude group:'com.facebook.flipper'
270 | }
271 |
272 | if (enableHermes) {
273 | //noinspection GradleDynamicVersion
274 | implementation("com.facebook.react:hermes-engine:+") { // From node_modules
275 | exclude group:'com.facebook.fbjni'
276 | }
277 | } else {
278 | implementation jscFlavor
279 | }
280 | }
281 |
282 | if (isNewArchitectureEnabled()) {
283 | // If new architecture is enabled, we let you build RN from source
284 | // Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
285 | // This will be applied to all the imported transtitive dependency.
286 | configurations.all {
287 | resolutionStrategy.dependencySubstitution {
288 | substitute(module("com.facebook.react:react-native"))
289 | .using(project(":ReactAndroid"))
290 | .because("On New Architecture we're building React Native from source")
291 | substitute(module("com.facebook.react:hermes-engine"))
292 | .using(project(":ReactAndroid:hermes-engine"))
293 | .because("On New Architecture we're building Hermes from source")
294 | }
295 | }
296 | }
297 |
298 | // Run this once to be able to run the application with BUCK
299 | // puts all compile dependencies into folder libs for BUCK to use
300 | task copyDownloadableDepsToLibs(type: Copy) {
301 | from configurations.implementation
302 | into 'libs'
303 | }
304 |
305 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
306 |
307 | def isNewArchitectureEnabled() {
308 | // To opt-in for the New Architecture, you can either:
309 | // - Set `newArchEnabled` to true inside the `gradle.properties` file
310 | // - Invoke gradle with `-newArchEnabled=true`
311 | // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
312 | return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
313 | }
314 |
--------------------------------------------------------------------------------
/example/ios/UnicornExample.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 54;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 0C80B921A6F3F58F76C31292 /* libPods-UnicornExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DCACB8F33CDC322A6C60F78 /* libPods-UnicornExample.a */; };
11 | 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; };
12 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13 | 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
14 | 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
15 | /* End PBXBuildFile section */
16 |
17 | /* Begin PBXFileReference section */
18 | 13B07F961A680F5B00A75B9A /* UnicornExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UnicornExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
19 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = UnicornExample/AppDelegate.h; sourceTree = ""; };
20 | 13B07FB01A68108700A75B9A /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = UnicornExample/AppDelegate.mm; sourceTree = ""; };
21 | 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = UnicornExample/Images.xcassets; sourceTree = ""; };
22 | 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = UnicornExample/Info.plist; sourceTree = ""; };
23 | 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = UnicornExample/main.m; sourceTree = ""; };
24 | 3B4392A12AC88292D35C810B /* Pods-UnicornExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UnicornExample.debug.xcconfig"; path = "Target Support Files/Pods-UnicornExample/Pods-UnicornExample.debug.xcconfig"; sourceTree = ""; };
25 | 5709B34CF0A7D63546082F79 /* Pods-UnicornExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-UnicornExample.release.xcconfig"; path = "Target Support Files/Pods-UnicornExample/Pods-UnicornExample.release.xcconfig"; sourceTree = ""; };
26 | 5DCACB8F33CDC322A6C60F78 /* libPods-UnicornExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-UnicornExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
27 | 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = UnicornExample/LaunchScreen.storyboard; sourceTree = ""; };
28 | ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
29 | /* End PBXFileReference section */
30 |
31 | /* Begin PBXFrameworksBuildPhase section */
32 | 13B07F8C1A680F5B00A75B9A /* Frameworks */ = {
33 | isa = PBXFrameworksBuildPhase;
34 | buildActionMask = 2147483647;
35 | files = (
36 | 0C80B921A6F3F58F76C31292 /* libPods-UnicornExample.a in Frameworks */,
37 | );
38 | runOnlyForDeploymentPostprocessing = 0;
39 | };
40 | /* End PBXFrameworksBuildPhase section */
41 |
42 | /* Begin PBXGroup section */
43 | 13B07FAE1A68108700A75B9A /* UnicornExample */ = {
44 | isa = PBXGroup;
45 | children = (
46 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */,
47 | 13B07FB01A68108700A75B9A /* AppDelegate.mm */,
48 | 13B07FB51A68108700A75B9A /* Images.xcassets */,
49 | 13B07FB61A68108700A75B9A /* Info.plist */,
50 | 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
51 | 13B07FB71A68108700A75B9A /* main.m */,
52 | );
53 | name = UnicornExample;
54 | sourceTree = "";
55 | };
56 | 2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
57 | isa = PBXGroup;
58 | children = (
59 | ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
60 | 5DCACB8F33CDC322A6C60F78 /* libPods-UnicornExample.a */,
61 | );
62 | name = Frameworks;
63 | sourceTree = "";
64 | };
65 | 832341AE1AAA6A7D00B99B32 /* Libraries */ = {
66 | isa = PBXGroup;
67 | children = (
68 | );
69 | name = Libraries;
70 | sourceTree = "";
71 | };
72 | 83CBB9F61A601CBA00E9B192 = {
73 | isa = PBXGroup;
74 | children = (
75 | 13B07FAE1A68108700A75B9A /* UnicornExample */,
76 | 832341AE1AAA6A7D00B99B32 /* Libraries */,
77 | 83CBBA001A601CBA00E9B192 /* Products */,
78 | 2D16E6871FA4F8E400B85C8A /* Frameworks */,
79 | BBD78D7AC51CEA395F1C20DB /* Pods */,
80 | );
81 | indentWidth = 2;
82 | sourceTree = "";
83 | tabWidth = 2;
84 | usesTabs = 0;
85 | };
86 | 83CBBA001A601CBA00E9B192 /* Products */ = {
87 | isa = PBXGroup;
88 | children = (
89 | 13B07F961A680F5B00A75B9A /* UnicornExample.app */,
90 | );
91 | name = Products;
92 | sourceTree = "";
93 | };
94 | BBD78D7AC51CEA395F1C20DB /* Pods */ = {
95 | isa = PBXGroup;
96 | children = (
97 | 3B4392A12AC88292D35C810B /* Pods-UnicornExample.debug.xcconfig */,
98 | 5709B34CF0A7D63546082F79 /* Pods-UnicornExample.release.xcconfig */,
99 | );
100 | path = Pods;
101 | sourceTree = "";
102 | };
103 | /* End PBXGroup section */
104 |
105 | /* Begin PBXNativeTarget section */
106 | 13B07F861A680F5B00A75B9A /* UnicornExample */ = {
107 | isa = PBXNativeTarget;
108 | buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "UnicornExample" */;
109 | buildPhases = (
110 | C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */,
111 | FD10A7F022414F080027D42C /* Start Packager */,
112 | 13B07F871A680F5B00A75B9A /* Sources */,
113 | 13B07F8C1A680F5B00A75B9A /* Frameworks */,
114 | 13B07F8E1A680F5B00A75B9A /* Resources */,
115 | 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
116 | 00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */,
117 | E235C05ADACE081382539298 /* [CP] Copy Pods Resources */,
118 | );
119 | buildRules = (
120 | );
121 | dependencies = (
122 | );
123 | name = UnicornExample;
124 | productName = UnicornExample;
125 | productReference = 13B07F961A680F5B00A75B9A /* UnicornExample.app */;
126 | productType = "com.apple.product-type.application";
127 | };
128 | /* End PBXNativeTarget section */
129 |
130 | /* Begin PBXProject section */
131 | 83CBB9F71A601CBA00E9B192 /* Project object */ = {
132 | isa = PBXProject;
133 | attributes = {
134 | LastUpgradeCheck = 1210;
135 | TargetAttributes = {
136 | 13B07F861A680F5B00A75B9A = {
137 | LastSwiftMigration = 1120;
138 | };
139 | };
140 | };
141 | buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "UnicornExample" */;
142 | compatibilityVersion = "Xcode 12.0";
143 | developmentRegion = en;
144 | hasScannedForEncodings = 0;
145 | knownRegions = (
146 | en,
147 | Base,
148 | );
149 | mainGroup = 83CBB9F61A601CBA00E9B192;
150 | productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */;
151 | projectDirPath = "";
152 | projectRoot = "";
153 | targets = (
154 | 13B07F861A680F5B00A75B9A /* UnicornExample */,
155 | );
156 | };
157 | /* End PBXProject section */
158 |
159 | /* Begin PBXResourcesBuildPhase section */
160 | 13B07F8E1A680F5B00A75B9A /* Resources */ = {
161 | isa = PBXResourcesBuildPhase;
162 | buildActionMask = 2147483647;
163 | files = (
164 | 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
165 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
166 | );
167 | runOnlyForDeploymentPostprocessing = 0;
168 | };
169 | /* End PBXResourcesBuildPhase section */
170 |
171 | /* Begin PBXShellScriptBuildPhase section */
172 | 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = {
173 | isa = PBXShellScriptBuildPhase;
174 | buildActionMask = 2147483647;
175 | files = (
176 | );
177 | inputPaths = (
178 | );
179 | name = "Bundle React Native code and images";
180 | outputPaths = (
181 | );
182 | runOnlyForDeploymentPostprocessing = 0;
183 | shellPath = /bin/sh;
184 | shellScript = "set -e\n\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
185 | };
186 | 00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = {
187 | isa = PBXShellScriptBuildPhase;
188 | buildActionMask = 2147483647;
189 | files = (
190 | );
191 | inputFileListPaths = (
192 | "${PODS_ROOT}/Target Support Files/Pods-UnicornExample/Pods-UnicornExample-frameworks-${CONFIGURATION}-input-files.xcfilelist",
193 | );
194 | name = "[CP] Embed Pods Frameworks";
195 | outputFileListPaths = (
196 | "${PODS_ROOT}/Target Support Files/Pods-UnicornExample/Pods-UnicornExample-frameworks-${CONFIGURATION}-output-files.xcfilelist",
197 | );
198 | runOnlyForDeploymentPostprocessing = 0;
199 | shellPath = /bin/sh;
200 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-UnicornExample/Pods-UnicornExample-frameworks.sh\"\n";
201 | showEnvVarsInLog = 0;
202 | };
203 | C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */ = {
204 | isa = PBXShellScriptBuildPhase;
205 | buildActionMask = 2147483647;
206 | files = (
207 | );
208 | inputFileListPaths = (
209 | );
210 | inputPaths = (
211 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock",
212 | "${PODS_ROOT}/Manifest.lock",
213 | );
214 | name = "[CP] Check Pods Manifest.lock";
215 | outputFileListPaths = (
216 | );
217 | outputPaths = (
218 | "$(DERIVED_FILE_DIR)/Pods-UnicornExample-checkManifestLockResult.txt",
219 | );
220 | runOnlyForDeploymentPostprocessing = 0;
221 | shellPath = /bin/sh;
222 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
223 | showEnvVarsInLog = 0;
224 | };
225 | E235C05ADACE081382539298 /* [CP] Copy Pods Resources */ = {
226 | isa = PBXShellScriptBuildPhase;
227 | buildActionMask = 2147483647;
228 | files = (
229 | );
230 | inputFileListPaths = (
231 | "${PODS_ROOT}/Target Support Files/Pods-UnicornExample/Pods-UnicornExample-resources-${CONFIGURATION}-input-files.xcfilelist",
232 | );
233 | name = "[CP] Copy Pods Resources";
234 | outputFileListPaths = (
235 | "${PODS_ROOT}/Target Support Files/Pods-UnicornExample/Pods-UnicornExample-resources-${CONFIGURATION}-output-files.xcfilelist",
236 | );
237 | runOnlyForDeploymentPostprocessing = 0;
238 | shellPath = /bin/sh;
239 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-UnicornExample/Pods-UnicornExample-resources.sh\"\n";
240 | showEnvVarsInLog = 0;
241 | };
242 | FD10A7F022414F080027D42C /* Start Packager */ = {
243 | isa = PBXShellScriptBuildPhase;
244 | buildActionMask = 2147483647;
245 | files = (
246 | );
247 | inputFileListPaths = (
248 | );
249 | inputPaths = (
250 | );
251 | name = "Start Packager";
252 | outputFileListPaths = (
253 | );
254 | outputPaths = (
255 | );
256 | runOnlyForDeploymentPostprocessing = 0;
257 | shellPath = /bin/sh;
258 | shellScript = "export RCT_METRO_PORT=\"${RCT_METRO_PORT:=8081}\"\necho \"export RCT_METRO_PORT=${RCT_METRO_PORT}\" > \"${SRCROOT}/../node_modules/react-native/scripts/.packager.env\"\nif [ -z \"${RCT_NO_LAUNCH_PACKAGER+xxx}\" ] ; then\n if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then\n if ! curl -s \"http://localhost:${RCT_METRO_PORT}/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly\"\n exit 2\n fi\n else\n open \"$SRCROOT/../node_modules/react-native/scripts/launchPackager.command\" || echo \"Can't start packager automatically\"\n fi\nfi\n";
259 | showEnvVarsInLog = 0;
260 | };
261 | /* End PBXShellScriptBuildPhase section */
262 |
263 | /* Begin PBXSourcesBuildPhase section */
264 | 13B07F871A680F5B00A75B9A /* Sources */ = {
265 | isa = PBXSourcesBuildPhase;
266 | buildActionMask = 2147483647;
267 | files = (
268 | 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */,
269 | 13B07FC11A68108700A75B9A /* main.m in Sources */,
270 | );
271 | runOnlyForDeploymentPostprocessing = 0;
272 | };
273 | /* End PBXSourcesBuildPhase section */
274 |
275 | /* Begin XCBuildConfiguration section */
276 | 13B07F941A680F5B00A75B9A /* Debug */ = {
277 | isa = XCBuildConfiguration;
278 | baseConfigurationReference = 3B4392A12AC88292D35C810B /* Pods-UnicornExample.debug.xcconfig */;
279 | buildSettings = {
280 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
281 | CLANG_CXX_LANGUAGE_STANDARD = "c++17";
282 | CLANG_ENABLE_MODULES = YES;
283 | CURRENT_PROJECT_VERSION = 1;
284 | ENABLE_BITCODE = NO;
285 | INFOPLIST_FILE = UnicornExample/Info.plist;
286 | LD_RUNPATH_SEARCH_PATHS = (
287 | "$(inherited)",
288 | "@executable_path/Frameworks",
289 | );
290 | OTHER_LDFLAGS = (
291 | "$(inherited)",
292 | "-ObjC",
293 | "-lc++",
294 | );
295 | PRODUCT_BUNDLE_IDENTIFIER = com.example.reactnativeunicorn;
296 | PRODUCT_NAME = UnicornExample;
297 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
298 | SWIFT_VERSION = 5.0;
299 | VERSIONING_SYSTEM = "apple-generic";
300 | };
301 | name = Debug;
302 | };
303 | 13B07F951A680F5B00A75B9A /* Release */ = {
304 | isa = XCBuildConfiguration;
305 | baseConfigurationReference = 5709B34CF0A7D63546082F79 /* Pods-UnicornExample.release.xcconfig */;
306 | buildSettings = {
307 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
308 | CLANG_CXX_LANGUAGE_STANDARD = "c++17";
309 | CLANG_ENABLE_MODULES = YES;
310 | CURRENT_PROJECT_VERSION = 1;
311 | INFOPLIST_FILE = UnicornExample/Info.plist;
312 | LD_RUNPATH_SEARCH_PATHS = (
313 | "$(inherited)",
314 | "@executable_path/Frameworks",
315 | );
316 | OTHER_LDFLAGS = (
317 | "$(inherited)",
318 | "-ObjC",
319 | "-lc++",
320 | );
321 | PRODUCT_BUNDLE_IDENTIFIER = com.example.reactnativeunicorn;
322 | PRODUCT_NAME = UnicornExample;
323 | SWIFT_VERSION = 5.0;
324 | VERSIONING_SYSTEM = "apple-generic";
325 | };
326 | name = Release;
327 | };
328 | 83CBBA201A601CBA00E9B192 /* Debug */ = {
329 | isa = XCBuildConfiguration;
330 | buildSettings = {
331 | ALWAYS_SEARCH_USER_PATHS = NO;
332 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
333 | CLANG_CXX_LANGUAGE_STANDARD = "c++17";
334 | CLANG_CXX_LIBRARY = "libc++";
335 | CLANG_ENABLE_MODULES = YES;
336 | CLANG_ENABLE_OBJC_ARC = YES;
337 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
338 | CLANG_WARN_BOOL_CONVERSION = YES;
339 | CLANG_WARN_COMMA = YES;
340 | CLANG_WARN_CONSTANT_CONVERSION = YES;
341 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
342 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
343 | CLANG_WARN_EMPTY_BODY = YES;
344 | CLANG_WARN_ENUM_CONVERSION = YES;
345 | CLANG_WARN_INFINITE_RECURSION = YES;
346 | CLANG_WARN_INT_CONVERSION = YES;
347 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
348 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
349 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
350 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
351 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
352 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
353 | CLANG_WARN_STRICT_PROTOTYPES = YES;
354 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
355 | CLANG_WARN_UNREACHABLE_CODE = YES;
356 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
357 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
358 | COPY_PHASE_STRIP = NO;
359 | ENABLE_STRICT_OBJC_MSGSEND = YES;
360 | ENABLE_TESTABILITY = YES;
361 | "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
362 | GCC_C_LANGUAGE_STANDARD = gnu99;
363 | GCC_DYNAMIC_NO_PIC = NO;
364 | GCC_NO_COMMON_BLOCKS = YES;
365 | GCC_OPTIMIZATION_LEVEL = 0;
366 | GCC_PREPROCESSOR_DEFINITIONS = (
367 | "DEBUG=1",
368 | "$(inherited)",
369 | );
370 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
371 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
372 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
373 | GCC_WARN_UNDECLARED_SELECTOR = YES;
374 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
375 | GCC_WARN_UNUSED_FUNCTION = YES;
376 | GCC_WARN_UNUSED_VARIABLE = YES;
377 | IPHONEOS_DEPLOYMENT_TARGET = 11.0;
378 | LD_RUNPATH_SEARCH_PATHS = (
379 | /usr/lib/swift,
380 | "$(inherited)",
381 | );
382 | LIBRARY_SEARCH_PATHS = (
383 | "\"$(SDKROOT)/usr/lib/swift\"",
384 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
385 | "\"$(inherited)\"",
386 | );
387 | MTL_ENABLE_DEBUG_INFO = YES;
388 | ONLY_ACTIVE_ARCH = YES;
389 | OTHER_CPLUSPLUSFLAGS = (
390 | "$(OTHER_CFLAGS)",
391 | "-DFOLLY_NO_CONFIG",
392 | "-DFOLLY_MOBILE=1",
393 | "-DFOLLY_USE_LIBCPP=1",
394 | );
395 | SDKROOT = iphoneos;
396 | };
397 | name = Debug;
398 | };
399 | 83CBBA211A601CBA00E9B192 /* Release */ = {
400 | isa = XCBuildConfiguration;
401 | buildSettings = {
402 | ALWAYS_SEARCH_USER_PATHS = NO;
403 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
404 | CLANG_CXX_LANGUAGE_STANDARD = "c++17";
405 | CLANG_CXX_LIBRARY = "libc++";
406 | CLANG_ENABLE_MODULES = YES;
407 | CLANG_ENABLE_OBJC_ARC = YES;
408 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
409 | CLANG_WARN_BOOL_CONVERSION = YES;
410 | CLANG_WARN_COMMA = YES;
411 | CLANG_WARN_CONSTANT_CONVERSION = YES;
412 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
413 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
414 | CLANG_WARN_EMPTY_BODY = YES;
415 | CLANG_WARN_ENUM_CONVERSION = YES;
416 | CLANG_WARN_INFINITE_RECURSION = YES;
417 | CLANG_WARN_INT_CONVERSION = YES;
418 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
419 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
420 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
421 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
422 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
423 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
424 | CLANG_WARN_STRICT_PROTOTYPES = YES;
425 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
426 | CLANG_WARN_UNREACHABLE_CODE = YES;
427 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
428 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
429 | COPY_PHASE_STRIP = YES;
430 | ENABLE_NS_ASSERTIONS = NO;
431 | ENABLE_STRICT_OBJC_MSGSEND = YES;
432 | "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
433 | GCC_C_LANGUAGE_STANDARD = gnu99;
434 | GCC_NO_COMMON_BLOCKS = YES;
435 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
436 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
437 | GCC_WARN_UNDECLARED_SELECTOR = YES;
438 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
439 | GCC_WARN_UNUSED_FUNCTION = YES;
440 | GCC_WARN_UNUSED_VARIABLE = YES;
441 | IPHONEOS_DEPLOYMENT_TARGET = 11.0;
442 | LD_RUNPATH_SEARCH_PATHS = (
443 | /usr/lib/swift,
444 | "$(inherited)",
445 | );
446 | LIBRARY_SEARCH_PATHS = (
447 | "\"$(SDKROOT)/usr/lib/swift\"",
448 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
449 | "\"$(inherited)\"",
450 | );
451 | MTL_ENABLE_DEBUG_INFO = NO;
452 | OTHER_CPLUSPLUSFLAGS = (
453 | "$(OTHER_CFLAGS)",
454 | "-DFOLLY_NO_CONFIG",
455 | "-DFOLLY_MOBILE=1",
456 | "-DFOLLY_USE_LIBCPP=1",
457 | );
458 | SDKROOT = iphoneos;
459 | VALIDATE_PRODUCT = YES;
460 | };
461 | name = Release;
462 | };
463 | /* End XCBuildConfiguration section */
464 |
465 | /* Begin XCConfigurationList section */
466 | 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "UnicornExample" */ = {
467 | isa = XCConfigurationList;
468 | buildConfigurations = (
469 | 13B07F941A680F5B00A75B9A /* Debug */,
470 | 13B07F951A680F5B00A75B9A /* Release */,
471 | );
472 | defaultConfigurationIsVisible = 0;
473 | defaultConfigurationName = Release;
474 | };
475 | 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "UnicornExample" */ = {
476 | isa = XCConfigurationList;
477 | buildConfigurations = (
478 | 83CBBA201A601CBA00E9B192 /* Debug */,
479 | 83CBBA211A601CBA00E9B192 /* Release */,
480 | );
481 | defaultConfigurationIsVisible = 0;
482 | defaultConfigurationName = Release;
483 | };
484 | /* End XCConfigurationList section */
485 | };
486 | rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */;
487 | }
488 |
--------------------------------------------------------------------------------