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

v2.0 Navigation.registerScreen #205

Closed
explorigin opened this issue Aug 16, 2016 · 4 comments
Closed

v2.0 Navigation.registerScreen #205

explorigin opened this issue Aug 16, 2016 · 4 comments
Assignees

Comments

@explorigin
Copy link

explorigin commented Aug 16, 2016

In < 2.0, I was using Navigation.registerScreen because registerComponent is not flexible enough for me. I see that it's no longer exposed in 2.0. Can we re-expose it?

My use-case is that I'm adding both a redux store and a translation object to the React context. In case you're curious, it looks like this:

function registerWrappedComponent(screenID, generator) {
    const generatorWrapper = () => {
        const InternalComponent = generator();
        return class extends Screen {
            static navigatorStyle = InternalComponent.navigatorStyle || {};
            static navigatorButtons = InternalComponent.navigatorButtons || {};
            render() {
                return (
                    <SuperProvider store={store} i18n={i18n}>
                        <InternalComponent navigator={this.navigator} {...this.props} />
                    </SuperProvider>
                );
            }
        };
    };
    Navigation.registerScreen(screenID, generatorWrapper);
    return generatorWrapper;
}
@explorigin
Copy link
Author

I'm working through this. Merely exposing it is not good enough. Currently getting a message:

Super expression must either be null or a function, not undefined.

@explorigin
Copy link
Author

Got it sorted. If you want this to be part of the final API, I did it like this: v2.0...twistle:v2.0

My register wrapper function ends up looking like:

function registerWrappedComponent(screenID, generator) {
    const generatorWrapper = () => {
        const InternalComponent = generator();
        return class extends Screen {
            static navigatorStyle = InternalComponent.navigatorStyle || {};
            static navigatorButtons = InternalComponent.navigatorButtons || {};
            constructor(props) {
                super(props);

                this.allProps = {
                    ...props,
                    ...PropRegistry.load(props.screenInstanceID),
                };
            }

            render() {
                return (
                    <SuperProvider store={store} i18n={i18n}>
                        <InternalComponent navigator={this.navigator} {...this.allProps} />
                    </SuperProvider>
                );
            }
        };
    };
    Navigation.registerScreen(screenID, generatorWrapper);
    return generatorWrapper;
}

@smooJitter
Copy link

I'm anticipating the same problem. In addition to the language api, I'm going with.
.

I've always thought tucking away redux provider was constraining.

I plan to use your solution. Thanks.

Neverless, perhaps there should be a way to configure the redux provider without tampering with package files. I'm not sure how that will work

@DanielZlotin
Copy link
Contributor

I agree @smooJitter . I think changing the API to require a factory method instead of a screenID would be better, and MUCH more flexible (instead me creating the Screen, you create it for me - the way you want).

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

No branches or pull requests

3 participants