private ReactInstanceManager(
            string jsBundleFile,
            string jsMainModuleName,
            IReadOnlyList <IReactPackage> packages,
            bool useDeveloperSupport,
            LifecycleState initialLifecycleState,
            UIImplementationProvider uiImplementationProvider,
            Action <Exception> nativeModuleCallExceptionHandler)
        {
            if (packages == null)
            {
                throw new ArgumentNullException(nameof(packages));
            }
            if (uiImplementationProvider == null)
            {
                throw new ArgumentNullException(nameof(uiImplementationProvider));
            }

            _jsBundleFile     = jsBundleFile;
            _jsMainModuleName = jsMainModuleName;
            _packages         = packages;

            _useDeveloperSupport = useDeveloperSupport;
            _devSupportManager   = _useDeveloperSupport
                ? (IDevSupportManager) new DevSupportManager(
                new ReactInstanceDevCommandsHandler(this),
                _jsBundleFile,
                _jsMainModuleName)
                : new DisabledDevSupportManager();

            _lifecycleState                   = initialLifecycleState;
            _uiImplementationProvider         = uiImplementationProvider;
            _nativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler;
        }
Пример #2
0
        public async Task UIManagerModule_Constants_ViewManager_CustomEvents()
        {
            var context      = new ReactContext();
            var viewManagers = new List <IViewManager> {
                new TestViewManager()
            };

            ReactNative.Bridge.DispatcherHelpers.MainDispatcher = Dispatcher.CurrentDispatcher;
            await DispatcherHelpers.RunOnDispatcherAsync(ReactChoreographer.Initialize);

            var uiImplementationProvider = new UIImplementationProvider();

            using (var actionQueue = new ActionQueue(ex => { }))
            {
                var module = await DispatcherHelpers.CallOnDispatcherAsync(
                    () => new UIManagerModule(context, viewManagers, uiImplementationProvider, actionQueue, UIManagerModuleOptions.None));

                var constants = ((INativeModule)module).Constants.GetMap("Test");
                Assert.AreEqual(42, constants.GetMap("directEventTypes").GetValue("otherSelectionChange").Value <int>());
                Assert.AreEqual(42, constants.GetMap("directEventTypes").GetMap("topSelectionChange").GetValue("registrationName").Value <int>());
                Assert.AreEqual(42, constants.GetMap("directEventTypes").GetMap("topLoadingStart").GetValue("foo").Value <int>());
                Assert.AreEqual(42, constants.GetMap("directEventTypes").GetValue("topLoadingError").Value <int>());
            }

            // Ideally we should dispose, but the original dispatcher is somehow lost/etc.
            // await DispatcherHelpers.RunOnDispatcherAsync(ReactChoreographer.Dispose);
        }
Пример #3
0
        public async Task UIManagerModule_Constants_ViewManager_LazyConstants()
        {
            var context      = new ReactContext();
            var viewManagers = new List <IViewManager> {
                new TestViewManager()
            };

            ReactNative.Bridge.DispatcherHelpers.MainDispatcher = Dispatcher.CurrentDispatcher;
            await DispatcherHelpers.RunOnDispatcherAsync(ReactChoreographer.Initialize);

            var uiImplementationProvider = new UIImplementationProvider();

            using (var actionQueue = new ActionQueue(ex => { }))
            {
                var module = await DispatcherHelpers.CallOnDispatcherAsync(
                    () => new UIManagerModule(context, viewManagers, uiImplementationProvider, actionQueue, UIManagerModuleOptions.LazyViewManagers));

                var obj = ((INativeModule)module).Constants.GetValue("ViewManagerNames");
                var viewManagerNames = obj as JArray;
                Assert.IsNotNull(viewManagerNames);
                Assert.AreEqual(1, viewManagerNames.Count());
                Assert.AreEqual("Test", viewManagerNames.Single().Value <string>());
            }

            // Ideally we should dispose, but the original dispatcher is somehow lost/etc.
            // await DispatcherHelpers.RunOnDispatcherAsync(ReactChoreographer.Dispose);
        }
