Skip to content

Commit

Permalink
Merge pull request #60 from OP-Engineering/bridgeless
Browse files Browse the repository at this point in the history
Bridgeless
  • Loading branch information
ospfranco authored Apr 2, 2024
2 parents b083c02 + 3515693 commit bea3ad0
Show file tree
Hide file tree
Showing 33 changed files with 4,054 additions and 9,470 deletions.
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ DerivedData
*.ipa
*.xcuserstate
project.xcworkspace
**/.xcode.env.local

# Android/IJ
#
Expand All @@ -47,7 +48,7 @@ vendor/

# Cocoapods
#
example/ios/Pods
**/Pods
example/vendor/bundle

# Temporary files created by Metro to check the health of the file watcher
Expand All @@ -73,4 +74,11 @@ android/.cxx
# generated by bob
lib/
# Gradle
android/gradle/
android/gradle/

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
Binary file removed .yarn/install-state.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.9.0)

set (PACKAGE_NAME "op-sqlite")
set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD 20)
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)

include_directories(
Expand Down Expand Up @@ -55,7 +55,7 @@ endif()

set_target_properties(
${PACKAGE_NAME} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
)
Expand Down
8 changes: 5 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ android {
}

defaultConfig {
minSdkVersion 21
minSdkVersion 23
targetSdkVersion safeExtGet('targetSdkVersion', 34)
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -127,9 +127,11 @@ android {

sourceSets.main {
java {
if (!isNewArchitectureEnabled()) {
// TODO removed the codegen config to allow the package to be built under bridgeless
// Once there is a stable API for C++ Turbo Modules, maybe this can be enabled again
// if (!isNewArchitectureEnabled()) {
srcDirs += 'src/paper/java'
}
// }
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions android/cpp-adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <jsi/jsi.h>
#include <typeinfo>

// This file is not using raw jni but rather fbjni, do not change how the native functions are registered
// https://github.com/facebookincubator/fbjni/blob/main/docs/quickref.md
struct OPSQLiteBridge : jni::JavaClass<OPSQLiteBridge> {
static constexpr auto kJavaDescriptor = "Lcom/op/sqlite/OPSQLiteBridge;";

Expand Down
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
OPSQLite_kotlinVersion=1.8.0
OPSQLite_kotlinVersion=1.9.22
4 changes: 3 additions & 1 deletion android/src/main/java/com/op/sqlite/OPSQLiteBridge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package com.op.sqlite

import com.facebook.react.bridge.ReactContext
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
import com.facebook.react.common.annotations.FrameworkAPI

@OptIn(FrameworkAPI::class)
class OPSQLiteBridge {
private external fun installNativeJsi(
jsContextNativePointer: Long,
jsCallInvokerHolder: CallInvokerHolderImpl,
docPath: String
)

private external fun clearStateNativeJsi()

fun install(context: ReactContext) {
val jsContextPointer = context.javaScriptContextHolder!!.get()
val jsCallInvokerHolder =
Expand Down
42 changes: 23 additions & 19 deletions android/src/main/java/com/op/sqlite/OPSQLiteModule.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package com.op.sqlite

import android.util.Log
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.bridge.ReactContextBaseJavaModule
import java.io.File
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream

@ReactModule(name = OPSQLiteModule.NAME)
internal class OPSQLiteModule(context: ReactApplicationContext?) :
NativeOPSQLiteSpec(context) {
//@ReactModule(name = OPSQLiteModule.NAME)
internal class OPSQLiteModule(context: ReactApplicationContext?) : ReactContextBaseJavaModule(context) {
override fun getName(): String {
return NAME
}

override fun getTypedExportedConstants(): MutableMap<String, Any> {
fun getTypedExportedConstants(): MutableMap<String, Any> {
val constants: MutableMap<String, Any> = HashMap()
val context = reactApplicationContext
val dbPath = context
.getDatabasePath("defaultDatabase")
.absolutePath
.replace("defaultDatabase", "")
val dbPath =
context.getDatabasePath("defaultDatabase")
.absolutePath
.replace("defaultDatabase", "")
constants["ANDROID_DATABASE_PATH"] = dbPath
val filesPath = context.filesDir.absolutePath
constants["ANDROID_FILES_PATH"] = filesPath
Expand All @@ -32,32 +32,35 @@ internal class OPSQLiteModule(context: ReactApplicationContext?) :
return constants
}

override fun getConstants(): MutableMap<String, Any>? {
return getTypedExportedConstants()
}

@ReactMethod(isBlockingSynchronousMethod = true)
override fun install(): Boolean {
fun install(): Boolean {
return try {
OPSQLiteBridge.instance.install(reactApplicationContext)
true
} catch (exception: Exception) {
Log.e(NAME, "Install exception: $exception")
false
}
}

@ReactMethod(isBlockingSynchronousMethod = true)
override fun moveAssetsDatabase(name: String, extension: String): Boolean {
fun moveAssetsDatabase(name: String, extension: String): Boolean {
val context = reactApplicationContext
val assetsManager = context.assets

try {

// val assets = assetsManager.list("");
// Open the input stream for the asset file
val inputStream: InputStream = assetsManager.open("custom/$name.$extension")

// Create the output file in the documents directory
val databasesFolder = context
.getDatabasePath("defaultDatabase")
.absolutePath
.replace("defaultDatabase", "")
val databasesFolder =
context.getDatabasePath("defaultDatabase")
.absolutePath
.replace("defaultDatabase", "")

val outputFile = File(databasesFolder, "$name.$extension")

Expand Down Expand Up @@ -85,7 +88,8 @@ internal class OPSQLiteModule(context: ReactApplicationContext?) :
}
}

override fun onCatalystInstanceDestroy() {
override fun invalidate() {
super.invalidate()
OPSQLiteBridge.instance.clearState()
}

Expand All @@ -96,4 +100,4 @@ internal class OPSQLiteModule(context: ReactApplicationContext?) :

const val NAME = "OPSQLite"
}
}
}
33 changes: 10 additions & 23 deletions android/src/main/java/com/op/sqlite/OPSQLitePackage.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
package com.op.sqlite

import com.facebook.react.TurboReactPackage
import com.facebook.react.ReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.module.model.ReactModuleInfoProvider
import com.facebook.react.module.model.ReactModuleInfo
import com.facebook.react.uimanager.ViewManager

class OPSQLitePackage : TurboReactPackage() {
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
if(name == OPSQLiteModule.NAME) {
return OPSQLiteModule(reactContext)
} else {
return null
}
class OPSQLitePackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
return listOf<NativeModule>(OPSQLiteModule(reactContext))
}

override fun getReactModuleInfoProvider() = ReactModuleInfoProvider {
mapOf(
OPSQLiteModule.NAME to ReactModuleInfo(
OPSQLiteModule.NAME,
OPSQLiteModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
true // isTurboModule
)
)
override fun createViewManagers(
reactContext: ReactApplicationContext
): List<ViewManager<*, *>> {
return emptyList()
}
}
}
1 change: 1 addition & 0 deletions cpp/DumbHostObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ DumbHostObject::getPropertyNames(jsi::Runtime &rt) {

jsi::Value DumbHostObject::get(jsi::Runtime &rt,
const jsi::PropNameID &propNameID) {

auto name = propNameID.utf8(rt);
auto fields = metadata.get();
for (int i = 0; i < fields->size(); i++) {
Expand Down
1 change: 1 addition & 0 deletions cpp/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace opsqlite {
/// Maps to hold the different objects
std::unordered_map<std::string, sqlite3 *> dbMap =
std::unordered_map<std::string, sqlite3 *>();

std::unordered_map<std::string, UpdateCallback> updateCallbackMap =
std::unordered_map<std::string, UpdateCallback>();

Expand Down
Binary file modified example/.yarn/install-state.gz
Binary file not shown.
1 change: 0 additions & 1 deletion example/.yarnrc.yml

This file was deleted.

3 changes: 2 additions & 1 deletion example/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ source 'https://rubygems.org'

ruby '>2.7.6'

gem 'cocoapods', '~> 1.11', '>= 1.11.2'
gem 'cocoapods', '>= 1.13', '< 1.15'
gem 'activesupport', '>= 6.1.7.5', '< 7.1.0'
19 changes: 4 additions & 15 deletions example/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ GEM
specs:
CFPropertyList (3.0.6)
rexml
activesupport (7.1.2)
base64
bigdecimal
activesupport (7.0.8.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
base64 (0.2.0)
bigdecimal (3.1.4)
claide (1.1.0)
cocoapods (1.14.3)
addressable (~> 2.8)
Expand Down Expand Up @@ -61,9 +54,6 @@ GEM
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
drb (2.2.0)
ruby2_keywords
escape (0.0.4)
ethon (0.16.0)
ffi (>= 1.15.0)
Expand All @@ -75,16 +65,14 @@ GEM
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.7.1)
minitest (5.20.0)
minitest (5.22.2)
molinillo (0.8.0)
mutex_m (0.2.0)
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
public_suffix (4.0.7)
rexml (3.2.6)
ruby-macho (2.5.1)
ruby2_keywords (0.0.5)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
Expand All @@ -101,7 +89,8 @@ PLATFORMS
ruby

DEPENDENCIES
cocoapods (~> 1.11, >= 1.11.2)
activesupport (>= 6.1.7.5, < 7.1.0)
cocoapods (>= 1.13, < 1.15)

RUBY VERSION
ruby 3.3.0p0
Expand Down
2 changes: 0 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ dependencies {

implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")

implementation("com.facebook.react:flipper-integration")

if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
Expand Down
Loading

0 comments on commit bea3ad0

Please sign in to comment.