Skip to content

Commit f0354ea

Browse files
author
Maciej Makowski
committed
Merge branch '@maciejmakowski/audio-context-oscillator'
2 parents a55e40f + 44c3808 commit f0354ea

36 files changed

+16962
-883
lines changed

CODE_OF_CONDUCT.md

Lines changed: 0 additions & 133 deletions
This file was deleted.

android/CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
1-
cmake_minimum_required(VERSION 3.4.1)
2-
project(AudioContext)
1+
cmake_minimum_required(VERSION 3.9.0)
2+
project(react-native-audio-context)
33

44
set (CMAKE_VERBOSE_MAKEFILE ON)
55
set (CMAKE_CXX_STANDARD 14)
66

7-
add_library(react-native-audio-context SHARED
8-
../cpp/react-native-audio-context.cpp
7+
add_library(react-native-audio-context
8+
SHARED
9+
../cpp/JSIExampleHostObject.cpp
910
cpp-adapter.cpp
1011
)
1112

1213
# Specifies a path to native header files.
1314
include_directories(
1415
../cpp
16+
../node_modules/react-native/ReactCommon/jsi
17+
)
18+
19+
find_package(ReactAndroid REQUIRED CONFIG)
20+
find_package(fbjni REQUIRED CONFIG)
21+
22+
target_link_libraries(
23+
react-native-audio-context
24+
ReactAndroid::jsi
25+
fbjni::fbjni
26+
android
1527
)

android/build.gradle

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import com.android.Version
2+
13
buildscript {
24
repositories {
35
google()
46
mavenCentral()
57
}
68

79
dependencies {
8-
classpath "com.android.tools.build:gradle:7.2.1"
10+
classpath "com.android.tools.build:gradle:7.2.2"
911
}
1012
}
1113

@@ -19,6 +21,7 @@ def isNewArchitectureEnabled() {
1921
}
2022

2123
apply plugin: "com.android.library"
24+
apply plugin: 'org.jetbrains.kotlin.android'
2225

2326
if (isNewArchitectureEnabled()) {
2427
apply plugin: "com.facebook.react"
@@ -32,8 +35,8 @@ def getExtOrIntegerDefault(name) {
3235
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["AudioContext_" + name]).toInteger()
3336
}
3437

35-
def supportsNamespace() {
36-
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
38+
static def supportsNamespace() {
39+
def parsed = Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
3740
def major = parsed[0].toInteger()
3841
def minor = parsed[1].toInteger()
3942

@@ -64,6 +67,7 @@ android {
6467
cmake {
6568
cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
6669
abiFilters (*reactNativeArchitectures())
70+
arguments "-DANDROID_STL=c++_shared"
6771
}
6872
}
6973
}
@@ -76,6 +80,7 @@ android {
7680

7781
buildFeatures {
7882
buildConfig true
83+
prefab true
7984
}
8085

8186
buildTypes {
@@ -103,6 +108,9 @@ android {
103108
}
104109
}
105110
}
111+
kotlinOptions {
112+
jvmTarget = '17'
113+
}
106114
}
107115

108116
repositories {
@@ -116,12 +124,14 @@ dependencies {
116124
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
117125
//noinspection GradleDynamicVersion
118126
implementation "com.facebook.react:react-native:+"
127+
implementation 'androidx.core:core-ktx:1.13.1'
128+
implementation 'com.facebook.fbjni:fbjni:0.6.0'
119129
}
120130

121131
if (isNewArchitectureEnabled()) {
122132
react {
123133
jsRootDir = file("../src/")
124-
libraryName = "AudioContext"
134+
libraryName = "react-native-audio-context"
125135
codegenJavaPackageName = "com.audiocontext"
126136
}
127137
}

android/cpp-adapter.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
#include <jni.h>
2-
#include "react-native-audio-context.h"
2+
#include <jsi/jsi.h>
3+
#include "AudioContextHostObject.h"
4+
5+
using namespace facebook;
6+
7+
void install(jsi::Runtime& runtime) {
8+
auto hostObject = std::make_shared<audiocontext::AudioContextHostObject>();
9+
auto object = jsi::Object::createFromHostObject(runtime, hostObject);
10+
runtime.global().setProperty(runtime, "__JSIExampleProxy", std::move(object));
11+
}
312

413
extern "C"
5-
JNIEXPORT jdouble JNICALL
6-
Java_com_audiocontext_AudioContextModule_nativeMultiply(JNIEnv *env, jclass type, jdouble a, jdouble b) {
7-
return audiocontext::multiply(a, b);
14+
JNIEXPORT void JNICALL
15+
Java_com_audiocontext_jsi_AudioContextModule_00024Companion_nativeInstall(JNIEnv *env, jobject clazz, jlong jsiPtr) {
16+
auto runtime = reinterpret_cast<jsi::Runtime*>(jsiPtr);
17+
if (runtime) {
18+
install(*runtime);
19+
}
820
}

android/src/main/cpp/AudioContext.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <fbjni/fbjni.h>
2+
#include <jsi/jsi.h>
3+
4+
namespace audiocontext {
5+
using namespace facebook;
6+
using namespace facebook::jni;
7+
8+
class AudioContext: public HybridClass<AudioContext> {
9+
public:
10+
static auto constexpr kJavaDescriptor =
11+
"Lcom/audiocontext/context/AudioContext;";
12+
13+
static void registerNatives() {
14+
javaClassStatic()->registerNatives({
15+
makeNativeMethod("initHybrid", AudioContext::initHybrid),
16+
});
17+
}
18+
19+
static HybridBase* initHybrid(alias_ref<jhybridobject> jThis) {
20+
return new AudioContext(jThis);
21+
}
22+
23+
private:
24+
global_ref<jobject> javaObject_;
25+
};
26+
}

android/src/main/java/com/audiocontext/AudioContextModule.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

android/src/main/java/com/audiocontext/AudioContextPackage.java

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.audiocontext
2+
3+
import com.audiocontext.jsi.AudioContextModule
4+
import com.facebook.react.ReactPackage
5+
import com.facebook.react.bridge.NativeModule
6+
import com.facebook.react.bridge.ReactApplicationContext
7+
import com.facebook.react.uimanager.ViewManager
8+
9+
class AudioContextPackage : ReactPackage {
10+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11+
return listOf<NativeModule>(AudioContextModule(reactContext))
12+
}
13+
14+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
15+
return emptyList()
16+
}
17+
}

0 commit comments

Comments
 (0)