Skip to content

feat: Allow brownfield iOS apps to handle storage. #35

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 16 commits into from
Apr 10, 2019

Conversation

tido64
Copy link
Member

@tido64 tido64 commented Mar 11, 2019

Summary:

Adds a delegate property to RNCAsyncStorage to allow custom handling of storage.

Implements #33.

Test Plan:

To manually test the delegate, shake the Simulator (^⌘Z) and toggle
"Set AsyncStorage Delegate". Otherwise, tests for JS have been duplicated for
the native delegate.

@tido64 tido64 force-pushed the tonguye/ios-delegate branch from 7e36847 to c8260fc Compare March 13, 2019 20:18
@tido64 tido64 marked this pull request as ready for review March 13, 2019 20:19
@tido64
Copy link
Member Author

tido64 commented Mar 13, 2019

@krizzu: How are you testing RNCAsyncStorage? I had to patch AsyncStorage.js to get the correct implementation:

diff --git a/lib/AsyncStorage.js b/lib/AsyncStorage.js
index 4769097..6c007d8 100644
--- a/lib/AsyncStorage.js
+++ b/lib/AsyncStorage.js
@@ -18,6 +18,7 @@ const {NativeModules} = require('react-native');
 const RCTAsyncStorage =
   NativeModules.AsyncRocksDBStorage ||
   NativeModules.RNC_AsyncSQLiteDBStorage ||
+  NativeModules.RNCAsyncStorage ||
   NativeModules.AsyncLocalStorage;

 type ReadOnlyArrayString = $ReadOnlyArray<string>;

@tido64 tido64 force-pushed the tonguye/ios-delegate branch from c8260fc to af7c6c1 Compare March 13, 2019 20:32
@tido64 tido64 changed the title iOS: Allow brownfield apps to handle storage. feat: Allow brownfield iOS apps to handle storage. Mar 13, 2019
@tido64
Copy link
Member Author

tido64 commented Mar 13, 2019

@krizzu: Also, it seems that in making it possible to run from Xcode, I broke Detox builds. Any suggestions here?

@tido64 tido64 force-pushed the tonguye/ios-delegate branch from af7c6c1 to 63310d2 Compare March 13, 2019 21:19
@tido64
Copy link
Member Author

tido64 commented Mar 13, 2019

Never mind. Figured out why Detox broke. 😁

@tido64
Copy link
Member Author

tido64 commented Mar 13, 2019

For the first question: #37

@krizzu
Copy link
Member

krizzu commented Mar 14, 2019

@tido64
This had to come up when we've changed naming on iOS side (some issues with camel case naming).

Your changes are already merged, so feel free to rebase.

@tido64 tido64 force-pushed the tonguye/ios-delegate branch from 63310d2 to 70478df Compare March 14, 2019 07:42
@tido64
Copy link
Member Author

tido64 commented Mar 14, 2019

@krizzu Thanks 👍

@tido64
Copy link
Member Author

tido64 commented Mar 25, 2019

@krizzu Let me know how I can make this PR better 😉

@krizzu
Copy link
Member

krizzu commented Mar 25, 2019

@tido64 Great, thanks!

I'm going to need a second pair of eyes on iOS code, but overall looks good. We could have some documentation about new feature - ideally in new doc file in docs directory.

Also, some tests would be good to check it too.

@krizzu krizzu added enhancement New feature or request platform: iOS This is iOS specific labels Mar 25, 2019
@krizzu
Copy link
Member

krizzu commented Mar 26, 2019

@tido64 Sorry for conflict that arised from merging #46.

@zhongwuzw
Copy link

@krizzu LGTM. I think we only need to add some tests and docs. 🤔

@tido64 tido64 force-pushed the tonguye/ios-delegate branch from 42d6597 to fe8ceda Compare March 26, 2019 22:53
@tido64
Copy link
Member Author

tido64 commented Mar 27, 2019

@krizzu @zhongwuzw I added docs and tests. Please have a look 😄

@krizzu
Copy link
Member

krizzu commented Mar 27, 2019

@tido64 Thanks! I'll have a look once I find a time later today

Copy link
Member

@krizzu krizzu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @tido64 , thanks for your awesome work!

I left few comments/suggestion that I think would be great to consider.

Also, I might be missing here somewhere, but I assumed that this "delegation" would work as a "plugin" for iOS module, where you change underlying implementation of AsyncStorage - you provide "object" with methods named same as original AsyncStorage , so those would be used instead.

In here, I believe you created a delegate in App delegate for testing purposes, correct?

thanks.

Copy link
Member Author

@tido64 tido64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look, @krizzu. I'll try to get to these within the week.

I'm not sure I follow your questions so bear with me 😄

  • Yes, a delegate is basically just an object with named functions. The interface is usually defined by the one that will be calling it.
  • The methods of AsyncStorage are never replaced. But it can be redirected to call the delegate instead. And if the passthrough property is set, the methods of AsyncStorage are still called.
  • In the test app, the AppDelegate implements this interface for testing purposes. In a normal app, usually another object would implement it.

