Skip to content

File tree

10 files changed

+138
-5
lines changed

10 files changed

+138
-5
lines changed

packages/jsi/LICENSE-brownie

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Callstack
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/jsi/NativescriptJsi.podspec

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ Pod::Spec.new do |s|
1313
s.platforms = { :ios => min_ios_version_supported, :osx => "12.0" }
1414
s.source = { :git => "https://github.com/NativeScript/napi-ios/tree/main/packages/jsi.git", :tag => "#{s.version}" }
1515

16-
s.source_files = "apple/**/*.{h,m,mm,swift,cpp}"
17-
s.private_header_files = "apple/**/*.h"
16+
s.source_files = [
17+
"apple/**/*.{h,m,mm,swift}",
18+
"cpp/**/*.{h,cpp}"
19+
]
20+
s.private_header_files = [
21+
"apple/**/*.h",
22+
"cpp/**/*.h"
23+
]
1824

1925
install_modules_dependencies(s)
2026
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#import <NativescriptJsiSpec/NativescriptJsiSpec.h>
2+
#import <ReactCommon/RCTTurboModuleWithJSIBindings.h>
23

3-
@interface NativescriptJsi : NSObject <NativeNativescriptJsiSpec>
4-
4+
@interface NativescriptJsi : NativeNativescriptJsiSpecBase <NativeNativescriptJsiSpec>
55
@end

packages/jsi/apple/NativescriptJsi.mm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
#import "NativescriptJsi.h"
2+
#import "NativescriptJsiInstaller.h"
3+
#import <jsi/jsi.h>
4+
5+
using namespace facebook;
6+
7+
@interface NativescriptJsi (JSIBindings) <RCTTurboModuleWithJSIBindings>
8+
@end
29

310
@implementation NativescriptJsi
411
- (NSNumber *)multiply:(double)a b:(double)b {
@@ -26,6 +33,11 @@ - (void)nativescript_init:(NSString *)metadata_path {
2633
// TODO: Port NativeScript/ffi/ObjCBridge.mm to JSI.
2734
}
2835

36+
- (void)installJSIBindingsWithRuntime:(facebook::jsi::Runtime &)runtime
37+
callInvoker:(const std::shared_ptr<facebook::react::CallInvoker> &)callinvoker {
38+
nativescriptjsi::NativescriptJsiInstaller::install(runtime);
39+
}
40+
2941
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
3042
(const facebook::react::ObjCTurboModule::InitParams &)params
3143
{
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "NativescriptJsiInstaller.h"
2+
#include "ObjcHostObject.h"
3+
4+
namespace nativescriptjsi {
5+
6+
void NativescriptJsiInstaller::install(facebook::jsi::Runtime &runtime) {
7+
// auto getStore = facebook::jsi::Function::createFromHostFunction(
8+
// runtime, facebook::jsi::PropNameID::forAscii(runtime, "__brownieGetStore"), 1,
9+
// [](facebook::jsi::Runtime &rt, const facebook::jsi::Value &,
10+
// const facebook::jsi::Value *args, size_t count) -> facebook::jsi::Value {
11+
// if (count < 1 || !args[0].isString()) {
12+
// throw facebook::jsi::JSError(rt,
13+
// "getStore requires a string key argument");
14+
// }
15+
16+
// std::string key = args[0].asString(rt).utf8(rt);
17+
// auto store = BrownieStoreManager::shared().getStore(key);
18+
19+
// if (!store) {
20+
// return facebook::jsi::Value::undefined();
21+
// }
22+
23+
// auto hostObject = std::make_shared<ObjcHostObject>();
24+
// return facebook::jsi::Object::createFromHostObject(rt, hostObject);
25+
// });
26+
27+
// runtime.global().setProperty(runtime, "__brownieGetStore", getStore);
28+
}
29+
30+
} // namespace nativescriptjsi
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include <jsi/jsi.h>
4+
5+
namespace nativescriptjsi {
6+
7+
class NativescriptJsiInstaller {
8+
public:
9+
static void install(facebook::jsi::Runtime& runtime);
10+
};
11+
12+
} // namespace nativescriptjsi
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "ObjcHostObject.h"
2+
#include <jsi/JSIDynamic.h>
3+
4+
namespace nativescriptjsi {
5+
6+
ObjcHostObject::ObjcHostObject() {}
7+
8+
facebook::jsi::Value ObjcHostObject::get(facebook::jsi::Runtime &rt,
9+
const facebook::jsi::PropNameID &name) {
10+
// TODO
11+
12+
return facebook::jsi::Value();
13+
}
14+
15+
void ObjcHostObject::set(facebook::jsi::Runtime &rt,
16+
const facebook::jsi::PropNameID &name,
17+
const facebook::jsi::Value &value) {
18+
// TODO
19+
}
20+
21+
std::vector<facebook::jsi::PropNameID>
22+
ObjcHostObject::getPropertyNames(facebook::jsi::Runtime &rt) {
23+
std::vector<facebook::jsi::PropNameID> names;
24+
25+
return names;
26+
}
27+
28+
} // namespace nativescriptjsi

packages/jsi/cpp/ObjcHostObject.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include <jsi/jsi.h>
4+
5+
#include <memory>
6+
7+
namespace nativescriptjsi {
8+
9+
class ObjcHostObject : public facebook::jsi::HostObject {
10+
public:
11+
explicit ObjcHostObject();
12+
13+
facebook::jsi::Value get(facebook::jsi::Runtime& rt,
14+
const facebook::jsi::PropNameID& name) override;
15+
16+
void set(facebook::jsi::Runtime& rt, const facebook::jsi::PropNameID& name,
17+
const facebook::jsi::Value& value) override;
18+
19+
std::vector<facebook::jsi::PropNameID> getPropertyNames(
20+
facebook::jsi::Runtime& rt) override;
21+
};
22+
23+
} // namespace nativescriptjsi

packages/jsi/example/macos/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,7 @@ SPEC CHECKSUMS:
26302630
fmt: 24e7591456deb60b4a77518f83d9a916ac84223f
26312631
glog: 0b31c25149b9d350b2666c7d459229861a00ec07
26322632
hermes-engine: d1e544246fbda6f5b9b0ebe261340f34645cb03a
2633-
NativescriptJsi: 716565d81fe7d789f16252fa1b44aaf909c33fa9
2633+
NativescriptJsi: dd2139dedc48b8c87b85169f0d862c216086ec93
26342634
RCT-Folly: 0a7558aedae101878b4a1273756c05613dbdfb61
26352635
RCTDeprecation: b60b889eafa75f46c3d6be5332681efbb16ad0c7
26362636
RCTRequired: 070d7f0ef937e7a93aab20761cef55419f16b5de

packages/jsi/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"ios",
2020
"cpp",
2121
"*.podspec",
22+
"LICENSE-brownie",
2223
"react-native.config.js",
2324
"!ios/build",
2425
"!android/build",

0 commit comments

Comments
 (0)