From e6ef0358875cb185ad1c7f6b81585e74dfa41d57 Mon Sep 17 00:00:00 2001 From: Ted de Koning Date: Sat, 14 Oct 2017 17:15:44 -0700 Subject: [PATCH] Android event documentation - Adding part about mapping event names. Summary: 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 --- docs/NativeComponentsAndroid.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/NativeComponentsAndroid.md b/docs/NativeComponentsAndroid.md index 463a3b52b6c4dd..5d0a96e2fc8087 100644 --- a/docs/NativeComponentsAndroid.md +++ b/docs/NativeComponentsAndroid.md @@ -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 { + ... + 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