This differential implements CommServicesAuthMetadataEmitter on Android in such a way that it callable from C++.
Details
- Apply this patch: https://gist.github.com/marcinwasowicz/7f04bd592dd4a800adbc96b720e200b7. It creates js code to subscribe for auth metadata events and sends this event from C++ upon each draft update (contents of the event are just dummy strings).
- Build Android app.
- Ensure that each time you write one letter you can see console.log with dummy auth metadata in native yarn dev terminal.
Diff Detail
- Repository
- rCOMM Comm
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Same as for iOS diff:
React native requires that event emitter is an instance of a class. On the other hand in order to smoothly call this object from Rust we need static method. Therefore I decided to use Singleton pattern for Rust <-> C++ interop. Object that is available to for C++ and Rust is set when the first JS listener subscribes and is removed when the last listener unsubscribes. This way we ensure that Rust/C++ won't try to send event if value under sharedInstance might be invalid. All calls that access or mutate sharedInstance are synchronized on class level.
For this differential important files are: CommServicesAuthMetadataEmitter.cpp and CommServicesAuthMetadataEmitter.java. Other files are pure boilerplate necessary to expose module to JS.
Reviewers can quickly and easily familiarise themselves with event emitter implementation on Android by reading the docs: https://reactnative.dev/docs/native-modules-android#sending-events-to-javascript