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

Using custom controls #95

Closed
approximator opened this issue Sep 13, 2018 · 4 comments
Closed

Using custom controls #95

approximator opened this issue Sep 13, 2018 · 4 comments

Comments

@approximator
Copy link
Contributor

approximator commented Sep 13, 2018

Hello,

I need some custom controls to work with an image currently opened in the lightbox.
Could you please give me a hint how does some custom control know which image is currently
opened in lightbox.

I can capture an image in lightboxWillOpen callback, but it will differ when user clics "Next".

Here is a piece of code with comments:

        <Gallery
            images={photos}
            rowHeight={250}
            onSelectImage={this.onSelectImage}
            lightboxWillOpen={(index) => {
                console.log(index)
                this.setState({ currentImage: index })
                // can set store index inside the state (for custom controls)
                // but how to keep track of current image when user clicks 
               // "Next" in lightbox?
           }}

            customControls={[
               <Button icon='images' onClick={() => {
                    // how to determine current image inside the lightbox?
                }}/>
           ]}
        />

Thank you!

@benhowell
Copy link
Owner

The current image is stored in this.state.currentImage. You shouldn't be setting it manually.

@approximator
Copy link
Contributor Author

approximator commented Sep 14, 2018

Thank you for the prompt answer.
Unfortunately, the this.state.currentImage is not available inside the custom control click handler.
Here is the simplified sandbox code of what I am trying to do: https://codesandbox.io/s/yj2po5m9px?module=%2Fsrc%2Fphotos.js

When a user opens lightbox and clicks "ClickMe" button, what is the correct way to get currentImage (I always get undefined when accessing this.state.currentImage)?
Thank you.

@benhowell
Copy link
Owner

The lightbox control and custom controls within it are handled by the react-images library. You'll need to take a look over there to answer your question as I've not had the need to implement custom controls so I don't know off the top of my head.

@approximator approximator changed the title Need help: Using custom controls Using custom controls Sep 14, 2018
@approximator
Copy link
Contributor Author

In react-images the currentImage supposed to be controlled from outside (parent) via props, thus currentImage is always known in the parent component and can be used in custom controls.

It seems that react-grid-gallery doesn't support that and custom controls quite useless here :(

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

2 participants