Skip to content

Commit b70fb47

Browse files
committed
refactor: use create-react-native-library nitro init
1 parent 2dc6a6e commit b70fb47

File tree

23 files changed

+121
-468
lines changed

23 files changed

+121
-468
lines changed

CONTRIBUTING.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ yarn
1919

2020
> Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development.
2121
22+
This project uses Nitro Modules. If you're not familiar with how Nitro works, make sure to check the [Nitro Modules Docs](https://nitro.margelo.com/).
23+
24+
You need to run [Nitrogen](https://nitro.margelo.com/docs/nitrogen) to generate the boilerplate code required for this project. The example app will not build without this step.
25+
26+
Run **Nitrogen** in following cases:
27+
28+
- When you make changes to any `*.nitro.ts` files.
29+
- When running the project for the first time (since the generated files are not committed to the repository).
30+
31+
To invoke **Nitrogen**, use the following command:
32+
33+
```sh
34+
yarn nitrogen
35+
```
36+
2237
The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make.
2338

2439
It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ Rive React Native
55
## Installation
66

77
```sh
8-
npm install react-native-rive
8+
npm install react-native-rive react-native-nitro-modules
9+
10+
> `react-native-nitro-modules` is required as this library relies on [Nitro Modules](https://nitro.margelo.com/).
911
```
1012

1113
## Usage
1214

1315

1416
```js
15-
import { RiveView } from "react-native-rive";
17+
import { multiply } from 'react-native-rive';
1618

1719
// ...
1820

19-
<RiveView color="tomato" />
21+
const result = multiply(3, 7);
2022
```
2123

2224

Rive.podspec

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ Pod::Spec.new do |s|
1313
s.platforms = { :ios => min_ios_version_supported }
1414
s.source = { :git => "https://github.com/rive-app/rive-nitro-react-native.git", :tag => "#{s.version}" }
1515

16-
s.source_files = "ios/**/*.{h,m,mm,cpp}"
17-
s.private_header_files = "ios/**/*.h"
16+
s.source_files = "ios/**/*.{h,m,mm,swift}"
17+
18+
load 'nitrogen/generated/ios/Rive+autolinking.rb'
19+
add_nitrogen_files(s)
1820

1921
install_modules_dependencies(s)
2022
end

android/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
project(ReactNativeRive)
1+
project(rive)
22
cmake_minimum_required(VERSION 3.9.0)
33

4-
set(PACKAGE_NAME ReactNativeRive)
4+
set(PACKAGE_NAME rive)
55
set(CMAKE_VERBOSE_MAKEFILE ON)
66
set(CMAKE_CXX_STANDARD 20)
77

88
# Define C++ library and add all sources
99
add_library(${PACKAGE_NAME} SHARED src/main/cpp/cpp-adapter.cpp)
1010

1111
# Add Nitrogen specs :)
12-
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/ReactNativeRive+autolinking.cmake)
12+
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/rive+autolinking.cmake)
1313

1414
# Set up local includes
1515
include_directories("src/main/cpp" "../cpp")

android/build.gradle

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ def reactNativeArchitectures() {
2020
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
2121
}
2222

23-
2423
apply plugin: "com.android.library"
2524
apply plugin: "kotlin-android"
26-
apply from: '../nitrogen/generated/android/ReactNativeRive+autolinking.gradle'
27-
25+
apply from: '../nitrogen/generated/android/rive+autolinking.gradle'
2826

2927
apply plugin: "com.facebook.react"
3028