Пример #4
0
        public async Task UIManagerModule_CustomEvents_Constants()
        {
            var context                  = new ReactContext();
            var viewManagers             = new List <IViewManager>();
            var uiImplementationProvider = new UIImplementationProvider();

            using (var actionQueue = new ActionQueue(ex => { }))
            {
                var module = await DispatcherHelpers.CallOnDispatcherAsync(
                    () => new UIManagerModule(context, viewManagers, uiImplementationProvider, actionQueue));

                var constants = module.Constants;

                Assert.AreEqual("onSelect", constants.GetMap("customBubblingEventTypes").GetMap("topSelect").GetMap("phasedRegistrationNames").GetValue("bubbled"));
                Assert.AreEqual("onSelectCapture", constants.GetMap("customBubblingEventTypes").GetMap("topSelect").GetMap("phasedRegistrationNames").GetValue("captured"));
                Assert.AreEqual("onChange", constants.GetMap("customBubblingEventTypes").GetMap("topChange").GetMap("phasedRegistrationNames").GetValue("bubbled"));
                Assert.AreEqual("onChangeCapture", constants.GetMap("customBubblingEventTypes").GetMap("topChange").GetMap("phasedRegistrationNames").GetValue("captured"));
                Assert.AreEqual("onTouchStart", constants.GetMap("customBubblingEventTypes").GetMap("topTouchStart").GetMap("phasedRegistrationNames").GetValue("bubbled"));
                Assert.AreEqual("onTouchStartCapture", constants.GetMap("customBubblingEventTypes").GetMap("topTouchStart").GetMap("phasedRegistrationNames").GetValue("captured"));
                Assert.AreEqual("onTouchMove", constants.GetMap("customBubblingEventTypes").GetMap("topTouchMove").GetMap("phasedRegistrationNames").GetValue("bubbled"));
                Assert.AreEqual("onTouchMoveCapture", constants.GetMap("customBubblingEventTypes").GetMap("topTouchMove").GetMap("phasedRegistrationNames").GetValue("captured"));
                Assert.AreEqual("onTouchEnd", constants.GetMap("customBubblingEventTypes").GetMap("topTouchEnd").GetMap("phasedRegistrationNames").GetValue("bubbled"));
                Assert.AreEqual("onTouchEndCapture", constants.GetMap("customBubblingEventTypes").GetMap("topTouchEnd").GetMap("phasedRegistrationNames").GetValue("captured"));

                Assert.AreEqual("onSelectionChange", constants.GetMap("customDirectEventTypes").GetMap("topSelectionChange").GetValue("registrationName"));
                Assert.AreEqual("onLoadingStart", constants.GetMap("customDirectEventTypes").GetMap("topLoadingStart").GetValue("registrationName"));
                Assert.AreEqual("onLoadingFinish", constants.GetMap("customDirectEventTypes").GetMap("topLoadingFinish").GetValue("registrationName"));
                Assert.AreEqual("onLoadingError", constants.GetMap("customDirectEventTypes").GetMap("topLoadingError").GetValue("registrationName"));
                Assert.AreEqual("onLayout", constants.GetMap("customDirectEventTypes").GetMap("topLayout").GetValue("registrationName"));
            }
        }
            /// <summary>
            /// Instantiates a new <see cref="ReactInstanceManager"/>.
            /// </summary>
            /// <returns>A React instance manager.</returns>
            public ReactInstanceManager Build()
            {
                AssertNotNull(_initialLifecycleState, nameof(InitialLifecycleState));

                if (!_useDeveloperSupport && _jsBundleFile == null)
                {
                    throw new InvalidOperationException("JavaScript bundle file has to be provided when dev support is disabled.");
                }

                if (_jsBundleFile == null && _jsMainModuleName == null)
                {
                    throw new InvalidOperationException("Either the main module name or the JavaScript bundle file must be provided.");
                }

                if (_uiImplementationProvider == null)
                {
                    _uiImplementationProvider = new UIImplementationProvider();
                }

                return(new ReactInstanceManager(
                           _jsBundleFile,
                           _jsMainModuleName,
                           _packages,
                           _useDeveloperSupport,
                           _initialLifecycleState.Value,
                           _uiImplementationProvider,
                           _nativeModuleCallExceptionHandler));
            }
        private ReactInstanceManager(
            string jsBundleFile,
            string jsMainModuleName,
            IReadOnlyList<IReactPackage> packages,
            bool useDeveloperSupport,
            LifecycleState initialLifecycleState,
            UIImplementationProvider uiImplementationProvider,
            Action<Exception> nativeModuleCallExceptionHandler)
        {
            if (packages == null)
                throw new ArgumentNullException(nameof(packages));
            if (uiImplementationProvider == null)
                throw new ArgumentNullException(nameof(uiImplementationProvider));

            _jsBundleFile = jsBundleFile;
            _jsMainModuleName = jsMainModuleName;
            _packages = packages;

            _useDeveloperSupport = useDeveloperSupport;
            _devSupportManager = _useDeveloperSupport
                ? (IDevSupportManager)new DevSupportManager(
                    new ReactInstanceDevCommandsHandler(this),
                    _jsBundleFile,
                    _jsMainModuleName)
                : new DisabledDevSupportManager();

            _lifecycleState = initialLifecycleState;
            _uiImplementationProvider = uiImplementationProvider;
            _nativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler;
        }
