Commit Graph
211 Commits
Author SHA1 Message Date
Marc RousavyandGitHub 96d15eaa85 feat: Variants for Swift and Kotlin 🥳 (#148)
* fix: Try generating Variants for Swift

* Update SwiftCxxBridgedType.ts

* feat: Create Variant Wrapper struct

* feat: Implement Kotlin Variant

* Update Variant.kt

* feat: Try this Variant

* feat: Stub out variant conversion for JNI for now

* fix: Do not strip in Proguard

* Update Variant.kt

* Format

* Update JVariant.hpp

* feat: Implement JVariant2

* Update JVariant.hpp

* fix: Make it fully dynamic/templated

* feat: Try using JVariant<...>

* fix: Kinda works?

* Update JVariant.hpp

* feat: Fuck all this, we generate variants now

* okay creating works

* Create helper

* feat: Implement Variant parsing to C++ as well

* fix: Clean up and remove `J`

* Same line

* Rename
2024-09-24 13:56:18 +02:00
Marc RousavyandGitHub adeffdac19 fix: Remove unused args parameter in createHybridObject(..) (#145)
* fix: Remove unused `args` parameter in `createHybridObject(..)`

* Update NativeNitroModules.cpp

* fix: Tidy up the ctor and dtor
2024-09-23 12:44:22 +02:00
Marc Rousavy 89a5995dd9 fix: Explicitly check against NDEBUG on Android 2024-09-17 15:14:58 +02:00
Marc RousavyandGitHub 1128d6a3c6 feat: Add NitroModules.box(...) to support using Nitro Modules from any Runtime/Worklets context (#138)
* feat: Add `NitroModules.box(...)` to support using Nitro Modules from any Runtime/Worklets context

* feat: Add `getPropertyNames` for `BoxedHybridObject`

* docs: Create Worklets/Threading docs
2024-09-17 14:45:28 +02:00
Marc RousavyandGitHub 46c9ca0a1b fix: Make string literals throw again, and test optional enums (#135)
* fix: Make string literals throw again, and test optional enums

* Update Podfile.lock

* fix tests

* hm compiler doesnt work

* fix: Fix nitrogen for optional enums

* fix: Optional enums or ArrayBuffers can be bridged directly

* fix: Disable codegen for Nitro Modules

* fix: Rename `Spec` to avoid running codegen

* fix: Disable autolinking by renaming the file so codegen doesnt find it

* fix: Format

* Update HybridObjectRegistry.cpp

* Update HybridObjectRegistry.cpp
2024-09-16 17:34:14 +02:00
Marc RousavyandGitHub 03e1a716cf fix: Fix NITRO_DEBUG debug/release preprocessor directive (#132)
* fix: Use `NITRO_DEBUG` flag to predictably run debug/release code

* feat: Add `NitroModules.buildType`

* fix: Style `debug` label
2024-09-16 16:18:05 +02:00
Marc Rousavy d291f63ec0 fix: Remove LOG_MEMORY_ALLOCATIONS test 2024-09-16 15:47:40 +02:00
Marc Rousavy 563ad61611 fix: Delete unused _deleteFuncContext member 2024-09-16 15:47:29 +02:00
Marc RousavyandGitHub 0f04af9a89 feat: Fully automatic autolinking for Nitrogen (#117)
* move to folders

* Refactor autolinking

* Generate code

* fix: Fix `map` undefined in `unregisterHybridObjectConstructor`

* Create `<ModuleName>OnLoad.mm`

* feat: Add register calls

* hmm

* Update createHybridObjectInitializer.ts

* i am stupid

* Add `autolinking` to `nitro.json`

* Fix missing includes

* feat: Create Swift part for iOS autolinking... 👀

* fix duplicate symbols...

* feat: Properly create Swift types

* Rename to `Autolinking`

* docs: Update docs on new autogenerate setup

* Android base

* It works

* Base

* Initialize natives

* fix: Set up autolinking Cpp file

* Update NitroImageOnLoad.hpp

* feat: Try

* fix: Fix Promise using `global_ref`

* Update index.ts

* fix: Replace `CriticalNative` with `FastNative`

* feat: Generate the code to register JNI.. almost there!

* fix: Fix JNI paths (`L*;`)

* Update nitrogen.md
2024-09-12 17:19:50 +02:00
Marc Rousavy 9f2fd827c9 feat: Add unregisterHybridObjectConstructor(...) method for @jpudysz
don't use this lol
2024-09-09 17:23:35 +02:00
Marc RousavyandGitHub ded7c08220 fix: Properly forward move-only types (future!) (#104)
* fix: Properly forward types (future!)

* Forward
2024-09-06 15:57:35 +02:00
Marc RousavyandGitHub 3fa2fe9bd6 feat: Add NitroModules.hasNativeState and NitroModules.removeNativeState (#83) 2024-08-29 19:38:48 +02:00
Marc RousavyandGitHub 661bea4cec feat: Add dispose() to HybridObject (and registerRawHybridMethod(...)) (#82)
* fix: Fix `SwiftClosure` not reading `void*` properly - use `Unmanaged<T>` again

* feat: Add a `dispose()` method to `HybridObject`

* feat: Split `registerRawHybridMethod` out of `registerHybridMethod`

* fix: Throw better error for when `NativeState` is nullptr

* Better debug info

* `FunctionType` -> `FunctionKind`

* fix: Either dynamically get name, or statically through typeinfo.
2024-08-29 16:51:11 +02:00
Marc RousavyandGitHub 992c709caf feat: Safely wrap a Swift closure in a C++ accessible SwiftClosure struct and allow parameters bi-directionally (#81)
* feat: Safely wrap a Swift closure in a `SwiftClosure` struct callable from C++

* Unsafely unwrap (`!`)

* fix: Fix visibility modifiers

* fix: Rename `ClosureWrapper` -> `SwiftClosure`

* Update SwiftClosure.hpp

* Update SwiftClosure.hpp

* Create `SwiftFunction` base

* regen

* feat: Properly create `std::function` from Swift closure

* fix: Forward params I think

* Update SwiftCxxBridgedType.ts

* feat: Use static function pointer to allow for C++ types

* fix: Only do this for Swift

* Update SwiftCxxBridgedType.ts

* fix: Properly unwrap using `Unmanaged`

* fix: Fix Swift compiler crash by moving function to `std::shared_ptr` before capturing it

* feat: Properly share func before capturing it

* Update SwiftCxxTypeHelper.ts
2024-08-29 15:21:25 +02:00
Marc RousavyandGitHub b4592244f2 feat: AnyMap for Kotlin/Android (#60)
* feat: Create `JAnyMap` base

* Update JNIOnLoad.cpp

* feat: Create `AnyMap` methods

* fix: Fix wrong name & format

* feat: `setNull`

* log dimmed

* Update README.md
2024-08-27 18:02:39 +02:00
Marc RousavyandGitHub dbadcc2151 feat: Create AnyMapHolder for Swift (#56)
* feat: Create `AnyMapHolder` for Swift

* feat: Bridge other types

* fix: Fix types

* feat: Make all public

* fix: Remove Arrays because of the Swift compiler bug

* feat: Create `AnyMapHolder`

* fix: Rename record `someMap` to `someRecord`

* feat: Use `someMap`

* fix: Fix "22 duplicate symbols" by making the funcs inline

* Update README.md
2024-08-20 23:16:55 +02:00
Marc RousavyandGitHub 3d4455eaa8 feat: Add support for ArrayBuffer in Kotlin Nitro Modules (#55)
* fix: More all Java files into `.core`

* fix: Remove unused `_runtime` member in `JSICache`

* feat: Create `JArrayBuffer`

* feat: Crate `JArrayBuffer` from both ways

* feat: Implement bidirectional `ArrayBuffer` for Kotlin

* Update JArrayBuffer.hpp

* fix: Fix include

* fix: Fix non-direct buffers

* Update README.md
2024-08-20 18:10:10 +02:00
Marc RousavyandGitHub e7b9f412eb fix: Rewrite Logger to use platform NSLog / __android_log_print (#54)
* fix: Fix wrong include..?

* fix: Reimplement NitroLogger as a platform-specific logger

* fix: Copy args, and use proper tag

* fix: Fix sprintf crash because of wrong format argument

* fix: Fix Logger usage on iOS
2024-08-20 16:20:44 +02:00
Marc RousavyandGitHub acca5baaa4 fix: Replace #if DEBUG with #ifndef NDEBUG to make it work on Android (#53)
* fix: Fix `hasNativeState` checks and provide better errors

* fix: Replace `#if DEBUG` with `#ifndef NDEBUG` to make it work on Android
2024-08-20 15:30:03 +02:00
Marc Rousavy f4ef4b7665 fix: Fix raw JSI functions and add test to example module 2024-08-20 12:13:55 +02:00
Marc RousavyandGitHub 065736dc2e feat: Base for Kotlin modules (#45)
* feat: Base for Kotlin modules

* fix: Properly make sure Nitro C++ is initialized

* Update JNIOnLoad.java

* feat: Set up `initHybrid()` in JHybridObject

* chore: Fix a bunch of linter issues

* fix: Fix fbjni codegen

* Update JHybridObject.hpp

* fix: Make `initHybrid()` JVM static

* feat: Make `mHybridData` private member of each in inheritance chain

* Generate specs

* feat: Set up proper inheritance graph in FBJNI using virtual inheritance `HybridObject` (#46)

* feat: Try to set up proper inheritance in FBJNI

* Virtual inheritance

* Update JHybridImageFactorySpec.cpp

* It works...

* feat: Virtual base

* Update HybridTestObject.hpp

* Update CMakeLists.txt

* Update JHybridObject.hpp

* Virtual dtor

* Dynamic cast to NativeState 🤔

* Virtual proper

* feat: Generate as virtual base?

* chore: Change to `updateNative`

* feat: Cannot default-construct HybridObject

* fix: Use `dynamic` pointer cast for `HybridContext` because `HybridObject` is now a virtual base

* Update README.md
2024-08-19 12:40:44 +02:00
Marc RousavyandGitHub 2c277fe6f0 feat: Support Promise<T> in Swift (#43)
* fix: Rename `wrap(wrappingDataWithoutCopy)`

* Update ArrayBufferHolder.swift

* Update ArrayBufferHolder.swift

* feat: Move to `utils/`

* feat: Create `Promise` base

* feat: Make `Promise` templated

* Delete HybridContext.cpp

* feat: Create `Promise<T>` in Swift

* Update Promise.swift

* feat: Add docs

* feat: Create `PromiseHolder`

* feat: Create

* `ArrayBuffer` ctors

* Create `PromiseHolder`

* feat: Convert from and to `PromiseHolder<T>`?

* fix: Remove wrong `Promise` declaration

* Update JSIConverter+Promise.hpp

* Update HybridSwiftKotlinTestObject.swift

* Update NitroModules.podspec
2024-08-15 18:30:43 +02:00
Marc RousavyandGitHub 46dc1f7fed feat: Allow passing Swift callbacks to JS (#42)
* feat: Allow converting a Swift closure to a C++ function

* Use `bind`

* return `func`

* feat: Generate std::bind placeholders

* Update ClosureWrapper.swift

* feat: Allow creating C++ func from (no argument) Swift callback!

* throw if func with more parameters is used bi-directionally

* Use helper function `ClosureWrapper.wrap`

* Update ClosureWrapper.swift
2024-08-15 13:35:21 +02:00
Marc RousavyandGitHub c31936286d feat: Support ArrayBuffer in Swift 🥳 (#37)
* feat: Support `ArrayBuffer` in Swift

* feat: Create `ArrayBufferHolder` that holds a `std::shared_ptr<ArrayBuffer>`

* fix: Fix `void*` cast in Swift

* feat: Create `.allocate(..)` helper init

* fix: Fix `initializeToZero`

* feat: Add `createNewBuffer`

* fix: regenerate missing specs

* fix: Move import to iOS only, on Android we dont have that

* chore: Format
2024-08-14 19:34:31 +02:00
Marc RousavyandGitHub 6d2338d096 feat: Add NitroModules.hasHybridObject(..) and NitroModules.getAllHybridMethodNames() (#30)
* feat: Add `NitroModules.hasHybridObject(..)` and `NitroModules.getAllHybridMethodNames()`

* Fix docs
2024-08-14 01:13:09 +02:00
Marc RousavyandGitHub f90a1325b2 feat: Approach 1 of implementing Swift (#24)
* feat: Convert `swift::String`

* Add arrays to swift

* Update createSwiftUmbrellaHeader.ts

* fix: Return values directly now, no more result types (breaks exceptions, fixes generics)

* Expose Swift test object

* feat: Try functions

* fix: Include pragma once

* Pragma

* feat: Create `Callback_...` for Swift

* add comments

* Create `Callback_*` in `bridge/`

* feat: `AnyMap` reserve ctor

* Create SwiftCxxTypeHelper.ts

* feat: Create Swift -> C++ bridged helper types

* feat: i dont even know what im doing anymore

* feat: Convert optionals

* indent

* feat: Fix umbrella

* indent
2024-08-13 22:13:29 +02:00
Marc RousavyandGitHub 0dd63227d8 fix: Fix Swift umbrella header includes (#19)
* feat: Try bridge more Swift

* Make all Promises `async` in swift

* Rename `Promise` to `JSPromise`

* Update JSPromise.hpp

* Update JSICache.cpp

* fix import

* fix: Init props

* fix: Remove AnyMap and ArrayBuffer apis for now

* fix import

* no more async? idk

* feat: Convert `std::optional<T>` to `swift::Optional<T>`

* Remove all funcs except hello

* fix: Generate Swift Umbrella header

* fix: Organize

* fix: Hardcode forward-decl

* feat: Properly generate umbrella header from known types

* fix: Fix indentation

* order

* feat: Try bridging some primitives over...

* Update NitroDefines.hpp

* Update Property.ts

* fallthrough looks better

* better error

* fix: Fix wrong enum `maxLength`

* feat: Try `CarSwift` experiment

* Revert "feat: Try `CarSwift` experiment"

This reverts commit 7794f38271.
2024-08-12 14:18:13 +02:00
Marc Rousavy f7646c34ba fix: Remove unresolved import on Android 2024-08-09 17:01:42 +02:00
Marc Rousavy ec910a7b27 fix: Add nullptr check to HybridObjectRegistry 2024-08-08 20:28:43 +02:00
Marc RousavyandGitHub c101faf948 feat: Cache toObject(...) using jsi::WeakObject and correctly set externalExternalMemoryPressure (#13)
* feat: Cache `toObject(...)` using `jsi::WeakObject` and set `externalMemoryPressure` properly

* feat: Support caching different JSI types - strongly typed
2024-08-08 12:28:33 +02:00
Marc Rousavy 0807098c86 Update HybridObject.cpp 2024-08-08 11:48:49 +02:00
Marc Rousavy f5bd9e157d perf: Do all .is.. checks only in DEBUG 2024-08-08 11:45:02 +02:00
Marc RousavyandGitHub 86c3702ffc feat: Make HybridObject a NativeState (#11)
* feat: Make `HybridObject` a `NativeState`

* feat: Get `NativeState` inside `callMethod(...)`, no more passing `this*`

* Update HybridObject.hpp

* fix: Convert NativeState to `jsi::Value` again

* Use `Object.create`

* fix broken test

* feat: Add `__type` hidden state to objects

* chore: Format

* `makeGlobal` -> `makeShared`

* feat: Extract to `HybridObjectPrototype`

* Update HybridObject.hpp

* feat: Properly build Prototype chain

* Cache prototypes

* fix: Fix prototype caching

* Extract to separate file

* fix: Some comments

* chore: Format

* feat: Freeze prototypes

* Remove freeze

* feat: Optimize `NativeState` performance, make it 56x faster (#12)

* fix: Fix `HybridFunction` usage

* Update HybridFunction.hpp

* mark final

* feat: Add new `registerHybrids(...)` API

* fix: Remove logs

* perf: Make `registerHybrids` faster by using function pointer instead of `std::function<...>`

* fix: Turn off memory allocations debugger

* refactor

* Format

* fix: Fix cyclic includes for `JSIConverter+HybridObject`

* DO_NULL_CHECKS

* fix: Use `jsi::Value` directly to avoid down and up casting again

* Add `__type` to `HybridObject` declaration

* feat: Throw `jsi::JSError` again

* feat: Add prototype tests

* feat: Set `__type` on Prototypes as well

* Delete PointerHolder.hpp

* Delete `JSIPrototypeCache`

* fix: Use `jsi::Value` directly
2024-08-08 11:39:17 +02:00
Marc Rousavy 790def8618 Update JSIConverter+Variant.hpp 2024-08-07 14:24:39 +02:00
Marc Rousavy f383d6909a fix: Better error messages for variant and ArrayBuffer 2024-08-07 14:13:44 +02:00
Marc Rousavy 0b0b14979c feat: Implement JSIConverter<enum>::canConvert (for TS unions) - NOW WE COVERED ALL CASES/TESTS! 🥳 2024-08-07 13:59:35 +02:00
Marc Rousavy 882054e587 feat: Support JSIConverter<AnyMap>::canConvert (+ AnyValue and unordered_map<string, T>) 2024-08-07 13:56:10 +02:00
Marc Rousavy 29101804ae fix: Return true for empty array's canConvert 2024-08-07 13:41:52 +02:00
Marc Rousavy f4c5581e98 feat: Add JSIConverter<struct>::canConvert 2024-08-07 13:41:06 +02:00
Marc Rousavy 8cd9644dc0 chore: Format 2024-08-07 13:04:08 +02:00
Marc Rousavy a0b6471fc5 fix: Fix a whole bunch of issues. 2024-08-07 13:03:46 +02:00
Marc Rousavy c7b0cde665 feat: Support dynamically converting jsi::Value to any T in a variant by adding JSIConverter<T>::canConvert(...) 🎉 2024-08-07 12:10:10 +02:00
Marc Rousavy 97c838b901 fix: Remove old TestHybridObject 2024-08-06 20:59:58 +02:00
Marc Rousavy 4456dfd95f Update JSICache.hpp 2024-08-06 01:49:08 +02:00
Marc Rousavy 0b7e2b5561 fix: Fix JSICache<T> being recreated each time because of C++ template specialization 2024-08-06 01:37:08 +02:00
Marc Rousavy 30c5775f71 Update JSICache.hpp 2024-08-06 01:02:46 +02:00
Marc Rousavy ef5d778bc6 Update JSICache.hpp 2024-08-06 01:02:40 +02:00
Marc Rousavy 56726f9662 fix: Pass more things by reference in nitrogen. 2024-08-06 01:02:30 +02:00
Marc Rousavy 0e51985a82 feat: Add tests for ArrayBuffer 2024-08-06 00:33:00 +02:00
Marc Rousavy 592ceb94ff feat: Support ArrayBuffers from JS, and fix JSIConverter<T> template 2024-08-06 00:22:26 +02:00