react-native-navigation的迁移库

ComponentEventsRegistry.ts 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { EventsRegistry } from './EventsRegistry';
  2. import { Store } from '../components/Store';
  3. export class ComponentEventsRegistry {
  4. constructor(private eventsRegistry: EventsRegistry, private store: Store) {
  5. this.componentDidAppear = this.componentDidAppear.bind(this);
  6. this.componentDidDisappear = this.componentDidDisappear.bind(this);
  7. this.onNavigationButtonPressed = this.onNavigationButtonPressed.bind(this);
  8. }
  9. public registerForAllComponents(): void {
  10. this.eventsRegistry.componentDidAppear(this.componentDidAppear);
  11. this.eventsRegistry.componentDidDisappear(this.componentDidDisappear);
  12. this.eventsRegistry.onNavigationButtonPressed(this.onNavigationButtonPressed);
  13. }
  14. private componentDidAppear(componentId: string) {
  15. const componentRef = this.store.getRefForId(componentId);
  16. if (componentRef && componentRef.componentDidAppear) {
  17. componentRef.componentDidAppear();
  18. }
  19. }
  20. private componentDidDisappear(componentId: string) {
  21. const componentRef = this.store.getRefForId(componentId);
  22. if (componentRef && componentRef.componentDidDisappear) {
  23. componentRef.componentDidDisappear();
  24. }
  25. }
  26. private onNavigationButtonPressed(componentId: string, buttonId: string) {
  27. const componentRef = this.store.getRefForId(componentId);
  28. if (componentRef && componentRef.onNavigationButtonPressed) {
  29. componentRef.onNavigationButtonPressed(buttonId);
  30. }
  31. }
  32. }