Пример #7
0
 public CoreModulesPackage(
     ReactInstanceManager reactInstanceManager,
     Action hardwareBackButtonHandler,
     UIImplementationProvider uiImplementationProvider)
 {
     _reactInstanceManager      = reactInstanceManager;
     _hardwareBackButtonHandler = hardwareBackButtonHandler;
     _uiImplementationProvider  = uiImplementationProvider;
 }
 public CoreModulesPackage(
     IReactInstanceManager reactInstanceManager,
     Action hardwareBackButtonHandler,
     UIImplementationProvider uiImplementationProvider)
 {
     _reactInstanceManager = reactInstanceManager;
     _hardwareBackButtonHandler = hardwareBackButtonHandler;
     _uiImplementationProvider = uiImplementationProvider;
 }
 public CoreModulesPackage(
     ReactInstanceManager reactInstanceManager,
     Action hardwareBackButtonHandler,
     UIImplementationProvider uiImplementationProvider,
     bool lazyViewManagersEnabled)
 {
     _reactInstanceManager      = reactInstanceManager;
     _hardwareBackButtonHandler = hardwareBackButtonHandler;
     _uiImplementationProvider  = uiImplementationProvider;
     _lazyViewManagersEnabled   = lazyViewManagersEnabled;
 }
        public void UIManagerModule_ArgumentChecks()
        {
            var context                  = new ReactContext();
            var viewManagers             = new List <IViewManager>();
            var uiImplementationProvider = new UIImplementationProvider();

            AssertEx.Throws <ArgumentNullException>(
                () => new UIManagerModule(context, null, uiImplementationProvider),
                ex => Assert.AreEqual("viewManagers", ex.ParamName));

            AssertEx.Throws <ArgumentNullException>(
                () => new UIManagerModule(context, viewManagers, null),
                ex => Assert.AreEqual("uiImplementationProvider", ex.ParamName));
        }
