Qeepsake / react-native-images-collage

Robust interactive image collage component for React Native
MIT License
116 stars 30 forks source link

Replacing Images via a reference method #22

Closed lukebrandonfarrell closed 3 years ago

lukebrandonfarrell commented 3 years ago

This PR adds the ability to easily replace images with a new reference method:

const collageRef = useRef(null);

<DynamicCollage
  ref={collageRef}
  ...

collageRef.current.replaceImage("https://picsum.photos/200", m, i);

Here is a video demo of it in action:

https://user-images.githubusercontent.com/18139277/107499831-5a088280-6b8d-11eb-8d55-1f36e0dbe895.mov

@jasimawan @harbolaez since you both are working with this feature in your projects, let me know your thoughts !

jasimawan commented 3 years ago

Looks good 😍, let me test it and I will let you know about it. @lukebrandonfarrell

lukebrandonfarrell commented 3 years ago

Thanks @jasimawan let me know, and I'll merge

harbolaez commented 3 years ago

lgtm! Just minor changes, what you think of adding the below code to as a callback of the setState:

this.setState({ images: replacedImages }, () => {
    const targetImage = this.refs[`image${m}-${i}`];
    targetImage.calculateImageSize();
    targetImage.calculateImagePosition();
  });

when an image with a different size is added, it does not calculate the image with the right sizes.

jasimawan commented 3 years ago

Just checked it on simulator as well as on real device. Working perfectly. @lukebrandonfarrell

lukebrandonfarrell commented 3 years ago

lgtm! Just minor changes, what you think of adding the below code to as a callback of the setState:

this.setState({ images: replacedImages }, () => {
    const targetImage = this.refs[`image${m}-${i}`];
    targetImage.calculateImageSize();
    targetImage.calculateImagePosition();
  });

when an image with a different size is added, it does not calculate the image with the right sizes.

@harbolaez Nice catch! 😮 I'll add your suggestion then merge

lukebrandonfarrell commented 3 years ago

Will be released in version 3.3.0