Skip to content

Commit 2e09cb2

Browse files
committed
Updated to RN 0.70.4
1 parent a47f364 commit 2e09cb2

24 files changed

+2100
-1256
lines changed

.bundle/config

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BUNDLE_PATH: "vendor/bundle"
2+
BUNDLE_FORCE_RUBY_PLATFORM: 1

.node-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16

.ruby-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.7.6
1+
2.7.5

Gemfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source 'https://rubygems.org'
2+
3+
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4+
ruby '2.7.5'
5+
6+
gem 'cocoapods', '~> 1.11', '>= 1.11.2'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package com.rndiffapp.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.FabricJSIModuleProvider;
20+
import com.facebook.react.fabric.ReactNativeConfig;
21+
import com.facebook.react.uimanager.ViewManagerRegistry;
22+
import com.rndiffapp.BuildConfig;
23+
import com.rndiffapp.newarchitecture.components.MainComponentsRegistry;
24+
import com.rndiffapp.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate;
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
28+
/**
29+
* A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both
30+
* TurboModule delegates and the Fabric Renderer.
31+
*
32+
* <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the
33+
* `newArchEnabled` property). Is ignored otherwise.
34+
*/
35+
public class MainApplicationReactNativeHost extends ReactNativeHost {
36+
public MainApplicationReactNativeHost(Application application) {
37+
super(application);
38+
}
39+
40+
@Override
41+
public boolean getUseDeveloperSupport() {
42+
return BuildConfig.DEBUG;
43+
}
44+
45+
@Override
46+
protected List<ReactPackage> getPackages() {
47+
List<ReactPackage> packages = new PackageList(this).getPackages();
48+
// Packages that cannot be autolinked yet can be added manually here, for example:
49+
// packages.add(new MyReactNativePackage());
50+
// TurboModules must also be loaded here providing a valid TurboReactPackage implementation:
51+
// packages.add(new TurboReactPackage() { ... });
52+
// If you have custom Fabric Components, their ViewManagers should also be loaded here
53+
// inside a ReactPackage.
54+
return packages;
55+
}
56+
57+
@Override
58+
protected String getJSMainModuleName() {
59+
return "index";
60+
}
61+
62+
@NonNull
63+
@Override
64+
protected ReactPackageTurboModuleManagerDelegate.Builder
65+
getReactPackageTurboModuleManagerDelegateBuilder() {
66+
// Here we provide the ReactPackageTurboModuleManagerDelegate Builder. This is necessary
67+
// for the new architecture and to use TurboModules correctly.
68+
return new MainApplicationTurboModuleManagerDelegate.Builder();
69+
}
70+
71+
@Override
72+
protected JSIModulePackage getJSIModulePackage() {
73+
return new JSIModulePackage() {
74+
@Override
75+
public List<JSIModuleSpec> getJSIModules(
76+
final ReactApplicationContext reactApplicationContext,
77+
final JavaScriptContextHolder jsContext) {
78+
final List<JSIModuleSpec> specs = new ArrayList<>();
79+
80+
// Here we provide a new JSIModuleSpec that will be responsible of providing the
81+
// custom Fabric Components.
82+
specs.add(
83+
new JSIModuleSpec() {
84+
@Override
85+
public JSIModuleType getJSIModuleType() {
86+
return JSIModuleType.UIManager;
87+
}
88+
89+
@Override
90+
public JSIModuleProvider<UIManager> getJSIModuleProvider() {
91+
final ComponentFactory componentFactory = new ComponentFactory();
92+
CoreComponentsRegistry.register(componentFactory);
93+
94+
// Here we register a Components Registry.
95+
// The one that is generated with the template contains no components
96+
// and just provides you the one from React Native core.
97+
MainComponentsRegistry.register(componentFactory);
98+
99+
final ReactInstanceManager reactInstanceManager = getReactInstanceManager();
100+
101+
ViewManagerRegistry viewManagerRegistry =
102+
new ViewManagerRegistry(
103+
reactInstanceManager.getOrCreateViewManagers(reactApplicationContext));
104+
105+
return new FabricJSIModuleProvider(
106+
reactApplicationContext,
107+
componentFactory,
108+
ReactNativeConfig.DEFAULT_CONFIG,
109+
viewManagerRegistry);
110+
}
111+
});
112+
return specs;
113+
}
114+
};
115+
}
116+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.rndiffapp.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+
* <p>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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.rndiffapp.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+
* <p>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<ReactPackage> 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<ReactPackage> 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("rndiffapp_appmodules");
45+
sIsSoLibraryLoaded = true;
46+
}
47+
}
48+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
# Define the library name here.
4+
project(rndiffapp_appmodules)
5+
6+
# This file includes all the necessary to let you build your application with the New Architecture.
7+
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "MainApplicationModuleProvider.h"
2+
3+
#include <rncli.h>
4+
#include <rncore.h>
5+
6+
namespace facebook {
7+
namespace react {
8+
9+
std::shared_ptr<TurboModule> MainApplicationModuleProvider(
10+
const std::string &moduleName,
11+
const JavaTurboModule::InitParams &params) {
12+
// Here you can provide your own module provider for TurboModules coming from
13+
// either your application or from external libraries. The approach to follow
14+
// is similar to the following (for a library called `samplelibrary`:
15+
//
16+
// auto module = samplelibrary_ModuleProvider(moduleName, params);
17+
// if (module != nullptr) {
18+
// return module;
19+
// }
20+
// return rncore_ModuleProvider(moduleName, params);
21+
22+
// Module providers autolinked by RN CLI
23+
auto rncli_module = rncli_ModuleProvider(moduleName, params);
24+
if (rncli_module != nullptr) {
25+
return rncli_module;
26+
}
27+
28+
return rncore_ModuleProvider(moduleName, params);
29+
}
30+
31+
} // namespace react
32+
} // namespace facebook
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include <memory>
4+
#include <string>
5+
6+
#include <ReactCommon/JavaTurboModule.h>
7+
8+
namespace facebook {
9+
namespace react {
10+
11+
std::shared_ptr<TurboModule> MainApplicationModuleProvider(
12+
const std::string &moduleName,
13+
const JavaTurboModule::InitParams &params);
14+
15+
} // namespace react
16+
} // namespace facebook
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "MainApplicationTurboModuleManagerDelegate.h"
2+
#include "MainApplicationModuleProvider.h"
3+
4+
namespace facebook {
5+
namespace react {
6+
7+
jni::local_ref<MainApplicationTurboModuleManagerDelegate::jhybriddata>
8+
MainApplicationTurboModuleManagerDelegate::initHybrid(
9+
jni::alias_ref<jhybridobject>) {
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<TurboModule>
24+
MainApplicationTurboModuleManagerDelegate::getTurboModule(
25+
const std::string &name,
26+
const std::shared_ptr<CallInvoker> &jsInvoker) {
27+
// Not implemented yet: provide pure-C++ NativeModules here.
28+
return nullptr;
29+
}
30+
31+
std::shared_ptr<TurboModule>
32+
MainApplicationTurboModuleManagerDelegate::getTurboModule(
33+
const std::string &name,
34+
const JavaTurboModule::InitParams &params) {
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <memory>
2+
#include <string>
3+
4+
#include <ReactCommon/TurboModuleManagerDelegate.h>
5+
#include <fbjni/fbjni.h>
6+
7+
namespace facebook {
8+
namespace react {
9+
10+
class MainApplicationTurboModuleManagerDelegate
11+
: public jni::HybridClass<
12+
MainApplicationTurboModuleManagerDelegate,
13+
TurboModuleManagerDelegate> {
14+
public:
15+
// Adapt it to the package you used for your Java class.
16+
static constexpr auto kJavaDescriptor =
17+
"Lcom/rndiffapp/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;";
18+
19+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject>);
20+
21+
static void registerNatives();
22+
23+
std::shared_ptr<TurboModule> getTurboModule(
24+
const std::string &name,
25+
const std::shared_ptr<CallInvoker> &jsInvoker) override;
26+
std::shared_ptr<TurboModule> getTurboModule(
27+
const std::string &name,
28+
const JavaTurboModule::InitParams &params) 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

0 commit comments

Comments
 (0)