Пример #11
0
        public async Task UIManagerModule_CustomEvents_Constants()
        {
            var context      = new ReactContext();
            var viewManagers = new List <IViewManager> {
                new NoEventsViewManager()
            };

            ReactNative.Bridge.DispatcherHelpers.MainDispatcher = Dispatcher.CurrentDispatcher;
            await DispatcherHelpers.RunOnDispatcherAsync(ReactChoreographer.Initialize);

            var uiImplementationProvider = new UIImplementationProvider();

            using (var actionQueue = new ActionQueue(ex => { }))
            {
                var module = await DispatcherHelpers.CallOnDispatcherAsync(
                    () => new UIManagerModule(context, viewManagers, uiImplementationProvider, actionQueue, UIManagerModuleOptions.None));

                var constants = ((INativeModule)module).Constants;

                Assert.AreEqual("onSelect", constants.GetMap("genericBubblingEventTypes").GetMap("topSelect").GetMap("phasedRegistrationNames").GetValue("bubbled").Value <string>());
                Assert.AreEqual("onSelectCapture", constants.GetMap("genericBubblingEventTypes").GetMap("topSelect").GetMap("phasedRegistrationNames").GetValue("captured").Value <string>());
                Assert.AreEqual("onChange", constants.GetMap("genericBubblingEventTypes").GetMap("topChange").GetMap("phasedRegistrationNames").GetValue("bubbled").Value <string>());
                Assert.AreEqual("onChangeCapture", constants.GetMap("genericBubblingEventTypes").GetMap("topChange").GetMap("phasedRegistrationNames").GetValue("captured").Value <string>());
                Assert.AreEqual("onTouchStart", constants.GetMap("genericBubblingEventTypes").GetMap("topTouchStart").GetMap("phasedRegistrationNames").GetValue("bubbled").Value <string>());
                Assert.AreEqual("onTouchStartCapture", constants.GetMap("genericBubblingEventTypes").GetMap("topTouchStart").GetMap("phasedRegistrationNames").GetValue("captured").Value <string>());
                Assert.AreEqual("onTouchMove", constants.GetMap("genericBubblingEventTypes").GetMap("topTouchMove").GetMap("phasedRegistrationNames").GetValue("bubbled").Value <string>());
                Assert.AreEqual("onTouchMoveCapture", constants.GetMap("genericBubblingEventTypes").GetMap("topTouchMove").GetMap("phasedRegistrationNames").GetValue("captured").Value <string>());
                Assert.AreEqual("onTouchEnd", constants.GetMap("genericBubblingEventTypes").GetMap("topTouchEnd").GetMap("phasedRegistrationNames").GetValue("bubbled").Value <string>());
                Assert.AreEqual("onTouchEndCapture", constants.GetMap("genericBubblingEventTypes").GetMap("topTouchEnd").GetMap("phasedRegistrationNames").GetValue("captured").Value <string>());
                Assert.AreEqual("onMouseOver", constants.GetMap("genericBubblingEventTypes").GetMap("topMouseOver").GetMap("phasedRegistrationNames").GetValue("bubbled").Value <string>());
                Assert.AreEqual("onMouseOverCapture", constants.GetMap("genericBubblingEventTypes").GetMap("topMouseOver").GetMap("phasedRegistrationNames").GetValue("captured").Value <string>());
                Assert.AreEqual("onMouseOut", constants.GetMap("genericBubblingEventTypes").GetMap("topMouseOut").GetMap("phasedRegistrationNames").GetValue("bubbled").Value <string>());
                Assert.AreEqual("onMouseOutCapture", constants.GetMap("genericBubblingEventTypes").GetMap("topMouseOut").GetMap("phasedRegistrationNames").GetValue("captured").Value <string>());

                Assert.AreEqual("onSelectionChange", constants.GetMap("genericDirectEventTypes").GetMap("topSelectionChange").GetValue("registrationName").Value <string>());
                Assert.AreEqual("onLoadingStart", constants.GetMap("genericDirectEventTypes").GetMap("topLoadingStart").GetValue("registrationName").Value <string>());
                Assert.AreEqual("onLoadingFinish", constants.GetMap("genericDirectEventTypes").GetMap("topLoadingFinish").GetValue("registrationName").Value <string>());
                Assert.AreEqual("onLoadingError", constants.GetMap("genericDirectEventTypes").GetMap("topLoadingError").GetValue("registrationName").Value <string>());
                Assert.AreEqual("onLayout", constants.GetMap("genericDirectEventTypes").GetMap("topLayout").GetValue("registrationName").Value <string>());
                Assert.AreEqual("onMouseEnter", constants.GetMap("genericDirectEventTypes").GetMap("topMouseEnter").GetValue("registrationName").Value <string>());
                Assert.AreEqual("onMouseLeave", constants.GetMap("genericDirectEventTypes").GetMap("topMouseLeave").GetValue("registrationName").Value <string>());
                Assert.AreEqual("onMessage", constants.GetMap("genericDirectEventTypes").GetMap("topMessage").GetValue("registrationName").Value <string>());
            }

            // Ideally we should dispose, but the original dispatcher is somehow lost/etc.
            // await DispatcherHelpers.RunOnDispatcherAsync(ReactChoreographer.Dispose);
        }
        public async Task UIManagerModule_Constants_ViewManagerOverrides()
        {
            var context      = new ReactContext();
            var viewManagers = new List <IViewManager> {
                new TestViewManager()
            };
            var uiImplementationProvider = new UIImplementationProvider();

            var module = await DispatcherHelpers.CallOnDispatcherAsync(
                () => new UIManagerModule(context, viewManagers, uiImplementationProvider));

            var constants = module.Constants;

            Assert.AreEqual(42, constants.GetMap("customDirectEventTypes").GetValue("otherSelectionChange"));
            Assert.AreEqual(42, constants.GetMap("customDirectEventTypes").GetMap("topSelectionChange").GetValue("registrationName"));
            Assert.AreEqual(42, constants.GetMap("customDirectEventTypes").GetMap("topLoadingStart").GetValue("foo"));
            Assert.AreEqual(42, constants.GetMap("customDirectEventTypes").GetValue("topLoadingError"));
        }
        internal ReactInstanceManager(
            string jsBundleFile,
            string jsMainModuleName,
            IReadOnlyList <IReactPackage> packages,
            bool useDeveloperSupport,
            LifecycleState initialLifecycleState,
            UIImplementationProvider uiImplementationProvider,
            Func <IJavaScriptExecutor> javaScriptExecutorFactory,
            Action <Exception> nativeModuleCallExceptionHandler,
            bool lazyViewManagersEnabled)
        {
            RnLog.Info(ReactConstants.RNW, $"ReactInstanceManager: constructor");

            if (packages == null)
            {
                throw new ArgumentNullException(nameof(packages));
            }
            if (uiImplementationProvider == null)
            {
                throw new ArgumentNullException(nameof(uiImplementationProvider));
            }
            if (javaScriptExecutorFactory == null)
            {
                throw new ArgumentNullException(nameof(javaScriptExecutorFactory));
            }

            _jsBundleFile     = jsBundleFile;
            _jsMainModuleName = jsMainModuleName;
            _packages         = packages;

            _useDeveloperSupport = useDeveloperSupport;
            _devSupportManager   = _useDeveloperSupport
                ? (IDevSupportManager) new DevSupportManager(
                new ReactInstanceDevCommandsHandler(this),
                _jsBundleFile == null,
                _jsMainModuleName)
                : new DisabledDevSupportManager();

            _lifecycleStateMachine            = new LifecycleStateMachine(initialLifecycleState);
            _uiImplementationProvider         = uiImplementationProvider;
            _javaScriptExecutorFactory        = javaScriptExecutorFactory;
            _nativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler;
            _lazyViewManagersEnabled          = lazyViewManagersEnabled;
        }
