react-native-navigation的迁移库

docs-screen-lifecycle.mdx 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ---
  2. id: screen-lifecycle
  3. title: Screen Lifecycle
  4. sidebar_label: Screen Lifecycle
  5. ---
  6. Any React Component registered with react-native-navigation is enhanced with two additional lifecycle events:
  7. * `componentDidAppear` - called each time a component is revealed to the user
  8. * `componentDidDisappear` - called each time a component is hidden from user's view **as a result of being detached from hierarchy**
  9. These methods compliment React's liefcycle methods:
  10. * `componentDidMount` - called once, when a component is attached to hierarchy **for the first time**
  11. * `componentWillUnmount` - called once, when a component is destroyed
  12. ### Mounting
  13. These methods are called in the following order when a component is created and attached to hierarchy.
  14. * constructor()
  15. * render()
  16. * componentDidMount()
  17. * componentDidAppear()
  18. ### Unmounting
  19. These methods are called when a component is being removed from hierarchy
  20. * componentDidDisappear()
  21. * componentWillUnmount()
  22. ### Modal
  23. When a modal is displayed, depending on the [modalPresentationStyle](options-root.mdx#modalpresentationstyle), content behind it might be detached from hierarchy. This affects the visibility events which are emitted to the content behind the modal.
  24. When Modals with `pageSheet` or `overCurrentContext` modalPresentationStyle are displayed, previous content is still visible to the user. Thus `componentDidDisappear` event is **not** emitted.
  25. Same is applied when a modal is dismissed. If it was originally presented with `pageSheet` or `overCurrentContext` modalPresentationStyle, when that modal is then dismissed, the previous context won't receive a `componentDidAppear` event.
  26. ### Overlay
  27. These methods are called in the following order when a component is displayed as an Overlay:
  28. * constructor()
  29. * render()
  30. * componentDidMount()
  31. * componentDidAppear()
  32. :::note
  33. Content displayed behind an Overlay does not receive the `componentDidDisappear`, since it's still visible to user and attached to the hierarchy.
  34. :::