Calling javascript funtion on pressing Native Windows Xaml Button #11448
-
I have a button which is created on XAML in UWP Windows app. I want to achieve functionality that when I press on Xaml button then the javascript function from React Native will be called and axios api will be called from the function. Note: I have achieved this functionality in Android, IOS and MacOS. I want to achieve it in windows. The problem I am facing is that I am getting null in ReactContext. In Android, I was able to get the current React Context through this statement: JAVA: For this I need ReactInstanceManager. But in windows, I am unable to see this ReactInstanceManager. I have creating a NativeButtonHandler.cs class in which I want to achieve this funtionality. I am calling it from ButtonOnPress inside Main.xaml.cs I want to use EventEmitter in windows for this functionality. I see that the ReactContext has a function named EmitJSEvent. But my windows app is crashing on pressing the button as it is getting reactcontext = null. Any help would be appreciated. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can get the |
Beta Was this translation helpful? Give feedback.
Something like:
In App.xaml.cs:
void InstanceCreated(object sender, InstanceCreatedEventArgs args)
{
this.ReactContext = args.Context;
}
public IReactContext ReactContext {get; set;}
In App()
add:
InstanceSettings.InstanceCreated += InstanceCreated
Then in your button handler you can use (Application.Current as App).ReactContext