Пример #1
0
        public async Task ReactInstanceManager_Lifecycle_Cleanup_Old_Context()
        {
            var jsBundleFile             = "ms-appx:///Resources/test.js";
            ReactInstanceManager manager = null;
            await DispatcherHelpers.CallOnDispatcherAsync(() => manager = CreateReactInstanceManager(jsBundleFile, LifecycleState.Foreground));

            var listener = new LifecycleEventsListener(new LifecycleEventsListener.Step[]
            {
                LifecycleEventsListener.Step.EnteredBackground,
                LifecycleEventsListener.Step.Suspend,
            });

            await DispatcherHelpers.CallOnDispatcherAsync(async() =>
            {
                var context = await manager.CreateReactContextAsync(CancellationToken.None);
                context.AddBackgroundEventListener(listener);
                context.AddLifecycleEventListener(listener);

                var newContext = await manager.RecreateReactContextAsync(CancellationToken.None);
            });

            listener.Dispose();
            await DispatcherHelpers.CallOnDispatcherAsync(async() => await DisposeInstanceManager(manager));
        }
        public async Task ReactInstanceManager_Lifecycle_Dispose_From_Foreground()
        {
            var jsBundleFile = "ms-appx:///Resources/test.js";
            var manager      = CreateReactInstanceManager(jsBundleFile, LifecycleState.Foreground);

            var listener = new LifecycleEventsListener(new LifecycleEventsListener.Step[]
            {
                LifecycleEventsListener.Step.EnteredBackground,
                LifecycleEventsListener.Step.Suspend,
                LifecycleEventsListener.Step.Destroy,
            });

            await DispatcherHelpers.CallOnDispatcherAsync(async() =>
            {
                var context = await manager.CreateReactContextAsync(CancellationToken.None);
                context.AddBackgroundEventListener(listener);
                context.AddLifecycleEventListener(listener);

                await manager.DisposeAsync();
            });

            listener.Dispose();
            ReactNative.Bridge.DispatcherHelpers.Initialize();
        }
Пример #3
0
        public async Task ReactInstanceManager_CreateReactContextAsync_EnsuresOneCall()
        {
            var jsBundleFile = "ms-appx:///Resources/test.js";
            var manager      = CreateReactInstanceManager(jsBundleFile);

            var caught = false;
            await DispatcherHelpers.RunOnDispatcherAsync(async() =>
            {
                var task = manager.CreateReactContextAsync(CancellationToken.None);

                try
                {
                    await manager.CreateReactContextAsync(CancellationToken.None);
                }
                catch (InvalidOperationException)
                {
                    caught = true;
                }
            });

            Assert.IsTrue(caught);

            await DispatcherHelpers.CallOnDispatcherAsync(manager.DisposeAsync);
        }
        public async Task ReactInstanceManager_OnDestroy_CreateInBackground()
        {
            var jsBundleFile = "ms-appx:///Resources/test.js";
            var manager      = CreateReactInstanceManager(jsBundleFile);

            var waitHandle = new AutoResetEvent(false);

            manager.ReactContextInitialized += (sender, args) => waitHandle.Set();

            await DispatcherHelpers.RunOnDispatcherAsync(
                () => manager.CreateReactContextInBackground());

            Assert.IsTrue(waitHandle.WaitOne());
            Assert.AreEqual(jsBundleFile, manager.SourceUrl);

            await DispatcherHelpers.CallOnDispatcherAsync(manager.DisposeAsync);

            await DispatcherHelpers.RunOnDispatcherAsync(
                () => manager.CreateReactContextInBackground());

            Assert.IsTrue(waitHandle.WaitOne());

            await DispatcherHelpers.CallOnDispatcherAsync(manager.DisposeAsync);
        }