@@ -40,13 +38,12 @@ android {
4038
defaultConfig {
4139
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
4240
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
43-
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true"
4441

4542
externalNativeBuild {
4643
cmake {
47-
cppFlags "-frtti -fexceptions -Wall -Wextra -fstack-protector-all"
44+
cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
4845
arguments "-DANDROID_STL=c++_shared"
49-
abiFilters (*reactNativeArchitectures())
46+
abiFilters(*reactNativeArchitectures())
5047

5148
buildTypes {
5249
debug {
@@ -66,32 +63,30 @@ android {
6663
}
6764
}
6865

66+
packagingOptions {
67+
excludes = ["META-INF",
68+
"META-INF/**",
69+
"**/libc++_shared.so",
70+
"**/libfbjni.so",
71+
"**/libjsi.so",
72+
"**/libfolly_json.so",
73+
"**/libfolly_runtime.so",
74+
"**/libglog.so",
75+
"**/libhermes.so",
76+
"**/libhermes-executor-debug.so",
77+
"**/libhermes_executor.so",
78+
"**/libreactnative.so",
79+
"**/libreactnativejni.so",
80+
"**/libturbomodulejsijni.so",
81+
"**/libreact_nativemodule_core.so",
82+
"**/libjscexecutor.so"]
83+
}
84+
6985
buildFeatures {
7086
buildConfig true
7187
prefab true
7288
}
7389

74-
packagingOptions {
75-
excludes = [
76-
"META-INF",
77-
"META-INF/**",
78-
"**/libc++_shared.so",
79-
"**/libfbjni.so",
80-
"**/libjsi.so",
81-
"**/libfolly_json.so",
82-
"**/libfolly_runtime.so",
83-
"**/libglog.so",
84-
"**/libhermes.so",
85-
"**/libhermes-executor-debug.so",
86-
"**/libhermes_executor.so",
87-
"**/libreactnative.so",
88-
"**/libreactnativejni.so",
89-
"**/libturbomodulejsijni.so",
90-
"**/libreact_nativemodule_core.so",
91-
"**/libjscexecutor.so"
92-
]
93-
}
94-
9590
buildTypes {
9691
release {
9792
minifyEnabled false
@@ -109,11 +104,8 @@ android {
109104

110105
sourceSets {
111106
main {
112-
java.srcDirs += [
113-
"generated/java",
114-
"generated/jni",
115-
"${project.buildDir}/generated/source/codegen/java"
116-
]
107+
java.srcDirs += ["generated/java",
108+
"generated/jni"]
117109
}
118110
}
119111
}
@@ -128,11 +120,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
128120
dependencies {
129121
implementation "com.facebook.react:react-android"
130122
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
123+
implementation 'app.rive:rive-android:10.1.3'
131124
implementation project(":react-native-nitro-modules")
132125
}
133126

134-
react {
135-
jsRootDir = file("../src/")
136-
libraryName = "RiveView"
137-
codegenJavaPackageName = "com.rive"
138-
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <jni.h>
2-
#include "ReactNativeRiveOnLoad.hpp"
2+
#include "riveOnLoad.hpp"
33

44
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
5-
return margelo::nitro::reactnativerive::initialize(vm);
5+
return margelo::nitro::rive::initialize(vm);
66
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.margelo.nitro.rive
2+
3+
import com.facebook.proguard.annotations.DoNotStrip
4+
5+
@DoNotStrip
6+
class Rive : HybridRiveSpec() {
7+
override fun multiply(a: Double, b: Double): Double {
8+
return a * b
9+
}
10+
}

android/src/main/java/com/margelo/nitro/reactnativerive/HybridRiveFileFactory.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,23 @@
11
package com.rive
22

3-
import com.facebook.react.BaseReactPackage
4-
import com.facebook.react.ReactPackage
3+
import com.facebook.react.TurboReactPackage
54
import com.facebook.react.bridge.NativeModule
65
import com.facebook.react.bridge.ReactApplicationContext
76
import com.facebook.react.module.model.ReactModuleInfoProvider
8-
import com.facebook.react.uimanager.ViewManager
9-
import com.margelo.nitro.reactnativerive.ReactNativeRiveOnLoad
10-
import java.util.ArrayList
7+
import com.margelo.nitro.rive.riveOnLoad
118

12-
class RiveViewPackage : BaseReactPackage() {
13-
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
14-
val viewManagers: MutableList<ViewManager<*, *>> = ArrayList()
15-
viewManagers.add(RiveViewManager())
16-
return viewManagers
17-
}
18-
19-
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
20-
return null
21-
}
22-
23-
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
24-
return ReactModuleInfoProvider { HashMap() }
25-
}
9+
class RivePackage : TurboReactPackage() {
10+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
11+
return null
12+
}
2613

27-
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
28-
return emptyList()
29-
}
14+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
15+
return ReactModuleInfoProvider { HashMap() }
16+
}
3017

31-
companion object {
32-
init {
33-
ReactNativeRiveOnLoad.initializeNative()
18+
companion object {
19+
init {
20+
riveOnLoad.initializeNative()
21+
}
3422
}
35-
}
3623
}
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
package com.rive
22

3-
import android.content.Context
4-
import android.util.AttributeSet
5-
import android.view.View
6-
7-
class RiveView : View {
8-
constructor(context: Context?) : super(context)
9-
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
10-
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
11-
context,
12-
attrs,
13-
defStyleAttr
14-
)
3+
class RiveView {
154
}

0 commit comments

Comments
 (0)