Пример #14
0
        public async Task UIManagerModule_CustomEvents_Constants()
        {
            await DispatcherHelpers.RunOnDispatcherAsync(ReactChoreographer.Initialize);

            var context      = new ReactContext();
            var viewManagers = new List <IViewManager> {
                new NoEventsViewManager()
            };
            var uiImplementationProvider = new UIImplementationProvider();

            using (var actionQueue = new ActionQueue(ex => { }))
            {
                var module = await DispatcherHelpers.CallOnDispatcherAsync(() => new UIManagerModule(context, viewManagers, uiImplementationProvider, actionQueue));

                var constants = module.Constants.GetMap("Test");

                Assert.AreEqual("onSelect", constants.GetMap("bubblingEventTypes").GetMap("topSelect").GetMap("phasedRegistrationNames").GetValue("bubbled"));
                Assert.AreEqual("onSelectCapture", constants.GetMap("bubblingEventTypes").GetMap("topSelect").GetMap("phasedRegistrationNames").GetValue("captured"));
                Assert.AreEqual("onChange", constants.GetMap("bubblingEventTypes").GetMap("topChange").GetMap("phasedRegistrationNames").GetValue("bubbled"));
                Assert.AreEqual("onChangeCapture", constants.GetMap("bubblingEventTypes").GetMap("topChange").GetMap("phasedRegistrationNames").GetValue("captured"));
                Assert.AreEqual("onTouchStart", constants.GetMap("bubblingEventTypes").GetMap("topTouchStart").GetMap("phasedRegistrationNames").GetValue("bubbled"));
                Assert.AreEqual("onTouchStartCapture", constants.GetMap("bubblingEventTypes").GetMap("topTouchStart").GetMap("phasedRegistrationNames").GetValue("captured"));
                Assert.AreEqual("onTouchMove", constants.GetMap("bubblingEventTypes").GetMap("topTouchMove").GetMap("phasedRegistrationNames").GetValue("bubbled"));
                Assert.AreEqual("onTouchMoveCapture", constants.GetMap("bubblingEventTypes").GetMap("topTouchMove").GetMap("phasedRegistrationNames").GetValue("captured"));
                Assert.AreEqual("onTouchEnd", constants.GetMap("bubblingEventTypes").GetMap("topTouchEnd").GetMap("phasedRegistrationNames").GetValue("bubbled"));
                Assert.AreEqual("onTouchEndCapture", constants.GetMap("bubblingEventTypes").GetMap("topTouchEnd").GetMap("phasedRegistrationNames").GetValue("captured"));
                Assert.AreEqual("onMouseOver", constants.GetMap("bubblingEventTypes").GetMap("topMouseOver").GetMap("phasedRegistrationNames").GetValue("bubbled"));
                Assert.AreEqual("onMouseOverCapture", constants.GetMap("bubblingEventTypes").GetMap("topMouseOver").GetMap("phasedRegistrationNames").GetValue("captured"));
                Assert.AreEqual("onMouseOut", constants.GetMap("bubblingEventTypes").GetMap("topMouseOut").GetMap("phasedRegistrationNames").GetValue("bubbled"));
                Assert.AreEqual("onMouseOutCapture", constants.GetMap("bubblingEventTypes").GetMap("topMouseOut").GetMap("phasedRegistrationNames").GetValue("captured"));

                Assert.AreEqual("onSelectionChange", constants.GetMap("directEventTypes").GetMap("topSelectionChange").GetValue("registrationName"));
                Assert.AreEqual("onLoadingStart", constants.GetMap("directEventTypes").GetMap("topLoadingStart").GetValue("registrationName"));
                Assert.AreEqual("onLoadingFinish", constants.GetMap("directEventTypes").GetMap("topLoadingFinish").GetValue("registrationName"));
                Assert.AreEqual("onLoadingError", constants.GetMap("directEventTypes").GetMap("topLoadingError").GetValue("registrationName"));
                Assert.AreEqual("onLayout", constants.GetMap("directEventTypes").GetMap("topLayout").GetValue("registrationName"));
                Assert.AreEqual("onMouseEnter", constants.GetMap("directEventTypes").GetMap("topMouseEnter").GetValue("registrationName"));
                Assert.AreEqual("onMouseLeave", constants.GetMap("directEventTypes").GetMap("topMouseLeave").GetValue("registrationName"));
                Assert.AreEqual("onMessage", constants.GetMap("directEventTypes").GetMap("topMessage").GetValue("registrationName"));
            }

            await DispatcherHelpers.RunOnDispatcherAsync(ReactChoreographer.Dispose);
        }
