Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bridgeless compat #5519

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Common/cpp/TurboModule/REATurboCppModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "REATurboCppModule.h"
#include "NativeProxy.h"

namespace facebook::react {

REATurboCppModule::REATurboCppModule(std::shared_ptr<CallInvoker> jsInvoker)
: NativeREATurboCppModuleCxxSpec(std::move(jsInvoker)) {}

bool REATurboCppModule::installBridgeless(jsi::Runtime& rt, jsi::String valueUnpackerCode) {
reanimated::bridgelessRnRuntime = &rt;
reanimated::bridgelessCallInvoker = jsInvoker_;
// RCTExecuteOnMainQueue(^{
// id appDelegate = [[UIApplication sharedApplication] delegate];
// RCTModuleRegistry *moduleRegistry =
// (RCTModuleRegistry *)[[appDelegate valueForKey:@"_reactHost"] valueForKey:@"_moduleRegistry"];
// if (moduleRegistry) {
// REAModule *reaModule = [moduleRegistry moduleForName:"ReanimatedModule"];
// [reaModule installBridgelessWithRuntime:&rt jsCallInvoker:jsInvoker_ valueUnpackerCode:std::move(valueUnpackerCode)];
// }
// });
// return YES;
return true;
}

} // namespace facebook::react
22 changes: 22 additions & 0 deletions Common/cpp/TurboModule/REATurboCppModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#if __has_include( \
<React-Codegen/rnreanimatedJSI.h>) // CocoaPod headers on Apple
#include <React-Codegen/rnreanimatedJSI.h>
#elif __has_include("rnreanimatedJSI.h") // CMake headers on Android
#include "rnreanimatedJSI.h"
#endif
#include <memory>
#include <string>

namespace facebook::react {

class REATurboCppModule
: public NativeREATurboCppModuleCxxSpec<REATurboCppModule> {
public:
explicit REATurboCppModule(std::shared_ptr<CallInvoker> jsInvoker);

bool installBridgeless(jsi::Runtime &rt, jsi::String valueUnpackerCode);
};

} // namespace facebook::react
23 changes: 23 additions & 0 deletions Common/cpp/TurboModule/REATurboCppModule.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "REATurboCppModule.h"

#include <RNReanimated/REAModule.h>

namespace facebook::react {

REATurboCppModule::REATurboCppModule(std::shared_ptr<CallInvoker> jsInvoker)
: NativeREATurboCppModuleCxxSpec(std::move(jsInvoker)) {}

bool REATurboCppModule::installBridgeless(jsi::Runtime& rt, jsi::String valueUnpackerCode) {
// RCTExecuteOnMainQueue(^{
id appDelegate = [[UIApplication sharedApplication] delegate];
RCTModuleRegistry *moduleRegistry =
(RCTModuleRegistry *)[[appDelegate valueForKey:@"_reactHost"] valueForKey:@"_moduleRegistry"];
if (moduleRegistry) {
REAModule *reaModule = [moduleRegistry moduleForName:"ReanimatedModule"];
[reaModule installBridgelessWithRuntime:&rt jsCallInvoker:jsInvoker_ valueUnpackerCode:std::move(valueUnpackerCode)];
}
// });
return YES;
}

} // namespace facebook::react
49 changes: 47 additions & 2 deletions FabricExample/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
import App from '../app';
import Animated, {
useSharedValue,
withTiming,
useAnimatedStyle,
Easing,
} from 'react-native-reanimated';
import {View, Button, StyleSheet} from 'react-native';
import React from 'react';

