Skip to content

Commit 7c1d1a7

Browse files
committed
Update NativeModulesWindows.md (microsoft#462)
1 parent da615d8 commit 7c1d1a7

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

docs/NativeModulesWindows.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ permalink: docs/native-modules-windows.html
77
next: native-components-windows
88
---
99

10-
Sometimes an app needs access to a platform API that React Native doesn't have a corresponding module for yet. Maybe you want to reuse some existing .NET code without having to reimplement it in JavaScript, or write some high performance, multi-threaded code such as for image processing, a database, or any number of advanced extensions.
10+
Sometimes an app needs access to a platform API that React Native doesn't have a corresponding module for yet. Maybe you want to reuse some existing .NET code without having to reimplement it in JavaScript, or write some high performance, multi-threaded code for image processing, a database, or any number of advanced extensions.
1111

1212
React Native was designed such that it is possible for you to write real native code and have access to the full power of the platform. This is a more advanced feature and we don't expect it to be part of the usual development process, however it is essential that it exists. If React Native doesn't support a native feature that you need, you should be able to build it yourself.
1313

@@ -95,7 +95,7 @@ public override IReadOnlyDictionary<string, object> Constants
9595
}
9696
```
9797

98-
To expose a method to JavaScript a .NET method must be annotated using the `[ReactMethod]` attribute. The return type of bridge methods is always `void`. React Native bridge is asynchronous, so the only way to pass a result to JavaScript is by using callbacks or emitting events (see below).
98+
To expose a method to JavaScript a .NET method must be annotated using the `[ReactMethod]` attribute. The return type of bridge methods is always `void`. The React Native bridge is asynchronous, so the only way to pass a result to JavaScript is by using callbacks or emitting events (see below).
9999

100100
```csharp
101101
[ReactMethod]
@@ -142,22 +142,16 @@ public void showAlert(
142142
}
143143
});
144144
}
145+
146+
private void OnInvoked(IUICommand target, ICallback callback)
147+
{
148+
callback.Invoke(ActionButtonClicked, target.Id);
149+
}
145150
```
146151

147152
### Argument Types
148153

149-
The following argument types are supported for methods annotated with the `[ReactMethod]` attribute and they directly map to their JavaScript equivalents. Note that this project uses [Newtonsoft Json.NET](http://www.newtonsoft.com/json) to provide interoperability with JavaScript types.
150-
151-
```
152-
Boolean -> Bool
153-
Integer -> Number
154-
Double -> Number
155-
Float -> Number
156-
String -> String
157-
ICallback -> function
158-
JValue -> Object
159-
JArray -> Array
160-
```
154+
This project uses [Newtonsoft Json.NET](http://www.newtonsoft.com/json) to provide interoperability with JavaScript types. The parameter types of a `[ReactMethod]` may be of any type that can be deserialized using Json.NET. Be aware that the use of composite types such as arrays, generics, and user-defined classes may not be supported out-of-the-box with [.NET Native](https://msdn.microsoft.com/en-us/library/dn584397.aspx) pre-compilation, and you may need add information to the [runtime directives (rd.xml)](https://msdn.microsoft.com/en-us/library/dn600639.aspx) file, or just manually deconstruct the JSON by using [`JArray`](http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JArray.htm) or [`JObject`](http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Linq_JObject.htm) as the parameter types.
161155

162156
### Register the Module
163157

@@ -327,7 +321,9 @@ public async void canOpenURL(string url, IPromise promise)
327321

328322
try
329323
{
330-
var support = await Launcher.QueryUriSupportAsync(uri, LaunchQuerySupportType.Uri).AsTask().ConfigureAwait(false);
324+
var support = await Launcher
325+
.QueryUriSupportAsync(uri, LaunchQuerySupportType.Uri)
326+
.AsTask().ConfigureAwait(false);
331327
promise.Resolve(support == LaunchQuerySupportStatus.Available);
332328
}
333329
catch (Exception ex)
@@ -409,9 +405,9 @@ componentWillMount: function() {
409405
...
410406
```
411407
412-
### Listening to LifeCycle events
408+
### Listening to Life Cycle Events
413409
414-
Listening to the activity's LifeCycle events such as `OnSuspend`, `OnResume` etc. may be important to your application. In order to listen to these events, the module must implement the `ILifecycleEventListener` interface. Then, you need to register a listener in the module's `Initialize` method.
410+
Listening to the application's life cycle events such as `OnSuspend`, `OnResume` etc. may be important to your application. In order to listen to these events, the module must implement the `ILifecycleEventListener` interface. Then, you need to register a listener in the module's `Initialize` method.
415411
416412
```csharp
417413
public override void Initialize()
@@ -420,21 +416,21 @@ public override void Initialize()
420416
}
421417
```
422418
423-
Now you can listen to the activity's LifeCycle events by implementing the following methods:
419+
Now you can listen to the application's life cycle events by implementing the following methods:
424420
425421
```csharp
426422
public void OnSuspend()
427423
{
428-
// Activity OnSuspend
424+
// Application Suspending
429425
}
430426

431427
public async void OnResume()
432428
{
433-
// Activity OnResume
429+
// Application Resuming
434430
}
435431

436432
public void OnDestroy()
437433
{
438-
// Activity OnDestroy
434+
// Application Terminating
439435
}
440-
```
436+
```

0 commit comments

Comments
 (0)