Android event documentation - Adding part about mapping event names.

Summary:
<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.

Help us understand your motivation by explaining why you decided to make this change.

You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html

Happy contributing!

-->

I was quite lost when the documentation told me to go figure the event mapping out myself. It took me quite a while to figure out that i needed to register the names in the `ViewManager`.

This code snippet just makes it way easier to figure out what you need to do to add events.
Closes https://github.com/facebook/react-native/pull/16293

Differential Revision: D6060595

Pulled By: ericnakagawa

fbshipit-source-id: c4755cdb8d99797ff5248ec4eb7e58e2f7ac2588
This commit is contained in:
Ted de Koning 2017-10-14 17:15:44 -07:00 committed by Facebook Github Bot
parent b9e141e900
commit e6ef035887

View File

@ -144,7 +144,24 @@ class MyCustomView extends View {
}
```
The event name `topChange` maps to the `onChange` callback prop in JavaScript (mappings are in `UIManagerModuleConstants.java`). This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:
To map the `topChange` event name to the `onChange` callback prop in JavaScript, register it by overriding the `getExportedCustomBubblingEventTypeConstants` method in your `ViewManager`:
```java
public class ReactImageManager extends SimpleViewManager<MyCustomView> {
...
public Map getExportedCustomBubblingEventTypeConstants() {
return MapBuilder.builder()
.put(
"topChange",
MapBuilder.of(
"phasedRegistrationNames",
MapBuilder.of("bubbled", "onChange")))
.build();
}
}
```
This callback is invoked with the raw event, which we typically process in the wrapper component to make a simpler API:
```js
// MyCustomView.js