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

Add lightbox for enlarging chat images #304

Merged
merged 5 commits into from
Jan 10, 2017
Merged

Conversation

cooperka
Copy link
Collaborator

@cooperka cooperka commented Dec 12, 2016

Images sent in messages will be enlarged when you tap them.

Also adds 2 new props: imageProps and lightboxProps. These will be passed through to the <Image> and <Lightbox>, respectively. For example, you can now specify an image onLoad callback.

Tested and verified on iOS and Android.


Note: Uses a commit hash instead of version number in order to fix a warning on Android that's currently unpublished.

You can read more about react-native-lightbox here 🍹

source={{uri: this.props.currentMessage.image}}
/>
<Lightbox
navigator={this.props.navigator}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cooperka I don't think you can assume this.props.navigator exists.
Even if it does, not everyone uses react-natives Navigator which is what this package is assuming.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If navigator is null, the lightbox still renders just fine :) In fact, I don't even use it myself. It's recommended by lightbox, but not necessary by any means.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added it to propTypes where it defaults to null. Hopefully this helps.

@kfiroo
Copy link
Collaborator

kfiroo commented Dec 13, 2016

@cooperka Hey! Thanks for the PR :)
I'm not sure that this fits the scope of this component, plus, it can be super easily achieved with overriding renderMessage / renderMessageImage.

I would love to hear what others have to say though

@cooperka
Copy link
Collaborator Author

Thanks @kfiroo! Honestly to me it seems like an oversight that this feature doesn't already exist, as everyone I've shown the chat interface to has tried to tap my mock image to see it larger and been disappointed when nothing happens. We could definitely let people implement this on a per-app basis instead, but that just seems a little redundant to me. This chat is supposed to be "gifted" 😉. I'm also interested to see what other people have to say.

@dgdavid
Copy link
Contributor

dgdavid commented Dec 14, 2016

Guys, at first I agree with @kfiroo's doubts about the component scope. But honestly we need to admit that @cooperka have good, strong arguments. So, I keep my thumb up for this feature.

@kfiroo
Copy link
Collaborator

kfiroo commented Dec 14, 2016

@cooperka @dgdavid Yeah, I hear you. I'm starting to turn too :)

Few questions though,

  1. Is the Lightboxed image zoomable? I feel like this is a must if we are going with this.
  2. We need to be able to use a custom Image component (like ResponsiveImage / CachedImage etc.)
  3. Do we want to be able to customize the Lightbox view (add some info / actions)?

@cooperka
Copy link
Collaborator Author

@kfiroo it looks like there are a ton of new features coming as part of a major refactor, and I'm not quite sure but maybe it will even be able to use its own instance of Lightbox.Navigator if you don't pass one in yourself? The GIF on that linked comment shows off the new stuff. Unfortunately progress seems to have halted on the refactor... I added a comment to inquire.

Before the refactor (currently):

  1. Lightbox is not zoomable, but the purpose of Lightbox is to zoom the image that was sent in chat. I feel like Lightbox is a must if we are going to allow images sent in chat, even if it lacks some features in the short-term
  2. Arbitrary custom content should already work, Lightbox seems to be able to zoom any child content, not just images (see the GIF in their README)
  3. That would be great! See below.

After the refactor:

  1. Yes
  2. Same answer
  3. It looks like this is made much easier by the refactor

TL;DR: I think we should go ahead and merge this PR, and if needed we/I can help contribute to Lightbox to bring it up to par with where we want it in the long-term.

@kfiroo
Copy link
Collaborator

kfiroo commented Dec 14, 2016

@cooperka take a look at this fork https://github.com/shoutem/react-native-lightbox

@cooperka
Copy link
Collaborator Author

@kfiroo Nice! Want me to use that one here instead?

@kfiroo
Copy link
Collaborator

kfiroo commented Dec 14, 2016

@cooperka Not sure actually, we should use the one that works better :)
I'm also fiddling with "zoom views" now, I'll let you know if I have anything interesting.
Here's another interesting project https://github.com/ldn0x7dc/react-native-view-transformer
Which has a child projects https://github.com/ldn0x7dc/react-native-transformable-image and https://github.com/ldn0x7dc/react-native-gallery

@cooperka
Copy link
Collaborator Author

Interesting, let me know how it turns out! Lightbox does seem by far the most popular of the options, and intends to cover the gallery use-case with the refactor, but if something else works better I'm all for it.

@kfiroo
Copy link
Collaborator

kfiroo commented Dec 14, 2016

I wouldn't hold my breath waiting for that refactor to land.. repo hasn't changed in a year or so

@cooperka
Copy link
Collaborator Author

