IReactContext
Kind: interface
The IReactContext
object is a weak pointer to the React instance. It allows native modules and view managers to communicate with the application, and with other native modules and view managers.
Since the IReactContext
is a weak pointer to the React instance, some of its functionality becomes unavailable after the React instance is unloaded. When a React instance is reloaded inside of the ReactNativeHost
, the previous React instance is unloaded and then a new React instance is created with a new IReactContext
.
- Use the
Properties
to share native module's data with other components. - Use the
Notifications
to exchange events with other components. - Use
CallJSFunction
to call JavaScript functions, andEmitJSEvent
to raise JavaScript events. - Use
UIDispatcher
to post asynchronous work in the UI thread. - Use
JSDispatcher
to post asynchronous work in the JavaScript engine thread.
Properties
JSDispatcher
readonly
IReactDispatcher
JSDispatcher
Gets the JavaScript engine thread dispatcher.
It is a shortcut for the ReactDispatcherHelper.JSDispatcherProperty
from the Properties
property bag.
JSRuntime
readonly
Object JSRuntime
Gets the JavaScript runtime for the running React instance. It can be null if Web debugging is used. **Note: do not use this property directly. It is an experimental property that may be removed or changed in version 0.65.
Notifications
readonly
IReactNotificationService
Notifications
Gets IReactNotificationService
shared with the ReactInstanceSettings.Notifications
.
It can be used to send notifications events between components and the application.
All notification subscriptions added to the IReactContext.Notifications
are automatically removed after the IReactContext
is destroyed.
The notification subscriptions added to the ReactInstanceSettings.Notifications
are kept as long as the ReactInstanceSettings
is alive.
Properties
readonly
IReactPropertyBag
Properties
Gets IReactPropertyBag
shared with the ReactInstanceSettings.Properties
.
It can be used to share values and state between components and the applications.
SettingsSnapshot
readonly
IReactSettingsSnapshot
SettingsSnapshot
Gets the settings snapshot that was used to start the React instance.
UIDispatcher
readonly
IReactDispatcher
UIDispatcher
Gets the UI thread dispatcher.
It is a shortcut for the ReactDispatcherHelper.UIDispatcherProperty
from the Properties
property bag.
Methods
CallJSFunction
void CallJSFunction
(string moduleName, string methodName, JSValueArgWriter
paramsArgWriter)
Calls the JavaScript function named methodName
of moduleName
with the paramsArgWriter
.
The paramsArgWriter
is a JSValueArgWriter
delegate that receives IJSValueWriter
to serialize the method parameters.
DispatchEvent
void DispatchEvent
(FrameworkElement
view, string eventName, JSValueArgWriter
eventDataArgWriter)
Deprecated: Use
XamlUIService.DispatchEvent
instead
Deprecated property. Use XamlUIService.DispatchEvent
instead. It will be removed in version 0.65.
EmitJSEvent
void EmitJSEvent
(string eventEmitterName, string eventName, JSValueArgWriter
paramsArgWriter)
Emits JavaScript module event eventName
for the eventEmitterName
with the paramsArgWriter
.
It is a specialized CallJSFunction
call where the method name is always
emitand the
eventNameis added to parameters. The
paramsArgWriteris a [
JSValueArgWriter](JSValueArgWriter) delegate that receives [
IJSValueWriter`](IJSValueWriter) to serialize the event parameters.