public JavaScriptModuleInvocationHandler( IReactInstance reactInstance, JavaScriptModuleRegistration moduleRegistration) { _reactInstance = reactInstance; _moduleRegistration = moduleRegistration; }
/// <summary> /// Invoke a method on a native module. /// </summary> /// <param name="reactInstance">The React instance.</param> /// <param name="moduleId">The module ID.</param> /// <param name="methodId">The method ID.</param> /// <param name="parameters">The parameters.</param> internal void Invoke( IReactInstance reactInstance, int moduleId, int methodId, JArray parameters) { if (moduleId < 0) { throw new ArgumentOutOfRangeException(nameof(moduleId), "Invalid module ID: " + moduleId); } if (_moduleTable.Count < moduleId) { throw new ArgumentOutOfRangeException(nameof(moduleId), "Call to unknown module: " + moduleId); } var actionQueue = _moduleTable[moduleId].Target.ActionQueue; if (actionQueue != null) { actionQueue.Dispatch(() => _moduleTable[moduleId].Invoke(reactInstance, methodId, parameters)); } else { _moduleTable[moduleId].Invoke(reactInstance, methodId, parameters); } }
private void AttachMeasuredRootViewToInstance( ReactRootView rootView, IReactInstance reactInstance) { DispatcherHelpers.AssertOnDispatcher(); // Reset view content as it's going to be populated by the // application content from JavaScript rootView.TouchHandler?.Dispose(); rootView.Children.Clear(); rootView.Tag = null; var uiManagerModule = reactInstance.GetNativeModule <UIManagerModule>(); var rootTag = uiManagerModule.AddMeasuredRootView(rootView); rootView.TouchHandler = new TouchHandler(rootView); var jsAppModuleName = rootView.JavaScriptModuleName; var appParameters = new Dictionary <string, object> { { "rootTag", rootTag }, { "initalProps", null /* TODO: add launch options to root view */ } }; reactInstance.GetJavaScriptModule <AppRegistry>().runApplication(jsAppModuleName, appParameters); }
public void Invoke(IReactInstance reactInstance, JArray jsArguments) { using (Tracer.Trace(Tracer.TRACE_TAG_REACT_BRIDGE, "callNativeModuleMethod").Start()) { _invokeDelegate.Value(_instance, reactInstance, jsArguments); } }
public void Invoke(IReactInstance reactInstance, int methodId, JArray parameters) { var method = _methods[methodId]; //using (RNTracer.Trace(RNTracer.TRACE_TAG_REACT_BRIDGE, method.TracingName).Start()) { method.Method.Invoke(reactInstance, parameters); } }
public JToken Invoke(IReactInstance reactInstance, int methodId, JArray parameters) { var method = _methods[methodId]; using (Tracer.Trace(Tracer.TRACE_TAG_REACT_BRIDGE, method.TracingName).Start()) { return(method.Method.Invoke(reactInstance, parameters)); } }
/// <summary> /// Instantiates the <see cref="Callback"/>. /// </summary> /// <param name="id">The callback ID.</param> /// <param name="instance">The React instance.</param> public Callback(int id, IReactInstance instance) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } _id = id; _instance = instance; }
private void DetachViewFromInstance(ReactRootView rootView, IReactInstance reactInstance) { DispatcherHelpers.AssertOnDispatcher(); var uiManagerModule = reactInstance.GetNativeModule <UIManagerModule>(); uiManagerModule.DetachRootView(rootView); reactInstance.GetJavaScriptModule <AppRegistry>().unmountApplicationComponentAtRootTag(rootView.GetTag()); }
private void DetachViewFromInstance(ReactRootView rootView, IReactInstance reactInstance) { DispatcherHelpers.AssertOnDispatcher(); if (-1 != rootView.GetTag()) { reactInstance.GetJavaScriptModule <AppRegistry>().unmountApplicationComponentAtRootTag(rootView.GetTag()); } // timming issue Thread.Sleep(2 * 1000); }
private static void Invoke( MethodInfo method, int expectedArguments, IList <Func <IReactInstance, JArray, int, Result> > extractors, IGenericDelegate genericDelegate, INativeModule moduleInstance, IReactInstance reactInstance, JArray jsArguments) { if (moduleInstance == null) { throw new ArgumentNullException(nameof(moduleInstance)); } if (reactInstance == null) { throw new ArgumentNullException(nameof(reactInstance)); } if (jsArguments == null) { throw new ArgumentNullException(nameof(jsArguments)); } var n = expectedArguments; var c = extractors.Count; if (jsArguments.Count != n) { throw new NativeArgumentsParseException( Invariant($"Module '{moduleInstance.Name}' method '{method.Name}' got '{jsArguments.Count}' arguments, expected '{n}'."), nameof(jsArguments)); } var idx = 0; var args = new object[extractors.Count]; for (var j = 0; j < c; ++j) { var result = extractors[j](reactInstance, jsArguments, idx); args[j] = result.Value; idx = result.NextIndex; } if (genericDelegate != null) { genericDelegate.Invoke(args); } else { // This should only happen for React methods with greater than 16 arguments. method.Invoke(moduleInstance, args); } }
public void Invoke(IReactInstance reactInstance, JArray jsArguments) { //using (RNTracer.Trace(RNTracer.TRACE_TAG_REACT_BRIDGE, "callNativeModuleMethod").Start()) { /* * foreach (var args in jsArguments) * { * Log.Info(ReactConstants.Tag, "### Invoke ### arguments: " + args.ToString()); * } */ _invokeDelegate.Value(_instance, reactInstance, jsArguments); } }
/// <summary> /// Set and initialize the <see cref="IReactInstance"/> instance /// for this context. /// </summary> /// <param name="instance">The React instance.</param> /// <remarks> /// This method should be called exactly once. /// </remarks> internal void InitializeWithInstance(IReactInstance instance) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } if (_reactInstance != null) { throw new InvalidOperationException("React instance has already been set."); } _reactInstance = instance; }
/// <summary> /// Gets an instance of a <see cref="IJavaScriptModule"/>. /// </summary> /// <typeparam name="T">Type of JavaScript module.</typeparam> /// <param name="instance">The React instance.</param> /// <returns>The JavaScript module instance.</returns> public T GetJavaScriptModule <T>(IReactInstance instance) where T : IJavaScriptModule, new() { lock (_moduleInstances) { if (!_moduleInstances.TryGetValue(typeof(T), out var moduleInstance)) { var type = typeof(T); moduleInstance = new T(); var invokeHandler = new JavaScriptModuleInvocationHandler(instance, type.Name); moduleInstance.InvocationHandler = invokeHandler; _moduleInstances.Add(type, moduleInstance); } return((T)moduleInstance); } }
private void AttachMeasuredRootViewToInstance( ReactRootView rootView, IReactInstance reactInstance) { DispatcherHelpers.AssertOnDispatcher(); var rootTag = reactInstance.GetNativeModule <UIManagerModule>() .AddMeasuredRootView(rootView); var jsAppModuleName = rootView.JavaScriptModuleName; var appParameters = new Dictionary <string, object> { { "rootTag", rootTag }, { "initialProps", rootView.InitialProps } }; reactInstance.GetJavaScriptModule <AppRegistry>().runApplication(jsAppModuleName, appParameters); }
private async Task DetachViewFromInstanceAsync( ReactRootView rootView, IReactInstance reactInstance) { DispatcherHelpers.AssertOnDispatcher(); // Detaches ReactRootView from instance manager root view list and size change monitoring. // This has to complete before unmounting the application. // Returns a task to await the completion of the `removeRootView` UIManager call (an effect of // unmounting the application) and the release of all dispatcher affined UI objects. var rootViewRemovedTask = await reactInstance.GetNativeModule <UIManagerModule>() .DetachRootViewAsync(rootView); reactInstance.GetJavaScriptModule <AppRegistry>().unmountApplicationComponentAtRootTag(rootView.GetTag()); await rootViewRemovedTask; }
/// <summary> /// Invoke a method on a native module. /// </summary> /// <param name="reactInstance">The React instance.</param> /// <param name="moduleId">The module ID.</param> /// <param name="methodId">The method ID.</param> /// <param name="parameters">The parameters.</param> internal void Invoke( IReactInstance reactInstance, int moduleId, int methodId, JArray parameters) { if (moduleId < 0) { throw new ArgumentOutOfRangeException("Invalid module ID: " + moduleId, nameof(moduleId)); } if (_moduleTable.Count < moduleId) { throw new ArgumentOutOfRangeException("Call to unknown module: " + moduleId, nameof(moduleId)); } _moduleTable[moduleId].Invoke(reactInstance, methodId, parameters); }
/// <summary> /// Invoke the native method synchronously. /// </summary> /// <param name="reactInstance">The React instance.</param> /// <param name="moduleId">The module ID.</param> /// <param name="methodId">The method ID.</param> /// <param name="parameters">The parameters.</param> /// <returns>The value returned from the method.</returns> internal JToken InvokeSync( IReactInstance reactInstance, int moduleId, int methodId, JArray parameters) { if (moduleId < 0) { throw new ArgumentOutOfRangeException(nameof(moduleId), "Invalid module ID: " + moduleId); } if (_moduleTable.Count < moduleId) { throw new ArgumentOutOfRangeException(nameof(moduleId), "Call to unknown module: " + moduleId); } return(_moduleTable[moduleId].Invoke(reactInstance, methodId, parameters)); }
private static void Invoke( MethodInfo method, int expectedArguments, IList <Func <IReactInstance, JArray, int, Result> > extractors, INativeModule moduleInstance, IReactInstance reactInstance, JArray jsArguments) { if (moduleInstance == null) { throw new ArgumentNullException(nameof(moduleInstance)); } if (reactInstance == null) { throw new ArgumentNullException(nameof(reactInstance)); } if (jsArguments == null) { throw new ArgumentNullException(nameof(jsArguments)); } var n = expectedArguments; var c = extractors.Count; if (jsArguments.Count != n) { throw new NativeArgumentsParseException( $"Module '{moduleInstance.Name}' method '{method.Name}' got '{jsArguments.Count}' arguments, expected '{n}'.", nameof(jsArguments)); } var idx = 0; var args = new object[extractors.Count]; for (var j = 0; j < c; ++j) { var result = extractors[j](reactInstance, jsArguments, idx); args[j] = result.Value; idx = result.NextIndex; } method.Invoke(moduleInstance, args); }
private async Task AttachMeasuredRootViewToInstanceAsync( ReactRootView rootView, IReactInstance reactInstance) { RnLog.Info(ReactConstants.RNW, $"ReactInstanceManager: AttachMeasuredRootViewToInstanceAsync ({rootView.JavaScriptModuleName}) - entry"); DispatcherHelpers.AssertOnDispatcher(); var rootTag = await reactInstance.GetNativeModule <UIManagerModule>() .AddMeasuredRootViewAsync(rootView); RnLog.Info(ReactConstants.RNW, $"ReactInstanceManager: AttachMeasuredRootViewToInstanceAsync ({rootView.JavaScriptModuleName}) - added to UIManager (tag: {rootTag}), starting React app"); var jsAppModuleName = rootView.JavaScriptModuleName; var appParameters = new Dictionary <string, object> { { "rootTag", rootTag }, { "initialProps", rootView.InitialProps } }; reactInstance.GetJavaScriptModule <AppRegistry>().runApplication(jsAppModuleName, appParameters); RnLog.Info(ReactConstants.RNW, $"ReactInstanceManager: AttachMeasuredRootViewToInstanceAsync ({rootView.JavaScriptModuleName}) - done"); }
/// <summary> /// Gets an instance of a <see cref="IJavaScriptModule"/>. /// </summary> /// <typeparam name="T">Type of JavaScript module.</typeparam> /// <param name="instance">The React instance.</param> /// <returns>The JavaScript module instance.</returns> public T GetJavaScriptModule <T>(IReactInstance instance) where T : IJavaScriptModule { lock (_moduleInstances) { var moduleInstance = default(IJavaScriptModule); if (!_moduleInstances.TryGetValue(typeof(T), out moduleInstance)) { var registration = default(JavaScriptModuleRegistration); if (!_moduleRegistrations.TryGetValue(typeof(T), out registration)) { throw new InvalidOperationException( Invariant($"JS module '{typeof(T)}' hasn't been registered.")); } var type = registration.ModuleInterface; moduleInstance = (IJavaScriptModule)Activator.CreateInstance(type); var invokeHandler = new JavaScriptModuleInvocationHandler(instance, registration); moduleInstance.InvocationHandler = invokeHandler; _moduleInstances.Add(type, moduleInstance); } return((T)moduleInstance); } }
private void AttachMeasuredRootViewToInstance( ReactRootView rootView, IReactInstance reactInstance) { DispatcherHelpers.AssertOnDispatcher(); // Reset view content as it's going to be populated by the // application content from JavaScript rootView.TouchHandler?.Dispose(); rootView.Children.Clear(); rootView.Tag = null; var uiManagerModule = reactInstance.GetNativeModule<UIManagerModule>(); var rootTag = uiManagerModule.AddMeasuredRootView(rootView); rootView.TouchHandler = new TouchHandler(rootView); var jsAppModuleName = rootView.JavaScriptModuleName; var appParameters = new Dictionary<string, object> { { "rootTag", rootTag }, { "initalProps", null /* TODO: add launch options to root view */ } }; reactInstance.GetJavaScriptModule<AppRegistry>().runApplication(jsAppModuleName, appParameters); }
public void Invoke(IReactInstance reactInstance, int methodId, JArray parameters) { _methods[methodId].Method.Invoke(reactInstance, parameters); }
/// <summary> /// Invoke the native method. /// </summary> /// <param name="reactInstance">The React instance.</param> /// <param name="arguments">The arguments.</param> /// <returns>The native method result.</returns> public JToken Invoke(IReactInstance reactInstance, JArray arguments) { return(_func(reactInstance, arguments)); }
private void AttachMeasuredRootViewToInstance( ReactRootView rootView, IReactInstance reactInstance) { Log.Info(ReactConstants.Tag, "[ReactInstanceManager] ## Enter AttachMeasuredRootViewToInstance ##"); DispatcherHelpers.AssertOnDispatcher(); // Reset view content as it's going to be populated by the // application content from JavaScript //rootView.TouchHandler?.Dispose(); //rootView.RemoveAllView(); rootView.SetTag(0); var uiManagerModule = reactInstance.GetNativeModule <UIManagerModule>(); var rootTag = uiManagerModule.AddMeasuredRootView(rootView); //rootView.TouchHandler = new TouchHandler(rootView); // TODO: commented temporarily var jsAppModuleName = rootView.JavaScriptModuleName; var appParameters = new Dictionary <string, object> { { "rootTag", rootTag }, { "initalProps", null /* TODO: add launch options to root view */ } }; /* Entry of RN.js world */ Log.Info(ReactConstants.Tag, "[ReactInstanceManager] Entry of RN.js world:[" + jsAppModuleName.ToString() + "]"); reactInstance.GetJavaScriptModule <AppRegistry>().runApplication(jsAppModuleName, appParameters); // [UT-STUB] // TEST STUB BGN //Log.Info("MPM", "## MediaPlayerModule Test begin ##"); //MediaPlayerModule mpModule = _currentReactContext.ReactInstance.GetNativeModule<MediaPlayerModule>(); //mpModule.play(); // exceptional testing // to pick which one ? //mpModule.init("http://109.123.100.75:8086/assets/MusicPlayer/resources/music.mp3?platform=tizen&hash=5a9a91184e611dae3fed162b8787ce5f"); //mpModule.init("https://pc.tedcdn.com/talk/stream/2017S/None/SineadBurke_2017S-950k.mp4"); // mpModule.init("/opt/usr/apps/MusicPlayer.Tizen/shared/res/assets/MusicPlayer/resources/adele.mp3"); //mpModule.seekTo(20*1000); /* * string[] uri= {"/opt/baisuzhen.mp3", "/opt/aaa.mp3"}; * * for (int i = 0; i < 100; i++) * { * mpModule.init(uri[i%2]); // wrong type with right source * mpModule.play(); * Thread.Sleep(1000*5); * } */ //mpModule.init("/opt/baisuzhen.mp3"); // wrong type with right source //mpModule.setVolume(0.1f); //mpModule.setSubtitle("/opt/[zmk.tw]The.Circle.2017.srt"); //mpModule.play(); //Thread.Sleep(1000*5); // mpModule.stop(); //Thread.Sleep(1000*3); //mpModule.play(); //Thread.Sleep(1000*15); //mpModule.deInit(); //mpModule.pause(); //mpModule.seekTo(20*1000); //mpModule.seekTo(700*1000); //mpModule.setVolume(0.4f); //mpModule.play(); //Thread.Sleep(1000*36); //mpModule.pause(); //mpModule.deInit(); //mpModule.play(); //Log.Info(ReactConstants.Tag, "## MediaPlayerModule 55555555555 ##"); //Thread.Sleep(1000*650); //Log.Info("MediaPlayerModule", $"## MediaPlayerModule 5555555555"); //mpModule.stop(); //Log.Info(ReactConstants.Tag, "## MediaPlayerModule 66666666666 ##"); // TEST STUB END /* * // Create 'Button' thread * Thread th_On = new Thread(new ParameterizedThreadStart(UT_CreateView)); * th_On.IsBackground = true; * th_On.Start(this); * * // terminate 'Button' thread * Thread th_Off = new Thread(new ParameterizedThreadStart(UT_DropView)); * th_Off.IsBackground = true; * th_Off.Start(this); * * // No detach mode = =!! * //th_On.Join(); * //th_Off.Join(); * */ //UT_UIManagerModuleTest(this); // [UT-STUB] Log.Info(ReactConstants.Tag, "[ReactInstanceManager] ## Exit AttachMeasuredRootViewToInstance ThreadID=" + Thread.CurrentThread.ManagedThreadId.ToString() + " ##"); }
public JavaScriptModuleInvocationHandler(IReactInstance reactInstance, string moduleName) { _reactInstance = reactInstance; _moduleName = moduleName; }
private void DetachViewFromInstance(ReactRootView rootView, IReactInstance reactInstance) { DispatcherHelpers.AssertOnDispatcher(); reactInstance.GetJavaScriptModule<AppRegistry>().unmountApplicationComponentAtRootTag(rootView.GetTag()); }
public Callback(int id, IReactInstance instance) { _id = id; _instance = instance; }
/// <summary> /// Create a promise. /// </summary> /// <param name="resolveToken">The resolve callback ID token.</param> /// <param name="rejectToken">The reject callback ID token.</param> /// <param name="reactInstance">The React instance.</param> /// <returns>The promise.</returns> protected static IPromise CreatePromise(JToken resolveToken, JToken rejectToken, IReactInstance reactInstance) { var resolveCallback = CreateCallback(resolveToken, reactInstance); var rejectCallback = CreateCallback(rejectToken, reactInstance); return(new Promise(resolveCallback, rejectCallback)); }
/// <summary> /// Create a callback. /// </summary> /// <param name="callbackToken">The callback ID token.</param> /// <param name="reactInstance">The React instance.</param> /// <returns>The callback.</returns> protected static ICallback CreateCallback(JToken callbackToken, IReactInstance reactInstance) { var id = callbackToken.Value <int>(); return(new Callback(id, reactInstance)); }