Skip to content

chore(sqlite-storage): merge to main #1082

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

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions .github/actions/setup-project/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ inputs:
required: false
description: node version to install
default: 20.10.0 # is already cached in Ubuntu 22.04 runner
windows-fix:
required: false
description: https://github.com/actions/setup-node/issues/899#issuecomment-1837381044
default: "false"
runs:
using: composite
steps:
- uses: actions/setup-node@v4
if: ${{ inputs.windows-fix == 'true' }}
name: (Windows fix) Setup node without cache
with:
node-version: ${{ inputs.node-version }}
- name: Enable corepack
shell: bash
run: |
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/default-storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
token: ${{ secrets.GH_RELEASE_TOKEN }}
filters: |
storage:
- 'packages/default-storage'
- 'packages/default-storage/**'

android:
name: Android
Expand Down Expand Up @@ -127,6 +127,8 @@ jobs:
uses: actions/checkout@v4
- name: Setup project
uses: ./.github/actions/setup-project
with:
windows-fix: true
- name: Install JS dependencies
run: |
yarn
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ local.properties
#workspaces
/packages/*/lib
.turbo
build/
2 changes: 1 addition & 1 deletion packages/default-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"src/",
"windows/"
],
"author": "Krzysztof Borowy <hello@krizzu.dev>",
"author": "Krzysztof Borowy <contact@kborowy.com>",
"contributors": [
"Evan Bacon <bacon@expo.io> (https://github.com/evanbacon)",
"Tommy Nguyen <4123478+tido64@users.noreply.github.com> (https://github.com/tido64)"
Expand Down
2 changes: 1 addition & 1 deletion packages/default-storage/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.build.json",
"extends": "../../.config/tsconfig.base.json",
"compilerOptions": {
"noEmit": true,
"types": [
Expand Down
3 changes: 3 additions & 0 deletions packages/sqlite-storage/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pbxproj -text
# specific for windows script files
*.bat text eol=crlf
3 changes: 3 additions & 0 deletions packages/sqlite-storage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Async Storage SQLite

Key-value persistent storage for React Native backed by SQLite.
41 changes: 41 additions & 0 deletions packages/sqlite-storage/RNAsyncStorageSQLite.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

Pod::Spec.new do |s|
s.name = File.basename(__FILE__, '.podspec')
s.version = package["version"]
s.summary = package["description"]
s.homepage = package["homepage"]
s.license = package["license"]
s.authors = package["author"]

s.platforms = { :ios => min_ios_version_supported }
s.source = { :git => "https://github.com/react-native-async-storage/async-storage.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm,swift}"

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
if respond_to?(:install_modules_dependencies, true)
install_modules_dependencies(s)
else
s.dependency "React-Core"

# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
s.dependency "React-Codegen"
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end
end
end
94 changes: 94 additions & 0 deletions packages/sqlite-storage/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
buildscript {
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["SqliteStorage_kotlinVersion"]

repositories {
google()
mavenCentral()
}

dependencies {
classpath "com.android.tools.build:gradle:7.2.1"
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}

apply plugin: "com.android.library"
apply plugin: "kotlin-android"

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["SqliteStorage_" + name]
}

def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["SqliteStorage_" + name]).toInteger()
}

def supportsNamespace() {
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
def major = parsed[0].toInteger()
def minor = parsed[1].toInteger()

// Namespace support was added in 7.3.0
return (major == 7 && minor >= 3) || major >= 8
}

android {
if (supportsNamespace()) {
namespace "org.rnasyncstorage.sqlitestorage"

sourceSets {
main {
manifest.srcFile "src/main/AndroidManifestNew.xml"
}
}
}

compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

defaultConfig {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")

}

buildTypes {
release {
minifyEnabled false
}
}

lintOptions {
disable "GradleCompatible"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

repositories {
mavenCentral()
google()
}

def kotlin_version = getExtOrDefault("kotlinVersion")

dependencies {
// For < 0.71, this will be from the local maven repo
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

5 changes: 5 additions & 0 deletions packages/sqlite-storage/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SqliteStorage_kotlinVersion=1.7.0
SqliteStorage_minSdkVersion=21
SqliteStorage_targetSdkVersion=31
SqliteStorage_compileSdkVersion=31
SqliteStorage_ndkversion=21.4.7075529
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.rnasyncstorage.sqlitestorage">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.rnasyncstorage.sqlitestorage

import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.Promise

class SqliteStorageModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {

override fun getName(): String {
return NAME
}

// Example method
// See https://reactnative.dev/docs/native-modules-android
@ReactMethod
fun multiply(a: Double, b: Double, promise: Promise) {
promise.resolve(a * b)
}

companion object {
const val NAME = "SqliteStorage"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.rnasyncstorage.sqlitestorage

import com.facebook.react.ReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ViewManager


class SqliteStoragePackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
return listOf(SqliteStorageModule(reactContext))
}

override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
return emptyList()
}
}
3 changes: 3 additions & 0 deletions packages/sqlite-storage/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ["module:@react-native/babel-preset"],
};
1 change: 1 addition & 0 deletions packages/sqlite-storage/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require("@react-native-async-storage/eslint-config");
1 change: 1 addition & 0 deletions packages/sqlite-storage/example/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
70 changes: 70 additions & 0 deletions packages/sqlite-storage/example/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, { useState } from "react";
import {
Button,
SafeAreaView,
ScrollView,
Text,
StatusBar,
StyleSheet,
useColorScheme,
View,
} from "react-native";
import { Colors } from "react-native/Libraries/NewAppScreen";
import { multiply } from "@react-native-async-storage/sqlite-storage";

function App(): React.JSX.Element {
const isDarkMode = useColorScheme() === "dark";
const [result, setResult] = useState<string | null>(null);

const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};

async function test() {
const random = Math.round(Math.random() * 100);
const result = await multiply(random, 2);
setResult(`${random} * 2 = ${result}`);
}

return (
<SafeAreaView style={[backgroundStyle, styles.container]}>
<StatusBar
barStyle={isDarkMode ? "light-content" : "dark-content"}
backgroundColor={backgroundStyle.backgroundColor}
/>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={backgroundStyle}
>
<Button title="test module" onPress={() => test()} />
<View style={styles.result}>
{result ? <Text style={styles.title}>{result}</Text> : null}
</View>
</ScrollView>
</SafeAreaView>
);
}

const styles = StyleSheet.create({
container: {
marginTop: 32,
paddingHorizontal: 24,
},
title: {
fontSize: 24,
fontWeight: "600",
textAlign: "center",
},
sectionDescription: {
marginTop: 8,
fontSize: 24,
fontWeight: "400",
},
result: {
fontSize: 24,
marginTop: 24,
fontWeight: "700",
},
});

export default App;
42 changes: 42 additions & 0 deletions packages/sqlite-storage/example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
buildscript {
apply(from: {
def searchDir = rootDir.toPath()
do {
def p = searchDir.resolve("node_modules/react-native-test-app/android/dependencies.gradle")
if (p.toFile().exists()) {
return p.toRealPath().toString()
}
} while (searchDir = searchDir.getParent())
throw new GradleException("Could not find `react-native-test-app`");
}())

repositories {
mavenCentral()
google()
}

dependencies {
getReactNativeDependencies().each { dependency ->
classpath(dependency)
}
}
}

allprojects {
repositories {
maven {
url({
def searchDir = rootDir.toPath()
do {
def p = searchDir.resolve("node_modules/react-native/android")
if (p.toFile().exists()) {
return p.toRealPath().toString()
}
} while (searchDir = searchDir.getParent())
throw new GradleException("Could not find `react-native`");
}())
}
mavenCentral()
google()
}
}
Loading