Exemplo n.º 1
0
        /// <summary>
        /// Attach given <paramref name="rootView"/> to a React instance
        /// manager and start the JavaScript application using the JavaScript
        /// module provided by the <see cref="ReactRootView.JavaScriptModuleName"/>. If
        /// the React context is currently being (re-)created, or if the react
        /// context has not been created yet, the JavaScript application
        /// associated with the provided root view will be started
        /// asynchronously. This view will then be tracked by this manager and
        /// in case of React instance restart, it will be re-attached.
        /// WARNING! Has to be called by the thread associated with the view.
        /// </summary>
        /// <param name="rootView">The root view.</param>
        public async Task AttachMeasuredRootViewAsync(ReactRootView rootView)
        {
            if (rootView == null)
            {
                throw new ArgumentNullException(nameof(rootView));
            }

            DispatcherHelpers.AssertOnDispatcher(rootView);
            rootView.Children.Clear();
            ViewExtensions.ClearData(rootView);

            await DispatcherHelpers.CallOnDispatcher(() =>
            {
                _attachedRootViews.Add(rootView);

                // If the React context is being created in the background, the
                // JavaScript application will be started automatically when
                // creation completes, as root view is part of the attached root
                // view list.
                var currentReactContext = _currentReactContext;
                if (currentReactContext != null)
                {
                    AttachMeasuredRootViewToInstance(rootView, currentReactContext.ReactInstance);
                }

                return(true);
            }, true); // inlining allowed
        }
Exemplo n.º 2
0
        /// <summary>
        /// Detach given <paramref name="rootView"/> from the current react
        /// instance. This method is idempotent and can be called multiple
        /// times on the same <see cref="ReactRootView"/> instance.
        /// </summary>
        /// <param name="rootView">The root view.</param>
        public void DetachRootView(ReactRootView rootView)
        {
            Log.Info(ReactConstants.Tag, "[ReactInstanceManager] Enter DetachRootView ");
            if (rootView == null)
            {
                throw new ArgumentNullException(nameof(rootView));
            }

            DispatcherHelpers.AssertOnDispatcher();

            if (_attachedRootViews.Remove(rootView))
            {
                var currentReactContext = _currentReactContext;
                if (currentReactContext != null && currentReactContext.HasActiveReactInstance)
                {
                    DetachViewFromInstance(rootView, currentReactContext.ReactInstance);
                }
            }

            // release 'RootView'
            Log.Info(ReactConstants.Tag, $"Time to release RootView, but its children count = {rootView.GetChildrenCount()} ThreadID={Thread.CurrentThread.ManagedThreadId}");

            // TODO: TO BE FIXXED
            // When 'Teminate', operation for 'remove' won't be execute, so,
            // if rootView want to be unrealized, firstly, its children must
            // be removed, otherwise, it will coredump ...
            rootView.RemoveViewInfo();
            rootView.Unrealize();

            Log.Info(ReactConstants.Tag, "[ReactInstanceManager] Exit DetachRootView ");
        }
        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 },
                { "initialProps", rootView.InitialProps }
            };

            reactInstance.GetJavaScriptModule <AppRegistry>().runApplication(jsAppModuleName, appParameters);
        }
 public static void OnCreate(this ReactRootView rootView, ReactNativeHost host)
 {
     rootView.Background = (Brush)Application.Current.Resources["ApplicationPageBackgroundThemeBrush"];
     if (DispatcherHelpers.IsOnDispatcher())
     {
         SystemNavigationManager.GetForCurrentView().BackRequested += (sender, e) => OnBackRequested(host, sender, e);
         Window.Current.CoreWindow.Dispatcher.AcceleratorKeyActivated += (sender, e) => OnAcceleratorKeyActivated(host, sender, e);
     }
 }
