Trigger appear event after dismissModal (modalPresentationStyle -> overCurrentContext) #7361
Replies: 5 comments 5 replies
-
Well, that is the essence of So the premise Now,
In both cases, the disappear event was sent because the view is gone, hence, not visible to the user, and in the case of So what you are suggesting is defying the logic behind
|
Beta Was this translation helpful? Give feedback.
-
Converted to a discussion under ideas. |
Beta Was this translation helpful? Give feedback.
-
Yes, so I get your point regarding So the left image we do get did appear but unable to set background transparent. The middle is what we want but none did appear when closed. Right does not give any did appear event either. So ideally the best thing would be to just support transparent background for Your proposal with |
Beta Was this translation helpful? Give feedback.
-
Another solution would just be to expose a method that gets the current componentId. Then I can just do something like this.
edit: Might just do this for |
Beta Was this translation helpful? Give feedback.
-
So I have played around a bit and this is the best approach I have found. Have removed quite a lot of business logic we have on our side but this might help others that struggles with the same problem. Basically we do as follow. Always listen to the If a modal is closed we listen to So now we can listen on
Sorry for wall of text! import EventEmitter from "events"
import { Navigation, CommandName } from "react-native-navigation"
const state = {
other: '',
bottomSheet: [],
}
function getRoute(componentId: string) {
// Logic we have to get a route definition
// routes = { key: { component, presentation, ... } }
}
export function getCurrentComponentId() {
return state.bottomSheet.length ? state.bottomSheet.length[state.bottomSheet.length - 1] : state.other
}
export const emitter = new EventEmitter()
Navigation.events().registerCommandListener((command)=> {
// Clear bottomSheet stack if SetRoot or DismissAllModals is called
if(command === CommandName.SetRoot || command === CommandName.DismissAllModals) {
state.bottomSheet = []
}
})
Navigation.events().registerModalDismissedListener(({ componentId }) => {
// Get route by componentId
const route = getRoute(componentId)
// Only handle cases when the current modal is `bottomSheet`.
// For other modals we get `componentDidAppear` event when closed
// and can decide current screen
if (route?.presentation === 'bottomSheet') {
// Remove dismissed modal from state
state.bottomSheet = state.bottomSheet.filter((cId) => cId !== componentId)
// Get current route
const current = getCurrentComponentId()
// emit
emitter.emit('focus', { appeared: current, disappeared: componentId })
}
})
Navigation.events().registerComponentDidAppearListener(({ componentId }) => {
// Get route by componentId
const route = getRoute(componentId)
// Get current route which will be emitted as previous
const prev = getCurrentComponentId()
// Check if current route has presentation `bottomSheet` (overCurrentContext)
if (route?.presentation === 'bottomSheet') {
state.bottomSheet.push(componentId)
} else {
state.other = componentId
}
// emit
emitter.emit('focus', { appeared: componentId, disappeared: prev })
}) |
Beta Was this translation helpful? Give feedback.
-
🚀 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 belowThis works great until we show a modal with
overCurrentContext
. Below is a user journey where our problems occur.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.
Are you willing to resolve this issue by submitting a Pull Request?
Beta Was this translation helpful? Give feedback.
All reactions