Skip to content

Commit 5cf240b

Browse files
maciejmakowski2003Maciej Makowski
andauthored
Refactor/jsi and jni (#235)
* refactor: removed wrappers abstraction level * ci: yarn format * feat: implemented base class for HostObjects * feat: introduced JsiHostObject class as a base for all HostObjects * refactor: swapped JsiPromise namespace to audioapi * refactor: added jsi folder * refactor: refactored JsiPromise class * fix: fixed visabilty of buffer prop * fix: fixed merge changes * ci: fix yarn lint --------- Co-authored-by: Maciej Makowski <maciej.makowski@swmansion.com>
1 parent f26788c commit 5cf240b

File tree

75 files changed

+987
-2568
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+987
-2568
lines changed

apps/fabric-example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,7 @@ SPEC CHECKSUMS:
21572157
RNReanimated: 006a5d3961bf09c1e96d62ed436e02b2e43b89bb
21582158
RNScreens: e389d6a6a66a4f0d3662924ecae803073ccce8ec
21592159
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
2160-
Yoga: 1d66db49f38fd9e576a1d7c3b081e46ab4c28b9e
2160+
Yoga: f8ec45ce98bba1bc93dd28f2ee37215180e6d2b6
21612161

21622162
PODFILE CHECKSUM: d4b0da00bac00e3eab4bc0a377fa848fc7bb5276
21632163

packages/react-native-audio-api/android/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ file(GLOB_RECURSE SOURCE_FILES
2121
"../common/cpp/*.h"
2222
"../common/cpp/core/*.cpp"
2323
"../common/cpp/core/*.h"
24-
"../common/cpp/wrappers/*.cpp"
25-
"../common/cpp/wrappers/*.h"
2624
"../common/cpp/HostObjects/*.cpp"
2725
"../common/cpp/HostObjects/*.h"
2826
"../common/cpp/utils/*.cpp"
2927
"../common/cpp/utils/*.h"
28+
"../common/cpp/jsi/*.h"
29+
"../common/cpp/jsi/*.cpp"
3030
"../common/cpp/types/*.h"
3131
)
3232

packages/react-native-audio-api/android/src/main/cpp/AudioAPIInstaller/AudioAPIInstaller.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@ AudioAPIInstaller::AudioAPIInstaller(
1313
jsCallInvoker_(jsCallInvoker) {}
1414

1515
void AudioAPIInstaller::install() {
16-
auto audioAPIInstallerWrapper =
17-
std::make_shared<AudioAPIInstallerWrapper>(this);
18-
AudioAPIInstallerHostObject::createAndInstallFromWrapper(
19-
audioAPIInstallerWrapper, rnRuntime_, jsCallInvoker_);
16+
auto hostObject =
17+
std::make_shared<AudioAPIInstallerHostObject>(rnRuntime_, jsCallInvoker_);
18+
hostObject->install();
2019
}
21-
22-
std::shared_ptr<AudioContext> AudioAPIInstaller::createAudioContext() {
23-
return std::make_shared<AudioContext>();
24-
}
25-
2620
} // namespace audioapi

packages/react-native-audio-api/android/src/main/cpp/AudioAPIInstaller/AudioAPIInstaller.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <utility>
99

1010
#include "AudioAPIInstallerHostObject.h"
11-
#include "AudioAPIInstallerWrapper.h"
1211
#include "AudioContext.h"
1312

1413
namespace audioapi {
@@ -38,7 +37,6 @@ class AudioAPIInstaller : public jni::HybridClass<AudioAPIInstaller> {
3837
});
3938
}
4039

41-
std::shared_ptr<AudioContext> createAudioContext();
4240
void install();
4341

4442
private:

packages/react-native-audio-api/common/cpp/AudioAPIInstaller/AudioAPIInstallerHostObject.cpp

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

packages/react-native-audio-api/common/cpp/AudioAPIInstaller/AudioAPIInstallerHostObject.h

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,43 @@
66
#include <utility>
77
#include <vector>
88

9-
#include "AudioAPIInstallerWrapper.h"
9+
#include <JsiHostObject.h>
10+
#include <JsiPromise.h>
1011
#include "AudioContextHostObject.h"
11-
#include "JsiPromise.h"
1212

1313
namespace audioapi {
1414
using namespace facebook;
1515

16-
class AudioAPIInstallerWrapper;
17-
18-
class AudioAPIInstallerHostObject : public jsi::HostObject {
16+
class AudioAPIInstallerHostObject
17+
: public JsiHostObject,
18+
public std::enable_shared_from_this<AudioAPIInstallerHostObject> {
1919
public:
2020
explicit AudioAPIInstallerHostObject(
21-
const std::shared_ptr<AudioAPIInstallerWrapper> &wrapper,
2221
jsi::Runtime *runtime,
23-
const std::shared_ptr<react::CallInvoker> &jsInvoker);
24-
25-
#ifdef ANDROID
26-
static void createAndInstallFromWrapper(
27-
const std::shared_ptr<AudioAPIInstallerWrapper> &wrapper,
28-
jsi::Runtime *rnRuntime,
29-
const std::shared_ptr<react::CallInvoker> &jsInvoker) {
30-
auto hostObject = std::make_shared<AudioAPIInstallerHostObject>(
31-
wrapper, rnRuntime, jsInvoker);
32-
auto object = jsi::Object::createFromHostObject(*rnRuntime, hostObject);
33-
rnRuntime->global().setProperty(
34-
*rnRuntime, "__AudioAPIInstaller", std::move(object));
35-
}
36-
#endif
22+
const std::shared_ptr<react::CallInvoker> &jsInvoker)
23+
: rnRuntime_(runtime) {
24+
promiseVendor_ = std::make_shared<PromiseVendor>(runtime, jsInvoker);
3725

38-
jsi::Value get(jsi::Runtime &runtime, const jsi::PropNameID &name) override;
26+
addFunctions(
27+
JSI_EXPORT_FUNCTION(AudioAPIInstallerHostObject, createAudioContext));
28+
}
3929

40-
void set(
41-
jsi::Runtime &runtime,
42-
const jsi::PropNameID &name,
43-
const jsi::Value &value) override;
30+
void install() {
31+
auto object =
32+
jsi::Object::createFromHostObject(*rnRuntime_, shared_from_this());
33+
rnRuntime_->global().setProperty(
34+
*rnRuntime_, "__AudioAPIInstaller", std::move(object));
35+
}
4436

45-
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
37+
JSI_HOST_FUNCTION(createAudioContext) {
38+
auto audioContext = std::make_shared<AudioContext>();
39+
auto audioContextHostObject =
40+
std::make_shared<AudioContextHostObject>(audioContext, promiseVendor_);
41+
return jsi::Object::createFromHostObject(runtime, audioContextHostObject);
42+
}
4643

4744
private:
48-
std::shared_ptr<AudioAPIInstallerWrapper> wrapper_;
49-
std::shared_ptr<JsiPromise::PromiseVendor> promiseVendor_;
45+
std::shared_ptr<PromiseVendor> promiseVendor_;
46+
jsi::Runtime *rnRuntime_;
5047
};
5148
} // namespace audioapi

packages/react-native-audio-api/common/cpp/AudioAPIInstaller/AudioAPIInstallerWrapper.h

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

packages/react-native-audio-api/common/cpp/AudioAPIInstaller/android/AudioAPIInstallerWrapper.cpp

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

packages/react-native-audio-api/common/cpp/AudioAPIInstaller/ios/AudioAPIInstallerWrapper.cpp

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

0 commit comments

Comments
 (0)