Merge pull request #4318 from sunnylqm/patch-10
Give more details about js require.
This commit is contained in:
commit
bfab7cdcd9
|
@ -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.
|
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
|
```js
|
||||||
/**
|
|
||||||
* @providesModule ToastAndroid
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This exposes the native ToastAndroid module as a JS module. This has a function 'show'
|
* This exposes the native ToastAndroid module as a JS module. This has a function 'show'
|
||||||
* which takes the following parameters:
|
* which takes the following parameters:
|
||||||
|
@ -142,14 +137,12 @@ var { NativeModules } = require('react-native');
|
||||||
module.exports = NativeModules.ToastAndroid;
|
module.exports = NativeModules.ToastAndroid;
|
||||||
```
|
```
|
||||||
|
|
||||||
Now, from your JavaScript file you can call the method like this:
|
Now, from your other JavaScript file you can call the method like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var ToastAndroid = require('ToastAndroid')
|
var ToastAndroid = require('./ToastAndroid');
|
||||||
ToastAndroid.show('Awesome', ToastAndroid.SHORT);
|
|
||||||
|
|
||||||
// Note: We require ToastAndroid without any relative filepath because
|
ToastAndroid.show('Awesome', ToastAndroid.SHORT);
|
||||||
// of the @providesModule directive. Using @providesModule is optional.
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Beyond Toasts
|
## Beyond Toasts
|
||||||
|
|
Loading…
Reference in New Issue