Skip to content

Allow JS init with param app Id #72

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 6 commits into from
Oct 14, 2020

Conversation

podotki
Copy link
Contributor

@podotki podotki commented Sep 15, 2020

Hi !

As the title says, just add handling of the parameter app Id at the init.
Let me know if it's ok for you.
This is not a big change and I think it can help a lot the community so feel free to update the code to be cleaner as I really wish that PR to be merged ;)

Thanks a lot :)

@fbartho
Copy link
Contributor

fbartho commented Sep 15, 2020

@podotki -- is this ready for review? -- It looks great already -- thanks for contributing!

@podotki
Copy link
Contributor Author

podotki commented Sep 15, 2020

Mmm I think there is an error as I don't know much about Objective-C neither Java...
I'm checking it ;)

@fbartho
Copy link
Contributor

fbartho commented Sep 29, 2020

At your leisure @podotki please let me know if you've got it working and this is ready for review!

@fbartho
Copy link
Contributor

fbartho commented Oct 7, 2020

@podotki I'm starting to think about a new release -- do you think this is ready for final review and testing?

@fbartho fbartho merged commit f7c387f into taskrabbit:main Oct 14, 2020
@fbartho
Copy link
Contributor

fbartho commented Oct 28, 2020

This code is available with other changes in https://www.npmjs.com/package/react-native-zendesk-chat/v/0.4.1-beta.4

@emkman
Copy link
Contributor

emkman commented Dec 4, 2020

@podotki @fbartho this breaks existing apps unfortunately. Despite the docs stating appId is optional, it is not declared that way in objective C and upgrading casues this error:

RNZendeskChatModule.init was called with 1 arguments but expects 2 arguments. If you haven't changed this method yourself, this usually means that your versions of the native code and JavaScript code are out of sync. Updating both should make this error go away.

-[RCTModuleMethod invokeWithBridge:module:arguments:]
    RCTModuleMethod.mm:549
facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&)
facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const
invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_lane_serial_drain
_dispatch_lane_invoke
_dispatch_workloop_worker_thread
_pthread_wqthread
start_wqthread

I had to change:
ZendeskChat.init(env.ZENDESK_ACCOUNT_KEY);
to
ZendeskChat.init(env.ZENDESK_ACCOUNT_KEY, null);
but I don't think this is the expected or desired behavior

@fbartho
Copy link
Contributor

fbartho commented Dec 4, 2020

@emkman -- that's strange. I'm not getting that error in our codebase -- indeed I only saw that error on Android and fixed it in the release branch.

What version of React-Native are you using?
Are you using Hermes?

@emkman
Copy link
Contributor

emkman commented Dec 4, 2020

@fbartho "react-native": "0.63.3", on iOS 14 in the simulator. Not using Hermes.

Looking at RNZendeskChatModule.m it seems like appId is a required string param of init now. I think you could change it from NSString to id or override the method with a second definition though I am not sure how that works with RCT_EXPORT tbh.

RCT_EXPORT_METHOD(init:(NSString *)zenDeskKey appId:(NSString *)appId) {
	if (appId) {
		[ZDKChat initializeWithAccountKey:zenDeskKey appId:appId queue:dispatch_get_main_queue()];
	} else {
		[ZDKChat initializeWithAccountKey:zenDeskKey queue:dispatch_get_main_queue()];
	}
}

@fbartho
Copy link
Contributor

fbartho commented Dec 4, 2020

I suspect maybe RN < 0.63.3 behaves differently, or something else was going on.

@emkman -- I don't think overrides work with RCT_EXPORT_METHOD
Regardless, if you want to fix it, I patched a similar thing for Android in this commit: 6906a29

So we could apply a similar patch for iOS.

If you're feeling up to it, in this PR I fixed a similar

@emkman
Copy link
Contributor

emkman commented Dec 4, 2020

So we could apply a similar patch for iOS.

If both OSes need this, does it make sense to keep using the Platform patch at the RN level? It might be cleaner to just implement separate init and initWithAppId methods.

@fbartho
Copy link
Contributor

fbartho commented Dec 4, 2020

@emkman I agree with what you're suggesting with a slight twist:

Instead of Platform.select, just always attach an init method:

RNZendeskChatModule.init = (key, appId) => {
 	return RNZendeskChatModule._initWith2Args(key, appId || null);
};

And define _initWith2Args on iOS as well as on Android

@emkman
Copy link
Contributor

emkman commented Dec 4, 2020

@fbartho this way would mean no changes are needed for Android, correct? Works for me.

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

Successfully merging this pull request may close these issues.

4 participants