Definitely agree. I asked about the status in that thread (oblador/react-native-lightbox#8 (comment)), and at worst I'll just fork the repo in order to merge a few of the nice PRs there. Should work fine either way.

@cooperka
Copy link
Collaborator Author

@kfiroo there's an update here: oblador/react-native-lightbox#8. Honestly we don't need all the bells and whistles from the proposed refactor of lightbox, but there are several PRs that would be nice to have merged. Shall we fork it?

@kfiroo
Copy link
Collaborator

kfiroo commented Dec 21, 2016

@cooperka I didn't like how it works, but I guess it might be a good enough, out-of-the-box solution for many users, so I we can merge it or try with the navigator-refactor, what ever you think is better.
I'm only missing a way to disable it, but I guess you could override renderMessageImage and render what ever you want.

In my app, I ended up writing something myself, I can try to extract it to its own repo and see if we like it better.

@cooperka
Copy link
Collaborator Author

I agree that lightbox is not ideal... if you can extract your logic into something simple and usable I'm all for it! How long do you expect that to take?

@kfiroo
Copy link
Collaborator

kfiroo commented Dec 21, 2016

@cooperka I'll try to do it this weekend

@coderberry
Copy link

+1

@cooperka
Copy link
Collaborator Author

@kfiroo how goes your extraction?

I updated the props a bit on this PR, I think it's better and more generic after the changes. Also allows passing image props like onLoad now.

@kfiroo
Copy link
Collaborator

kfiroo commented Jan 10, 2017

@cooperka I couldn't find time to do it, I think we can merge your PR for now and get to it later if I ever get to it :)
Can I merge this? Are we good on both android and ios?

@cooperka
Copy link
Collaborator Author

Yes, good to merge! I tested it just now after adding the new prop.

@kfiroo kfiroo merged commit 9d7ca0b into FaridSafi:master Jan 10, 2017
@booboothefool
Copy link

booboothefool commented Mar 9, 2017

@cooperka Does this work out of the box, or is there something I have to configure to get the lightbox to pop up? I simply tried updating to the latest version of react-native-gifted-chat and clicked on an image, but nothing happened. Sorry for the stupid question. 😛

UPDATE:

  1. had to restart packager terminal and simulator
  2. I was specifying lightboxProps thinking I had to, but not needed, as it just works great with the default props

Thanks for the pr. So awesome! 👍

@cooperka
Copy link
Collaborator Author

cooperka commented Mar 9, 2017

@booboothefool yeah it should work out of the box, no setup needed! You can try getting it to work in the example app, and if it's still not working just send us a link to your code and we can take a look.

Might be silly, but also make sure you've run npm install and reloaded your app after updating your version of the library.

Also, if you're passing in a custom component e.g. renderBubble or renderMessageImage then of course you won't get the new changes unless you update the component yourself.

@booboothefool
Copy link

@cooperka Well I got everything hooked up, but do you notice any performance issues with lightbox? The close is extremely slow on iOS. It's like the laggiest thing I've ever seen. 😆

oblador/react-native-lightbox#2
oblador/react-native-lightbox#6

Doesn't seem to be any solid solutions though, unfortunately.

@cooperka
Copy link
Collaborator Author

Haha yeah it's really bad for large images. The issue is actually that it's trying to display an enormous image at full resolution instead of down-sampling it.

I wrote custom logic in my client app to resize the image to 720p at 80% quality before displaying, and then it works very smoothly.

@booboothefool
Copy link

booboothefool commented Mar 10, 2017

@cooperka Can you explain how you did it?

I'm using https://github.com/ivpusic/react-native-image-crop-picker for the upload:

    CropPicker.openPicker({
      compressImageMaxWidth: 100,
      compressImageMaxHeight: 100,
      compressImageQuality: 0.1,
    })

which makes the image look like a butthole, like you can see every single big pixel and can't even tell what the picture is anymore, but I still can't get the animation smooth. 😝

UPDATE: Nevermind. I can't get this to work smoothly enough for my needs, so I just ended up using react-native-router-flux to just throw up another modal, and it's super smooth, even with huge full-resolution images. Just without the super slick lightbox animation unfortunately, but I'd rather it not lag. 👍

@mengpeilee
Copy link

Does image can be zoomed now?
I see the PR(zoom image) still open in react-native-lightbox

@mafiusu
Copy link

mafiusu commented Apr 5, 2018

Sadly there is not much engagement for react-native-lightbox. Last change was 7 month ago.

@mengpeilee
Copy link

mengpeilee commented Apr 6, 2018

Oh no><
@mafiusu
Does there have any way to let zoom image become possible?

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

Successfully merging this pull request may close these issues.

7 participants