Пример #15
0
        public void UIManagerModule_ArgumentChecks()
        {
            var context                  = new ReactContext();
            var viewManagers             = new List <IViewManager>();
            var uiImplementationProvider = new UIImplementationProvider();

            using (var actionQueue = new ActionQueue(ex => { }))
            {
                ArgumentNullException ex1 = Assert.Throws <ArgumentNullException>(
                    () => new UIManagerModule(context, null, uiImplementationProvider, actionQueue));
                Assert.AreEqual("viewManagers", ex1.ParamName);

                ArgumentNullException ex2 = Assert.Throws <ArgumentNullException>(
                    () => new UIManagerModule(context, viewManagers, null, actionQueue));
                Assert.AreEqual("uiImplementationProvider", ex2.ParamName);

                ArgumentNullException ex3 = Assert.Throws <ArgumentNullException>(
                    () => new UIManagerModule(context, viewManagers, uiImplementationProvider, null));
                Assert.AreEqual("layoutActionQueue", ex3.ParamName);
            }
        }
Пример #16
0
        /// <summary>
        /// Instantiates a new <see cref="ReactInstanceManager"/>.
        /// </summary>
        /// <param name="modifyBundle">Callback for bundle modification from outside.</param>
        /// <returns>The instance.</returns>
        public ReactInstanceManager Build(Func <string, string> modifyBundle)
        {
            if (!_initialLifecycleState.HasValue)
            {
                throw new InvalidOperationException("Initial lifecycle state was not set.");
            }

            if (!_useDeveloperSupport && _jsBundleFile == null)
            {
                throw new InvalidOperationException(
                          "JavaScriptBundleFile must be provided when UseDeveloperSupport is false.");
            }

            if (_jsBundleFile == null && _jsMainModuleName == null)
            {
                throw new InvalidOperationException("Either MainModulePath or the JavaScriptBundleFile must be provided.");
            }

            if (_uiImplementationProvider == null)
            {
                _uiImplementationProvider = new UIImplementationProvider();
            }

            if (_jsExecutorFactory == null)
            {
                _jsExecutorFactory = () => new ChakraJavaScriptExecutor(modifyBundle);
            }

            return(new ReactInstanceManager(
                       _jsBundleFile,
                       _jsMainModuleName,
                       _packages,
                       _useDeveloperSupport,
                       _initialLifecycleState.Value,
                       _uiImplementationProvider,
                       _jsExecutorFactory,
                       _nativeModuleCallExceptionHandler,
                       _lazyViewManagersEnabled));
        }