Exemplo n.º 5
0
        private void DetachViewFromInstance(ReactRootView rootView, IReactInstance reactInstance)
        {
            DispatcherHelpers.AssertOnDispatcher();

            var uiManagerModule = reactInstance.GetNativeModule <UIManagerModule>();

            uiManagerModule.DetachRootView(rootView);

            reactInstance.GetJavaScriptModule <AppRegistry>().unmountApplicationComponentAtRootTag(rootView.GetTag());
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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>
        /// Detach given <paramref name="rootView"/> from the current react
        /// instance. This method is idempotent and can be called multiple
        /// times on the same <see cref="ReactRootView"/> instance.
        /// </summary>
        /// <param name="rootView">The root view.</param>
        public void DetachRootView(ReactRootView rootView)
        {
            if (rootView == null)
            {
                throw new ArgumentNullException(nameof(rootView));
            }

            DispatcherHelpers.AssertOnDispatcher();

            if (_attachedRootViews.Remove(rootView))
            {
                var currentReactContext = _currentReactContext;
                if (currentReactContext != null && currentReactContext.HasActiveReactInstance)
                {
                    DetachViewFromInstance(rootView, currentReactContext.ReactInstance);
                }
            }
        }
        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>
        /// Attach given <paramref name="rootView"/> to a React instance
        /// manager and start the JavaScript application using the JavaScript
        /// module provided by the <see cref="ReactRootView.JavaScriptModuleName"/>. If
        /// the React context is currently being (re-)created, or if the react
        /// context has not been created yet, the JavaScript application
        /// associated with the provided root view will be started
        /// asynchronously. This view will then be tracked by this manager and
        /// in case of React instance restart, it will be re-attached.
        /// </summary>
        /// <param name="rootView">The root view.</param>
        public void AttachMeasuredRootView(ReactRootView rootView)
        {
            if (rootView == null)
            {
                throw new ArgumentNullException(nameof(rootView));
            }

            DispatcherHelpers.AssertOnDispatcher();

            _attachedRootViews.Add(rootView);

            // If the React context is being created in the background, the
            // JavaScript application will be started automatically when
            // creation completes, as root view is part of the attached root
            // view list.
            var currentReactContext = _currentReactContext;

            if (_contextInitializationTask == null && currentReactContext != null)
            {
                AttachMeasuredRootViewToInstance(rootView, currentReactContext.ReactInstance);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Detach given <paramref name="rootView"/> from the current react
        /// instance. This method is idempotent and can be called multiple
        /// times on the same <see cref="ReactRootView"/> instance.
        /// WARNING! Has to be called by the thread assocviated with the view.
        /// </summary>
        /// <param name="rootView">The root view.</param>
        public async Task DetachRootViewAsync(ReactRootView rootView)
        {
            if (rootView == null)
            {
                throw new ArgumentNullException(nameof(rootView));
            }

            DispatcherHelpers.AssertOnDispatcher(rootView);

            await DispatcherHelpers.CallOnDispatcher(() =>
            {
                if (_attachedRootViews.Remove(rootView))
                {
                    var currentReactContext = _currentReactContext;
                    if (currentReactContext != null && currentReactContext.HasActiveReactInstance)
                    {
                        DetachViewFromInstance(rootView, currentReactContext.ReactInstance);
                    }
                }

                return(true);
            }, true); // inlining allowed
        }
        /// <summary>
        /// Detach given <paramref name="rootView"/> from the current react
        /// instance. This method is idempotent and can be called multiple
        /// times on the same <see cref="ReactRootView"/> instance.
        /// WARNING! Has to be called by the thread assocviated with the view.
        /// </summary>
        /// <param name="rootView">The root view.</param>
        public async Task DetachRootViewAsync(ReactRootView rootView)
        {
            if (rootView == null)
            {
                throw new ArgumentNullException(nameof(rootView));
            }

            DispatcherHelpers.AssertOnDispatcher(rootView);

            await DispatcherHelpers.CallOnDispatcher(() =>
            {
                if (_attachedRootViews.Remove(rootView))
                {
                    var currentReactContext = _currentReactContext;
                    if (currentReactContext != null && currentReactContext.HasActiveReactInstance)
                    {
                        return(DetachViewFromInstanceAsync(rootView, currentReactContext.ReactInstance));
                    }
                }

                // return Task.CompletedTask;
                return(Net46.Net45.Task.CompletedTask);
            }, true /* inlining allowed */).Unwrap(); // await inner task
        }
        /// <summary>
        /// Attach given <paramref name="rootView"/> to a React instance
        /// manager and start the JavaScript application using the JavaScript
        /// module provided by the <see cref="ReactRootView.JavaScriptModuleName"/>. If
        /// the React context is currently being (re-)created, or if the react
        /// context has not been created yet, the JavaScript application
        /// associated with the provided root view will be started
        /// asynchronously. This view will then be tracked by this manager and
        /// in case of React instance restart, it will be re-attached.
        /// </summary>
        /// <param name="rootView">The root view.</param>
        public void AttachMeasuredRootView(ReactRootView rootView)
        {
            if (rootView == null)
                throw new ArgumentNullException(nameof(rootView));

            DispatcherHelpers.AssertOnDispatcher();

            _attachedRootViews.Add(rootView);

            // If the React context is being created in the background, the
            // JavaScript application will be started automatically when
            // creation completes, as root view is part of the attached root
            // view list.
            var currentReactContext = _currentReactContext;
            if (_contextInitializationTask == null && currentReactContext != null)
            {
                AttachMeasuredRootViewToInstance(rootView, currentReactContext.ReactInstance);
            }
        }
        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);
        }
 private void DetachViewFromInstance(ReactRootView rootView, IReactInstance reactInstance)
 {
     DispatcherHelpers.AssertOnDispatcher();
     reactInstance.GetJavaScriptModule<AppRegistry>().unmountApplicationComponentAtRootTag(rootView.GetTag());
 }
Exemplo n.º 17
0
        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() + " ##");
        }
        /// <summary>
        /// Detach given <paramref name="rootView"/> from the current react
        /// instance. This method is idempotent and can be called multiple
        /// times on the same <see cref="ReactRootView"/> instance.
        /// </summary>
        /// <param name="rootView">The root view.</param>
        public void DetachRootView(ReactRootView rootView)
        {
            if (rootView == null)
                throw new ArgumentNullException(nameof(rootView));

            DispatcherHelpers.AssertOnDispatcher();

            if (_attachedRootViews.Remove(rootView))
            {
                var currentReactContext = _currentReactContext;
                if (currentReactContext != null && currentReactContext.HasActiveReactInstance)
                {
                    DetachViewFromInstance(rootView, currentReactContext.ReactInstance);
                }
            }
        }