Peep
Peep

Reputation: 430

Callback when Component gets on / off screen from Navigator

Is there any callbacks to rendered components from the Navigator when a view gets on / off screen?

Upvotes: 1

Views: 407

Answers (1)

Tucker Connelly
Tucker Connelly

Reputation: 875

In the renderScene() method, you can pass a prop like isRendered={route.index === 0} for the first card, isRendered={route.index === 1} for the second, etc.

And then in the components themselves, you can use componentWillReceiveProps like:

componentWillReceiveProps(next) {
  const { isRendered } = this.props
  if (isRendered && !next.isRendered) // going off screen
  if (!isRendered && next.isRendered) // coming on screen
}

Upvotes: 2

Related Questions