export default App;
export default function AnimatedStyleUpdateExample() {
const randomWidth = useSharedValue(10);

const config = {
duration: 500,
easing: Easing.bezierFn(0.5, 0.01, 0, 1),
};

const style = useAnimatedStyle(() => {
return {
width: withTiming(randomWidth.value, config),
};
});

return (
<View style={styles.container}>
<Animated.View style={[styles.box, style]} />
<Button
title="toggle"
onPress={() => {
randomWidth.value = Math.random() * 350;
}}
/>
</View>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
},
box: {
width: 100,
height: 80,
backgroundColor: 'black',
margin: 30,
},
});
99 changes: 99 additions & 0 deletions FabricExample/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.6)
rexml
activesupport (7.0.8)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
claide (1.1.0)
cocoapods (1.14.3)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.14.3)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 2.1, < 3.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.6.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (>= 2.3.0, < 3.0)
gh_inspector (~> 1.0)
molinillo (~> 0.8.0)
nap (~> 1.0)
ruby-macho (>= 2.3.0, < 3.0)
xcodeproj (>= 1.23.0, < 2.0)
cocoapods-core (1.14.3)
activesupport (>= 5.0, < 8)
addressable (~> 2.8)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
netrc (~> 0.11)
public_suffix (~> 4.0)
typhoeus (~> 1.0)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (2.1)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.1)
cocoapods-trunk (1.6.0)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.2.2)
escape (0.0.4)
ethon (0.16.0)
ffi (>= 1.15.0)
ffi (1.16.3)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.7.1)
minitest (5.20.0)
molinillo (0.8.0)
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
public_suffix (4.0.7)
rexml (3.2.6)
ruby-macho (2.5.1)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
xcodeproj (1.23.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
rexml (~> 3.2.4)

PLATFORMS
ruby

DEPENDENCIES
activesupport (>= 6.1.7.3, < 7.1.0)
cocoapods (~> 1.13)

RUBY VERSION
ruby 3.2.1p31

BUNDLED WITH
2.4.6
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import 'react-native';
import React from 'react';
import App from '../App';

// Note: import explicitly to use the types shipped with jest.
import {it} from '@jest/globals';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';

Expand Down
61 changes: 6 additions & 55 deletions FabricExample/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"

import com.android.build.OutputFile

/**
* This is the configuration block to customize your React Native Android app.
* By default you don't need to apply any configuration, just uncomment the lines you need.
Expand All @@ -13,8 +12,8 @@ react {
// root = file("../")
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
// reactNativeDir = file("../node_modules/react-native")
// The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen
// codegenDir = file("../node_modules/react-native-codegen")
// The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
// codegenDir = file("../node_modules/@react-native/codegen")
// The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
// cliFile = file("../node_modules/react-native/cli.js")

Expand Down Expand Up @@ -54,14 +53,6 @@ react {

project.ext["isReanimatedExampleApp"] = true

/**
* Set this to true to create four separate APKs instead of one,
* one for each native architecture. This is useful if you don't
* use App Bundles (https://developer.android.com/guide/app-bundle/)
* and want to have separate APKs to upload to the Play Store.
*/
def enableSeparateBuildPerCPUArchitecture = false

/**
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
*/
Expand All @@ -80,20 +71,10 @@ def enableProguardInReleaseBuilds = false
*/
def jscFlavor = 'org.webkit:android-jsc:+'

/**
* Private function to get the list of Native Architectures you want to build.
* This reads the value from reactNativeArchitectures in your gradle.properties
* file and works together with the --active-arch-only flag of react-native run-android.
*/
def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

android {
ndkVersion rootProject.ext.ndkVersion

compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdk rootProject.ext.compileSdkVersion

namespace "com.fabricexample"
defaultConfig {
Expand All @@ -103,15 +84,6 @@ android {
versionCode 1
versionName "1.0"
}

splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include (*reactNativeArchitectures())
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
Expand All @@ -132,34 +104,13 @@ android {
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}

// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}

}
}
}

dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
implementation("com.facebook.react:flipper-integration")

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.squareup.okhttp3', module:'okhttp'
}

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
Expand Down
6 changes: 1 addition & 5 deletions FabricExample/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application
android:usesCleartextTraffic="true"
tools:targetApi="28"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
</application>
tools:ignore="GoogleAppIndexingWarning"/>
</manifest>
Loading