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

init method return promise, but it is used as sync in example #72

Open
punksta opened this issue Jan 10, 2018 · 2 comments
Open

init method return promise, but it is used as sync in example #72

punksta opened this issue Jan 10, 2018 · 2 comments

Comments

@punksta
Copy link

punksta commented Jan 10, 2018

_twitterSignIn = () => {
RNTwitterSignIn.init(Constants.TWITTER_COMSUMER_KEY, Constants.TWITTER_CONSUMER_SECRET)
RNTwitterSignIn.logIn()
.then(loginData => {
console.log(loginData)
const { authToken, authTokenSecret } = loginData
if (authToken && authTokenSecret) {
this.setState({
isLoggedIn: true
})
}
})
.catch(error => {
console.log(error)
}
)

public void init(String consumerKey, String consumerSecret, Promise promise) {
TwitterConfig config = new TwitterConfig.Builder(this.reactContext)
.logger(new DefaultLogger(Log.DEBUG))
.twitterAuthConfig(new TwitterAuthConfig(consumerKey, consumerSecret))
.debug(true)
.build();
Twitter.initialize(config);
WritableMap map = Arguments.createMap();
promise.resolve(map);
}

I am not sure, but looks like possible issue is here.
Also: better to wrap init into try {} catch() {} to avoid uncathed native crashes

@jslz
Copy link

jslz commented Jun 21, 2018

+1 I think this is confusing at least, and maybe buggy at worst.

https://github.com/facebook/react-native/blob/master/React/Base/RCTBridgeModule.h#L133

https://github.com/GoldenOwlAsia/react-native-twitter-signin/blob/master/ios/RNTwitterSignIn.m#L23

The init() should invoke the resolve or reject, or should be written to not look like it uses promises at all?

@frncs-eu
Copy link

frncs-eu commented Feb 5, 2019

I've stumbled into this problem today, and i've spent 4 hours straight debugging my own code, trying to understand why the init was resolving in Android but not on iOS.
I then took a look inside the plugin code...
The java implementation does indeed work correctly as a promise, while in the obj-C code the resolve parameter is never executed at all:

RCT_EXPORT_METHOD(init: (NSString *)consumerKey consumerSecret:(NSString *)consumerSecret resolver:(RCTPromiseResolveBlock)resolve  
rejecter:(RCTPromiseRejectBlock)reject)
{
    [[Twitter sharedInstance] startWithConsumerKey:consumerKey consumerSecret:consumerSecret];
}

I assume this is wrong, as the js interface should be identical between the two platforms.
Let me know if I can be of any help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants