Skip to main content
Version: 0.83

IReactContext

New Architecture​

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, and EmitJSEvent 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​

CallInvoker​

readonly CallInvoker CallInvoker

used to schedule work on the JS runtime. Most direct usage of this should be avoided by using ReactContext.CallInvoker.

JSDispatcher​

readonly IReactDispatcher JSDispatcher

Deprecated: Use IReactContext.CallInvoker instead

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 will be removed in a future version. Deprecated for new Arch: Use IReactContext.CallInvoker instead.

LoadingState​

readonly LoadingState LoadingState

Gets the state of the ReactNative instance.

Notifications​

readonly IReactNotificationService Notifications

Gets the 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 the 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.

EmitJSEvent​

void EmitJSEvent(string eventEmitterName, string eventName, JSValueArgWriter paramsArgWriter)

Emits JavaScript module event eventName for the eventEmitterName with the paramsArgWriter. It is a specialized CallJSFunctioncall where the method name is alwaysemitand theeventNameis added to parameters. TheparamsArgWriter is a [JSValueArgWriter](JSValueArgWriter) delegate that receives [IJSValueWriter`](IJSValueWriter) to serialize the event parameters.

Referenced by​

Old Architecture​

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, and EmitJSEvent 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​

CallInvoker​

readonly CallInvoker CallInvoker

used to schedule work on the JS runtime. Most direct usage of this should be avoided by using ReactContext.CallInvoker.

JSDispatcher​

readonly IReactDispatcher JSDispatcher

Deprecated: Use IReactContext.CallInvoker instead

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 will be removed in a future version. Deprecated for new Arch: Use IReactContext.CallInvoker instead.

LoadingState​

readonly LoadingState LoadingState

Gets the state of the ReactNative instance.

Notifications​

readonly IReactNotificationService Notifications

Gets the 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 the 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 a future version.

EmitJSEvent​

void EmitJSEvent(string eventEmitterName, string eventName, JSValueArgWriter paramsArgWriter)

Emits JavaScript module event eventName for the eventEmitterName with the paramsArgWriter. It is a specialized CallJSFunctioncall where the method name is alwaysemitand theeventNameis added to parameters. TheparamsArgWriter is a [JSValueArgWriter](JSValueArgWriter) delegate that receives [IJSValueWriter`](IJSValueWriter) to serialize the event parameters.

Referenced by​