Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Scene Component ignored onEnter function #3283

Closed
gabrielbuzziv opened this issue Sep 20, 2018 · 2 comments
Closed

Custom Scene Component ignored onEnter function #3283

gabrielbuzziv opened this issue Sep 20, 2018 · 2 comments
Labels

Comments

@gabrielbuzziv
Copy link

gabrielbuzziv commented Sep 20, 2018

Version

  • react-native-router-flux v4.0.1
  • react v16.5.0
  • react-native v0.57.0

Expected behaviour

I would like to create a component named PrivateScene that would verify by onEnter property if this scene is allowed for guests... with this custom component would become easier to call this scenes on my Routes file.

Instead of <Scene key="something" component={Component} onEnter={this.onEnter} /> i would have <PrivateScene key="something" component={Component} />.

Less code and easier to do changes.

Actual behaviour

The onEnter method don't work unless i call like this <Scene key="something" component={Component} onEnter={this.onEnter} />, but in my PrivateScene component, i already have a Scene component calling the onEnter.

Steps to reproduce

PrivateScene.js

import React, { Component } from 'react';

import { Scene } from 'react-native-router-flux';

class PrivateScene extends Component {
  handleEnter = () => {
    console.log('Check here if the user is authenticated');
  };

  render() {
    return <Scene {...this.props} onEnter={this.handleEnter} />;
  }
}

export default PrivateScene;

Routes.js

import React, { Component } from 'react';

import { Router, Stack, Scene } from 'react-native-router-flux';

import * as Pages from 'pages';
import { PrivateScene } from './components';

class Routes extends Component {
  state = {};

  render() {
    return (
      <Router>
        <Stack key="root">
          <Scene key="login" component={Pages.Auth.Login} initial />

          <PrivateScene key="welcome" component={Pages.Welcome} />
        </Stack>
      </Router>
    );
  }
}

export default Routes;

The onEnter only works if i handle it in Routes.js component.

@daviscabral
Copy link
Collaborator

I believe this is a duplicated of #3208. Not sure if this is supported right now - the solution we found out was a HoC to provide it, like I wrote here: #3208 (comment). In case you want to contribute providing this support, PRs are welcome.

@mahyar33
Copy link

mahyar33 commented Nov 24, 2018

I couldn't handle onEnter with your solution
I want to create PrivateSeen if the user didn't authorize, it redirects them to login scene
can you give me an example please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants