Example #1
0
        internal async Task LoadBundleAsync()
        {
            // #1) Get the private ReactInstanceManager, which is what includes
            //     the logic to reload the current React context.
            FieldInfo info = typeof(ReactPage)
                             .GetField("_reactInstanceManager", BindingFlags.NonPublic | BindingFlags.Instance);

#if WINDOWS_UWP
            var reactInstanceManager = (ReactInstanceManager)typeof(ReactPage)
                                       .GetField("_reactInstanceManager", BindingFlags.NonPublic | BindingFlags.Instance)
                                       .GetValue(_codePush.MainPage);
#else
            var reactInstanceManager = ((Lazy <IReactInstanceManager>) typeof(ReactPage)
                                        .GetField("_reactInstanceManager", BindingFlags.NonPublic | BindingFlags.Instance)
                                        .GetValue(_codePush.MainPage)).Value as ReactInstanceManager;
#endif

            // #2) Update the locally stored JS bundle file path
            Type   reactInstanceManagerType = typeof(ReactInstanceManager);
            string latestJSBundleFile       = await _codePush.GetJavaScriptBundleFileAsync(_codePush.AssetsBundleFileName).ConfigureAwait(false);

            reactInstanceManagerType
            .GetField("_jsBundleFile", BindingFlags.NonPublic | BindingFlags.Instance)
            .SetValue(reactInstanceManager, latestJSBundleFile);

            // #3) Get the context creation method and fire it on the UI thread (which RN enforces)
            Context.RunOnDispatcherQueueThread(reactInstanceManager.RecreateReactContextInBackground);
        }
        public string GetJavaScriptBundleFile(string assetsBundleFileName)
        {
            if (CurrentInstance == null)
            {
                throw new InvalidOperationException("A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?");
            }

            return(CurrentInstance.GetJavaScriptBundleFileAsync(assetsBundleFileName).Result);
        }
Example #3
0
        internal async Task LoadBundleAsync()
        {
            // #1) Get the private ReactInstanceManager, which is what includes
            //     the logic to reload the current React context.
            var reactInstanceManager = _codePush.ReactInstanceManager;

            // #2) Update the locally stored JS bundle file path
            Type   reactInstanceManagerType = typeof(ReactInstanceManager);
            string latestJSBundleFile       = await _codePush.GetJavaScriptBundleFileAsync(_codePush.AssetsBundleFileName).ConfigureAwait(false);

            reactInstanceManagerType
            .GetField("_jsBundleFile", BindingFlags.NonPublic | BindingFlags.Instance)
            .SetValue(reactInstanceManager, latestJSBundleFile);

            // #3) Get the context creation method and fire it on the UI thread (which RN enforces)
            Context.RunOnDispatcherQueueThread(() => reactInstanceManager.RecreateReactContextAsync(CancellationToken.None));
        }