@tido64 tido64 force-pushed the tonguye/ios-delegate branch 4 times, most recently from 9d6a0ad to 5411c4c Compare April 8, 2019 07:56
@tido64 tido64 force-pushed the tonguye/ios-delegate branch from 5411c4c to 3197ae1 Compare April 8, 2019 18:09
Copy link
Member

@krizzu krizzu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Thanks you! 💪 🚀

@tido64 tido64 merged commit a30fc51 into react-native-async-storage:master Apr 10, 2019
@tido64 tido64 deleted the tonguye/ios-delegate branch April 10, 2019 08:56
@stigi
Copy link

stigi commented Apr 12, 2019

Hi team,

just a heads up that this breaks native linking via cocoapods, as the library is linked as react-native-async-storage and expects imports of headers as #import <react-native-async-storage/RNCAsyncStorageDelegate.h> and not #import <RNCAsyncStorage/RNCAsyncStorageDelegate.h>.

There are two ways to move forward:

  • change the import to #import <react-native-async-storage/RNCAsyncStorageDelegate.h>
  • rename the pod (name of .podspec file and value of s.name) to RNCAsyncStorage

Let me know, I'd be happy to put up a PR

@krizzu
Copy link
Member

krizzu commented Apr 12, 2019

@stigi Thanks for heads up!

I'm happy to go with the first approach. WDYT @tido64 ?

@stigi
Copy link

stigi commented Apr 12, 2019

The second approach also requires the current user of cocoa pod linking to update their Podfiles, so option 1 is less intrusive, even though cringe seeing the import from <react-native-async-storage...> :neckbeard:

@tido64
Copy link
Member Author

tido64 commented Apr 12, 2019 via email

@lightman73
Copy link

First, thank you, you just saved me. I spent the last hour trying to understand why the hell Xcode wasn't finding RNCAsyncStorageDelegate.h ...

I manually implemented solution #1 and it's building everything as expected.

That said, I vote for #2 as well. Although it is breaking on upgrade, it's the cleanest solution, imho.

Thank again !

@krizzu
Copy link
Member

krizzu commented Apr 12, 2019

Okay, seems like we made a decision.
Just to be clear: what steps would have to be taken to successfully upgrade with solution 2?

@tido64
Copy link
Member Author

tido64 commented Apr 12, 2019

Somebody correct me if I'm mistaken, but if you're using react-native link, isn't it just a matter of re-linking it? We use manual linking at work so we would just fix the relevant line in our Podfile.

@tido64
Copy link
Member Author

tido64 commented Apr 13, 2019

@krizzu @stigi Sorry, I got a little impatient since I broke this release. I've implemented the fix here: #75. I've checked that react-native link will pick up the new .podspec but it won't clean up the old one. We will unfortunately have to ask users to go into their Podfile and make manual changes. 😞

krizzu pushed a commit that referenced this pull request Apr 14, 2019
Summary:
---------

Multiple people have reported that RNCAsyncStorage fails to build after #35. See #35 (comment), #73, and #74.

After a little discussion, we agreed to rename the `.podspec` and the name of the Pod to be more in line with Apple's naming guidelines and the rest of the community. Unfortunately, this means that the next upgrade will break.

I got a little impatient knowing that I broke the latest release so I went ahead and implemented the fix. Sorry if you've already started looking at this.

Migration Plan:
---------------

Even though `react-native link` will be able to link the new `.podspec`, it won't clean up existing entries. Please find your Podfile, and make the following changes:

```diff
- pod 'react-native-async-storage', :path => '../node_modules/@react-native-community/async-storage'
+ pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'
```
Corey-Peyton added a commit to Corey-Peyton/async-storage that referenced this pull request Jul 14, 2021
Summary:
---------

Multiple people have reported that RNCAsyncStorage fails to build after #35. See react-native-async-storage/async-storage#35 (comment), #73, and #74.

After a little discussion, we agreed to rename the `.podspec` and the name of the Pod to be more in line with Apple's naming guidelines and the rest of the community. Unfortunately, this means that the next upgrade will break.

I got a little impatient knowing that I broke the latest release so I went ahead and implemented the fix. Sorry if you've already started looking at this.

Migration Plan:
---------------

Even though `react-native link` will be able to link the new `.podspec`, it won't clean up existing entries. Please find your Podfile, and make the following changes:

```diff
- pod 'react-native-async-storage', :path => '../node_modules/@react-native-community/async-storage'
+ pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'
```
DenisSolution pushed a commit to DenisSolution/React-native-async-storage that referenced this pull request Aug 27, 2022
Summary:
---------

Multiple people have reported that RNCAsyncStorage fails to build after #35. See react-native-async-storage/async-storage#35 (comment), #73, and #74.

After a little discussion, we agreed to rename the `.podspec` and the name of the Pod to be more in line with Apple's naming guidelines and the rest of the community. Unfortunately, this means that the next upgrade will break.

I got a little impatient knowing that I broke the latest release so I went ahead and implemented the fix. Sorry if you've already started looking at this.

Migration Plan:
---------------

Even though `react-native link` will be able to link the new `.podspec`, it won't clean up existing entries. Please find your Podfile, and make the following changes:

```diff
- pod 'react-native-async-storage', :path => '../node_modules/@react-native-community/async-storage'
+ pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request platform: iOS This is iOS specific
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants