Skip to content

Commit

Permalink
chore(sqlite-storage): merge to main (#1082)
Browse files Browse the repository at this point in the history
sqlite-storage: scaffold workspace (#1071)

* chore(deps): bump follow-redirects from 1.15.4 to 1.15.6 (#1074)

* feat(default-storage): Add Privacy Manifest for iOS (#1075)

privacy file

* chore(release): 1.23.0 [skip ci]

* fix(default-storage): Privacy manifest missing key (#1076)

add missing key

* chore(release): 1.23.1 [skip ci]

* chore(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 (#1077)

Bumps [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) from 5.3.3 to 5.3.4.
- [Release notes](https://github.com/webpack/webpack-dev-middleware/releases)
- [Changelog](https://github.com/webpack/webpack-dev-middleware/blob/v5.3.4/CHANGELOG.md)
- [Commits](webpack/webpack-dev-middleware@v5.3.3...v5.3.4)

---
updated-dependencies:
- dependency-name: webpack-dev-middleware
  dependency-type: indirect
...




* chore: GH workflows, turbo and other chores (#1073)

* explicit prettierrc

* turbo

* format test

* pull-request workflow

* update actions

* bump to yarn 4

* build script

* init

* examples

* comments

* fix glob

* namespace

* windows build

* fixing windows action

* android example search for node_modules

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: AsyncStorageBot <118817110+AsyncStorageBot@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 10, 2024
1 parent d4a3eee commit 1e2518e
Show file tree
Hide file tree
Showing 43 changed files with 4,424 additions and 140 deletions.
9 changes: 9 additions & 0 deletions .github/actions/setup-project/action.yml
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
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
Expand Up @@ -31,3 +31,4 @@ local.properties
#workspaces
/packages/*/lib
.turbo
build/
2 changes: 1 addition & 1 deletion packages/default-storage/package.json
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,5 @@
SqliteStorage_kotlinVersion=1.7.0
SqliteStorage_minSdkVersion=21
SqliteStorage_targetSdkVersion=31
SqliteStorage_compileSdkVersion=31
SqliteStorage_ndkversion=21.4.7075529
3 changes: 3 additions & 0 deletions packages/sqlite-storage/android/src/main/AndroidManifest.xml
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.rnasyncstorage.sqlitestorage">
</manifest>
@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
@@ -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"
}
}
@@ -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
@@ -0,0 +1,3 @@
module.exports = {
presets: ["module:@react-native/babel-preset"],
};
1 change: 1 addition & 0 deletions packages/sqlite-storage/eslint.config.js
@@ -0,0 +1 @@
module.exports = require("@react-native-async-storage/eslint-config");
1 change: 1 addition & 0 deletions packages/sqlite-storage/example/.watchmanconfig
@@ -0,0 +1 @@
{}
70 changes: 70 additions & 0 deletions packages/sqlite-storage/example/App.tsx
@@ -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
@@ -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()
}
}

0 comments on commit 1e2518e

Please sign in to comment.