Skip to content

Commit

Permalink
Android event documentation - Adding part about mapping event names.
Browse files Browse the repository at this point in the history
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 #16293

Differential Revision: D6060595

Pulled By: ericnakagawa

fbshipit-source-id: c4755cdb8d99797ff5248ec4eb7e58e2f7ac2588
  • Loading branch information
tdekoning authored and facebook-github-bot committed Oct 15, 2017
1 parent b9e141e commit e6ef035
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion docs/NativeComponentsAndroid.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e6ef035

Please sign in to comment.