@@ -18,8 +18,9 @@ import {
1818} from '../interfaces/ComponentEvents' ;
1919import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver' ;
2020import { Store } from '../components/Store' ;
21+ import { NavigationComponentListener } from 'react-native-navigation/interfaces/NavigationComponentListener'
2122
22- type ReactComponentWithIndexing = React . Component < any > & Record < string , any > ;
23+ type ReactComponentWithIndexing = NavigationComponentListener & Record < string , any > ;
2324
2425export class ComponentEventsObserver {
2526 private listeners : Record < string , Record < string , ReactComponentWithIndexing > > = { } ;
@@ -60,13 +61,21 @@ export class ComponentEventsObserver {
6061 if ( ! isString ( computedComponentId ) ) {
6162 throw new Error ( `bindComponent expects a component with a componentId in props or a componentId as the second argument` ) ;
6263 }
63- if ( isNil ( this . listeners [ computedComponentId ] ) ) {
64- this . listeners [ computedComponentId ] = { } ;
64+
65+ return this . registerComponentListener ( component as NavigationComponentListener , computedComponentId ) ;
66+ }
67+
68+ public registerComponentListener ( listener : NavigationComponentListener , componentId : string ) : EventSubscription {
69+ if ( ! isString ( componentId ) ) {
70+ throw new Error ( `registerComponentListener expects a componentId as the second argument` ) ;
71+ }
72+ if ( isNil ( this . listeners [ componentId ] ) ) {
73+ this . listeners [ componentId ] = { } ;
6574 }
6675 const key = uniqueId ( ) ;
67- this . listeners [ computedComponentId ] [ key ] = component ;
76+ this . listeners [ componentId ] [ key ] = listener ;
6877
69- return { remove : ( ) => unset ( this . listeners [ computedComponentId ] , key ) } ;
78+ return { remove : ( ) => unset ( this . listeners [ componentId ] , key ) } ;
7079 }
7180
7281 public unmounted ( componentId : string ) {
0 commit comments