Skip to content

Trigger appear event after dismissModal (modalPresentationStyle -> overCurrentContext) #7359

Description

@lindesvard

🚀 Feature

I want to be able to listen if a screen did appear even if the modalPresentationStyle is overCurrentContext. We have a quite large app with many independent teams and routes.

We need to keep track what the current displayed screen is. We do this by listening on componentDidAppear. Something like below

import { Navigation, ComponentDidAppearEvent } from 'react-native-navigation'

class NavigationStore {
  private currentComponentId = ''

  constructor(navigation: typeof Navigation) {
    navigation.events().registerComponentDidAppearListener(this.registerCurrentComponentId)
  }

  private registerCurrentComponentId({ componentId }: ComponentDidAppearEvent): void {
    this.currentComponentId = componentId
  }

  public get current(): string {
    return this.currentComponentId
  }
}

This works great until we show a modal with overCurrentContext. Below is a user journey where our problems occur.

push(A) // will trigger appear A
showModal(B) // will trigger appear B
dismissModal(B) // will trigger appear A
showModal(C, { modalPresentationStyle: 'overCurrentContext' }) // will trigger appear C
dismissModal(C) // will NOT trigger any appear event on A 

Not sure if this is a restriction on iOS but would love if we could get the appear event when a modal is closed with overCurrentContext.

Motivation

So have already talked about the motivation a bit but I can see this be quite useful for developers to know if a screen below a modal with overCurrentContext would re-appear after the modal is close. React to that, refetch data, track current componentId.

Pitch

Not sure if this would be supported under the hood (on iOS) but otherwise it could be implemented like this.

// pseudo code somewhere in dismissModal
await internal.dismissModal(componentId)

// does closed modal have overCurrentContext
if(options.modalPresentationStyle == 'overCurrentContext') {
  // basic check to find out what screen should trigger appear event
  if (!overlay.isEmpty()) {
    emitDidAppearEvent(overlay.getLast())
  } else if (!modal.isEmpty()) {
    emitDidAppearEvent(modal.getLast())
  } else {
    emitDidAppearEvent(stack.getLast())
  }
}

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️   Yes, I have the time, and I know how to start.
  • ✅   Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✅   No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions