From ec34501fb99a6bac070d692e9a36be618874f06c Mon Sep 17 00:00:00 2001 From: Yogev Ben David Date: Tue, 31 Aug 2021 10:09:34 +0300 Subject: [PATCH] Avoid calling AppRegistry.registerComponent in mocked mode (#7234) --- lib/src/Mock/mocks/AppRegistryService.ts | 5 +++++ lib/src/Navigation.ts | 7 ++++--- lib/src/NavigationDelegate.ts | 13 +++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 lib/src/Mock/mocks/AppRegistryService.ts diff --git a/lib/src/Mock/mocks/AppRegistryService.ts b/lib/src/Mock/mocks/AppRegistryService.ts new file mode 100644 index 00000000000..0194cdbec9e --- /dev/null +++ b/lib/src/Mock/mocks/AppRegistryService.ts @@ -0,0 +1,5 @@ +import { ComponentProvider } from 'react-native'; + +export class AppRegistryService { + registerComponent(_appKey: string, _getComponentFunc: ComponentProvider) {} +} diff --git a/lib/src/Navigation.ts b/lib/src/Navigation.ts index fa8e80aefed..9c80cc7b478 100644 --- a/lib/src/Navigation.ts +++ b/lib/src/Navigation.ts @@ -48,7 +48,8 @@ export class NavigationRoot { constructor( private readonly nativeCommandsSender: NativeCommandsSender, - private readonly nativeEventsReceiver: NativeEventsReceiver + private readonly nativeEventsReceiver: NativeEventsReceiver, + private readonly appRegistryService: AppRegistryService ) { this.componentWrapper = new ComponentWrapper(); this.store = new Store(); @@ -59,12 +60,12 @@ export class NavigationRoot { this.nativeEventsReceiver, this.store ); - const appRegistryService = new AppRegistryService(); + this.componentRegistry = new ComponentRegistry( this.store, this.componentEventsObserver, this.componentWrapper, - appRegistryService + this.appRegistryService ); this.layoutTreeParser = new LayoutTreeParser(this.uniqueIdProvider); const optionsProcessor = new OptionsProcessor( diff --git a/lib/src/NavigationDelegate.ts b/lib/src/NavigationDelegate.ts index 00ff027b271..da06c18f3e8 100644 --- a/lib/src/NavigationDelegate.ts +++ b/lib/src/NavigationDelegate.ts @@ -9,21 +9,24 @@ import { OptionsProcessor as OptionProcessor } from './interfaces/Processors'; import { NavigationRoot } from './Navigation'; import { NativeCommandsSender } from './adapters/NativeCommandsSender'; import { NativeEventsReceiver } from './adapters/NativeEventsReceiver'; +import { AppRegistryService } from './adapters/AppRegistryService'; export class NavigationDelegate { private concreteNavigation: NavigationRoot; constructor() { this.concreteNavigation = this.createConcreteNavigation( new NativeCommandsSender(), - new NativeEventsReceiver() + new NativeEventsReceiver(), + new AppRegistryService() ); } private createConcreteNavigation( nativeCommandsSender: NativeCommandsSender, - nativeEventsReceiver: NativeEventsReceiver + nativeEventsReceiver: NativeEventsReceiver, + appRegistryService: AppRegistryService ) { - return new NavigationRoot(nativeCommandsSender, nativeEventsReceiver); + return new NavigationRoot(nativeCommandsSender, nativeEventsReceiver, appRegistryService); } /** @@ -226,9 +229,11 @@ export class NavigationDelegate { public mockNativeComponents() { const { NativeCommandsSender } = require('./Mock/mocks/NativeCommandsSender'); const { NativeEventsReceiver } = require('./Mock/mocks/NativeEventsReceiver'); + const { AppRegistryService } = require('./Mock/mocks/AppRegistryService'); this.concreteNavigation = this.createConcreteNavigation( new NativeCommandsSender(), - new NativeEventsReceiver() + new NativeEventsReceiver(), + new AppRegistryService() ); }