react-native-yoga-jsi 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +27 -0
- package/README.md +166 -0
- package/android/CMakeLists.txt +72 -0
- package/android/build.gradle +190 -0
- package/android/gradle.properties +6 -0
- package/android/src/main/AndroidManifestNew.xml +3 -0
- package/android/src/main/cpp/cpp-adapter.cpp +17 -0
- package/android/src/main/java/com/yogajsi/YogaJSIModule.java +51 -0
- package/android/src/main/java/com/yogajsi/YogaJSIPackage.java +25 -0
- package/cpp/configCreation.h +91 -0
- package/cpp/macros.h +111 -0
- package/cpp/nodeCreation.h +65 -0
- package/cpp/nodeProperties.h +609 -0
- package/cpp/yogaJSI.h +23 -0
- package/ios/YogaJSIModule.h +5 -0
- package/ios/YogaJSIModule.mm +40 -0
- package/lib/commonjs/coreTypes.js +133 -0
- package/lib/commonjs/coreTypes.js.map +1 -0
- package/lib/commonjs/derived/index.js +39 -0
- package/lib/commonjs/derived/index.js.map +1 -0
- package/lib/commonjs/derived/styleHandler.js +326 -0
- package/lib/commonjs/derived/styleHandler.js.map +1 -0
- package/lib/commonjs/derived/useOnDepsChaneg.js +20 -0
- package/lib/commonjs/derived/useOnDepsChaneg.js.map +1 -0
- package/lib/commonjs/derived/useStyle.js +52 -0
- package/lib/commonjs/derived/useStyle.js.map +1 -0
- package/lib/commonjs/derived/utils.js +67 -0
- package/lib/commonjs/derived/utils.js.map +1 -0
- package/lib/commonjs/index.js +46 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/coreTypes.js +129 -0
- package/lib/module/coreTypes.js.map +1 -0
- package/lib/module/derived/index.js +6 -0
- package/lib/module/derived/index.js.map +1 -0
- package/lib/module/derived/styleHandler.js +322 -0
- package/lib/module/derived/styleHandler.js.map +1 -0
- package/lib/module/derived/useOnDepsChaneg.js +17 -0
- package/lib/module/derived/useOnDepsChaneg.js.map +1 -0
- package/lib/module/derived/useStyle.js +49 -0
- package/lib/module/derived/useStyle.js.map +1 -0
- package/lib/module/derived/utils.js +61 -0
- package/lib/module/derived/utils.js.map +1 -0
- package/lib/module/index.js +21 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/src/coreTypes.d.ts +259 -0
- package/lib/typescript/src/coreTypes.d.ts.map +1 -0
- package/lib/typescript/src/derived/index.d.ts +4 -0
- package/lib/typescript/src/derived/index.d.ts.map +1 -0
- package/lib/typescript/src/derived/styleHandler.d.ts +69 -0
- package/lib/typescript/src/derived/styleHandler.d.ts.map +1 -0
- package/lib/typescript/src/derived/useOnDepsChaneg.d.ts +3 -0
- package/lib/typescript/src/derived/useOnDepsChaneg.d.ts.map +1 -0
- package/lib/typescript/src/derived/useStyle.d.ts +15 -0
- package/lib/typescript/src/derived/useStyle.d.ts.map +1 -0
- package/lib/typescript/src/derived/utils.d.ts +21 -0
- package/lib/typescript/src/derived/utils.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +147 -0
- package/react-native-yoga-jsi.podspec +40 -0
- package/src/coreTypes.ts +298 -0
- package/src/derived/index.ts +3 -0
- package/src/derived/styleHandler.ts +433 -0
- package/src/derived/useOnDepsChaneg.ts +20 -0
- package/src/derived/useStyle.ts +79 -0
- package/src/derived/utils.ts +86 -0
- package/src/index.ts +22 -0
package/LICENSE
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
**react-native-yoga-jsi**
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Copyright (c) 2021 Margelo GmbH
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
9
|
+
in the Software without restriction, including without limitation the rights
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
12
|
+
furnished to do so, subject to the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
15
|
+
copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
SOFTWARE.
|
24
|
+
|
25
|
+
**NodeJS Crypto**
|
26
|
+
|
27
|
+
See https://github.com/nodejs/node/blob/main/LICENSE
|
package/README.md
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
<a href="https://margelo.io">
|
2
|
+
<img src="./docs/img/banner.svg" width="100%" />
|
3
|
+
</a>
|
4
|
+
|
5
|
+
# ⚡️ react-native-yoga-jsi
|
6
|
+
|
7
|
+
A fast implementation of Node's `crypto` module.
|
8
|
+
|
9
|
+
> Note: This version `0.x` is the Old Architecture, Bridged version for React Native. The `1.x` and higher branches are refactored to work with the New Architecture, Bridgeless, and [`Nitro Modules`](https://github.com/mrousavy/react-native-nitro). Status, as always, will be represented in [implementation-coverage.md](../0.x/docs/implementation-coverage.md).
|
10
|
+
|
11
|
+
## Features
|
12
|
+
|
13
|
+
Unlike any other current JS-based polyfills, react-native-yoga-jsi is written in C/C++ JSI and provides much greater performance - especially on mobile devices.
|
14
|
+
QuickCrypto can be used as a drop-in replacement for your Web3/Crypto apps to speed up common cryptography functions.
|
15
|
+
|
16
|
+
- 🏎️ Up to 58x faster than all other solutions
|
17
|
+
- ⚡️ Lightning fast implementation with pure C++ and JSI, instead of JS
|
18
|
+
- 🧪 Well tested in JS and C++ (OpenSSL)
|
19
|
+
- 💰 Made for crypto apps and Wallets
|
20
|
+
- 🔢 Secure native compiled cryptography
|
21
|
+
- 🔁 Easy drop-in replacement for [crypto-browserify](https://github.com/browserify/crypto-browserify) or [react-native-crypto](https://github.com/tradle/react-native-crypto)
|
22
|
+
|
23
|
+
## Versions
|
24
|
+
|
25
|
+
| Version | RN Architecture | Modules |
|
26
|
+
| -------------------- | ------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------- |
|
27
|
+
| `0.x` (you are here) | old | Bridge & JSI |
|
28
|
+
| `1.x`+ | new [->](https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md) | Nitro Modules [->](https://github.com/margelo/react-native-nitro) |
|
29
|
+
|
30
|
+
## Benchmarks
|
31
|
+
|
32
|
+
For example, creating a Wallet using ethers.js uses complex algorithms to generate a private-key/mnemonic-phrase pair:
|
33
|
+
|
34
|
+
```ts
|
35
|
+
const start = performance.now();
|
36
|
+
const wallet = ethers.Wallet.createRandom();
|
37
|
+
const end = performance.now();
|
38
|
+
console.log(`Creating a Wallet took ${end - start} ms.`);
|
39
|
+
```
|
40
|
+
|
41
|
+
**Without** react-native-yoga-jsi 🐢:
|
42
|
+
|
43
|
+
```
|
44
|
+
Creating a Wallet took 16862 ms
|
45
|
+
```
|
46
|
+
|
47
|
+
**With** react-native-yoga-jsi ⚡️:
|
48
|
+
|
49
|
+
```
|
50
|
+
Creating a Wallet took 289 ms
|
51
|
+
```
|
52
|
+
|
53
|
+
---
|
54
|
+
|
55
|
+
## Installation
|
56
|
+
|
57
|
+
<h3>
|
58
|
+
React Native <a href="#"><img src="./docs/img/react-native.png" height="15" /></a>
|
59
|
+
</h3>
|
60
|
+
|
61
|
+
```sh
|
62
|
+
yarn add react-native-yoga-jsi
|
63
|
+
cd ios && pod install
|
64
|
+
```
|
65
|
+
|
66
|
+
<h3>
|
67
|
+
Expo <a href="#"><img src="./docs/img/expo.png" height="12" /></a>
|
68
|
+
</h3>
|
69
|
+
|
70
|
+
```sh
|
71
|
+
expo install react-native-yoga-jsi
|
72
|
+
expo prebuild
|
73
|
+
```
|
74
|
+
|
75
|
+
Optional: override `global.Buffer` and `global.crypto` in your application as early as possible for example in index.js.
|
76
|
+
|
77
|
+
```ts
|
78
|
+
import { install } from 'react-native-yoga-jsi';
|
79
|
+
|
80
|
+
install();
|
81
|
+
```
|
82
|
+
|
83
|
+
## Replace `crypto-browserify`
|
84
|
+
|
85
|
+
If you are using a library that depends on `crypto`, instead of polyfilling it with `crypto-browserify` (or `react-native-crypto`) you can use `react-native-yoga-jsi` for a fully native implementation. This way you can get much faster crypto operations with just a single-line change!
|
86
|
+
|
87
|
+
### Using metro config
|
88
|
+
|
89
|
+
Use the [`resolveRequest`](https://facebook.github.io/metro/docs/resolution#resolverequest-customresolver) configuration option in your `metro.config.js`
|
90
|
+
|
91
|
+
```js
|
92
|
+
config.resolver.resolveRequest = (context, moduleName, platform) => {
|
93
|
+
if (moduleName === 'crypto') {
|
94
|
+
// when importing crypto, resolve to react-native-yoga-jsi
|
95
|
+
return context.resolveRequest(context, 'react-native-yoga-jsi', platform);
|
96
|
+
}
|
97
|
+
// otherwise chain to the standard Metro resolver.
|
98
|
+
return context.resolveRequest(context, moduleName, platform);
|
99
|
+
};
|
100
|
+
```
|
101
|
+
|
102
|
+
### Using babel-plugin-module-resolver
|
103
|
+
|
104
|
+
You need to install `babel-plugin-module-resolver`, it's a babel plugin that will alias any imports in the code with the values you pass to it. It tricks any module that will try to import certain dependencies with the native versions we require for React Native.
|
105
|
+
|
106
|
+
```sh
|
107
|
+
yarn add --dev babel-plugin-module-resolver
|
108
|
+
```
|
109
|
+
|
110
|
+
Then, in your `babel.config.js`, add the plugin to swap the `crypto`, `stream` and `buffer` dependencies:
|
111
|
+
|
112
|
+
```diff
|
113
|
+
module.exports = {
|
114
|
+
presets: ['module:metro-react-native-babel-preset'],
|
115
|
+
plugins: [
|
116
|
+
+ [
|
117
|
+
+ 'module-resolver',
|
118
|
+
+ {
|
119
|
+
+ alias: {
|
120
|
+
+ 'crypto': 'react-native-yoga-jsi',
|
121
|
+
+ 'stream': 'readable-stream',
|
122
|
+
+ 'buffer': '@craftzdog/react-native-buffer',
|
123
|
+
+ },
|
124
|
+
+ },
|
125
|
+
+ ],
|
126
|
+
...
|
127
|
+
],
|
128
|
+
};
|
129
|
+
```
|
130
|
+
|
131
|
+
Then restart your bundler using `yarn start --reset-cache`.
|
132
|
+
|
133
|
+
## Usage
|
134
|
+
|
135
|
+
For example, to hash a string with SHA256 you can do the following:
|
136
|
+
|
137
|
+
```ts
|
138
|
+
import QuickCrypto from 'react-native-yoga-jsi';
|
139
|
+
|
140
|
+
const hashed = QuickCrypto.createHash('sha256')
|
141
|
+
.update('Damn, Margelo writes hella good software!')
|
142
|
+
.digest('hex');
|
143
|
+
```
|
144
|
+
|
145
|
+
## Limitations
|
146
|
+
|
147
|
+
As the library uses JSI for synchronous native methods access, remote debugging (e.g. with Chrome) is no longer possible. Instead, you should use [Flipper](https://fbflipper.com).
|
148
|
+
|
149
|
+
Not all cryptographic algorithms are supported yet. See the [implementation coverage](./docs/implementation-coverage.md) document for more details. If you need a specific algorithm, please open a `feature request` issue and we'll see what we can do.
|
150
|
+
|
151
|
+
## Community Discord
|
152
|
+
|
153
|
+
[Join the Margelo Community Discord](https://discord.gg/6CSHz2qAvA) to chat about react-native-yoga-jsi or other Margelo libraries.
|
154
|
+
|
155
|
+
## Adopting at scale
|
156
|
+
|
157
|
+
react-native-yoga-jsi was built at Margelo, an elite app development agency. For enterprise support or other business inquiries, contact us at <a href="mailto:hello@margelo.io?subject=Adopting react-native-yoga-jsi at scale">hello@margelo.io</a>!
|
158
|
+
|
159
|
+
## Contributing
|
160
|
+
|
161
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
162
|
+
|
163
|
+
## License
|
164
|
+
|
165
|
+
- react-native-yoga-jsi is licensed under MIT.
|
166
|
+
- react-native-yoga-jsi is heavily inspired by NodeJS Crypto, which is licensed under [nodejs/LICENSE](https://github.com/nodejs/node/blob/main/LICENSE).
|
@@ -0,0 +1,72 @@
|
|
1
|
+
project(ReactNativeYogaJSI)
|
2
|
+
cmake_minimum_required(VERSION 3.10.2)
|
3
|
+
|
4
|
+
set(PACKAGE_NAME "reactnativeyogajsi")
|
5
|
+
set(BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
|
6
|
+
set(CMAKE_VERBOSE_MAKEFILE ON)
|
7
|
+
set(CMAKE_CXX_STANDARD 17)
|
8
|
+
|
9
|
+
# set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
|
10
|
+
# set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
|
11
|
+
|
12
|
+
# Third party libraries (Prefabs)
|
13
|
+
find_package(fbjni REQUIRED CONFIG)
|
14
|
+
find_package(ReactAndroid REQUIRED CONFIG)
|
15
|
+
find_package(openssl REQUIRED CONFIG)
|
16
|
+
find_library(LOG_LIB log)
|
17
|
+
|
18
|
+
# Set the Yoga path and include all files recursively
|
19
|
+
set(YOGA_PATH "${NODE_MODULES_DIR}/react-native/ReactCommon/yoga")
|
20
|
+
file(GLOB_RECURSE YOGA_SOURCES "${YOGA_PATH}/*.cpp" "${YOGA_PATH}/*.h")
|
21
|
+
|
22
|
+
# Add main library sources
|
23
|
+
add_library(
|
24
|
+
${PACKAGE_NAME}
|
25
|
+
SHARED
|
26
|
+
"../cpp/yogaJSI.h"
|
27
|
+
"../cpp/nodeCreation.h"
|
28
|
+
"../cpp/configCreation.h"
|
29
|
+
"../cpp/macros.h"
|
30
|
+
"src/main/cpp/cpp-adapter.cpp"
|
31
|
+
${YOGA_SOURCES} # Add Yoga sources
|
32
|
+
)
|
33
|
+
|
34
|
+
# Include directories for Yoga and other dependencies
|
35
|
+
target_include_directories(
|
36
|
+
${PACKAGE_NAME}
|
37
|
+
PRIVATE
|
38
|
+
"../cpp"
|
39
|
+
"src/main/cpp"
|
40
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon"
|
41
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
|
42
|
+
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/react/turbomodule"
|
43
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
|
44
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/turbomodule/core"
|
45
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/react/nativemodule/core"
|
46
|
+
${YOGA_PATH} # Add Yoga path to include directories
|
47
|
+
)
|
48
|
+
|
49
|
+
# Linking libraries
|
50
|
+
target_link_libraries(
|
51
|
+
${PACKAGE_NAME}
|
52
|
+
fbjni::fbjni # <-- fbjni
|
53
|
+
${LOG_LIB} # <-- Logcat logger
|
54
|
+
ReactAndroid::jsi # <-- RN: JSI
|
55
|
+
android # <-- Android JNI core
|
56
|
+
openssl::crypto # <-- OpenSSL (Crypto)
|
57
|
+
)
|
58
|
+
|
59
|
+
# Conditionally link libraries based on ReactAndroid version
|
60
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
61
|
+
target_link_libraries(
|
62
|
+
${PACKAGE_NAME}
|
63
|
+
ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
|
64
|
+
)
|
65
|
+
else()
|
66
|
+
target_link_libraries(
|
67
|
+
${PACKAGE_NAME}
|
68
|
+
ReactAndroid::turbomodulejsijni
|
69
|
+
ReactAndroid::reactnativejni # <-- RN: React Native JNI bindings
|
70
|
+
ReactAndroid::react_nativemodule_core # <-- RN: React Native native module core
|
71
|
+
)
|
72
|
+
endif()
|
@@ -0,0 +1,190 @@
|
|
1
|
+
import java.nio.file.Paths
|
2
|
+
import com.android.Version
|
3
|
+
|
4
|
+
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
|
5
|
+
def agpVersionMajor = agpVersion.tokenize('.')[0].toInteger()
|
6
|
+
def agpVersionMinor = agpVersion.tokenize('.')[1].toInteger()
|
7
|
+
|
8
|
+
buildscript {
|
9
|
+
repositories {
|
10
|
+
maven {
|
11
|
+
url "https://plugins.gradle.org/m2/"
|
12
|
+
}
|
13
|
+
mavenCentral()
|
14
|
+
google()
|
15
|
+
}
|
16
|
+
|
17
|
+
dependencies {
|
18
|
+
classpath("com.android.tools.build:gradle:8.3.1")
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
def isNewArchitectureEnabled() {
|
23
|
+
// To opt-in for the New Architecture, you can either:
|
24
|
+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
|
25
|
+
// - Invoke gradle with `-newArchEnabled=true`
|
26
|
+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
|
27
|
+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
|
28
|
+
}
|
29
|
+
|
30
|
+
def resolveBuildType() {
|
31
|
+
Gradle gradle = getGradle()
|
32
|
+
String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString()
|
33
|
+
|
34
|
+
return tskReqStr.contains('Release') ? 'release' : 'debug'
|
35
|
+
}
|
36
|
+
|
37
|
+
if (isNewArchitectureEnabled()) {
|
38
|
+
apply plugin: "com.facebook.react"
|
39
|
+
}
|
40
|
+
apply plugin: 'com.android.library'
|
41
|
+
|
42
|
+
def safeExtGet(prop, fallback) {
|
43
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
44
|
+
}
|
45
|
+
|
46
|
+
def reactNativeArchitectures() {
|
47
|
+
def value = project.getProperties().get("reactNativeArchitectures")
|
48
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
49
|
+
}
|
50
|
+
|
51
|
+
static def findNodeModules(baseDir) {
|
52
|
+
def basePath = baseDir.toPath().normalize()
|
53
|
+
// Node's module resolution algorithm searches up to the root directory,
|
54
|
+
// after which the base path will be null
|
55
|
+
while (basePath) {
|
56
|
+
def nodeModulesPath = Paths.get(basePath.toString(), "node_modules")
|
57
|
+
def reactNativePath = Paths.get(nodeModulesPath.toString(), "react-native")
|
58
|
+
if (nodeModulesPath.toFile().exists() && reactNativePath.toFile().exists()) {
|
59
|
+
return nodeModulesPath.toString()
|
60
|
+
}
|
61
|
+
basePath = basePath.getParent()
|
62
|
+
}
|
63
|
+
throw new GradleException("react-native-yoga-jsi: Failed to find node_modules/ path!")
|
64
|
+
}
|
65
|
+
|
66
|
+
def nodeModules = findNodeModules(projectDir)
|
67
|
+
|
68
|
+
repositories {
|
69
|
+
google()
|
70
|
+
mavenCentral()
|
71
|
+
}
|
72
|
+
|
73
|
+
android {
|
74
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 31)
|
75
|
+
|
76
|
+
if ((agpVersionMajor == 7 && agpVersionMinor >= 3) || agpVersionMajor >= 8) {
|
77
|
+
// Namespace support was added in 7.3.0
|
78
|
+
namespace "com.yogajsi"
|
79
|
+
|
80
|
+
sourceSets {
|
81
|
+
main {
|
82
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
if (agpVersionMajor >= 8) {
|
88
|
+
buildFeatures {
|
89
|
+
buildConfig = true
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
// Used to override the NDK path/version on internal CI or by allowing
|
94
|
+
// users to customize the NDK path/version from their root project (e.g. for M1 support)
|
95
|
+
if (rootProject.hasProperty("ndkPath")) {
|
96
|
+
ndkPath rootProject.ext.ndkPath
|
97
|
+
}
|
98
|
+
if (rootProject.hasProperty("ndkVersion")) {
|
99
|
+
ndkVersion rootProject.ext.ndkVersion
|
100
|
+
}
|
101
|
+
|
102
|
+
buildFeatures {
|
103
|
+
prefab true
|
104
|
+
}
|
105
|
+
|
106
|
+
defaultConfig {
|
107
|
+
minSdkVersion safeExtGet('minSdkVersion', 23)
|
108
|
+
targetSdkVersion safeExtGet('targetSdkVersion', 31)
|
109
|
+
versionCode 1
|
110
|
+
versionName "1.0"
|
111
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
112
|
+
externalNativeBuild {
|
113
|
+
cmake {
|
114
|
+
cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all -DANDROID"
|
115
|
+
arguments "-DANDROID_STL=c++_shared", "-DNODE_MODULES_DIR=${nodeModules}"
|
116
|
+
abiFilters (*reactNativeArchitectures())
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
externalNativeBuild {
|
122
|
+
cmake {
|
123
|
+
path "CMakeLists.txt"
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
packagingOptions {
|
128
|
+
doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : ''
|
129
|
+
excludes = [
|
130
|
+
"**/libc++_shared.so",
|
131
|
+
"**/libfbjni.so",
|
132
|
+
"**/libreactnativejni.so",
|
133
|
+
"**/libjsi.so",
|
134
|
+
"**/libreact_nativemodule_core.so",
|
135
|
+
"**/libturbomodulejsijni.so",
|
136
|
+
"**/MANIFEST.MF",
|
137
|
+
]
|
138
|
+
}
|
139
|
+
|
140
|
+
buildTypes {
|
141
|
+
release {
|
142
|
+
minifyEnabled false
|
143
|
+
}
|
144
|
+
debug {
|
145
|
+
packagingOptions {
|
146
|
+
doNotStrip '**/*.so'
|
147
|
+
}
|
148
|
+
minifyEnabled false
|
149
|
+
debuggable true
|
150
|
+
jniDebuggable true
|
151
|
+
renderscriptDebuggable true
|
152
|
+
}
|
153
|
+
}
|
154
|
+
|
155
|
+
lintOptions {
|
156
|
+
disable 'GradleCompatible'
|
157
|
+
}
|
158
|
+
compileOptions {
|
159
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
160
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
repositories {
|
166
|
+
mavenCentral()
|
167
|
+
google()
|
168
|
+
}
|
169
|
+
|
170
|
+
dependencies {
|
171
|
+
//noinspection GradleDynamicVersion
|
172
|
+
implementation "com.facebook.react:react-android:+"
|
173
|
+
// https://mvnrepository.com/artifact/com.android.ndk.thirdparty/openssl
|
174
|
+
implementation 'com.android.ndk.thirdparty:openssl:1.1.1q-beta-1'
|
175
|
+
}
|
176
|
+
|
177
|
+
// Resolves "LOCAL_SRC_FILES points to a missing file, Check that libfb.so exists or that its path is correct".
|
178
|
+
tasks.whenTaskAdded { task ->
|
179
|
+
if (task.name.contains("configureCMakeDebug")) {
|
180
|
+
rootProject.getTasksByName("packageReactNdkDebugLibs", true).forEach {
|
181
|
+
task.dependsOn(it)
|
182
|
+
}
|
183
|
+
}
|
184
|
+
// We want to add a dependency for both configureCMakeRelease and configureCMakeRelWithDebInfo
|
185
|
+
if (task.name.contains("configureCMakeRel")) {
|
186
|
+
rootProject.getTasksByName("packageReactNdkReleaseLibs", true).forEach {
|
187
|
+
task.dependsOn(it)
|
188
|
+
}
|
189
|
+
}
|
190
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#include <fbjni/fbjni.h>
|
2
|
+
#include <jni.h>
|
3
|
+
#include <jsi/jsi.h>
|
4
|
+
#include "yogaJSI.h"
|
5
|
+
#include <ReactCommon/CallInvokerHolder.h>
|
6
|
+
|
7
|
+
using namespace facebook;
|
8
|
+
|
9
|
+
extern "C" JNIEXPORT void JNICALL
|
10
|
+
Java_com_yogajsi_YogaJSIModule_nativeInstall(JNIEnv *env, jobject thiz, jlong jsiPtr)
|
11
|
+
{
|
12
|
+
auto runtime = reinterpret_cast<jsi::Runtime *>(jsiPtr);
|
13
|
+
if (runtime)
|
14
|
+
{
|
15
|
+
yogaJSI::install(*runtime);
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
package com.yogajsi;
|
2
|
+
|
3
|
+
import android.util.Log;
|
4
|
+
|
5
|
+
import androidx.annotation.NonNull;
|
6
|
+
|
7
|
+
import com.facebook.react.bridge.JavaScriptContextHolder;
|
8
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
9
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
10
|
+
import com.facebook.react.bridge.ReactMethod;
|
11
|
+
import com.facebook.react.module.annotations.ReactModule;
|
12
|
+
|
13
|
+
@ReactModule(name = YogaJSIModule.NAME)
|
14
|
+
public class YogaJSIModule extends ReactContextBaseJavaModule {
|
15
|
+
public static final String NAME = "YogaJSI";
|
16
|
+
|
17
|
+
public YogaJSIModule(ReactApplicationContext reactContext) {
|
18
|
+
super(reactContext);
|
19
|
+
}
|
20
|
+
|
21
|
+
@NonNull
|
22
|
+
@Override
|
23
|
+
public String getName() {
|
24
|
+
return NAME;
|
25
|
+
}
|
26
|
+
|
27
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
28
|
+
public boolean install() {
|
29
|
+
try {
|
30
|
+
Log.i(NAME, "Loading C++ library...");
|
31
|
+
System.loadLibrary("reactnativeyogajsi");
|
32
|
+
|
33
|
+
JavaScriptContextHolder jsContext = getReactApplicationContext().getJavaScriptContextHolder();
|
34
|
+
if (jsContext.get() == 0) {
|
35
|
+
Log.e(NAME, "JSI Runtime is not available in JavaScriptContextHolder.");
|
36
|
+
return false;
|
37
|
+
}
|
38
|
+
|
39
|
+
Log.i(NAME, "Installing JSI Bindings for react-native-yoga-jsi...");
|
40
|
+
nativeInstall(jsContext.get());
|
41
|
+
Log.i(NAME, "Successfully installed JSI Bindings for react-native-yoga-jsi!");
|
42
|
+
|
43
|
+
return true;
|
44
|
+
} catch (Exception exception) {
|
45
|
+
Log.e(NAME, "Failed to install JSI Bindings for react-native-yoga-jsi!", exception);
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
private native void nativeInstall(long jsiPtr);
|
51
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
package com.yogajsi;
|
2
|
+
|
3
|
+
import androidx.annotation.NonNull;
|
4
|
+
|
5
|
+
import com.facebook.react.ReactPackage;
|
6
|
+
import com.facebook.react.bridge.NativeModule;
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
8
|
+
import com.facebook.react.uimanager.ViewManager;
|
9
|
+
|
10
|
+
import java.util.Collections;
|
11
|
+
import java.util.List;
|
12
|
+
|
13
|
+
public class YogaJSIPackage implements ReactPackage {
|
14
|
+
@NonNull
|
15
|
+
@Override
|
16
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
17
|
+
return Collections.singletonList(new YogaJSIModule(reactContext));
|
18
|
+
}
|
19
|
+
|
20
|
+
@NonNull
|
21
|
+
@Override
|
22
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
23
|
+
return Collections.emptyList();
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#ifndef CONFIG_CREATION_H
|
2
|
+
#define CONFIG_CREATION_H
|
3
|
+
|
4
|
+
#include <jsi/jsi.h>
|
5
|
+
#include <yoga/Yoga.h>
|
6
|
+
#include "macros.h"
|
7
|
+
|
8
|
+
#define INSTALL_HOST_FUN_TO_CONFIG_CREATION(funcName, argCount, body) \
|
9
|
+
auto funcName = Function::createFromHostFunction(rt, \
|
10
|
+
PropNameID::forAscii(rt, #funcName), \
|
11
|
+
argCount, \
|
12
|
+
[](Runtime & runtime, const Value &thisValue, const Value *arguments, size_t count) -> Value body); \
|
13
|
+
configCreationObject.setProperty(rt, #funcName, std::move(funcName));
|
14
|
+
|
15
|
+
#define INSTALL_HOST_FUN_TO_CONFIG(funcName, argCount, body) \
|
16
|
+
auto funcName = Function::createFromHostFunction(runtime, \
|
17
|
+
PropNameID::forAscii(runtime, #funcName), \
|
18
|
+
argCount, \
|
19
|
+
[config](Runtime & runtime, const Value &thisValue, const Value *arguments, size_t count) -> Value body); \
|
20
|
+
configObject.setProperty(runtime, #funcName, std::move(funcName));
|
21
|
+
|
22
|
+
using namespace facebook::jsi;
|
23
|
+
|
24
|
+
namespace configCreation
|
25
|
+
{
|
26
|
+
|
27
|
+
void setUpConfigObject()
|
28
|
+
{
|
29
|
+
}
|
30
|
+
|
31
|
+
void setConfigCreationObj(Object &yogaJsi, Runtime &rt)
|
32
|
+
{
|
33
|
+
auto configCreationObject = Object(rt);
|
34
|
+
|
35
|
+
INSTALL_HOST_FUN_TO_CONFIG_CREATION(create, 0, {
|
36
|
+
YGConfigRef config = YGConfigNew();
|
37
|
+
|
38
|
+
auto configObject = Object(runtime);
|
39
|
+
|
40
|
+
std::uintptr_t configPtr = reinterpret_cast<std::uintptr_t>(config);
|
41
|
+
|
42
|
+
char buffer[20];
|
43
|
+
std::snprintf(buffer, sizeof(buffer), "%lx", configPtr);
|
44
|
+
std::string configStr(buffer);
|
45
|
+
|
46
|
+
configObject.setProperty(runtime, "__config__", configStr);
|
47
|
+
|
48
|
+
INSTALL_HOST_FUN_TO_CONFIG(setPointScaleFactor, 1, {
|
49
|
+
YGConfigSetPointScaleFactor(config, arguments[0].getNumber());
|
50
|
+
return Value::undefined();
|
51
|
+
})
|
52
|
+
|
53
|
+
INSTALL_HOST_FUN_TO_CONFIG(setUseWebDefaults, 1, {
|
54
|
+
YGConfigSetUseWebDefaults(config, arguments[0].getBool());
|
55
|
+
return Value::undefined();
|
56
|
+
});
|
57
|
+
|
58
|
+
INSTALL_HOST_FUN_TO_CONFIG(useWebDefaults, 0, {
|
59
|
+
return Value(YGConfigGetUseWebDefaults(config));
|
60
|
+
});
|
61
|
+
|
62
|
+
INSTALL_HOST_FUN_TO_CONFIG(free, 0, {
|
63
|
+
YGConfigFree(config);
|
64
|
+
return Value::undefined();
|
65
|
+
});
|
66
|
+
|
67
|
+
INSTALL_HOST_FUN_TO_CONFIG(setExperimentalFeatureEnabled, 2, {
|
68
|
+
YGConfigSetExperimentalFeatureEnabled(
|
69
|
+
config, static_cast<YGExperimentalFeature>(arguments[0].getNumber()), arguments[1].getBool());
|
70
|
+
return Value::undefined();
|
71
|
+
});
|
72
|
+
|
73
|
+
INSTALL_HOST_FUN_TO_CONFIG(isExperimentalFeatureEnabled, 1, {
|
74
|
+
return Value(YGConfigIsExperimentalFeatureEnabled(
|
75
|
+
config, static_cast<YGExperimentalFeature>(arguments[0].getNumber())));
|
76
|
+
});
|
77
|
+
|
78
|
+
return configObject;
|
79
|
+
})
|
80
|
+
|
81
|
+
INSTALL_HOST_FUN_TO_CONFIG_CREATION(destroy, 1, {
|
82
|
+
READ_CONFIG(arguments[0])
|
83
|
+
YGConfigFree(config);
|
84
|
+
return Value::undefined();
|
85
|
+
})
|
86
|
+
|
87
|
+
yogaJsi.setProperty(rt, "Config", std::move(configCreationObject));
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
#endif // CONFIG_CREATION_H
|