Пример #17
0
        public async Task UIManagerModule_getConstantsForViewManager()
        {
            await DispatcherHelpers.RunOnDispatcherAsync(ReactChoreographer.Initialize);

            var context      = new ReactContext();
            var viewManagers = new List <IViewManager> {
                new TestViewManager()
            };
            var uiImplementationProvider = new UIImplementationProvider();

            using (var actionQueue = new ActionQueue(ex => { }))
            {
                var module = await DispatcherHelpers.CallOnDispatcherAsync(() => new UIManagerModule(context, viewManagers, uiImplementationProvider, actionQueue, UIManagerModuleOptions.LazyViewManagers));

                var constants = module.getConstantsForViewManager("Test");
                Assert.AreEqual(42, constants.GetMap("directEventTypes").GetValue("otherSelectionChange").Value <int>());
                Assert.AreEqual(42, constants.GetMap("directEventTypes").GetMap("topSelectionChange").GetValue("registrationName").Value <int>());
                Assert.AreEqual(42, constants.GetMap("directEventTypes").GetMap("topLoadingStart").GetValue("foo").Value <int>());
                Assert.AreEqual(42, constants.GetMap("directEventTypes").GetValue("topLoadingError").Value <int>());
            }

            await DispatcherHelpers.RunOnDispatcherAsync(ReactChoreographer.Dispose);
        }
            /// <summary>
            /// Instantiates a new <see cref="ReactInstanceManager"/>.
            /// </summary>
            /// <returns>A React instance manager.</returns>
            public ReactInstanceManager Build()
            {
                AssertNotNull(_initialLifecycleState, nameof(InitialLifecycleState));

                if (!_useDeveloperSupport && _jsBundleFile == null)
                {
                    throw new InvalidOperationException("JavaScript bundle file has to be provided when dev support is disabled.");
                }

                if (_jsBundleFile == null && _jsMainModuleName == null)
                {
                    throw new InvalidOperationException("Either the main module name or the JavaScript bundle file must be provided.");
                }

                if (_uiImplementationProvider == null)
                {
                    _uiImplementationProvider = new UIImplementationProvider();
                }

                return new ReactInstanceManager(
                    _jsBundleFile,
                    _jsMainModuleName,
                    _packages,
                    _useDeveloperSupport,
                    _initialLifecycleState.Value,
                    _uiImplementationProvider,
                    _nativeModuleCallExceptionHandler);
            }