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

Replacing Images via a reference method #22

Merged
merged 6 commits into from
Feb 12, 2021

Conversation

lukebrandonfarrell
Copy link
Contributor

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:

Replace.Images.mov

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

@jasimawan
Copy link
Contributor

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

@lukebrandonfarrell
Copy link
Contributor Author

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

@lukebrandonfarrell lukebrandonfarrell added the enhancement New feature or request label Feb 10, 2021
@harbolaez
Copy link
Contributor

harbolaez commented Feb 10, 2021

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
Copy link
Contributor

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

@lukebrandonfarrell
Copy link
Contributor Author

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 lukebrandonfarrell merged commit 8a35f3e into master Feb 12, 2021
@lukebrandonfarrell
Copy link
Contributor Author

Will be released in version 3.3.0

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

Successfully merging this pull request may close these issues.

None yet

3 participants