From 0ba56eb1bcdb7fd37a61b51c92b7b16411ee3277 Mon Sep 17 00:00:00 2001 From: Alexander Kuttig Date: Tue, 6 Mar 2018 09:13:08 +0100 Subject: [PATCH 1/5] added promise to set and remove to/from bucket to make the async calls awaitable --- .../github/alinz/rnsk/bucket/BucketModule.java | 6 ++++-- ios/RNSKBucket/RNSKBucket.m | 8 ++++++-- lib/bucket/index.android.js | 14 +++++++++++--- lib/bucket/index.ios.js | 16 ++++++++++++---- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/com/github/alinz/rnsk/bucket/BucketModule.java b/android/src/main/java/com/github/alinz/rnsk/bucket/BucketModule.java index 2a7045d..c44ad0f 100644 --- a/android/src/main/java/com/github/alinz/rnsk/bucket/BucketModule.java +++ b/android/src/main/java/com/github/alinz/rnsk/bucket/BucketModule.java @@ -39,20 +39,22 @@ public void get(String key, String bucketName, Callback callback) { } @ReactMethod - public void set(String key, String value, String bucketName) { + public void set(String key, String value, String bucketName, Callback callback) { SharedPreferences preferences = getBucket(bucketName); SharedPreferences.Editor editor = preferences.edit(); editor.putString(key, value); editor.commit(); + callback.invoke(); } @ReactMethod - public void remove(String key, String bucketName) { + public void remove(String key, String bucketName, Callback callback) { SharedPreferences preferences = getBucket(bucketName); SharedPreferences.Editor editor = preferences.edit(); editor.remove(key); editor.commit(); + callback.invoke(); } } diff --git a/ios/RNSKBucket/RNSKBucket.m b/ios/RNSKBucket/RNSKBucket.m index 0c140ae..b41349d 100644 --- a/ios/RNSKBucket/RNSKBucket.m +++ b/ios/RNSKBucket/RNSKBucket.m @@ -15,11 +15,13 @@ - (NSUserDefaults *)bucketByName:(NSString*)name { RCT_EXPORT_METHOD(set:(NSString *) key value:(NSString *) value - bucketName:(NSString*) bucketName) + bucketName:(NSString*) bucketName + callback:(RCTResponseSenderBlock)callback) { NSUserDefaults* bucket = [self bucketByName: bucketName]; [bucket setObject:value forKey:key]; [bucket synchronize]; + callback(@[NSNull null]); } RCT_EXPORT_METHOD(get:(NSString *) key @@ -37,11 +39,13 @@ - (NSUserDefaults *)bucketByName:(NSString*)name { } RCT_EXPORT_METHOD(remove:(NSString *) key - bucketName:(NSString*) bucketName) + bucketName:(NSString*) bucketName + callback:(RCTResponseSenderBlock)callback) { NSUserDefaults* bucket = [self bucketByName: bucketName]; [bucket removeObjectForKey: key]; [bucket synchronize]; + callback(@[NSNull null]); } @end diff --git a/lib/bucket/index.android.js b/lib/bucket/index.android.js index 52d36e7..93d729d 100644 --- a/lib/bucket/index.android.js +++ b/lib/bucket/index.android.js @@ -4,17 +4,25 @@ const { RNSKBucket } = NativeModules const Bucket = { set: (key, value, groupName) => { - RNSKBucket.set(key, value, groupName) + return new Promise(resolve => { + RNSKBucket.set(key, value, groupName, () => { + resolve() + }) + }) }, get: (key, groupName) => { - return new Promise((resolve, reject) => { + return new Promise(resolve => { RNSKBucket.get(key, groupName, (value) => { resolve(value) }) }) }, remove: (key, groupName) => { - RNSKBucket.remove(key, groupName) + return new Promise(resolve => { + RNSKBucket.remove(key, groupName, () => { + resolve() + }) + }) } } diff --git a/lib/bucket/index.ios.js b/lib/bucket/index.ios.js index 52d36e7..73062f4 100644 --- a/lib/bucket/index.ios.js +++ b/lib/bucket/index.ios.js @@ -4,18 +4,26 @@ const { RNSKBucket } = NativeModules const Bucket = { set: (key, value, groupName) => { - RNSKBucket.set(key, value, groupName) + return new Promise(resolve => { + RNSKBucket.set(key, value, groupName, () => { + resolve() + }) + }) }, get: (key, groupName) => { - return new Promise((resolve, reject) => { + return new Promise(resolve => { RNSKBucket.get(key, groupName, (value) => { resolve(value) }) }) }, remove: (key, groupName) => { - RNSKBucket.remove(key, groupName) + return new Promise(resolve => { + RNSKBucket.remove(key, groupName, () => { + resolve() + }) + }) } -} +}; export default Bucket From 60acda01c60a16ebef734257bf68005583688e02 Mon Sep 17 00:00:00 2001 From: Alexander Kuttig Date: Tue, 6 Mar 2018 09:19:12 +0100 Subject: [PATCH 2/5] fixed ios callback --- ios/RNSKBucket/RNSKBucket.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/RNSKBucket/RNSKBucket.m b/ios/RNSKBucket/RNSKBucket.m index b41349d..7c17877 100644 --- a/ios/RNSKBucket/RNSKBucket.m +++ b/ios/RNSKBucket/RNSKBucket.m @@ -21,7 +21,7 @@ - (NSUserDefaults *)bucketByName:(NSString*)name { NSUserDefaults* bucket = [self bucketByName: bucketName]; [bucket setObject:value forKey:key]; [bucket synchronize]; - callback(@[NSNull null]); + callback(NULL); } RCT_EXPORT_METHOD(get:(NSString *) key @@ -45,7 +45,7 @@ - (NSUserDefaults *)bucketByName:(NSString*)name { NSUserDefaults* bucket = [self bucketByName: bucketName]; [bucket removeObjectForKey: key]; [bucket synchronize]; - callback(@[NSNull null]); + callback(NULL); } @end From 0ff75c0b9e34efaab95805f845694ffe4ea966fd Mon Sep 17 00:00:00 2001 From: Alexander Kuttig Date: Wed, 19 Feb 2020 21:08:31 +0100 Subject: [PATCH 3/5] added pods to header search paths --- ios/RNSKBucket.xcodeproj/project.pbxproj | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ios/RNSKBucket.xcodeproj/project.pbxproj b/ios/RNSKBucket.xcodeproj/project.pbxproj index c661a50..f1f0f9f 100644 --- a/ios/RNSKBucket.xcodeproj/project.pbxproj +++ b/ios/RNSKBucket.xcodeproj/project.pbxproj @@ -210,7 +210,10 @@ 413522D21D18398B007ACD21 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../node_modules/react-native/React/**"; + HEADER_SEARCH_PATHS = ( + "$(SRCROOT)/../../../node_modules/react-native/React/**", + "$(SRCROOT)/../../../ios/Pods/**", + ); OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -220,7 +223,10 @@ 413522D31D18398B007ACD21 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - HEADER_SEARCH_PATHS = "$(SRCROOT)/../../../node_modules/react-native/React/**"; + HEADER_SEARCH_PATHS = ( + "$(SRCROOT)/../../../node_modules/react-native/React/**", + "$(SRCROOT)/../../../ios/Pods/**", + ); OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; From 6dd9796f8a03662ff5da36e3bc6c07a94f97c8d7 Mon Sep 17 00:00:00 2001 From: Alexander Kuttig Date: Wed, 26 Feb 2020 17:25:45 +0100 Subject: [PATCH 4/5] added podspec --- react-native-swiss-knife.podspec | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 react-native-swiss-knife.podspec diff --git a/react-native-swiss-knife.podspec b/react-native-swiss-knife.podspec new file mode 100644 index 0000000..20326a7 --- /dev/null +++ b/react-native-swiss-knife.podspec @@ -0,0 +1,19 @@ +require 'json' + +package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) + +Pod::Spec.new do |s| + s.name = "react-native-voice" + s.version = package['version'] + s.summary = package['description'] + s.license = package['license'] + + s.authors = package['author'] + s.homepage = package['homepage'] + s.platform = :ios, "9.0" + + s.source = { :git => "https://github.com/alexkuttig/react-native-swiss-knife.git" } + s.source_files = "ios/**/*.{h,m}" + + s.dependency 'React' +end From 00018670bdae6d1e42d65efbcd385305a1d9b295 Mon Sep 17 00:00:00 2001 From: Alexander Kuttig Date: Wed, 26 Feb 2020 17:28:30 +0100 Subject: [PATCH 5/5] added homepage & fixed path --- package.json | 1 + react-native-swiss-knife.podspec | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2b94d06..382ad2e 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "homepage": "https://github.com/alexkuttig/react-native-swiss-knife", "keywords": ["react-native", "react-component"], "author": "Ali Najafizadeh", "license": "MIT" diff --git a/react-native-swiss-knife.podspec b/react-native-swiss-knife.podspec index 20326a7..beda61b 100644 --- a/react-native-swiss-knife.podspec +++ b/react-native-swiss-knife.podspec @@ -3,7 +3,7 @@ require 'json' package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) Pod::Spec.new do |s| - s.name = "react-native-voice" + s.name = "react-native-swiss-knife" s.version = package['version'] s.summary = package['description'] s.license = package['license']