From e919567323ce9e66ac625b9de786958911f41dab Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Tue, 24 Nov 2015 17:30:36 +0800 Subject: [PATCH 1/2] Give more details about js require. Native developers may get confused by require statement. --- docs/NativeModulesAndroid.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/NativeModulesAndroid.md b/docs/NativeModulesAndroid.md index dbbcd0cd3..8ce2ef3d2 100644 --- a/docs/NativeModulesAndroid.md +++ b/docs/NativeModulesAndroid.md @@ -142,10 +142,12 @@ var { NativeModules } = require('react-native'); module.exports = NativeModules.ToastAndroid; ``` -Now, from your JavaScript file you can call the method like this: +Save the above code into a file named "ToastAndroid.js". Now, from your other JavaScript file you can call the method like this: ```js -var ToastAndroid = require('ToastAndroid') +// Suppose this js file is under the same directory as ToastAndroid.js. +// Otherwise change the require path. +var ToastAndroid = require('./ToastAndroid'); ToastAndroid.show('Awesome', ToastAndroid.SHORT); // Note: We require ToastAndroid without any relative filepath because From a1077ba6e9eae571285db9ac561ecaf6550ec49e Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Mon, 14 Dec 2015 15:10:00 +0800 Subject: [PATCH 2/2] remove the undocumented @provideModules Using relative file path --- docs/NativeModulesAndroid.md | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/docs/NativeModulesAndroid.md b/docs/NativeModulesAndroid.md index 8ce2ef3d2..56a8c2f83 100644 --- a/docs/NativeModulesAndroid.md +++ b/docs/NativeModulesAndroid.md @@ -125,12 +125,7 @@ mReactInstanceManager = ReactInstanceManager.builder() To make it simpler to access your new functionality from JavaScript, it is common to wrap the native module in a JavaScript module. This is not necessary but saves the consumers of your library the need to pull it off of `NativeModules` each time. This JavaScript file also becomes a good location for you to add any JavaScript side functionality. ```js -/** - * @providesModule ToastAndroid - */ - 'use strict'; - /** * This exposes the native ToastAndroid module as a JS module. This has a function 'show' * which takes the following parameters: @@ -142,16 +137,12 @@ var { NativeModules } = require('react-native'); module.exports = NativeModules.ToastAndroid; ``` -Save the above code into a file named "ToastAndroid.js". Now, from your other JavaScript file you can call the method like this: +Now, from your other JavaScript file you can call the method like this: ```js -// Suppose this js file is under the same directory as ToastAndroid.js. -// Otherwise change the require path. var ToastAndroid = require('./ToastAndroid'); -ToastAndroid.show('Awesome', ToastAndroid.SHORT); -// Note: We require ToastAndroid without any relative filepath because -// of the @providesModule directive. Using @providesModule is optional. +ToastAndroid.show('Awesome', ToastAndroid.SHORT); ``` ## Beyond Toasts