Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridgeless #60

Merged
merged 31 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
50e6333
Bump version
ospfranco Feb 24, 2024
be89f05
Remove old dependencies and update to RN 0.74-rc
ospfranco Feb 26, 2024
0f5ed0d
Remove non bridgeless dependencies
ospfranco Feb 27, 2024
45d81e5
Add annotation for Frameworks API
ospfranco Feb 28, 2024
c788c32
Change cpp-adapter to be more JNI
ospfranco Feb 28, 2024
ca05aed
Add patch to allow pods to be installed
ospfranco Feb 28, 2024
7d71c35
Do not import +private for bridgeless
ospfranco Mar 1, 2024
998fc86
Merge branch 'main' into bridgeless
ospfranco Mar 1, 2024
c3a4ed3
fix yarn patch
ospfranco Mar 4, 2024
a3dc9e8
lock file
ospfranco Mar 4, 2024
58bb2cb
change cocoapods commands
ospfranco Mar 4, 2024
be38834
change cocoapods instal step
ospfranco Mar 4, 2024
0c4b9e8
add build scripts to example app
ospfranco Mar 4, 2024
5ca9863
Fix project name on build command
ospfranco Mar 4, 2024
a38ffcf
Merge branch 'main' into bridgeless
ospfranco Mar 15, 2024
bd66b69
Try nightly
ospfranco Mar 15, 2024
229fa5b
comment out rn performance
ospfranco Mar 16, 2024
fe96a86
Upgrade to rc4
ospfranco Mar 20, 2024
14b74c7
Revert changes to cpp-adapter
ospfranco Mar 27, 2024
255481d
Remove using statement
ospfranco Mar 27, 2024
9bb229c
Merge branch 'main' into bridgeless
ospfranco Mar 27, 2024
3917ffc
create new patch for 0.74-rc5
ospfranco Mar 28, 2024
78ddfcf
Revert to yarn1 and create patches for RC5
ospfranco Mar 28, 2024
2fd06b8
New patch file
ospfranco Mar 28, 2024
1184e31
Update patch file
ospfranco Mar 28, 2024
beb6d26
Fix patch
ospfranco Apr 2, 2024
76c648a
Disable turbo module so bridgeless works
ospfranco Apr 2, 2024
3c031dc
Update dependencies
ospfranco Apr 2, 2024
aa52de6
Update pod lock
ospfranco Apr 2, 2024
8e925df
Polishing
ospfranco Apr 2, 2024
3515693
update locks
ospfranco Apr 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading